boppreh / keyboard

Hook and simulate global keyboard events on Windows and Linux.
MIT License
3.8k stars 433 forks source link

Problems with add_hotkey + write + certain apps #549

Open mythofechelon opened 2 years ago

mythofechelon commented 2 years ago

"Certain" (affected) apps = Notepad++ and Notepad, so far. Unaffected apps = Google Chrome and Microsoft Word, so far.

Problem #1: First character of string / text isn't sent

Example: >>> import keyboard >>> keyboard.add_hotkey("Alt + O", lambda: keyboard.write("Test"), suppress=True)

Result: Only "est" is written.

Somehow, this seems to be caused by how rapidly you press the hotkey. For example, if you press Alt + O simultaneously then this happens, but if you press Alt, wait ~1 second, and then press O then it works as expected. Adding something like delay=0.05 doesn't make a difference.

Problem #2: Alt Gr doesn't work

Example: >>> import keyboard >>> keyboard.add_hotkey("Alt Gr + Tab", lambda: keyboard.write("Test"), suppress=True)

Result:

My environment (all latest, as of writing):