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

查看:1111
本文介绍了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?

推荐答案

可以在Run窗口的特殊模式下使用.

It's possible in a special mode of the Run window.

  • 选中Run/Debug Configurations
  • 中的Emulate terminal in output console设置复选框

这篇关于PyCharm:msvcrt.kbhit()和msvcrt.getch()不起作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆