How to split triggers on XBOX One controller?

I would like to be able to detect trigger frames independently of each other, but triggers seem to have one axis.

I didn't see anything on Xbox One controllers in MSDN docs, but for Xbox 360 controllers, DirectInput triggers use an axis, and XInput selects separate axes for each trigger. This suggests that pygame uses DirectInput, not Xinput, but I don't know how to get pygame to use Xinput instead.

(How) can I force pygame to use xinput instead of direct input? If this is not realistic, I would like to use a different language.

I use this script to read input from a 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 to write this completely, but in the meantime I found this code that works for me (on the Xbox One Spectra controller): https://github.com/r4dian/Xbox-360-Controller-for- Python

+5
source share
1 answer

Firstly:

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

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

Secondly:

Pygame - binding to SDL.

So pygame may have XInput support if the SDL has it. Unfortunately, SDL does not. The reason is that I wrote earlier, DirectInput more popular. Also check: http://forums.libsdl.org/viewtopic.php?t=6352&sid=35bdc1b1615f9ea081671ff548a7e360

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

EDIT:

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

+1
source

Source: https://habr.com/ru/post/1262129/


All Articles