|
4 | 4 |
|
5 | 5 | from math import sqrt |
6 | 6 |
|
7 | | -import glm |
8 | | - |
9 | 7 | XINPUT_DLL_NAMES = ( |
10 | 8 | "XInput1_4.dll", |
11 | 9 | "XInput9_1_0.dll", |
|
19 | 17 | for name in XINPUT_DLL_NAMES: |
20 | 18 | found = ctypes.util.find_library(name) |
21 | 19 | if found: |
22 | | - libXInput = ctypes.CDLL(found) |
| 20 | + libXInput = ctypes.WinDLL(found) |
23 | 21 | break |
24 | 22 |
|
25 | 23 | if not libXInput: |
@@ -108,6 +106,14 @@ def XInputGetBatteryInformation(dwUserIndex, devType, batteryInformation): |
108 | 106 | class XInputNotConnectedError(Exception): |
109 | 107 | pass |
110 | 108 |
|
| 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 | + |
111 | 117 | def get_state(user_index): |
112 | 118 | state = XINPUT_STATE() |
113 | 119 | res = XInputGetState(user_index, state) |
@@ -135,7 +141,7 @@ def set_vibration(user_index, left_speed, right_speed): |
135 | 141 | vibration.wLeftMotorSpeed = int(left_speed) |
136 | 142 | vibration.wRightMotorSpeed = int(right_speed) |
137 | 143 |
|
138 | | - return XInputSetState(user_index, vibration) |
| 144 | + return XInputSetState(user_index, vibration) == 0 |
139 | 145 |
|
140 | 146 | def get_button_values(state): |
141 | 147 | wButtons = state.Gamepad.wButtons |
@@ -211,5 +217,5 @@ def get_thumb_values(state): |
211 | 217 | else: |
212 | 218 | magR = 0 |
213 | 219 |
|
214 | | - return (glm.vec2(normLX, normLY) * normMagL, glm.vec2(normRX, normRY) * normMagR) |
| 220 | + return ((normLX * normMagL, normLY * normMagL), (normRX * normMagR, normRY * normMagR)) |
215 | 221 |
|
0 commit comments