Comments (12)
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
down 164 56 0
up 164 56 0
down 164 56 0
up 164 56 0
When I press right alt, this prints
down 165 56 1
up 165 56 1
down 164 56 0
up 164 56 0
When I press any other key, it only prints two lines.
I'm using a US keyboard.
from keyboard.
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".
But I think it's pretty important for key combos involving alt to work.
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.
from keyboard.
OS: Windows 10.0.15063 x64
Python: 3.6.2
Keyboard: Lenovo ThinkPad Compact USB Keyboard
My left-alt key is detected correctly, but the right-alt key is not detected at all.
It is, however, detected by the online key-event-viewer
utility that @Hyphen-ated linked to.
All other modifiers work as expected and work on both left & right sides.
Tested with keyboard.hook
and keyboard.add_hotkey
.
from keyboard.
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.
from keyboard.
When I run my two test programs from the top of this thread on master, pressing left alt makes them correctly print
alt, 56, down
alt, 56, up
and
down 164 56 0
up 164 56 0
respectively.
Pressing right alt makes them both print nothing.
from keyboard.
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.
from keyboard.
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
from keyboard.
I've looked everywhere and there's only one thing left to test: on _winkeyboard.py
there's a check if vk == 165: return True
(currently line 493) to skip a duplicated event in case of AltGr. Can you try commenting out that check to see if right alt prints something?
from keyboard.
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):
right alt, 56, down
right alt, 56, up
and
down 165 56 1
up 165 56 1
from keyboard.
I'm revisiting old issues, and I think I found a better (but still not elegant) solution to this problem.
Summary of the problem:
- If a keyboard has an alt-gr key, pressing it emits two interleaved events:
alt gr
andright alt
. - If a keyboard only has a right alt key, it only emits a
right alt
event.
Number 1. is a problem because it makes holding alt gr
look like it applies two different modifiers, making a hotkey like alt gr+a
not match. The previous hack was to completely discard any events with vk 165 (right alt), because I didn't know any keyboards that had such a key, and at the time it was reporting an incorrect name (menu
).
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.
from keyboard.
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:
alt, 56, down
alt, 56, up
right alt, 56, down
right alt, 56, up
This looks correct
from keyboard.
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.
from keyboard.
Related Issues (20)
- Capture the activation of a hotkey while other keys are being pressed HOT 1
- Sometimes the keys are not pressed
- Using exit(0) inside on_press_key() lambda doesn't exit the program
- Keys like "D" Counting as other keys HOT 1
- keyboard.suppress blocks keyboard.is_pressing
- TOO MANY dependencies HOT 3
- suppress=True breaks shift-click selection in Notepad, Explorer
- suppress=True breaks Windows Start Menu HOT 3
- Key name '~' in not mapped to any known key
- 'right alt' and 'left alt' parsable hotkeys behaves the same as the 'alt' parsable hotkey on Windows
- suppress=True doesn't work with read_hotkey and on_release_key HOT 1
- How to stop `Keyboard.hook` hooking `keyboard.send` or `keyboard.write`?
- Alt Down not detected with Streamdeck
- Returns upper and lower cases on Windows but only lower cases on Linux
- An OSError when the device is unplugged on RaspberrypiOS HOT 2
- Suddenly not working in mac os
- Periodicaly produce a TypeError: object of type 'NoneType' has no len()
- Cannot hold a key
- 'LMB + Ctrl' mulfunctions when `suppress = True`
- German and English Keyboard. Mixed letters (Z<-->Y)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from keyboard.