Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

using numpad numbers as hotkeys ? #161

Open
ornariece opened this issue Apr 26, 2018 · 11 comments
Open

using numpad numbers as hotkeys ? #161

ornariece opened this issue Apr 26, 2018 · 11 comments

Comments

@ornariece
Copy link

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
Copy link

Apollys commented May 5, 2018

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

@boppreh
Copy link
Owner

boppreh commented May 5, 2018

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
Copy link
Author

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

@Apollys
Copy link

Apollys commented May 7, 2018

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

@boppreh
Copy link
Owner

boppreh commented May 7, 2018

@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
Copy link

Apollys commented May 13, 2018

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
Copy link
Owner

boppreh commented May 13, 2018

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
Copy link

csm10495 commented May 8, 2020

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

@Avasam
Copy link
Contributor

Avasam commented Aug 15, 2021

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

@Glazkovich
Copy link

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
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants