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?
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?
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");