boppreh / keyboard

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

sending `shift+home` is not working #535

Open TheYarin opened 2 years ago

TheYarin commented 2 years ago

I tried to select the current text with a hotkey.

The following code:

import keyboard
keyboard.add_hotkey('a', lambda: keyboard.send('shift+home'))
keyboard.wait()

results in these events: (recorded with python -m keyboard in the background)

{"event_type": "down", "scan_code": 30, "name": "a", "time": 1648061975.2208292, "is_keypad": false}
{"event_type": "down", "scan_code": 42, "name": "shift", "time": 1648061975.2218308, "is_keypad": false}
{"event_type": "up", "scan_code": 554, "name": "shift", "time": 1648061975.2228332, "is_keypad": false}
{"event_type": "down", "scan_code": 71, "name": "home", "time": 1648061975.2248325, "is_keypad": true}
{"event_type": "up", "scan_code": 71, "name": "home", "time": 1648061975.2258315, "is_keypad": true}
{"event_type": "down", "scan_code": 42, "name": "shift", "time": 1648061975.227833, "is_keypad": false}
{"event_type": "up", "scan_code": 42, "name": "shift", "time": 1648061975.2298317, "is_keypad": false}
{"event_type": "up", "scan_code": 30, "name": "a", "time": 1648061975.276829, "is_keypad": false}

If I send shift, shift+s or home it works fine.

Weird, isn't it?

Edit: I did some digging and found these:

Edit # 2: Tried adding kb.block_key(554), but it didn't make a difference.

FYI: sending shift+home with the pynput package works just fine, and with that package the weird 554 scan code doesn't appear in the logs of python -m keyboard:

with keyboardController.pressed(Key.shift):
        keyboardController.tap(Key.home)