using numpad numbers as hotkeys ?
ornariece opened this issue · comments
it is currently not possible to use numpad numbers as hotkeys, they are considered as the same as normal numbers on the keyboard :/
it would add options on hotkeys
Im also trying to accomplish this. Has anyone found a way to do this with the keyboard package?
I still have to work on it to ensure everything is correct, but try removing the lines on _canonial_names (https://github.com/boppreh/keyboard/blob/master/keyboard/_canonical_names.py#L70) that transform "num 5" to simply "5".
And you can always just listen by scan code.
Thanks for the answer. Sorry if this is trivial but how can we know the corresponding scan_codes ?
Can we create a combo-hotkey with scan codes? E.g. ctrl-Numpad*
@ornariece any hooks will give you an event object with the scan code. The easiest way is to run "python -m keyboard", press the key and watch what is printed.
@Apollys sure, just pass a list of integers. For multi-step step hotkeys, pass a list of list of integers. Check "parse_hotkey" for more details. All high level functions should support this kind of flexible input.
Solved: used tuples instead of lists.
--
Am I using the wrong function?
File "scancodetest.py", line 12, in main
keyboard.add_hotkey([29, 30], callback)
File "C:\ProgramData\Anaconda3\lib\site-packages\keyboard\__init__.py", line 660, in add_hotkey
_hotkeys[hotkey] = _hotkeys[remove_] = _hotkeys[callback] = remove_
TypeError: unhashable type: 'list'
Of course same result if I do keyboard.hook_key([29, 30], callback)
, since it's all the same underneath.
Ah, I see the problem. It's a bug that'll be fixing soon, but for now you can workaround by passing a tuple instead of a list. So if you were doing add_hotkey([55, 65], callback)
or something similar, replace with add_hotkey((55, 65), callback)
(note the parenthesis and brackets). More precisely, the "hotkey" argument has to be immutable.
@boppreh , how do i hook on an event only if is_keypad is True?
I've had to use asweigart/pyautogui to actually send the right event for numpad keys. See Toufool/AutoSplit/pull/61
Well, I just found a way to make numpad work in the keyboard.add_hotkey function.
Looking through the documentation, I went into "_canonical_names.py" and changed the part with numpads.
For example:
'num 7': '7', to 'num 7': 'num 7',
Works perfectly now.
Well, I just found a way to make numpad work in the keyboard.add_hotkey function. Looking through the documentation, I went into "_canonical_names.py" and changed the part with numpads. For example: 'num 7': '7', to 'num 7': 'num 7',
Works perfectly now.
I did that and nothing changed.