Pygame多个PS3控制器按钮编号不一致



我正在为两个玩家/两个PS3控制器编写基于pygame的代码。 我的问题是,同时使用两个控制器时,控制器之间的按钮编号似乎不一致。 (按下一个控制器上的黄色按钮可能会给我一个按钮编号 4,但另一个控制器的按钮编号为 0(。 这是正常行为还是我的代码有误?

import pygame
pygame.init()    
clock = pygame.time.Clock()
# Get the number of joysticks attached
joystick_count = pygame.joystick.get_count()
# Check for events
while True:
for event in pygame.event.get():
if event.type == pygame.JOYBUTTONDOWN:
print("Joystick button pressed.")
if event.type == pygame.JOYBUTTONUP:
print("Joystick button released.")
# For each joystick:
for j in range(joystick_count):
joystick = pygame.joystick.Joystick(j)
joystick.init()
buttons = joystick.get_numbuttons()
for i in range( buttons ):
button = joystick.get_button( i )
if button != 0:
print("Joystick {:1} Button {:>2} value: {}".format(j,i,button) )
clock.tick(20)

一个控制器设置为DirectInput(它适用于我的pygame(,而另一个控制器设置为Xinput。 当它们都设置为直接输入时,按钮映射始终是一致的!

最新更新