0

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.

Ben Chadwick
  • 11
  • 2
  • 9
  • Did you take a look at the [python-xlib](https://github.com/python-xlib/python-xlib) module? – Felix Apr 14 '17 at 16:15
  • @Felix I have just had a quick look at that and searched about it on the internet but can't work out how to use it to detect Xbox button presses. Also, I want to be able to make this into one script without external modules because I'm sure it shouldn't take lots of code to detect XInput button presses if it already has an API built into Windows – Ben Chadwick Apr 15 '17 at 00:26
  • Oh please forget what I recommended before. There's XInput in Windows and Linux and I assumed you were talking about Linux. Xlib won't work with Windows – Felix Apr 15 '17 at 10:00
  • Oh ok. Any ideas on how to achieve my goal then? – Ben Chadwick Apr 15 '17 at 21:41

1 Answers1

2

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.

Felix
  • 6,131
  • 4
  • 24
  • 44
  • After a few minutes fixing my pip install so I could download the required package, it works! Thank you so much! – Ben Chadwick Apr 16 '17 at 04:40
  • Code works great but the events were a pain, as you can't access the stuff in the loop you're running it in. Wrote myself a quick wrapper to fix it, might as well share in case anyone else has the same issue - https://pastebin.com/8KDYbpaj – Peter Nov 10 '17 at 20:51