PyCharm: msvcrt.kbhit() and msvcrt.getch() not working?

亡梦爱人 提交于 2019-12-04 02:50:37

问题


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?


回答1:


It's possible in a special mode of the Run window.

  • Check the Emulate terminal in output console setting checkbox in Run/Debug Configurations


来源:https://stackoverflow.com/questions/30534218/pycharm-msvcrt-kbhit-and-msvcrt-getch-not-working

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!