How to hold a key press on the pyautogui

1

I would like to hold down a key for x seconds. I know that tapping the key is:

pyautogui.press("key")

But how can I keep it pressed?

    
asked by anonymous 29.10.2017 / 01:55

1 answer

1

As the documentation says, the press function is nothing more than a shortcut to the execution of the keyDown function followed by the keyUP function. That is, when executing the keyDown function, the key will be pressed until the keyUp function is executed. So a simple example of holding down the left arrow for 5 seconds would be:

x = 5
pyautogui.keyDown("left")
time.sleep(x)
pyautogui.keyUp("left");
    
29.10.2017 / 02:08