PyCharm:msvcrt.kbhit() 和 msvcrt.getch() 不起作用?

PyCharm: msvcrt.kbhit() and msvcrt.getch() not working?(PyCharm:msvcrt.kbhit() 和 msvcrt.getch() 不起作用?)

本文介绍了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() 不起作用?

基础教程推荐