-
Notifications
You must be signed in to change notification settings - Fork 433
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
Should it be this awkward to have a user define a hotkey? #47
Comments
That's a very good request. I think the existing
That's a bug. Thanks for reporting. By the way, using |
As for your previously awkward code, it should be possible to reimplement this way:
Does this look ok to you? |
Yes, that looks great, thanks. On further inspection, I was only seeing the F13 key show up as "unknown", but it was the one I was actually trying to use in the application I'm writing, so I was testing it more than other keys. (I have my left windows key bound to F13 using a registry script from this website: http://www.grismar.net/ventrilocapsfix/ ) |
Can you give a try on the latest version and tell me if it's reporting as F13 correctly? |
Yes, F13 works now. import keyboard
def info(event):
print event.name + " " + event.event_type
keyboard.hook(info)
keyboard.wait("esc") When I press and release left alt, I get 4 events instead of 2: down, up, down, up. They are correctly "left" instead of "right" now, though. I think I saw this happen on 0.9.10, but I blamed it on a jittery finger or piece of keyboard debris. Every other key appears to be working correctly. |
Hmm. I don't have a right alt to test (only alt+gr). Left/right ctrl/shift are working as expected, though, in both the built-in keyboard and an external one. Also I can't reproduce the double alt issue at all, in either Python2 or Python3. This is really weird. Did you modify you registry to alter keys in any other way? |
I have two of my media keys reymapped to volume up and volume down, and I have capslock mapped to esc, which is being detected correctly. |
I just tested on linux too, and everything seems working, though some keys don't report side (e.g. "ctrl" instead of "left ctrl"). To be honest I have absolutely no idea why this is happening, or event how to debug it. There's only one place that KeyboardEvents are created, and that's inside the Windows low level keyboard hook. If the alt is being reported more than once, it's because the hook is being invoked more than once, and that's indistinguishable from two separate events. I'm sorry, but I don't think I can fix this problem at the moment. I'm going to close this issue, as the original problem was solved (we now have And thank you for the previous reports. This sort of feedback is highly appreciated. |
Note for future visitors: the library now includes a |
I'm writing an application where the user can define their own global hotkeys. The interface for this is: they click a button, it says "press the key you want", they press it.
This was slightly more complicated to accomplish using "keyboard" than I expected it to be. Here is some simplified example code:
Am I missing something that makes this simpler? I expected to find something like, say, "keyboard.read_key()" that blocks until they press a key and returns what key they pressed.
I also found it surprising that if I don't cast my_key to int on that third-to-last line, I receive an error like
(30L is what it says if I press 'a', since its scancode is 30)
Shouldn't the library be able to receive a scancode back as the same kind of datatype it gave to me?
(I'm using the scancode and not the name because the name is reported as "unknown" for
manysome keys, and incorrectly for others. like my left ctrl and left alt both show as having "right" in their name instead of left)The text was updated successfully, but these errors were encountered: