boppreh / keyboard

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

linux german sharp-s/question key: no mapping #588

Open adabru opened 1 year ago

adabru commented 1 year ago

Arch, xfce 4, python 3.10, keyboard 0.13.5

Using "shift+question" causes ValueError: ("Key 'question' is not mapped to any known key.", None)

dumpkeys --keys-only shows following block 12 which is not registered:

keycode  11 = zero             equal            braceright
keycode  12 =
        shift   keycode  12 = question
        altgr   keycode  12 = backslash
        altgr   control keycode  12 = Control_backslash
keycode  13 = dead_acute       dead_grave
        alt     keycode  13 = 0x08b4
        shift   alt     keycode  13 = Meta_grave

python -c 'import keyboard; from pprint import pprint; pprint(keyboard._os_keyboard.from_name)' | grep 12

            'f12': [(88, ())],
             'menu': [(127, ())],
             'windows': [(125, ()), (126, ())],

I assume the regex in https://github.com/boppreh/keyboard/blob/cbace634e219cb8b009b2b2733bb145a1f48710b/keyboard/_nixkeyboard.py#L71 doesn't work out. dumpkeys_full.txt

adabru commented 1 year ago

Workaround:

# see https://github.com/boppreh/keyboard/issues/588
keyboard._os_keyboard.register_key(
    (12, ()), keyboard._os_keyboard.normalize_name("ssharp")
)
keyboard._os_keyboard.register_key(
    (12, (keyboard._os_keyboard.normalize_name("shift"),)),
    keyboard._os_keyboard.normalize_name("question"),
)
keyboard._os_keyboard.register_key(
    (12, (keyboard._os_keyboard.normalize_name("altgr"),)),
    keyboard._os_keyboard.normalize_name("backslash"),
)