360 controller interface in python

For questions about using Classic.

Post » Mon Apr 18, 2011 4:16 am

Hey all! Has anyone tried handling input from a Xbox360 controller in python? The analog sticks and triggers seem pretty straightforward, but I haven't been able to figure out how to get button presses (face buttons, shoulders, etc).

Using the excellent Python Shell by Silent Cacophony I was able to locate the Xbox360Controller.ButtonState and XboxController360.IsButtonDown functions, but they both take a second mystery parameter that I'm unable to figure out (the first parameter, of course, being the controller index (non-zero based, incidentally)).

All these return false:

Xbox360Controller.ButtonState(controllerIndex, "B")
Xbox360Controller.ButtonState(controllerIndex, "Button B")
Xbox360Controller.ButtonState(controllerIndex, "Button_B")

Has anyone had any success with either of these functions, or can someone point me to some documentation for the Xbox360Controller plugin?

Thanks!
B
1
G
1
Posts: 4
Reputation: 433

Post » Mon Apr 18, 2011 4:44 am

[quote:2msn40p7]non-zero based, incidentally[/quote:2msn40p7]

Perhaps the second parameter is.
Cough, Boolean.
Image Image
B
161
S
48
G
90
Posts: 7,356
Reputation: 66,767

Post » Mon Apr 18, 2011 4:53 am

The best reference is just plain events. The first param is the controller (1-4).
With the "control is down" condition, param 2 is a combo box to select a button. Parameters that were combos in the events are an index in python, 0 for the fist line and so on. "Button B" would be 13. I imagine it works the same way with "ButtonState" but since I don't have a controller I can't test it.

So this should test button B on controler 1:
Xbox360Controller.ButtonState(1, 13)
B
79
S
24
G
54
Posts: 4,747
Reputation: 40,757

Post » Mon Apr 18, 2011 8:10 am

Brilliant! That worked perfectly, R0J0 - I'll file that bit of knowledge away for future use.

For anyone else who's curious about the specifics:
Xbox360Controller.ButtonState(1, 13) returns 1.0 if B is pressed on controller 1, 0.0 otherwise.
Xbox360Controller.IsButtonDown(1,13) returns True if B is pressed on controller 1, False otherwise.
B
1
G
1
Posts: 4
Reputation: 433


Return to Help & Support using Construct Classic

Who is online

Users browsing this forum: No registered users and 4 guests