Search code examples
c#pythoncontrollersxinput

How can I use XInput in Python ()WITHOUT PYGAME) to sniff button presses on the controller?


I've been scouring the forums for days now trying to find a way to sniff XInput from an XInput controller. I haven't found any way to detect if a button is pressed down and most the forum posts are about the analog sticks. I also want to achieve my goal WITHOUT PyGame or bulky, external modules. All I need to be able to do is detect when the A, B, RB (Right Bumper) and D-Pad buttons are pressed on the controller and when they are pressed, run some code. I would like to be able to distinguish between which button is pressed, not just the fact that a button has been pressed because I need to convert these inputs into VK codes to add controller support for a certain game (I know there are already applications out there for this but I want to make one that is in a single script and is less bulky.)

Also, if this is easier in another language than Python, please explain anyway. I only said in Python because I know the language more than others. Also, I have quite little coding experience, keep that in mind.


Solution

  • Take a look at this Github repo:

    https://github.com/r4dian/Xbox-360-Controller-for-Python

    It seems to contain exactly what you want. I think that using this lib is the simplest way to make the controller work with python.