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

(question) how to check is_keypad in callback? #216

Open
jayquonmarton opened this issue Oct 11, 2018 · 3 comments
Open

(question) how to check is_keypad in callback? #216

jayquonmarton opened this issue Oct 11, 2018 · 3 comments

Comments

@jayquonmarton
Copy link

jayquonmarton commented Oct 11, 2018

I want to setup hotkeys for the numpad 1 key. In #215 (comment) , KeyboardEvent.is_keypad is mentioned as a workaround. How do you check that KeyboardEvent property when you add hotkeys via the add_hotkey API? I don't see a way to access the KeyboardEvent in the add_hotkey callback.

Thanks

@jayquonmarton jayquonmarton changed the title checking is_keypad in callback (question) how to check is_keypad in callback? Oct 11, 2018
@boppreh
Copy link
Owner

boppreh commented Oct 22, 2018

Hi @jayquonmarton . Sorry for taking so long to answer, life's been keeping me busy.

Unfortunately you are correct, the hotkey API does not provide this functionality. You would have to implement your own hotkey handling on top of hook and similar, or monkey-patch the listener code.

Fine grained event filtering for hotkeys (also useful for making physical-keyboard-specific hotkeys) is something I've been considering, but I don't see any clear answers.

@jayquonmarton
Copy link
Author

Would it be possible for the library to pass the KeyboardEvent as a parameter to the callback (similar to how many event callback APIs are designed e.g. javascript DOM event handlers if you're familiar with that)?

The current way you specify args in the add_hotkey API seems superfluous since you can pass arbitrary args in a closure (and other ways) in python. Maybe consider changing/adjusting the callback API so that it is passed the event object (then possibly args* after the event object?)?

Or would it be better to filter the events by allowing the user to specify a keypad modifier in the add_hotkey API e.g. add_hotkey("keypad+shift+3", my_callback)?

Or perhaps both are worthwhile?

@Pluckerpluck
Copy link

Pluckerpluck commented Feb 17, 2019

@jayquonmarton Obviously this may not be useful to you now, but so you know and for others, you can use:

keyboard.add_hotkey(79, callback)

In order to specifically listen for num 1. Or use keyboard.add_hotkey(("ctrl", 79), callback) if you need modifiers.

The scancodes are as follows:

num 0 = 82
num 1 = 79
num 2 = 80
num 3 = 81
num 4 = 75
num 5 = 76
num 6 = 77
num 7 = 71
num 8 = 72
num 9 = 73

I believe hotkeys should differentiate num 1 from 1. If you want both, you should bind both.

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

3 participants