专注于其他应用程序时,win32api.getasynckeystate无法检测到密钥

时间:2019-06-28 09:59:59

标签: python

它已经连续3个问题了,我尝试了不同的提问方式,但未能获得确切的答案。问题很清楚,标题。当窗口聚焦在其他应用程序上时,未检测到键盘按下的键,有什么帮助吗?该代码与Sentdex使用GTA 5的代码几乎相同。

import win32api as wapi
import time

left = 37
up = 38
right = 39
down = 40

keyList = ["Q","W","E","A","S","D",left,up,right,down]


def key_check():
    keys = []
    for key in keyList:
        if str(key).isdigit():
            if wapi.GetAsyncKeyState(key):
                if key==37:
                    key="left"
                elif key==38:
                    key="up"
                elif key==39:
                    key="right"
                elif key==40:
                    key="down"
                keys.append(key)
        else:
            if wapi.GetAsyncKeyState(ord(key)):
                keys.append(key)
    print(keys)
    return keys

0 个答案:

没有答案