How do I press 2 keys at a time using pyautogui?

Question:

I want to press control + left arrow on my mac to swipe my screen.

This is what I tried:

import pyautogui

pyautogui.press(["ctrl" ,"left"])

it does not work.

Asked By: bar coding

||

Answers:

For this you can use pyautogui.hotkey(). In your example you would run :

pyautogui.hotkey('ctrl', 'left')
Answered By: Wemmons

the code seems correct. the problem might be because you are running the code in your IDE, and you might have clicked on the text or something like that (it happended to me before). Try adding a for loop.

import pyautogui

for i in range(5):
    pyautogui.press(["ctrl" ,"left"])

if it works then consider making a simple prompt with a button to do it.

import pyautogui

while True:
    result = pyautogui.confirm('click "swipe" to swipe', buttons = ["swipe", "no"])
    if result == "swipe":
        pyautogui.press(["ctrl" ,"left"])
Answered By: Coding_Guy
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.