boppreh / keyboard

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

How to stop `Keyboard.hook` hooking `keyboard.send` or `keyboard.write`? #636

Open CherryBerryKiwi opened 4 months ago

CherryBerryKiwi commented 4 months ago

On the Windows 10 system, everything is working very well. However, on Linux, keyboard.hook(on_key_event) not only hooks the user's input but also hooks keyboard.send or keyboard.write, sometimes leading to an infinite loop.

For example, if the user types 'IA', then I want the script to send 'Backspace*2' and rewrite 'ÎA'. Here, the library again hooks the 'A' sent by keyboard.write and falls into an infinite loop.

I have a workaround for Linux only, that I read the device id of user's real keyboard and the keyboard library to exclude. However, this does not work every time.