This doesn't work for me either, nor does martineau's suggested code even after fixing the TypeError (in an edit he rejected, by the way). As far as I can tell, the PyCharm console is consuming the input before the program has a chance to read it.
In looking for other solutions to read input without blocking, I'm convinced it's an issue with PyCharm. For instance, asciimatics
is known to not work in the console window either:
http://asciimatics.readthedocs.io/en/stable/troubleshooting.html#i-can-t-run-it-inside-pycharm-or-other-ides
If you want to use msvcrt
with the PyCharm editor, a possible workaround is to "emulate terminal in output console" available on editing the Run/Debug Configuration. This was successful for me!
You could also switch to a different interface by using tkinter
or pygame
, both of which work with PyCharm. These open a new window, however.
Hoping someone more knowledgeable of PyCharm will comment on this, and maybe even bug it in that project. Especially across platforms, non-blocking text input is so simple yet so annoying! Grrr!