I've tried to read one char from the console in PyCharm (without pressing enter), but to no avail.
The functions msvcrt.getch()
stops the code, but does not react to key presses (even enter), and msvcrt.kbhit()
always returns 0. For example this code prints nothing:
import msvcrt
while 1:
if msvcrt.kbhit():
print 'reading'
print 'done'
I am using Windows 7, PyCharm 3.4 (the same heppens in idle).
What is wrong? Is there any other way to just read input without enter?
The functions msvcrt.getch () stops the code, but does not react to key presses (even enter), and msvcrt.kbhit () always returns 0. For example this code prints nothing: I am using Windows 7, PyCharm 3.4 (the same heppens in idle).
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.
The RFC 4716 format for OpenSSH keys is not supported by PyCharm. Repeat the configuration step in the Add Python interpreter dialog. The Profile command is not available in the Run menu. This functionality is available only in the Professional edition of PyCharm. The Diagrams plugin that is bundled with PyCharm Professional has been disabled.
You do not have permissions to write in the directories used by PyCharm. Check and modify your permissions. Package installation fails. pip is not available for a particular Python interpreter, or any of the installation requirements is not met.
It's possible in a special mode of the Run
window.
Emulate terminal in output console
setting checkbox in Run/Debug Configurations
You are trying to compare <Class 'Bytes'>
to <Class 'string'>
.
Cast the key
to a string
and then compare:
import msvcrt
while True:
if msvcrt.kbhit():
key = str(msvcrt.getch())
if key == "b'w'":
print(key)
To run the program in the Command Line go to: edit Configurations > Execution > enable "Emulate terminal in output console".
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With