【发布时间】:2017-03-28 13:28:54
【问题描述】:
我对 python 有点陌生,我尝试在 Windows 上按下时打印密钥并在弹出消息中显示密钥:
import msvcrt
import ctypes # An included library with Python install.
def Mbox(title, text, style):
ctypes.windll.user32.MessageBoxW(0, text, title, style)
while True:
if msvcrt.kbhit()== True:
key = msvcrt.getch()
print(key) # just to show the result
Mbox(key, key, 1)
问题是:
1) 如果我按下一个键,输出是不同的,例如:"A" is "b'A'" 为什么?以及如何将其更改为仅“A”? (弹出窗口的输出更奇怪:当我按下 1 时为 1X,当我按下 2 时为 2*x)
2) While True: 是否让代码一直运行,并以此保持检测是否有按键被按下?
3) 是否有任何用于检测 windows 和 Linux 按键的 python 库?
【问题讨论】:
标签: python popup keypress msvcrt