Search code examples
pythonpywin32pyautoguiautopy

How to NOT release keypress in autopy or pyautogui?


When we press a key (such as 'a') in a notebook, and don't release it, we will get aaaaaaaaaaaaaaaa......

I want to simulate the key-press in python. So I've coded as follows.

import pyautogui, autopy

pyautogui.keyDown('a')
# or
autopy.key.toggle('a')

Then, I get just one 'a', even I didn't release the key-press.

How do I solve the problem?


Solution

  • Performs a keyboard key press without the release. This will put that key in a held down state.

    NOTE: For some reason, this does not seem to cause key repeats like would happen if a keyboard key was held down on a text field.

    import pyautogui
    while True:
        pyautogui.press('a')