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

5

我希望能够独立检测扳机的拉动,但扳机似乎共享一个轴。

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

我该如何强制pygame使用xinput而不是direct input?如果这真的不可行,我愿意使用其他语言。

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

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

1个回答

1

第一:

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

截至2011年,XInput 适用于 Xbox 360 手柄,而 DirectInput 适用于任何手柄。

第二:

Pygame 是一个 SDL 绑定。

所以如果 SDL 有支持,pygame 可以具备 XInput 支持。不幸的是,SDL 没有支持。 原因就是我之前写过的,DirectInput 更受欢迎。 还可以查看: http://forums.libsdl.org/viewtopic.php?t=6352&sid=35bdc1b1615f9ea081671ff548a7e360

如果您愿意,仍然可以编写一个XInput API的包装器。

编辑:

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


感谢您的帮助! - AGCodes

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接