boppreh / keyboard

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

Causes stutter / lag in game (Starcraft 2) when keys are being pressed #653

Open manuelseeger opened 1 month ago

manuelseeger commented 1 month ago

I tried to build some automation around streaming with OBS and Starcraft 2 using keyboard. I have added a hotkey using keyboard.add_hotkey().

While my Python program is running, the game Starcraft 2 lags/stutters when keys are being pressed. It looks like there is a small stutter about every ~3 seconds. I tried replacing keyboard.wait() with my own threading.Event wait() / set() and still registering the hotkey causes the same problem.

If no keys are being pressed, no stutter is noticable. If I spam keys then every ~3 seconds there is a stutter in the game.

I realize something like capturing keys can be difficult to make work together with games, but maybe thre is a simple fix or something I could do different to work around the problem?