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() 不起作用?
基础教程推荐
- 尝试制作WhatsApp机器人 2022-01-01
- 由Python将MP3转换为MIDI(类型错误:无法加载插件:mtg-Melodia:Melodia) 2022-01-01
- 在 Celery 工作人员中捕获 Heroku SIGTERM 以优雅地关 2022-01-01
- numpy float:比算术运算中内置的慢 10 倍? 2022-01-01
- 与常规 dict 相比,Python manager.dict() 非常慢 2022-01-01
- 用 Python 编写 Fortran 无格式文件 2022-01-01
- 使用生成器和迭代器时 Python 多循环失败 2022-01-01
- Discord.py 缺少必需的参数 2022-01-01
- 将 x 轴刻度更改为自定义字符串 2022-01-01
- pyserial - 可以从线程 a 写入串行端口,是否阻塞从线程 b 读取? 2022-01-01
