Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/302.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python(3.6.1)按键检测和弹出窗口_Python_Popup_Keypress_Msvcrt - Fatal编程技术网

Python(3.6.1)按键检测和弹出窗口

Python(3.6.1)按键检测和弹出窗口,python,popup,keypress,msvcrt,Python,Popup,Keypress,Msvcrt,我对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

我对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”是“b'a”” 为什么?我如何才能将其更改为仅“A”?(弹出窗口上的输出甚至更奇怪,如:当我按1时为1X,或当我按2时为2*x)

2) 是
而不是True:
使代码始终运行,从而使其能够检测是否按下了键


3) 有没有python库可以检测到windows和Linux的按键?

好的,我找到了一些答案:

1)
msvcrt.getwch()
getch()的宽字符变量,返回Unicode值

更多信息请访问:

2) 我想是的,如果有人能证实,我会很高兴的

3) 我不知道,每个op系统都有diff lib(如果我错了,请在这里留个便条)