如何在 XBOX One 控制器上拆分触发器?

How to split triggers on XBOX One controllers?

我希望能够独立检测触发器拉动,但触发器似乎共享一个轴。

我在 MSDN 文档中没有看到有关 Xbox One 控制器的任何内容,但对于 Xbox 360 控制器,DirectInput 触发器共享轴,而 XInput 为每个触发器提供单独的轴。这表明 pygame 使用的是 DirectInput 而不是 Xinput,但我不知道如何强制 pygame 使用 Xinput。

(如何)我可以强制 pygame 使用 xinput 而不是直接输入? 如果这真的不可行,我愿意使用不同的语言。

我正在使用这个脚本从控制器读取输入:

import pygame
pygame.init()

screen = pygame.display.set_mode((400,400))
joysticks = []

for i in range(0, pygame.joystick.get_count()):
    joysticks.append(pygame.joystick.Joystick(i))
    joysticks[-1].init()

while True:
    for event in pygame.event.get():
        print event

编辑:我现在没有时间完整地写出来,但与此同时,我发现这段代码似乎对我有用(在一个 Xbox One Spectra 控制器):https://github.com/r4dian/Xbox-360-Controller-for-Python

第一个:

来自 https://en.wikipedia.org/wiki/DirectInput#DirectInput_vs_XInput

As of 2011 XInput is for Xbox 360 controllers, while DirectInput is for any controller

第二个:

Pygame is an SDL binding.

所以 pygame 可以有 XInput 支持,如果 SDL 有。遗憾的是,SDL 没有。 原因是我之前写的,DirectInput比较流行。 另请查看: http://forums.libsdl.org/viewtopic.php?t=6352&sid=35bdc1b1615f9ea081671ff548a7e360

如果你愿意,你仍然可以围绕 XInput API 编写一个包装器。

编辑:

您链接的存储库使用 ctypes 围绕 XInput 创建包装器 API。