5

I'd like to be able to detect trigger pulls independently, but the triggers appear to share a single axis.

I didn't see anything on Xbox One controllers in the MSDN docs, but for Xbox 360 controllers, DirectInput triggers share the axis, and XInput gives separate axes to each trigger. This suggests that pygame is using DirectInput rather than Xinput, but I don't know how to force pygame to use Xinput instead.

(How) can I force pygame to use xinput instead of direct input? If this is not really feasible, I'd be willing to use a different language.

I am using this script to read input from the controller:

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

EDIT: I don't have time at the moment to write this out in full, but in the meantime, I found this code which appears to work for me (on an Xbox One Spectra controller): https://github.com/r4dian/Xbox-360-Controller-for-Python

4

1 回答 1

1

第一的:

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

截至 2011 年XInput适用于Xbox 360控制器,而DirectInput适用于任何控制器

第二:

Pygame 是一个 SDL 绑定。

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

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

编辑:

您链接的 repo 使用 ctypes 围绕 XInput API 创建一个包装器。

于 2016-12-31T21:14:35.613 回答