Skip to content

Commit af2bcb0

Browse files
committed
Update to Version 0.2.0
1 parent 46892c6 commit af2bcb0

File tree

8 files changed

+765
-22
lines changed

8 files changed

+765
-22
lines changed

.gitignore

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,6 @@
1-
1+
build/
2+
dist/
3+
XInput_Python.egg-info/
24
runreadmelang.bat
5+
*.pyc
6+
*.bat

MANIFEST.in

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
include LICENSE
2+
include README.md

README.md

Lines changed: 80 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,20 @@
1-
# XInput
1+
# XInput\-Python
22
## 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\.
44

55
## 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:
818
`get_connected() -> (bool, bool, bool, bool)` Query which controllers are connected \(note: don't query each frame\)
919

1020
`get_state(user_index) -> State` Get the State of the controller `user_index`
@@ -17,4 +27,69 @@ XInput provides a few functions:
1727

1828
`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\.
1929

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\.

README.rml

Lines changed: 72 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,16 @@
1-
[title]XInput[/title]
1+
[title]XInput-Python[/title]
22
[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.
44

55
[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:
814
[code]get_connected() -> (bool, bool, bool, bool)[/code] Query which controllers are connected (note: don't query each frame)
915

1016
[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:
1723

1824
[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.
1925

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.

README.rst

Lines changed: 104 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,40 @@
11

2-
######
3-
XInput
4-
######
2+
##############
3+
XInput\-Python
4+
##############
55

66
********************************************************
77
A simple to use interface to the XInput API for Python\.
88
********************************************************
9-
| **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\.
1010
|
1111
1212
Tiny Documentation
1313
==================
14+
| *XInput is Windows only*
1415
15-
Using XInput
16+
Installation
1617
------------
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\:
1838
| :code:`get_connected() -> (bool, bool, bool, bool)` Query which controllers are connected \(note\: don\'t query each frame\)
1939
|
2040
| :code:`get_state(user_index) -> State` Get the State of the controller :code:`user_index`
@@ -27,4 +47,81 @@ Using XInput
2747
|
2848
| :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\.
2949
|
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

Comments
 (0)