4

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?

Emma
  • 27,428
  • 11
  • 44
  • 69
Levi Nie
  • 43
  • 7

1 Answers1

2

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')
Smart Manoj
  • 5,230
  • 4
  • 34
  • 59