-
Notifications
You must be signed in to change notification settings - Fork 431
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
Number pad keys have same scan code as some other keys #18
Comments
The library just takes the scan codes as reported by the OS. If the OS reports two keys as having the same scan code there's no way to differentiate between them. When the OS reports correctly you can see if the key is on the keypad or not by checking the Num lock, scroll lock and caps lock are not treated differently from other keys. What you can do is listen for their key press events and update some internal variable with the current (imagined) state. I'm still researching on how to get the current state of those keys. |
I am currently using amd64 Python35 Win10. Keyboard is definitely marking the middle keys (insert, home, etc.) as numbers. I will investigate this further but may not be able to resolve this issue because I am not familiar with the underlying c infrastructure. |
This can be done using GetKeyState with VK_CAPITAL, VK_NUMLOCK and VK_SCROLL. The least significant bit is set if they are toggled on. >>> GetKeyState(VK_CAPITAL) & 1 #caps lock currently off
0
>>> GetKeyState(VK_CAPITAL) & 1 #caps lock currently on
1 Windows-only, however. |
Thank you @clugg, that will be extremely helpful. I'll be implemented it as soon as possible. @xoviat, I just updated the Windows scan-code-table-building function to prefer non-keypad names when possible, please give release 0.9.5 a try. Unfortunately Windows gives no indication if a key was pressed as keypad or not (same scan code, same name, same virtual code, same flags). Maybe checking for num lock status with @clugg's solution may help. I'll check later. |
It appears that the scan code is not enough information to distinguish whether the number pad keys are being pressed. The virtual key code is required to determine specifically the difference between the middle keys and the number keys. There are several options here and I am willing to contribute. The best option (I think) would probably be to modify the scan code immediately within the queue processor if the vk code determines that the number keys are being pressed. Preferably, they should be modified to be the same scan codes as those that would be on a linux/mac machine for the number pad if possible. Also, this project is looking kind of dead at this point (which is why I am using keyboard), but it does have some useful code for closing this issue. |
Good news everyone! Since version 0.9.6 the This patch required some manual hacking, and there seems to be a bug on Windows ( If any of you still experience problems feel free to reopen the issue. |
How can I register a hotkey to num pad number that doesn't activate when pressing the number regularly? |
Ideally 'num 5' should only trigger with num pad 5 key, but it's working at the moment. As a workaround you can use the raw scan code, or 'hook'ing a Händler and checking the' is_keypad' attribute for every event. |
Can I expect an update that will fix this undesired behavior anytime soon? |
It's on the roadmap for sure, but I still have to publish the new suppression system and implement the xlib backend for linux. I'll give it a try between tasks, in case it's easier than it sounds. Sorry, I work on this project on my free time with absolutely no remuneration, so I can't promise any dates. |
I discovered a difference in behavior between the current master branch and the latest release (Win10):
Whereas in both versions hooking the raw scan code of "num 1" would trigger "delete" and "num 1". It seems that this older version (latest release) could distinguish between "num 1" and "delete". If it wasn't for hooking "delete" when hooking "1" I would have had a fix to my problem - this fix currently lead to "num 1" only hooking "num 1", but "1" hooking "1" and "delete". |
The solution has to be not to use the raw scan code for hooking but the combination of scan code and is_keypad flag. |
I have noticed that the number pad keys have the same scan code as other keys. This is a problem because I cannot distinguish the difference between pressing arrow down and pressing "2." I also do not seem to be able to distinguish when number lock is pressed.
The text was updated successfully, but these errors were encountered: