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() 不起作用?


- ";find_element_by_name(';name';)";和&QOOT;FIND_ELEMENT(BY NAME,';NAME';)";之间有什么区别? 2022-01-01
- YouTube API v3 返回截断的观看记录 2022-01-01
- 使用公司代理使Python3.x Slack(松弛客户端) 2022-01-01
- 我如何透明地重定向一个Python导入? 2022-01-01
- CTR 中的 AES 如何用于 Python 和 PyCrypto? 2022-01-01
- 计算测试数量的Python单元测试 2022-01-01
- 检查具有纬度和经度的地理点是否在 shapefile 中 2022-01-01
- 我如何卸载 PyTorch? 2022-01-01
- 使用 Cython 将 Python 链接到共享库 2022-01-01
- 如何使用PYSPARK从Spark获得批次行 2022-01-01