Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to split triggers on XBOX One controllers?

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

like image 506
AGCodes Avatar asked Nov 08 '22 04:11

AGCodes


1 Answers

First:

From https://en.wikipedia.org/wiki/DirectInput#DirectInput_vs_XInput:

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

Second:

Pygame is an SDL binding.

So pygame can have XInput support if SDL has. Sadly, SDL don't has. The reason is what I wrote before, DirectInput is more popular. Also check out: http://forums.libsdl.org/viewtopic.php?t=6352&sid=35bdc1b1615f9ea081671ff548a7e360

You can still write a wrapper around XInput API, if you want to.

EDIT:

The repo you linked in uses ctypes to create a wrapper around the XInput API.

like image 63
Sasszem Avatar answered Nov 15 '22 08:11

Sasszem