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() 不起作用?
基础教程推荐
- kivy 应用程序中的一个简单网页作为小部件 2022-01-01
- Python 中是否有任何支持将长字符串转储为块文字或折叠块的 yaml 库? 2022-01-01
- 在 Django Admin 中使用内联 OneToOneField 2022-01-01
- matplotlib 设置 yaxis 标签大小 2022-01-01
- Kivy 使用 opencv.调整图像大小 2022-01-01
- 究竟什么是“容器"?在蟒蛇?(以及所有的 python 容器类型是什么?) 2022-01-01
- Python,确定字符串是否应转换为 Int 或 Float 2022-01-01
- 对多索引数据帧的列进行排序 2022-01-01
- 比较两个文本文件以找出差异并将它们输出到新的文本文件 2022-01-01
- 在 Python 中将货币解析为数字 2022-01-01
