Comments (9)
I expected to find something like, say, "keyboard.read_key()" that blocks until they press a key and returns what key they pressed.
That's a very good request. I think the existing wait
function is perfect for that, but a read_key
alias wouldn't hurt. I'll post here when this gets implemented.
I also found it surprising that if I don't cast my_key to int on that third-to-last line
That's a bug. Thanks for reporting.
By the way, using while ...: pass
is called "busy waiting" and is usually frowned upon because the CPU is running at 100% while it waits. Fans speed up, notebook batteries are trashed, etc. You can use locks and queues for that, or at least add a sleep inside the loop instead of "pass". Take a look at the source code for the wait
function to see an example of more efficient waiting.
from keyboard.
wait
was already overloaded to wait forever when not given a hotkey, so I had to create a new functionread_key
.long
values in Python2 no longer create type errors when used in hotkeys.- Windows should now report left and right modifiers correctly. Not sure about the unknown keys though, could you give more details?
As for your previously awkward code, it should be possible to reimplement this way:
import keyboard
print('Enter the key to be registered')
hotkey = keyboard.read_key().scan_code
def fn():
print('you pressed it')
keyboard.add_hotkey(hotkey, fn)
keyboard.wait('esc')
Does this look ok to you?
from keyboard.
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/ )
from keyboard.
Can you give a try on the latest version and tell me if it's reporting as F13 correctly?
from keyboard.
Yes, F13 works now.
I tested every key I have with the following program:
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.
When I press right alt, it's reported as left alt. I do not think this was happening on 0.9.10. (the opposite was happening)
Every other key appears to be working correctly.
from keyboard.
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?
from keyboard.
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.
from keyboard.
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 read_key
). If the right-alt problems persist, please do create a new one with as much information as you can. Or email me, or continue posting here. I'll be read and reply anyway.
And thank you for the previous reports. This sort of feedback is highly appreciated.
from keyboard.
Note for future visitors: the library now includes a keyboard.read_hotkey()
function that returns complex hotkeys, such as "ctrl+shift+a".
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.