You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
## A simple to use interface to the XInput API for Python\.
3
-
**XInput** provides a few simple methods that can be used to query controller information\.
3
+
**XInput\-Python** provides a few simple methods that can be used to query controller information\.
4
4
5
5
## Tiny Documentation
6
-
### Using XInput
7
-
XInput provides a few functions:
6
+
*XInput is Windows only*
7
+
### Installation
8
+
XInput\-Python is available from the [PyPI](https://pypi.org) using
9
+
10
+
pip install XInput-Python
11
+
12
+
It can be inmported like this:
13
+
14
+
import XInput
15
+
16
+
### Using XInput\-Python
17
+
XInput\-Python provides a few functions:
8
18
`get_connected() -> (bool, bool, bool, bool)` Query which controllers are connected \(note: don't query each frame\)
9
19
10
20
`get_state(user_index) -> State` Get the State of the controller `user_index`
@@ -17,4 +27,69 @@ XInput provides a few functions:
17
27
18
28
`set_vibration(user_index, left_speed, right_speed) -> bool (Success)` Sets the vibration of the left and right motors of `user_index` to values between `0` and `65535` or in range `0.0` to `1.0` respectively\.
19
29
20
-
`get_battery_information(user_index) -> (<type>, <level>)` Returns the battery information for `user_index`
30
+
`get_battery_information(user_index) -> (<type>, <level>)` Returns the battery information for `user_index`
31
+
32
+
#### Using Events
33
+
You can also use the Event\-system:
34
+
35
+
events = get_events()
36
+
37
+
38
+
`get_events` will return a generator that yields instances of the `Event` class\.
39
+
40
+
The `Event` class always has the following members:
41
+
`Event.user_index`\(range 0 to 3\)\- the id of the controller that issued this event
42
+
`Event.type`\- which type of event was issued
43
+
44
+
The following events exist:
45
+
`XInput.EVENT_CONNECTED == 1`\- a controller with this `user_index` was connected \(this event will even occur if the controller was connected before the script was started\)
46
+
47
+
`XInput.EVENT_DISCONNECTED == 2`\- a controller with this `user_index` was disconnected
48
+
49
+
`XInput.EVENT_BUTTON_PRESSED == 3`\- a button was pressed on the controller `user_index`
50
+
51
+
`XInput.EVENT_BUTTON_RELEASED == 4`\- a button was released on the controller `user_index`
52
+
53
+
`XInput.EVENT_TRIGGER_MOVED == 5`\- a trigger was moved on the controller `user_index`
54
+
55
+
`XInput.EVENT_STICK_MOVED == 6`\- a thumb stick was moved on the controller `user_index`
56
+
57
+
**Button Events**
58
+
All button related Events have the following additional members:
59
+
`Event.button_id`\- the XInput numerical representation of the button
60
+
`Event.button`\- a literal representation of the button
61
+
62
+
The following buttons exist:
63
+
64
+
"DPAD_UP" == 1
65
+
"DPAD_DOWN" == 2
66
+
"DPAD_LEFT" == 4
67
+
"DPAD_RIGHT" == 8
68
+
"START" == 16
69
+
"BACK" == 32
70
+
"LEFT_THUMB" == 64
71
+
"RIGHT_THUMB" == 128
72
+
"LEFT_SHOULDER" == 256
73
+
"RIGHT_SHOULDER" == 512
74
+
"A" == 4096
75
+
"B" == 8192
76
+
"X" == 16384
77
+
"Y" == 32768
78
+
79
+
80
+
81
+
**Trigger Events**
82
+
All trigger related Events have the following additional members:
83
+
`Event.trigger`\(either `XInput.LEFT == 0` or `XInput.RIGHT == 1`\)\- which trigger was moved
84
+
`Event.value`\(range 0\.0 to 1\.0\)\- by how much the trigger is currently pressed
85
+
86
+
**Stick Events**
87
+
All thumb stick related Events have the following additional members:
88
+
`Event.stick`\(either `XInput.LEFT == 0` or `XInput.RIGHT == 1`\)\- which stick was moved
89
+
`Event.x`\(range \-1\.0 to 1\.0\)\- the position of the stick on the X axis
90
+
`Event.y`\(range \-1\.0 to 1\.0\)\- the position of the stick on the Y axis
91
+
`Event.value`\(range 0\.0 to 1\.0\)\- the distance of the stick from it's center position
92
+
`Event.dir`\(tuple of X and Y\)\- the direction the stick is currently pointing
93
+
94
+
### Demo
95
+
Run `XInput.py` as main \(`python XInput.py`\) to see a vidual representation of the controller input\.
[subtitle]A simple to use interface to the XInput API for Python.[/subtitle]
3
-
[b]XInput[/] provides a few simple methods that can be used to query controller information.
3
+
[b]XInput-Python[/] provides a few simple methods that can be used to query controller information.
4
4
5
5
[s1]Tiny Documentation[/]
6
-
[s2]Using XInput[/]
7
-
XInput provides a few functions:
6
+
[i]XInput is Windows only[/]
7
+
[s2]Installation[/]
8
+
XInput-Python is available from the [url=https://pypi.org]PyPI[/] using
9
+
[code]pip install XInput-Python[/code]
10
+
It can be inmported like this:
11
+
[code]import XInput[/code]
12
+
[s2]Using XInput-Python[/]
13
+
XInput-Python provides a few functions:
8
14
[code]get_connected() -> (bool, bool, bool, bool)[/code] Query which controllers are connected (note: don't query each frame)
9
15
10
16
[code]get_state(user_index) -> State[/code] Get the State of the controller [code]user_index[/code]
@@ -17,4 +23,65 @@ XInput provides a few functions:
17
23
18
24
[code]set_vibration(user_index, left_speed, right_speed) -> bool (Success)[/code] Sets the vibration of the left and right motors of [code]user_index[/] to values between [code]0[/] and [code]65535[/] or in range [code]0.0[/] to [code]1.0[/] respectively.
19
25
20
-
[code]get_battery_information(user_index) -> (<type>, <level>)[/] Returns the battery information for [code]user_index[/]
26
+
[code]get_battery_information(user_index) -> (<type>, <level>)[/] Returns the battery information for [code]user_index[/]
27
+
28
+
[s3]Using Events[/]
29
+
You can also use the Event-system:
30
+
[code]events = get_events()[/code]
31
+
32
+
[code]get_events[/code] will return a generator that yields instances of the [code]Event[/code] class.
33
+
34
+
The [code]Event[/code] class always has the following members:
35
+
[code]Event.user_index[/code] (range 0 to 3) - the id of the controller that issued this event
36
+
[code]Event.type[/code] - which type of event was issued
37
+
38
+
The following events exist:
39
+
[code]XInput.EVENT_CONNECTED == 1[/code] - a controller with this [code]user_index[/code] was connected (this event will even occur if the controller was connected before the script was started)
40
+
41
+
[code]XInput.EVENT_DISCONNECTED == 2[/code] - a controller with this [code]user_index[/code] was disconnected
42
+
43
+
[code]XInput.EVENT_BUTTON_PRESSED == 3[/code] - a button was pressed on the controller [code]user_index[/code]
44
+
45
+
[code]XInput.EVENT_BUTTON_RELEASED == 4[/code] - a button was released on the controller [code]user_index[/code]
46
+
47
+
[code]XInput.EVENT_TRIGGER_MOVED == 5[/code] - a trigger was moved on the controller [code]user_index[/code]
48
+
49
+
[code]XInput.EVENT_STICK_MOVED == 6[/code] - a thumb stick was moved on the controller [code]user_index[/code]
50
+
51
+
[b]Button Events[/]
52
+
All button related Events have the following additional members:
53
+
[code]Event.button_id[/code] - the XInput numerical representation of the button
54
+
[code]Event.button[/code] - a literal representation of the button
55
+
56
+
The following buttons exist:
57
+
[code]"DPAD_UP" == 1
58
+
"DPAD_DOWN" == 2
59
+
"DPAD_LEFT" == 4
60
+
"DPAD_RIGHT" == 8
61
+
"START" == 16
62
+
"BACK" == 32
63
+
"LEFT_THUMB" == 64
64
+
"RIGHT_THUMB" == 128
65
+
"LEFT_SHOULDER" == 256
66
+
"RIGHT_SHOULDER" == 512
67
+
"A" == 4096
68
+
"B" == 8192
69
+
"X" == 16384
70
+
"Y" == 32768
71
+
[/code]
72
+
73
+
[b]Trigger Events[/]
74
+
All trigger related Events have the following additional members:
75
+
[code]Event.trigger[/code] (either [code]XInput.LEFT == 0[/code] or [code]XInput.RIGHT == 1[/code]) - which trigger was moved
76
+
[code]Event.value[/code] (range 0.0 to 1.0) - by how much the trigger is currently pressed
77
+
78
+
[b]Stick Events[/]
79
+
All thumb stick related Events have the following additional members:
80
+
[code]Event.stick[/code] (either [code]XInput.LEFT == 0[/code] or [code]XInput.RIGHT == 1[/code]) - which stick was moved
81
+
[code]Event.x[/code] (range -1.0 to 1.0) - the position of the stick on the X axis
82
+
[code]Event.y[/code] (range -1.0 to 1.0) - the position of the stick on the Y axis
83
+
[code]Event.value[/code] (range 0.0 to 1.0) - the distance of the stick from it's center position
84
+
[code]Event.dir[/code] (tuple of X and Y) - the direction the stick is currently pointing
85
+
86
+
[s2]Demo[/]
87
+
Run [code]XInput.py[/code] as main ([code]python XInput.py[/code]) to see a vidual representation of the controller input.
|**XInput** provides a few simple methods that can be used to query controller information\.
9
+
|**XInput\-Python** provides a few simple methods that can be used to query controller information\.
10
10
|
11
11
12
12
Tiny Documentation
13
13
==================
14
+
|*XInput is Windows only*
14
15
15
-
Using XInput
16
+
Installation
16
17
------------
17
-
|XInput provides a few functions\:
18
+
|XInput\-Python is available from the `PyPI <https://pypi.org>`_ using
19
+
20
+
21
+
::
22
+
23
+
pip install XInput-Python
24
+
25
+
26
+
|It can be inmported like this\:
27
+
28
+
29
+
::
30
+
31
+
import XInput
32
+
33
+
34
+
35
+
Using XInput\-Python
36
+
--------------------
37
+
|XInput\-Python provides a few functions\:
18
38
|:code:`get_connected() -> (bool, bool, bool, bool)` Query which controllers are connected \(note\: don\'t query each frame\)
19
39
|
20
40
|:code:`get_state(user_index) -> State` Get the State of the controller :code:`user_index`
@@ -27,4 +47,81 @@ Using XInput
27
47
|
28
48
|:code:`set_vibration(user_index, left_speed, right_speed) -> bool (Success)` Sets the vibration of the left and right motors of :code:`user_index` to values between :code:`0` and :code:`65535` or in range :code:`0.0` to :code:`1.0` respectively\.
29
49
|
30
-
|:code:`get_battery_information(user_index) -> (<type>, <level>)` Returns the battery information for :code:`user_index`
50
+
|:code:`get_battery_information(user_index) -> (<type>, <level>)` Returns the battery information for :code:`user_index`
51
+
|
52
+
53
+
Using Events
54
+
^^^^^^^^^^^^
55
+
|You can also use the Event\-system\:
56
+
57
+
58
+
::
59
+
60
+
events = get_events()
61
+
62
+
63
+
|
64
+
|:code:`get_events` will return a generator that yields instances of the :code:`Event` class\.
65
+
|
66
+
|The :code:`Event` class always has the following members\:
67
+
|:code:`Event.user_index` \(range 0 to 3\) \- the id of the controller that issued this event
68
+
|:code:`Event.type` \- which type of event was issued
69
+
|
70
+
|The following events exist\:
71
+
|:code:`XInput.EVENT_CONNECTED == 1` \- a controller with this :code:`user_index` was connected \(this event will even occur if the controller was connected before the script was started\)
72
+
|
73
+
|:code:`XInput.EVENT_DISCONNECTED == 2` \- a controller with this :code:`user_index` was disconnected
74
+
|
75
+
|:code:`XInput.EVENT_BUTTON_PRESSED == 3` \- a button was pressed on the controller :code:`user_index`
76
+
|
77
+
|:code:`XInput.EVENT_BUTTON_RELEASED == 4` \- a button was released on the controller :code:`user_index`
78
+
|
79
+
|:code:`XInput.EVENT_TRIGGER_MOVED == 5` \- a trigger was moved on the controller :code:`user_index`
80
+
|
81
+
|:code:`XInput.EVENT_STICK_MOVED == 6` \- a thumb stick was moved on the controller :code:`user_index`
82
+
|
83
+
|**Button Events**
84
+
|All button related Events have the following additional members\:
85
+
|:code:`Event.button_id` \- the XInput numerical representation of the button
86
+
|:code:`Event.button` \- a literal representation of the button
87
+
|
88
+
|The following buttons exist\:
89
+
90
+
91
+
::
92
+
93
+
"DPAD_UP" == 1
94
+
"DPAD_DOWN" == 2
95
+
"DPAD_LEFT" == 4
96
+
"DPAD_RIGHT" == 8
97
+
"START" == 16
98
+
"BACK" == 32
99
+
"LEFT_THUMB" == 64
100
+
"RIGHT_THUMB" == 128
101
+
"LEFT_SHOULDER" == 256
102
+
"RIGHT_SHOULDER" == 512
103
+
"A" == 4096
104
+
"B" == 8192
105
+
"X" == 16384
106
+
"Y" == 32768
107
+
108
+
109
+
110
+
|
111
+
|**Trigger Events**
112
+
|All trigger related Events have the following additional members\:
113
+
|:code:`Event.trigger` \(either :code:`XInput.LEFT == 0` or :code:`XInput.RIGHT == 1`\) \- which trigger was moved
114
+
|:code:`Event.value` \(range 0\.0 to 1\.0\) \- by how much the trigger is currently pressed
115
+
|
116
+
|**Stick Events**
117
+
|All thumb stick related Events have the following additional members\:
118
+
|:code:`Event.stick` \(either :code:`XInput.LEFT == 0` or :code:`XInput.RIGHT == 1`\) \- which stick was moved
119
+
|:code:`Event.x` \(range \-1\.0 to 1\.0\) \- the position of the stick on the X axis
120
+
|:code:`Event.y` \(range \-1\.0 to 1\.0\) \- the position of the stick on the Y axis
121
+
|:code:`Event.value` \(range 0\.0 to 1\.0\) \- the distance of the stick from it\'s center position
122
+
|:code:`Event.dir` \(tuple of X and Y\) \- the direction the stick is currently pointing
123
+
|
124
+
125
+
Demo
126
+
----
127
+
|Run :code:`XInput.py` as main \(:code:`python XInput.py`\) to see a vidual representation of the controller input\.
0 commit comments