所以我在玩pygame游戏杆时遇到了一个问题。我的控制器(康耐视USB控制面板)上的十个按钮中有四个可以正常工作,但其他六个则无法工作。在我的代码中,我用python打印了我刚刚按下的按钮。这适用于输入0-3,但是当我尝试四个并按下控制器上的其他按钮之一时,出现错误:
if j.get_button(4):
pygame.error: Invalid joystick button
Python还会打印出其他两个有效的按钮名称。 (打印的按钮名称根据我按下的按钮而改变)
这是我的完整代码:
import pygame
from pygame import locals
pygame.init()
pygame.joystick.init()
try:
j = pygame.joystick.Joystick(0)
j.init()
print("Enabled joystick: " + j.get_name())
while True:
events = pygame.event.get()
for event in events:
if j.get_button(0):
print("A2")
if j.get_button(1):
print("A3")
if j.get_button(2):
print("A1")
if j.get_button(3):
print("A4")
if j.get_button(4):
print("Test")
我尝试将数字更改为5或6,甚至更高,但似乎无济于事。如果您知道如何使控制器上的其他按钮正常工作,我们将不胜感激。谢谢。