Skip to content

Commit 46892c6

Browse files
committed
Updated README
1 parent fc4c82c commit 46892c6

File tree

6 files changed

+377
-6
lines changed

6 files changed

+377
-6
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
2+
runreadmelang.bat

README.md

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,20 @@
1-
# XInput
1+
# XInput
2+
## 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\.
4+
5+
## Tiny Documentation
6+
### Using XInput
7+
XInput provides a few functions:
8+
`get_connected() -> (bool, bool, bool, bool)` Query which controllers are connected \(note: don't query each frame\)
9+
10+
`get_state(user_index) -> State` Get the State of the controller `user_index`
11+
12+
`get_button_values(state) -> dict` Returns a dictionary, showing which buttons are currently being pressed\.
13+
14+
`get_trigger_values(state) -> (LT, RT)` Returns a tuple with the values of the left and right triggers in range `0.0` to `1.0`
15+
16+
`get_thumb_values(state) -> ((LX, LY), (RX, RY))` Returns the values of the thumb sticks, expressed in X and Y ranging from `0.0` to `1.0`
17+
18+
`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+
20+
`get_battery_information(user_index) -> (<type>, <level>)` Returns the battery information for `user_index`

README.rml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
[title]XInput[/title]
2+
[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.
4+
5+
[s1]Tiny Documentation[/]
6+
[s2]Using XInput[/]
7+
XInput provides a few functions:
8+
[code]get_connected() -> (bool, bool, bool, bool)[/code] Query which controllers are connected (note: don't query each frame)
9+
10+
[code]get_state(user_index) -> State[/code] Get the State of the controller [code]user_index[/code]
11+
12+
[code]get_button_values(state) -> dict[/code] Returns a dictionary, showing which buttons are currently being pressed.
13+
14+
[code]get_trigger_values(state) -> (LT, RT)[/code] Returns a tuple with the values of the left and right triggers in range [code]0.0[/] to [code]1.0[/]
15+
16+
[code]get_thumb_values(state) -> ((LX, LY), (RX, RY))[/code] Returns the values of the thumb sticks, expressed in X and Y ranging from [code]0.0[/] to [code]1.0[/]
17+
18+
[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+
20+
[code]get_battery_information(user_index) -> (<type>, <level>)[/] Returns the battery information for [code]user_index[/]

README.rst

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
2+
######
3+
XInput
4+
######
5+
6+
********************************************************
7+
A simple to use interface to the XInput API for Python\.
8+
********************************************************
9+
| **XInput** provides a few simple methods that can be used to query controller information\.
10+
|
11+
12+
Tiny Documentation
13+
==================
14+
15+
Using XInput
16+
------------
17+
| XInput provides a few functions\:
18+
| :code:`get_connected() -> (bool, bool, bool, bool)` Query which controllers are connected \(note\: don\'t query each frame\)
19+
|
20+
| :code:`get_state(user_index) -> State` Get the State of the controller :code:`user_index`
21+
|
22+
| :code:`get_button_values(state) -> dict` Returns a dictionary\, showing which buttons are currently being pressed\.
23+
|
24+
| :code:`get_trigger_values(state) -> (LT, RT)` Returns a tuple with the values of the left and right triggers in range :code:`0.0` to :code:`1.0`
25+
|
26+
| :code:`get_thumb_values(state) -> ((LX, LY), (RX, RY))` Returns the values of the thumb sticks\, expressed in X and Y ranging from :code:`0.0` to :code:`1.0`
27+
|
28+
| :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+
|
30+
| :code:`get_battery_information(user_index) -> (<type>, <level>)` Returns the battery information for :code:`user_index`

XInput.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44

55
from math import sqrt
66

7-
import glm
8-
97
XINPUT_DLL_NAMES = (
108
"XInput1_4.dll",
119
"XInput9_1_0.dll",
@@ -19,7 +17,7 @@
1917
for name in XINPUT_DLL_NAMES:
2018
found = ctypes.util.find_library(name)
2119
if found:
22-
libXInput = ctypes.CDLL(found)
20+
libXInput = ctypes.WinDLL(found)
2321
break
2422

2523
if not libXInput:
@@ -108,6 +106,14 @@ def XInputGetBatteryInformation(dwUserIndex, devType, batteryInformation):
108106
class XInputNotConnectedError(Exception):
109107
pass
110108

109+
def get_connected():
110+
state = XINPUT_STATE()
111+
out = [False] * 4
112+
for i in range(4):
113+
out[i] = (XInputGetState(i, state) == 0)
114+
115+
return tuple(out)
116+
111117
def get_state(user_index):
112118
state = XINPUT_STATE()
113119
res = XInputGetState(user_index, state)
@@ -135,7 +141,7 @@ def set_vibration(user_index, left_speed, right_speed):
135141
vibration.wLeftMotorSpeed = int(left_speed)
136142
vibration.wRightMotorSpeed = int(right_speed)
137143

138-
return XInputSetState(user_index, vibration)
144+
return XInputSetState(user_index, vibration) == 0
139145

140146
def get_button_values(state):
141147
wButtons = state.Gamepad.wButtons
@@ -211,5 +217,5 @@ def get_thumb_values(state):
211217
else:
212218
magR = 0
213219

214-
return (glm.vec2(normLX, normLY) * normMagL, glm.vec2(normRX, normRY) * normMagR)
220+
return ((normLX * normMagL, normLY * normMagL), (normRX * normMagR, normRY * normMagR))
215221

0 commit comments

Comments
 (0)