-
Notifications
You must be signed in to change notification settings - Fork 434
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
Alt keys aren't detected properly #48
Comments
I inserted print "{} {} {} {}".format(event_type, vk, scan_code, is_extended) at https://github.com/boppreh/keyboard/blob/master/keyboard/_winkeyboard.py#L368 When I press left alt, this prints When I press right alt, this prints When I press any other key, it only prints two lines. |
The alt key is kind of weird, so maybe it's okay to just say "you know what, you can't bind things directly to the alt key". def okay():
print "okay"
keyboard.add_hotkey('alt+q', okay) This hotkey is triggered once when I press alt+q with the left alt key. It is not triggered when I use the right alt key. In other applications, alt shortcuts work just fine using either alt key. |
This should help with #48, where the alt key was appearing double. In my computer a single click of 'alt' sent 'down, up, down', leaving the key in a pressed state. The reporter complains about a slightly different problem, but it's likely connected. I noticed the second key had the INJECTED flag, so this patch ignores injected events. Still have to watch out for unintended consequences. Note that I'm keeping the _listener.is_replaying code that tries to ignore replayed keys, because this fix is Windows-only.
My left-alt key is detected correctly, but the right-alt key is not detected at all. All other modifiers work as expected and work on both left & right sides. Tested with |
I could never reproduce the issue, but detection of alt gr has been greatly improved in the latest version. If anyone who is having this issue could try the master branch, I would greatly appreciate. |
When I run my two test programs from the top of this thread on master, pressing left alt makes them correctly print
and
respectively. Pressing right alt makes them both print nothing. |
Thank you for the quick answer! Is your right alt a normal alt key, or an alt gr? Does it work on other applications? Sometimes keys are not mapped at all. |
It's a normal alt key and it works in other applications. It's the same OS and hardware setup as the first two posts in this thread |
I've looked everywhere and there's only one thing left to test: on |
When I remove that check, I get what looks like it might be correct behavior (I'm not sure about what that 1 at the end instead of 0 for "is_extended" means exactly):
and
|
I'm revisiting old issues, and I think I found a better (but still not elegant) solution to this problem. Summary of the problem:
Number 1. is a problem because it makes holding What commit 9a462d2 does is to still discard events with vk 165, but only if they follow an alt gr event. So, still a hack, but closer to the truth. Alt-gr keyboards should report only a single alt-gr event, while right-alt keyboards still pass through. I need someone to test this solution (available on the master branch) with a keyboard that has a right alt. Until then I'm keeping the issue open, but hopefully solved. |
I checked out master and ran the program from the top of this thread. When I press+release left alt, then right alt, I get this: This looks correct |
Great, thank you. I'm finally closing this issue, but feel free to comment on it again and I'll reopen if you think some problem persists. |
As mentioned in a thread about a different issue:
When I run this program:
and press left alt, I see "left alt, 56, down" as expected. When I release left alt, I see
left alt, 56, up
left alt, 56, down
left alt, 56, up
When I press and release right alt, I see:
left alt, 56, down
left alt, 56, up
I went looking for someplace else to test my keyboard events, and found https://w3c.github.io/uievents/tools/key-event-viewer.html
When I press and release left alt and then right alt in this tool, it looks like this:
http://i.imgur.com/FNNKpZn.png
It's not showing either problem.
I was slightly surprised that it was reporting my numlock status in this other tool. I tried turning off numlock to see if that made any difference to my "keyboard" problem. It didn't.
Windows 8.1
Tested on Python 2.7.13 and 3.6.0
keyboard 0.9.12
The text was updated successfully, but these errors were encountered: