PyCharm: msvcrt.kbhit() and msvcrt.getch() not working?(PyCharm:msvcrt.kbhit() 和 msvcrt.getch() 不起作用?)
问题描述
我尝试从 PyCharm 中的控制台读取一个字符(不按 Enter),但无济于事.msvcrt.getch() 函数会停止代码,但不会对按键做出反应(甚至回车),并且
msvcrt.kbhit()
总是返回 0.例如这个代码什么也不打印:
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'
我使用的是 Windows 7,PyCharm 3.4(空闲时也是如此).
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?
推荐答案
可以在运行
窗口的特殊模式下.
It's possible in a special mode of the Run
window.
- 选中
Run/Debug Configurations
中的Emulate terminal in output console
设置复选框
这篇关于PyCharm:msvcrt.kbhit() 和 msvcrt.getch() 不起作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:PyCharm:msvcrt.kbhit() 和 msvcrt.getch() 不起作用?


基础教程推荐
- 修改列表中的数据帧不起作用 2022-01-01
- Plotly:如何设置绘图图形的样式,使其不显示缺失日期的间隙? 2022-01-01
- PermissionError: pip 从 8.1.1 升级到 8.1.2 2022-01-01
- 使用大型矩阵时禁止 Pycharm 输出中的自动换行符 2022-01-01
- PANDA VALUE_COUNTS包含GROUP BY之前的所有值 2022-01-01
- 无法导入 Pytorch [WinError 126] 找不到指定的模块 2022-01-01
- 包装空间模型 2022-01-01
- 在同一图形上绘制Bokeh的烛台和音量条 2022-01-01
- 求两个直方图的卷积 2022-01-01
- 在Python中从Azure BLOB存储中读取文件 2022-01-01