我想从python中的Xbox控制器获取密钥。我进行了很多搜索,但是到目前为止,我还没有找到一个很好的答案。我使用键盘做了类似的事情,通过这种方式,我只想知道如何获取运动箭头的键以及按钮A,B,X,Y,以最简单的方式在python脚本中使用它们。下面是从键盘获取键的代码。谢谢!
# -*- coding: utf-8 -*-
# Citation: Box Of Hats (https://github.com/Box-Of-Hats )
import win32api as wapi
import win32con as wcon
import time
keyList = ["\b"]
for char in "ABCDEFGHIJKLMNOPQRSTUVWXYZ 123456789,.'£$/\\":
keyList.append(char)
def key_check():
keys = []
for key in keyList:
if wapi.GetAsyncKeyState(ord(key)):
keys.append(key)
if wapi.GetAsyncKeyState(wcon.VK_UP):
keys.append('up')
if wapi.GetAsyncKeyState(wcon.VK_DOWN):
keys.append('down')
if wapi.GetAsyncKeyState(wcon.VK_RIGHT):
keys.append('right')
if wapi.GetAsyncKeyState(wcon.VK_LEFT):
keys.append('left')
if wapi.GetAsyncKeyState(wcon.VK_SPACE):
keys.append('space')
return keys