Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
make `getchar` work on Windows. #1108
No tests because the test suite can't properly test
The implemented behavior is not the best (see the comment; it's impossible to read French letter "à" as a single character), but it does fix a long-standing issue in a reasonable way.
hmm, this is a change of behavior though, so maybe not appropriate for a maintenance branch?
To reiterate: with Python 3 on Windows,
this pull request
Sep 12, 2018
Thank you for the pull request and the detailed code comments.
This function recurses indefinitely, but the Windows docs for
Is the issue with à that it will show up as two bytes rather than one, not that it can't be input at all? Is that something that can / should be solved with Unicode normalization?
Hmmm, apparently I'm wrong about what
I don't see what you mean by "recursing indefinitely". The second call calls
The issue with "à" is that if you press it,
I've been testing this on a Windows 2016 Server and Python 3.7 (it's what I have most readily available). The results make sense of the code, but don't jive perfectly with the comments.
Encoding handling was needed to deal with the fact that
On a French keyboard, "e with grave accent" works with a single call to
The msvcrt docs seem to say that two calls are only needed to handle function keys and other exotic keycodes, not general multiple-byte characters. That's the behavior I see as well -- if I hit a function key, I need to call
Regardless of the disagreement between what I see and the comment about
I'd like to hear back about that one discrepancy, and then I'd push ahead and merge this into
The problem is with a single particular character,
Try this to reproduce:
import msvcrt first = msvcrt.getwch() second = msvcrt.getwch() print(first, second)
For first attempt, press the Up arrow. The result is
For second attempt, use a French keyboard and type "àH":
The way I wrote this PR, signaling bytes
However, when you ask the user to "press any key", and they choose to press "à", nothing will happen until they also press a second key.
I welcome suggestions for improving the comment; apparently this problem is convoluted enough to warrant a clearer explanation?
I'm ok with waiting for 7.0, after all this is a potentially breaking change in behavior.
I've changed the PR base to
I don't think the comment needs improvement. Last night I was testing this with letters with acute accents (you can see my
There's another reasonable behavior available: to have
There are two documentation changes I'd like to see before this merges:
I'm fine with merging this along with @sirosen's requests.
How do other libraries handle this? Do they just block on à too?
Maybe we could add a a
I also considered the idea of a flag, e.g.
A cursory look at other projects on github shows that most people are either catching two chars like we will, or blissfully unaware of this snakepit. I'll keep looking around in case I see something clever, but I think this PR might represent the current state-of-the-art.