boppreh / keyboard

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

using numpad numbers as hotkeys ? #161

Open ornariece opened 6 years ago

ornariece commented 6 years ago

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

Apollys commented 6 years ago

Im also trying to accomplish this. Has anyone found a way to do this with the keyboard package?

boppreh commented 6 years ago

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.

ornariece commented 6 years ago

Thanks for the answer. Sorry if this is trivial but how can we know the corresponding scan_codes ?

Apollys commented 6 years ago

Can we create a combo-hotkey with scan codes? E.g. ctrl-Numpad*

boppreh commented 6 years ago

@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.

Apollys commented 6 years ago

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.

boppreh commented 6 years ago

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.

csm10495 commented 4 years ago

@boppreh , how do i hook on an event only if is_keypad is True?

Avasam commented 3 years ago

I've had to use asweigart/pyautogui to actually send the right event for numpad keys. See Toufool/Auto-Split/pull/61

Glazkovich commented 2 years ago

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.

ThisSome1 commented 1 year ago

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.