boppreh / keyboard

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

user32.keybd_event trigger a release for modifiers, which makes send function glitched #601

Open SunOfJudge opened 1 year ago

SunOfJudge commented 1 year ago

It seems that on windows platform __oskeyboard eventually calls _user32.keybdevent. However, it makes the pressed modifiers to release for some reason. Note that modifiers and non-modifiers are different and this affect only modifiers. You can replicate it through the following code:

import keyboard, time
while True:
    time.sleep(2)
    keyboard._os_keyboard.press(keyboard.key_to_scan_codes("right")[0])

Hold shift key and run the code, you will find that the text cursor moves but the text is not selected, which is a proof that the shift key is released for a sudden. This can be patched by modifying send function.

girvile commented 1 year ago

I think because right is an extended key (0xE05D), it is misread. maybe this can fix your problem: https://github.com/boppreh/keyboard/pull/606