-
Notifications
You must be signed in to change notification settings - Fork 46
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
Windows: properly supporting special key (arrows, etc.) #66
Comments
Since this is fatal I would suggest to quickly produce a fix for this! |
Should be fixed in 3.0.5. Could you please confirm it? |
Tested on Windows 11 - works! |
Nop this is not completly fixed. As I also explained on #65, this was a bad PR (in my opinion). While the UP,DOWN,LEFT,RIGHT key now work on some systems (recent Win10, which sets Also the other special keys (END, HOME, F1-F12, ect.) still don't work because they still have the old codes. |
I am gona start on prepearing a PR for this, I just need you to tell me which of the two options I presented you preffer @magmax |
I wrote unittest for windows to illiustrate this problem |
Not for me. Running Windows 10 With 3.0.5 i can turn off NumLock then use the numpad arrow keys to move up/down |
@Moreless91 in #71 I have implemented a lot of fixed on the windows side. Does this also fix your problem? |
@Cube707 I installed your branch: https://github.com/Cube707/python-readchar.git and it works |
I see the same. In cutie (they linked an issue for it above) , the up/down arrow keys work with readchar 3.0.4 but not 3.0.5. I saw this on several Windows computers, mix of 10 and 11. In 3.0.5 the numpad arrows did work with num lock off, but regular arrow keys did not. |
8 months later and this issue is still not fixed. I can reproduce the arrow keys issue on Windows 11. They work, however, when using numpad keys but not the keyboard arrow keys. |
The fix is ready and just waiting to be merged, but theres no feedback from the author |
Its the most important function and point of this project, to handle that corectly, maybe someone should make a fork.
|
allready done. See the sourcecode and I also uploaded the packages to test.pypi.org. But I am still hoping to get feedback here and maybe get added as a collaborator so we can avoid another slightly different version of this package getting pushed to pypi... You can also install directly from my git repo using |
Problem:
On Windows special keystrokes are sent to all Programs as a combination of two characters. The first one being a
\x00
(or\xe0
?).This is reflected in the code by checking the first read byte
a
and then reading again intob
ifa
meets this condition:python-readchar/readchar/readchar.py
Lines 70 to 71 in 549c17a
Then the two characters are used to calculate a number and look that up in a lookup table to find the corresponding constant to return.
However, this lookup table only has rows for
a
=224 and not fora
=0, which is what my windows10 Version uses. This leads to all calculated values being offset by 224 and resulting in aKeyError
and returningNone
.In #65, some values are corrected to match the calculations with
a
=0, but the rest is still left as is.Solution 1:
Add a second entry into the lookup table for every key, so that both calculation return valid results.
Form my perspective this seems stupid, so heres a better solution:
Solution 2:
Ignore
a
in the calculation. It is not needed anyway, as only the second byteb
is actually relevant for the pressed key. Use the value ofb
directly as keys.
This also makes it easier to maintain, as now the values listed in the sources can be used directly instead of having to do calculations every time. See Example below.
Discussion:
Which solution should be implemented? I would be willing to provide a pull request for either one.
Removing the while loop:
The
msvcrt.getch()
already blocks until the next keypress, so I believe thewhile 1
could be removed. But I might be mistaken and miss animportant detail elsewhere. This would solve the need for #42/#56.
Example:
The text was updated successfully, but these errors were encountered: