Giter Site home page Giter Site logo

Comments (9)

boppreh avatar boppreh commented on June 19, 2024

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.

boppreh avatar boppreh commented on June 19, 2024
  • wait was already overloaded to wait forever when not given a hotkey, so I had to create a new function read_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.

Hyphen-ated avatar Hyphen-ated commented on June 19, 2024

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.

boppreh avatar boppreh commented on June 19, 2024

Can you give a try on the latest version and tell me if it's reporting as F13 correctly?

from keyboard.

Hyphen-ated avatar Hyphen-ated commented on June 19, 2024

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.

boppreh avatar boppreh commented on June 19, 2024

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.

Hyphen-ated avatar Hyphen-ated commented on June 19, 2024

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.

boppreh avatar boppreh commented on June 19, 2024

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.

boppreh avatar boppreh commented on June 19, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.