python-3.x - msvcrt.kbhit() 总是返回 false 。无法检测到 Escape 键
问题描述
我试过if (msvcrt.getch() == chr(27).encode())
了,没用
我程序中的 msrcvt.getch() 总是在 debug-print 语句中打印到 b'\xff' 。
它根本没有检测到我正在按下的 ESC 键。如何使它工作。请提供 Python 3.8.x 的任何示例代码。
解决方案
尝试:如果 msvcrt.getch()==b'\x1b'
前任:
import msvcrt
while True:
if msvcrt.kbhit():
key_stroke = msvcrt.getch()
if key_stroke==b'\x1b':
print ("Esc key pressed")
else:
print (str(key_stroke).split("'")[1],"key pressed")
推荐阅读
- javascript - GlobalHotKeys(react-hotkeys)在专注于输入字段时不起作用
- c++ - 二叉树到堆树的转换 - 陷入无限循环
- html - 选择输入时如何仅勾勒边框半径?
- java - 静态类中的重复局部变量
- spring - 启动 spring 工具套件时发生错误
- swift - 我想知道使用 Firebase 身份验证获取的 Twitter 访问令牌的到期日期
- react-native - React native keyboardAvoidView 覆盖了一半 textInput
- python - 如何将内部列表存储到外部列表
- iphone - React Native:更改应用商店上传的目标 sdk 版本
- c++ - C ++声明一个继承的构造函数?