simplevgpad 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- simplevgpad-0.1.0/PKG-INFO +44 -0
- simplevgpad-0.1.0/README.md +35 -0
- simplevgpad-0.1.0/pyproject.toml +18 -0
- simplevgpad-0.1.0/setup.cfg +4 -0
- simplevgpad-0.1.0/src/simplevgpad/__init__.py +3 -0
- simplevgpad-0.1.0/src/simplevgpad/simplevgpad.py +806 -0
- simplevgpad-0.1.0/src/simplevgpad.egg-info/PKG-INFO +44 -0
- simplevgpad-0.1.0/src/simplevgpad.egg-info/SOURCES.txt +9 -0
- simplevgpad-0.1.0/src/simplevgpad.egg-info/dependency_links.txt +1 -0
- simplevgpad-0.1.0/src/simplevgpad.egg-info/requires.txt +1 -0
- simplevgpad-0.1.0/src/simplevgpad.egg-info/top_level.txt +1 -0
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: simplevgpad
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Simple wrapper around vgamepad for easier controller inputs
|
|
5
|
+
Author: Jakanon Clenkk
|
|
6
|
+
Requires-Python: >=3.8
|
|
7
|
+
Description-Content-Type: text/markdown
|
|
8
|
+
Requires-Dist: vgamepad
|
|
9
|
+
|
|
10
|
+
# simplevgpad
|
|
11
|
+
|
|
12
|
+
A Python helper library for simplified Xbox controller input using vgamepad.
|
|
13
|
+
|
|
14
|
+
Defines 2 classes which inherit the vgamepad.VX360Gamepad class, and adds methods to
|
|
15
|
+
slightly simplify controller input simulation for simple projects.
|
|
16
|
+
|
|
17
|
+
## Installation
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
pip install simplevgpad
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
## Examples
|
|
24
|
+
|
|
25
|
+
### controller
|
|
26
|
+
```py
|
|
27
|
+
from simplevgpad import controller
|
|
28
|
+
|
|
29
|
+
game = controller()
|
|
30
|
+
game.press_a()
|
|
31
|
+
game.hold_left_trigger(2)
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
### controller_async
|
|
35
|
+
```py
|
|
36
|
+
from simplevgpad import controller_async
|
|
37
|
+
import asyncio
|
|
38
|
+
|
|
39
|
+
async def main():
|
|
40
|
+
game = controller_async()
|
|
41
|
+
await game.press_a()
|
|
42
|
+
|
|
43
|
+
asyncio.run(main())
|
|
44
|
+
```
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
# simplevgpad
|
|
2
|
+
|
|
3
|
+
A Python helper library for simplified Xbox controller input using vgamepad.
|
|
4
|
+
|
|
5
|
+
Defines 2 classes which inherit the vgamepad.VX360Gamepad class, and adds methods to
|
|
6
|
+
slightly simplify controller input simulation for simple projects.
|
|
7
|
+
|
|
8
|
+
## Installation
|
|
9
|
+
|
|
10
|
+
```bash
|
|
11
|
+
pip install simplevgpad
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
## Examples
|
|
15
|
+
|
|
16
|
+
### controller
|
|
17
|
+
```py
|
|
18
|
+
from simplevgpad import controller
|
|
19
|
+
|
|
20
|
+
game = controller()
|
|
21
|
+
game.press_a()
|
|
22
|
+
game.hold_left_trigger(2)
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
### controller_async
|
|
26
|
+
```py
|
|
27
|
+
from simplevgpad import controller_async
|
|
28
|
+
import asyncio
|
|
29
|
+
|
|
30
|
+
async def main():
|
|
31
|
+
game = controller_async()
|
|
32
|
+
await game.press_a()
|
|
33
|
+
|
|
34
|
+
asyncio.run(main())
|
|
35
|
+
```
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=61.0"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "simplevgpad"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
description = "Simple wrapper around vgamepad for easier controller inputs"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.8"
|
|
11
|
+
|
|
12
|
+
authors = [
|
|
13
|
+
{ name="Jakanon Clenkk" }
|
|
14
|
+
]
|
|
15
|
+
|
|
16
|
+
dependencies = [
|
|
17
|
+
"vgamepad"
|
|
18
|
+
]
|
|
@@ -0,0 +1,806 @@
|
|
|
1
|
+
import vgamepad as vg
|
|
2
|
+
import time
|
|
3
|
+
import asyncio
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
class controller(vg.VX360Gamepad):
|
|
7
|
+
def __init__(self):
|
|
8
|
+
super().__init__()
|
|
9
|
+
|
|
10
|
+
def press_a(self):
|
|
11
|
+
""" Simulates a tap of the 'A' button on the controller """
|
|
12
|
+
self.press_button(vg.XUSB_BUTTON.XUSB_GAMEPAD_A)
|
|
13
|
+
self.update()
|
|
14
|
+
time.sleep(0.05)
|
|
15
|
+
self.release_button(vg.XUSB_BUTTON.XUSB_GAMEPAD_A)
|
|
16
|
+
self.update()
|
|
17
|
+
time.sleep(0.05)
|
|
18
|
+
|
|
19
|
+
def hold_a(self, duration: int):
|
|
20
|
+
""" Simulates holding of the 'A' button on the controller.
|
|
21
|
+
duration: time (in secconds) for how long to hold the input."""
|
|
22
|
+
self.press_button(vg.XUSB_BUTTON.XUSB_GAMEPAD_A)
|
|
23
|
+
self.update()
|
|
24
|
+
time.sleep(duration)
|
|
25
|
+
self.release_button(vg.XUSB_BUTTON.XUSB_GAMEPAD_A)
|
|
26
|
+
self.update()
|
|
27
|
+
time.sleep(0.05)
|
|
28
|
+
|
|
29
|
+
def press_b(self):
|
|
30
|
+
""" Simulates a tap of the 'B' button on the controller """
|
|
31
|
+
self.press_button(vg.XUSB_BUTTON.XUSB_GAMEPAD_B)
|
|
32
|
+
self.update()
|
|
33
|
+
time.sleep(0.05)
|
|
34
|
+
self.release_button(vg.XUSB_BUTTON.XUSB_GAMEPAD_B)
|
|
35
|
+
self.update()
|
|
36
|
+
time.sleep(0.05)
|
|
37
|
+
|
|
38
|
+
def hold_b(self, duration: int):
|
|
39
|
+
""" Simulates holding of the 'B' button on the controller.
|
|
40
|
+
duration: time (in secconds) for how long to hold the input."""
|
|
41
|
+
self.press_button(vg.XUSB_BUTTON.XUSB_GAMEPAD_B)
|
|
42
|
+
self.update()
|
|
43
|
+
time.sleep(duration)
|
|
44
|
+
self.release_button(vg.XUSB_BUTTON.XUSB_GAMEPAD_B)
|
|
45
|
+
self.update()
|
|
46
|
+
time.sleep(0.05)
|
|
47
|
+
|
|
48
|
+
def press_x(self):
|
|
49
|
+
""" Simulates a tap of the 'X' button on the controller """
|
|
50
|
+
self.press_button(vg.XUSB_BUTTON.XUSB_GAMEPAD_X)
|
|
51
|
+
self.update()
|
|
52
|
+
time.sleep(0.05)
|
|
53
|
+
self.release_button(vg.XUSB_BUTTON.XUSB_GAMEPAD_X)
|
|
54
|
+
self.update()
|
|
55
|
+
time.sleep(0.05)
|
|
56
|
+
|
|
57
|
+
def hold_x(self, duration: int):
|
|
58
|
+
""" Simulates holding of the 'X' button on the controller.
|
|
59
|
+
duration: time (in secconds) for how long to hold the input."""
|
|
60
|
+
self.press_button(vg.XUSB_BUTTON.XUSB_GAMEPAD_X)
|
|
61
|
+
self.update()
|
|
62
|
+
time.sleep(duration)
|
|
63
|
+
self.release_button(vg.XUSB_BUTTON.XUSB_GAMEPAD_X)
|
|
64
|
+
self.update()
|
|
65
|
+
time.sleep(0.05)
|
|
66
|
+
|
|
67
|
+
def press_y(self):
|
|
68
|
+
""" Simulates a tap of the 'Y' button on the controller """
|
|
69
|
+
self.press_button(vg.XUSB_BUTTON.XUSB_GAMEPAD_X)
|
|
70
|
+
self.update()
|
|
71
|
+
time.sleep(0.05)
|
|
72
|
+
self.release_button(vg.XUSB_BUTTON.XUSB_GAMEPAD_X)
|
|
73
|
+
self.update()
|
|
74
|
+
time.sleep(0.05)
|
|
75
|
+
|
|
76
|
+
def hold_y(self, duration: int):
|
|
77
|
+
""" Simulates holding of the 'Y' button on the controller.
|
|
78
|
+
duration: time (in secconds) for how long to hold the input."""
|
|
79
|
+
self.press_button(vg.XUSB_BUTTON.XUSB_GAMEPAD_Y)
|
|
80
|
+
self.update()
|
|
81
|
+
time.sleep(duration)
|
|
82
|
+
self.release_button(vg.XUSB_BUTTON.XUSB_GAMEPAD_Y)
|
|
83
|
+
self.update()
|
|
84
|
+
time.sleep(0.05)
|
|
85
|
+
|
|
86
|
+
def dpad_up(self):
|
|
87
|
+
""" Simulates a tap of the 'dpad up' button on the controller."""
|
|
88
|
+
self.press_button(vg.XUSB_BUTTON.XUSB_GAMEPAD_DPAD_UP)
|
|
89
|
+
self.update()
|
|
90
|
+
time.sleep(0.05)
|
|
91
|
+
self.release_button(vg.XUSB_BUTTON.XUSB_GAMEPAD_DPAD_UP)
|
|
92
|
+
self.update()
|
|
93
|
+
time.sleep(0.05)
|
|
94
|
+
|
|
95
|
+
def dpad_down(self):
|
|
96
|
+
""" Simulates a tap of the 'dpad down' button on the controller."""
|
|
97
|
+
self.press_button(vg.XUSB_BUTTON.XUSB_GAMEPAD_DPAD_DOWN)
|
|
98
|
+
self.update()
|
|
99
|
+
time.sleep(0.05)
|
|
100
|
+
self.release_button(vg.XUSB_BUTTON.XUSB_GAMEPAD_DPAD_DOWN)
|
|
101
|
+
self.update()
|
|
102
|
+
time.sleep(0.05)
|
|
103
|
+
|
|
104
|
+
def dpad_left(self):
|
|
105
|
+
""" Simulates a tap of the 'dpad left' button on the controller."""
|
|
106
|
+
self.press_button(vg.XUSB_BUTTON.XUSB_GAMEPAD_DPAD_LEFT)
|
|
107
|
+
self.update()
|
|
108
|
+
time.sleep(0.05)
|
|
109
|
+
self.release_button(vg.XUSB_BUTTON.XUSB_GAMEPAD_DPAD_LEFT)
|
|
110
|
+
self.update()
|
|
111
|
+
time.sleep(0.05)
|
|
112
|
+
|
|
113
|
+
def dpad_right(self):
|
|
114
|
+
""" Simulates a tap of the 'dpad right' button on the controller."""
|
|
115
|
+
self.press_button(vg.XUSB_BUTTON.XUSB_GAMEPAD_DPAD_RIGHT)
|
|
116
|
+
self.update()
|
|
117
|
+
time.sleep(0.05)
|
|
118
|
+
self.release_button(vg.XUSB_BUTTON.XUSB_GAMEPAD_DPAD_RIGHT)
|
|
119
|
+
self.update()
|
|
120
|
+
time.sleep(0.05)
|
|
121
|
+
|
|
122
|
+
def hold_dpad_up(self, duration):
|
|
123
|
+
""" Simulates holding of the 'dpad up' button on the controller.
|
|
124
|
+
duration: time (in secconds) for how long to hold the input."""
|
|
125
|
+
self.press_button(vg.XUSB_BUTTON.XUSB_GAMEPAD_DPAD_UP)
|
|
126
|
+
self.update()
|
|
127
|
+
time.sleep(duration)
|
|
128
|
+
self.release_button(vg.XUSB_BUTTON.XUSB_GAMEPAD_DPAD_UP)
|
|
129
|
+
self.update()
|
|
130
|
+
time.sleep(0.05)
|
|
131
|
+
|
|
132
|
+
def hold_dpad_down(self, duration):
|
|
133
|
+
""" Simulates holding of the 'dpad down' button on the controller.
|
|
134
|
+
duration: time (in secconds) for how long to hold the input."""
|
|
135
|
+
self.press_button(vg.XUSB_BUTTON.XUSB_GAMEPAD_DPAD_DOWN)
|
|
136
|
+
self.update()
|
|
137
|
+
time.sleep(duration)
|
|
138
|
+
self.release_button(vg.XUSB_BUTTON.XUSB_GAMEPAD_DPAD_DOWN)
|
|
139
|
+
self.update()
|
|
140
|
+
time.sleep(0.05)
|
|
141
|
+
|
|
142
|
+
def hold_dpad_left(self, duration):
|
|
143
|
+
""" Simulates holding of the 'dpad left' button on the controller.
|
|
144
|
+
duration: time (in secconds) for how long to hold the input."""
|
|
145
|
+
self.press_button(vg.XUSB_BUTTON.XUSB_GAMEPAD_DPAD_LEFT)
|
|
146
|
+
self.update()
|
|
147
|
+
time.sleep(duration)
|
|
148
|
+
self.release_button(vg.XUSB_BUTTON.XUSB_GAMEPAD_DPAD_LEFT)
|
|
149
|
+
self.update()
|
|
150
|
+
time.sleep(0.05)
|
|
151
|
+
|
|
152
|
+
def hold_dpad_right(self, duration):
|
|
153
|
+
""" Simulates holding of the 'dpad right' button on the controller.
|
|
154
|
+
duration: time (in secconds) for how long to hold the input."""
|
|
155
|
+
self.press_button(vg.XUSB_BUTTON.XUSB_GAMEPAD_DPAD_RIGHT)
|
|
156
|
+
self.update()
|
|
157
|
+
time.sleep(duration)
|
|
158
|
+
self.release_button(vg.XUSB_BUTTON.XUSB_GAMEPAD_DPAD_RIGHT)
|
|
159
|
+
self.update()
|
|
160
|
+
time.sleep(0.05)
|
|
161
|
+
|
|
162
|
+
def press_options(self):
|
|
163
|
+
""" Simulates a tap of the 'options' button on the controller."""
|
|
164
|
+
self.press_button(vg.XUSB_BUTTON.XUSB_GAMEPAD_BACK)
|
|
165
|
+
self.update()
|
|
166
|
+
time.sleep(0.05)
|
|
167
|
+
self.release_button(vg.XUSB_BUTTON.XUSB_GAMEPAD_BACK)
|
|
168
|
+
self.update()
|
|
169
|
+
time.sleep(0.05)
|
|
170
|
+
|
|
171
|
+
def press_left_bumper(self):
|
|
172
|
+
""" Simulates a tap of the 'left bumper' button on the controller."""
|
|
173
|
+
self.press_button(vg.XUSB_BUTTON.XUSB_GAMEPAD_LEFT_SHOULDER)
|
|
174
|
+
self.update()
|
|
175
|
+
time.sleep(0.05)
|
|
176
|
+
self.release_button(vg.XUSB_BUTTON.XUSB_GAMEPAD_LEFT_SHOULDER)
|
|
177
|
+
self.update()
|
|
178
|
+
time.sleep(0.05)
|
|
179
|
+
|
|
180
|
+
def hold_left_bumper(self, duration: int):
|
|
181
|
+
""" Simulates holding of the 'left bumper' button on the controller.
|
|
182
|
+
duration: time (in secconds) for how long to hold the input."""
|
|
183
|
+
self.press_button(vg.XUSB_BUTTON.XUSB_GAMEPAD_LEFT_SHOULDER)
|
|
184
|
+
self.update()
|
|
185
|
+
time.sleep(duration)
|
|
186
|
+
self.release_button(vg.XUSB_BUTTON.XUSB_GAMEPAD_LEFT_SHOULDER)
|
|
187
|
+
self.update()
|
|
188
|
+
time.sleep(0.05)
|
|
189
|
+
|
|
190
|
+
def press_right_bumper(self):
|
|
191
|
+
""" Simulates a tap of the 'right bumper' button on the controller."""
|
|
192
|
+
self.press_button(vg.XUSB_BUTTON.XUSB_GAMEPAD_LEFT_SHOULDER)
|
|
193
|
+
self.update()
|
|
194
|
+
time.sleep(0.05)
|
|
195
|
+
self.release_button(vg.XUSB_BUTTON.XUSB_GAMEPAD_LEFT_SHOULDER)
|
|
196
|
+
self.update()
|
|
197
|
+
time.sleep(0.05)
|
|
198
|
+
|
|
199
|
+
def hold_right_bumper(self, duration: int):
|
|
200
|
+
""" Simulates holding of the 'right bumper' button on the controller.
|
|
201
|
+
duration: time (in secconds) for how long to hold the input."""
|
|
202
|
+
self.press_button(vg.XUSB_BUTTON.XUSB_GAMEPAD_LEFT_SHOULDER)
|
|
203
|
+
self.update()
|
|
204
|
+
time.sleep(duration)
|
|
205
|
+
self.release_button(vg.XUSB_BUTTON.XUSB_GAMEPAD_LEFT_SHOULDER)
|
|
206
|
+
self.update()
|
|
207
|
+
time.sleep(0.05)
|
|
208
|
+
|
|
209
|
+
def press_left_trigger(self):
|
|
210
|
+
""" Simulates a tap of the 'left trigger' button on the controller."""
|
|
211
|
+
self.left_trigger(255)
|
|
212
|
+
self.update()
|
|
213
|
+
time.sleep(0.05)
|
|
214
|
+
self.left_trigger(0)
|
|
215
|
+
self.update()
|
|
216
|
+
time.sleep(0.05)
|
|
217
|
+
|
|
218
|
+
def hold_left_trigger(self, duration: int):
|
|
219
|
+
""" Simulates holding of the 'left trigger' button on the controller.
|
|
220
|
+
duration: time (in secconds) for how long to hold the input."""
|
|
221
|
+
self.left_trigger(255)
|
|
222
|
+
self.update()
|
|
223
|
+
time.sleep(duration)
|
|
224
|
+
self.left_trigger(0)
|
|
225
|
+
self.update()
|
|
226
|
+
time.sleep(0.05)
|
|
227
|
+
|
|
228
|
+
def press_right_trigger(self):
|
|
229
|
+
""" Simulates a tap of the 'right trigger' button on the controller."""
|
|
230
|
+
self.right_trigger(255)
|
|
231
|
+
self.update()
|
|
232
|
+
time.sleep(0.05)
|
|
233
|
+
self.right_trigger(0)
|
|
234
|
+
self.update()
|
|
235
|
+
time.sleep(0.05)
|
|
236
|
+
|
|
237
|
+
def hold_right_trigger(self, duration: int):
|
|
238
|
+
""" Simulates holding of the 'right trigger' button on the controller.
|
|
239
|
+
duration: time (in secconds) for how long to hold the input."""
|
|
240
|
+
self.right_trigger(255)
|
|
241
|
+
self.update()
|
|
242
|
+
time.sleep(duration)
|
|
243
|
+
self.right_trigger(0)
|
|
244
|
+
self.update()
|
|
245
|
+
time.sleep(0.05)
|
|
246
|
+
|
|
247
|
+
def left_joystick_up(self, duration: int):
|
|
248
|
+
""" Simulates holding of the 'left joystick' on the controller upwards.
|
|
249
|
+
duration: time (in secconds) for how long to hold the input."""
|
|
250
|
+
self.left_joystick_float(0.0, 1.0)
|
|
251
|
+
self.update()
|
|
252
|
+
time.sleep(duration)
|
|
253
|
+
self.left_joystick_float(0.0, 0.0)
|
|
254
|
+
self.update()
|
|
255
|
+
time.sleep(0.05)
|
|
256
|
+
|
|
257
|
+
def left_joystick_down(self, duration: int):
|
|
258
|
+
""" Simulates holding of the 'left joystick' on the controller downwards.
|
|
259
|
+
duration: time (in secconds) for how long to hold the input."""
|
|
260
|
+
self.left_joystick_float(0.0, -1.0)
|
|
261
|
+
self.update()
|
|
262
|
+
time.sleep(duration)
|
|
263
|
+
self.left_joystick_float(0.0, 0.0)
|
|
264
|
+
self.update()
|
|
265
|
+
time.sleep(0.05)
|
|
266
|
+
|
|
267
|
+
def left_joystick_right(self, duration: int):
|
|
268
|
+
""" Simulates holding of the 'left joystick' on the controller to the right.
|
|
269
|
+
duration: time (in secconds) for how long to hold the input."""
|
|
270
|
+
self.left_joystick_float(1.0, 0.0)
|
|
271
|
+
self.update()
|
|
272
|
+
time.sleep(duration)
|
|
273
|
+
self.left_joystick_float(0.0, 0.0)
|
|
274
|
+
self.update()
|
|
275
|
+
time.sleep(0.05)
|
|
276
|
+
|
|
277
|
+
def left_joystick_left(self, duration: int):
|
|
278
|
+
""" Simulates holding of the 'left joystick' on the controller to the left.
|
|
279
|
+
duration: time (in secconds) for how long to hold the input."""
|
|
280
|
+
self.left_joystick_float(-1.0, 0.0)
|
|
281
|
+
self.update()
|
|
282
|
+
time.sleep(duration)
|
|
283
|
+
self.left_joystick_float(0.0, 0.0)
|
|
284
|
+
self.update()
|
|
285
|
+
time.sleep(0.05)
|
|
286
|
+
|
|
287
|
+
def left_joystick_custom(self, x_axis: float, y_axis: float, duration: int):
|
|
288
|
+
""" Simulates moving of the 'left joystick' on the controller.\n
|
|
289
|
+
duration: time (in secconds) for how long to hold the input.\n
|
|
290
|
+
x_axis: float value range -1.0 to 1.0 to set x axis, 0 is resting position.\n
|
|
291
|
+
y_axis: float value range -1.0 to 1.0 to set y axis, 0 is resting position."""
|
|
292
|
+
if x_axis < -1.0 or x_axis > 1.0 or y_axis < -1.0 or y_axis > 1.0:
|
|
293
|
+
print(f"Custom joystick value error:\nValue of x_axis and y_axis must be between -1.0 and 1.0\nGot: x_axis: {x_axis} | y_axis: {y_axis}")
|
|
294
|
+
return
|
|
295
|
+
self.left_joystick_float(-1.0, 0.0)
|
|
296
|
+
self.update()
|
|
297
|
+
time.sleep(duration)
|
|
298
|
+
self.left_joystick_float(0.0, 0.0)
|
|
299
|
+
self.update()
|
|
300
|
+
time.sleep(0.05)
|
|
301
|
+
|
|
302
|
+
def right_joystick_up(self, duration: int):
|
|
303
|
+
""" Simulates holding of the 'right joystick' on the controller upwards.
|
|
304
|
+
duration: time (in secconds) for how long to hold the input."""
|
|
305
|
+
self.right_joystick_float(0.0, 1.0)
|
|
306
|
+
self.update()
|
|
307
|
+
time.sleep(duration)
|
|
308
|
+
self.right_joystick_float(0.0, 0.0)
|
|
309
|
+
self.update()
|
|
310
|
+
time.sleep(0.05)
|
|
311
|
+
|
|
312
|
+
def right_joystick_down(self, duration: int):
|
|
313
|
+
""" Simulates holding of the 'right joystick' on the controller downwards.
|
|
314
|
+
duration: time (in secconds) for how long to hold the input."""
|
|
315
|
+
self.right_joystick_float(0.0, -1.0)
|
|
316
|
+
self.update()
|
|
317
|
+
time.sleep(duration)
|
|
318
|
+
self.right_joystick_float(0.0, 0.0)
|
|
319
|
+
self.update()
|
|
320
|
+
time.sleep(0.05)
|
|
321
|
+
|
|
322
|
+
def right_joystick_right(self, duration: int):
|
|
323
|
+
""" Simulates holding of the 'right joystick' on the controller to the right.
|
|
324
|
+
duration: time (in secconds) for how long to hold the input."""
|
|
325
|
+
self.right_joystick_float(1.0, 0.0)
|
|
326
|
+
self.update()
|
|
327
|
+
time.sleep(duration)
|
|
328
|
+
self.right_joystick_float(0.0, 0.0)
|
|
329
|
+
self.update()
|
|
330
|
+
time.sleep(0.05)
|
|
331
|
+
|
|
332
|
+
def right_joystick_left(self, duration: int):
|
|
333
|
+
""" Simulates holding of the 'right joystick' on the controller to the right.
|
|
334
|
+
duration: time (in secconds) for how long to hold the input."""
|
|
335
|
+
self.right_joystick_float(-1.0, 0.0)
|
|
336
|
+
self.update()
|
|
337
|
+
time.sleep(duration)
|
|
338
|
+
self.right_joystick_float(0.0, 0.0)
|
|
339
|
+
self.update()
|
|
340
|
+
time.sleep(0.05)
|
|
341
|
+
|
|
342
|
+
def right_joystick_custom(self, x_axis: float, y_axis: float, duration: int):
|
|
343
|
+
""" Simulates moving of the 'right joystick' on the controller.\n
|
|
344
|
+
duration: time (in secconds) for how long to hold the input.\n
|
|
345
|
+
x_axis: float value range -1.0 to 1.0 to set x axis, 0 is resting position.\n
|
|
346
|
+
y_axis: float value range -1.0 to 1.0 to set y axis, 0 is resting position."""
|
|
347
|
+
if x_axis < -1.0 or x_axis > 1.0 or y_axis < -1.0 or y_axis > 1.0:
|
|
348
|
+
print(f"Custom joystick value error:\nValue of x_axis and y_axis must be between -1.0 and 1.0\nGot: x_axis: {x_axis} | y_axis: {y_axis}")
|
|
349
|
+
return
|
|
350
|
+
self.right_joystick_float(-1.0, 0.0)
|
|
351
|
+
self.update()
|
|
352
|
+
time.sleep(duration)
|
|
353
|
+
self.right_joystick_float(0.0, 0.0)
|
|
354
|
+
self.update()
|
|
355
|
+
time.sleep(0.05)
|
|
356
|
+
|
|
357
|
+
def press_left_thumb(self):
|
|
358
|
+
""" Simulates a tap of the 'left joystick' button on the controller."""
|
|
359
|
+
self.press_button(vg.XUSB_BUTTON.XUSB_GAMEPAD_LEFT_THUMB)
|
|
360
|
+
time.sleep(0.05)
|
|
361
|
+
self.release_button(vg.XUSB_BUTTON.XUSB_GAMEPAD_LEFT_THUMB)
|
|
362
|
+
time.sleep(0.05)
|
|
363
|
+
|
|
364
|
+
def hold_left_thumb(self, duration):
|
|
365
|
+
""" Simulates a holding of the 'left joystick' button on the controller.
|
|
366
|
+
duration: time (in secconds) for how long to hold the input."""
|
|
367
|
+
self.press_button(vg.XUSB_BUTTON.XUSB_GAMEPAD_LEFT_THUMB)
|
|
368
|
+
self.update()
|
|
369
|
+
time.sleep(duration)
|
|
370
|
+
self.release_button(vg.XUSB_BUTTON.XUSB_GAMEPAD_LEFT_THUMB)
|
|
371
|
+
self.update()
|
|
372
|
+
time.sleep(0.05)
|
|
373
|
+
|
|
374
|
+
def press_right_thumb(self):
|
|
375
|
+
""" Simulates a tap of the 'right joystick' button on the controller."""
|
|
376
|
+
self.press_button(vg.XUSB_BUTTON.XUSB_GAMEPAD_RIGHT_THUMB)
|
|
377
|
+
time.sleep(0.05)
|
|
378
|
+
self.release_button(vg.XUSB_BUTTON.XUSB_GAMEPAD_RIGHT_THUMB)
|
|
379
|
+
time.sleep(0.05)
|
|
380
|
+
|
|
381
|
+
def hold_right_thumb(self, duration):
|
|
382
|
+
""" Simulates holding of the 'right joystick' button on the controller.
|
|
383
|
+
duration: time (in secconds) for how long to hold the input."""
|
|
384
|
+
self.press_button(vg.XUSB_BUTTON.XUSB_GAMEPAD_RIGHT_THUMB)
|
|
385
|
+
self.update()
|
|
386
|
+
time.sleep(duration)
|
|
387
|
+
self.release_button(vg.XUSB_BUTTON.XUSB_GAMEPAD_RIGHT_THUMB)
|
|
388
|
+
self.update()
|
|
389
|
+
time.sleep(0.05)
|
|
390
|
+
|
|
391
|
+
|
|
392
|
+
class controller_async(vg.VX360Gamepad):
|
|
393
|
+
def __init__(self):
|
|
394
|
+
super().__init__()
|
|
395
|
+
self.movement_count = 0
|
|
396
|
+
|
|
397
|
+
async def press_a(self):
|
|
398
|
+
""" Simulates a tap of the 'A' button on the controller """
|
|
399
|
+
self.press_button(vg.XUSB_BUTTON.XUSB_GAMEPAD_A)
|
|
400
|
+
self.update()
|
|
401
|
+
await asyncio.sleep(0.05)
|
|
402
|
+
self.release_button(vg.XUSB_BUTTON.XUSB_GAMEPAD_A)
|
|
403
|
+
self.update()
|
|
404
|
+
|
|
405
|
+
async def hold_a(self, duration: int):
|
|
406
|
+
""" Simulates holding of the 'A' button on the controller.
|
|
407
|
+
duration: time (in secconds) for how long to hold the input."""
|
|
408
|
+
self.press_button(vg.XUSB_BUTTON.XUSB_GAMEPAD_A)
|
|
409
|
+
self.update()
|
|
410
|
+
await asyncio.sleep(duration)
|
|
411
|
+
self.release_button(vg.XUSB_BUTTON.XUSB_GAMEPAD_A)
|
|
412
|
+
self.update()
|
|
413
|
+
|
|
414
|
+
async def press_b(self):
|
|
415
|
+
""" Simulates a tap of the 'B' button on the controller """
|
|
416
|
+
self.press_button(vg.XUSB_BUTTON.XUSB_GAMEPAD_B)
|
|
417
|
+
self.update()
|
|
418
|
+
await asyncio.sleep(0.05)
|
|
419
|
+
self.release_button(vg.XUSB_BUTTON.XUSB_GAMEPAD_B)
|
|
420
|
+
self.update()
|
|
421
|
+
|
|
422
|
+
async def hold_b(self, duration: int):
|
|
423
|
+
""" Simulates holding of the 'B' button on the controller.
|
|
424
|
+
duration: time (in secconds) for how long to hold the input."""
|
|
425
|
+
self.press_button(vg.XUSB_BUTTON.XUSB_GAMEPAD_B)
|
|
426
|
+
self.update()
|
|
427
|
+
await asyncio.sleep(duration)
|
|
428
|
+
self.release_button(vg.XUSB_BUTTON.XUSB_GAMEPAD_B)
|
|
429
|
+
self.update()
|
|
430
|
+
|
|
431
|
+
async def press_x(self):
|
|
432
|
+
""" Simulates a tap of the 'X' button on the controller """
|
|
433
|
+
self.press_button(vg.XUSB_BUTTON.XUSB_GAMEPAD_X)
|
|
434
|
+
self.update()
|
|
435
|
+
await asyncio.sleep(0.05)
|
|
436
|
+
self.release_button(vg.XUSB_BUTTON.XUSB_GAMEPAD_X)
|
|
437
|
+
self.update()
|
|
438
|
+
|
|
439
|
+
async def hold_x(self, duration: int):
|
|
440
|
+
""" Simulates holding of the 'X' button on the controller.
|
|
441
|
+
duration: time (in secconds) for how long to hold the input."""
|
|
442
|
+
self.press_button(vg.XUSB_BUTTON.XUSB_GAMEPAD_X)
|
|
443
|
+
self.update()
|
|
444
|
+
await asyncio.sleep(duration)
|
|
445
|
+
self.release_button(vg.XUSB_BUTTON.XUSB_GAMEPAD_X)
|
|
446
|
+
self.update()
|
|
447
|
+
|
|
448
|
+
async def press_y(self):
|
|
449
|
+
""" Simulates a tap of the 'Y' button on the controller """
|
|
450
|
+
self.press_button(vg.XUSB_BUTTON.XUSB_GAMEPAD_Y)
|
|
451
|
+
self.update()
|
|
452
|
+
await asyncio.sleep(0.05)
|
|
453
|
+
self.release_button(vg.XUSB_BUTTON.XUSB_GAMEPAD_Y)
|
|
454
|
+
self.update()
|
|
455
|
+
|
|
456
|
+
async def hold_y(self, duration: int):
|
|
457
|
+
""" Simulates holding of the 'Y' button on the controller.
|
|
458
|
+
duration: time (in secconds) for how long to hold the input."""
|
|
459
|
+
self.press_button(vg.XUSB_BUTTON.XUSB_GAMEPAD_Y)
|
|
460
|
+
self.update()
|
|
461
|
+
await asyncio.sleep(duration)
|
|
462
|
+
self.release_button(vg.XUSB_BUTTON.XUSB_GAMEPAD_Y)
|
|
463
|
+
self.update()
|
|
464
|
+
|
|
465
|
+
async def dpad_up(self):
|
|
466
|
+
""" Simulates a tap of the 'dpad up' button on the controller."""
|
|
467
|
+
self.press_button(vg.XUSB_BUTTON.XUSB_GAMEPAD_DPAD_UP)
|
|
468
|
+
self.update()
|
|
469
|
+
await asyncio.sleep(0.05)
|
|
470
|
+
self.release_button(vg.XUSB_BUTTON.XUSB_GAMEPAD_DPAD_UP)
|
|
471
|
+
self.update()
|
|
472
|
+
|
|
473
|
+
async def dpad_down(self):
|
|
474
|
+
""" Simulates a tap of the 'dpad down' button on the controller."""
|
|
475
|
+
self.press_button(vg.XUSB_BUTTON.XUSB_GAMEPAD_DPAD_DOWN)
|
|
476
|
+
self.update()
|
|
477
|
+
await asyncio.sleep(0.05)
|
|
478
|
+
self.release_button(vg.XUSB_BUTTON.XUSB_GAMEPAD_DPAD_DOWN)
|
|
479
|
+
self.update()
|
|
480
|
+
|
|
481
|
+
async def dpad_left(self):
|
|
482
|
+
""" Simulates a tap of the 'dpad left' button on the controller."""
|
|
483
|
+
self.press_button(vg.XUSB_BUTTON.XUSB_GAMEPAD_DPAD_LEFT)
|
|
484
|
+
self.update()
|
|
485
|
+
await asyncio.sleep(0.05)
|
|
486
|
+
self.release_button(vg.XUSB_BUTTON.XUSB_GAMEPAD_DPAD_LEFT)
|
|
487
|
+
self.update()
|
|
488
|
+
|
|
489
|
+
async def dpad_right(self):
|
|
490
|
+
""" Simulates a tap of the 'dpad right' button on the controller."""
|
|
491
|
+
self.press_button(vg.XUSB_BUTTON.XUSB_GAMEPAD_DPAD_RIGHT)
|
|
492
|
+
self.update()
|
|
493
|
+
await asyncio.sleep(0.05)
|
|
494
|
+
self.release_button(vg.XUSB_BUTTON.XUSB_GAMEPAD_DPAD_RIGHT)
|
|
495
|
+
self.update()
|
|
496
|
+
|
|
497
|
+
async def hold_dpad_up(self, duration):
|
|
498
|
+
""" Simulates holding of the 'dpad up' button on the controller.
|
|
499
|
+
duration: time (in secconds) for how long to hold the input."""
|
|
500
|
+
self.press_button(vg.XUSB_BUTTON.XUSB_GAMEPAD_DPAD_UP)
|
|
501
|
+
self.update()
|
|
502
|
+
await asyncio.sleep(duration)
|
|
503
|
+
self.release_button(vg.XUSB_BUTTON.XUSB_GAMEPAD_DPAD_UP)
|
|
504
|
+
self.update()
|
|
505
|
+
|
|
506
|
+
async def hold_dpad_down(self, duration):
|
|
507
|
+
""" Simulates holding of the 'dpad down' button on the controller.
|
|
508
|
+
duration: time (in secconds) for how long to hold the input."""
|
|
509
|
+
self.press_button(vg.XUSB_BUTTON.XUSB_GAMEPAD_DPAD_DOWN)
|
|
510
|
+
self.update()
|
|
511
|
+
await asyncio.sleep(duration)
|
|
512
|
+
self.release_button(vg.XUSB_BUTTON.XUSB_GAMEPAD_DPAD_DOWN)
|
|
513
|
+
self.update()
|
|
514
|
+
|
|
515
|
+
async def hold_dpad_left(self, duration):
|
|
516
|
+
""" Simulates holding of the 'dpad left' button on the controller.
|
|
517
|
+
duration: time (in secconds) for how long to hold the input."""
|
|
518
|
+
self.press_button(vg.XUSB_BUTTON.XUSB_GAMEPAD_DPAD_LEFT)
|
|
519
|
+
self.update()
|
|
520
|
+
await asyncio.sleep(duration)
|
|
521
|
+
self.release_button(vg.XUSB_BUTTON.XUSB_GAMEPAD_DPAD_LEFT)
|
|
522
|
+
self.update()
|
|
523
|
+
|
|
524
|
+
async def hold_dpad_right(self, duration):
|
|
525
|
+
""" Simulates holding of the 'dpad right' button on the controller.
|
|
526
|
+
duration: time (in secconds) for how long to hold the input."""
|
|
527
|
+
self.press_button(vg.XUSB_BUTTON.XUSB_GAMEPAD_DPAD_RIGHT)
|
|
528
|
+
self.update()
|
|
529
|
+
await asyncio.sleep(duration)
|
|
530
|
+
self.release_button(vg.XUSB_BUTTON.XUSB_GAMEPAD_DPAD_RIGHT)
|
|
531
|
+
self.update()
|
|
532
|
+
|
|
533
|
+
async def press_options(self):
|
|
534
|
+
""" Simulates a tap of the 'options' button on the controller."""
|
|
535
|
+
self.press_button(vg.XUSB_BUTTON.XUSB_GAMEPAD_BACK)
|
|
536
|
+
self.update()
|
|
537
|
+
await asyncio.sleep(0.05)
|
|
538
|
+
self.release_button(vg.XUSB_BUTTON.XUSB_GAMEPAD_BACK)
|
|
539
|
+
self.update()
|
|
540
|
+
|
|
541
|
+
async def press_left_bumper(self):
|
|
542
|
+
""" Simulates a tap of the 'left bumper' button on the controller."""
|
|
543
|
+
self.press_button(vg.XUSB_BUTTON.XUSB_GAMEPAD_LEFT_SHOULDER)
|
|
544
|
+
self.update()
|
|
545
|
+
await asyncio.sleep(0.05)
|
|
546
|
+
self.release_button(vg.XUSB_BUTTON.XUSB_GAMEPAD_LEFT_SHOULDER)
|
|
547
|
+
self.update()
|
|
548
|
+
|
|
549
|
+
async def hold_left_bumper(self, duration: int):
|
|
550
|
+
""" Simulates holding of the 'left bumper' button on the controller.
|
|
551
|
+
duration: time (in secconds) for how long to hold the input."""
|
|
552
|
+
self.press_button(vg.XUSB_BUTTON.XUSB_GAMEPAD_LEFT_SHOULDER)
|
|
553
|
+
self.update()
|
|
554
|
+
await asyncio.sleep(duration)
|
|
555
|
+
self.release_button(vg.XUSB_BUTTON.XUSB_GAMEPAD_LEFT_SHOULDER)
|
|
556
|
+
self.update()
|
|
557
|
+
|
|
558
|
+
async def press_right_bumper(self):
|
|
559
|
+
""" Simulates a tap of the 'right bumper' button on the controller."""
|
|
560
|
+
self.press_button(vg.XUSB_BUTTON.XUSB_GAMEPAD_RIGHT_SHOULDER)
|
|
561
|
+
self.update()
|
|
562
|
+
await asyncio.sleep(0.05)
|
|
563
|
+
self.release_button(vg.XUSB_BUTTON.XUSB_GAMEPAD_RIGHT_SHOULDER)
|
|
564
|
+
self.update()
|
|
565
|
+
|
|
566
|
+
async def hold_right_bumper(self, duration: int):
|
|
567
|
+
""" Simulates holding of the 'right bumper' button on the controller.
|
|
568
|
+
duration: time (in secconds) for how long to hold the input."""
|
|
569
|
+
self.press_button(vg.XUSB_BUTTON.XUSB_GAMEPAD_RIGHT_SHOULDER)
|
|
570
|
+
self.update()
|
|
571
|
+
await asyncio.sleep(duration)
|
|
572
|
+
self.release_button(vg.XUSB_BUTTON.XUSB_GAMEPAD_RIGHT_SHOULDER)
|
|
573
|
+
self.update()
|
|
574
|
+
|
|
575
|
+
async def press_left_trigger(self):
|
|
576
|
+
""" Simulates a tap of the 'left trigger' button on the controller."""
|
|
577
|
+
self.left_trigger(255)
|
|
578
|
+
self.update()
|
|
579
|
+
await asyncio.sleep(0.05)
|
|
580
|
+
self.left_trigger(0)
|
|
581
|
+
self.update()
|
|
582
|
+
|
|
583
|
+
async def hold_left_trigger(self, duration: int):
|
|
584
|
+
""" Simulates holding of the 'left trigger' button on the controller.
|
|
585
|
+
duration: time (in secconds) for how long to hold the input."""
|
|
586
|
+
self.left_trigger(255)
|
|
587
|
+
self.update()
|
|
588
|
+
await asyncio.sleep(duration)
|
|
589
|
+
self.left_trigger(0)
|
|
590
|
+
self.update()
|
|
591
|
+
|
|
592
|
+
async def press_right_trigger(self):
|
|
593
|
+
""" Simulates a tap of the 'right trigger' button on the controller."""
|
|
594
|
+
self.right_trigger(255)
|
|
595
|
+
self.update()
|
|
596
|
+
await asyncio.sleep(0.05)
|
|
597
|
+
self.right_trigger(0)
|
|
598
|
+
self.update()
|
|
599
|
+
|
|
600
|
+
async def hold_right_trigger(self, duration: int):
|
|
601
|
+
""" Simulates holding of the 'right trigger' button on the controller.
|
|
602
|
+
duration: time (in secconds) for how long to hold the input."""
|
|
603
|
+
self.right_trigger(255)
|
|
604
|
+
self.update()
|
|
605
|
+
await asyncio.sleep(duration)
|
|
606
|
+
self.right_trigger(0)
|
|
607
|
+
self.update()
|
|
608
|
+
|
|
609
|
+
async def left_joystick_up(self, duration: int):
|
|
610
|
+
""" Simulates holding of the 'left joystick' on the controller upwards.
|
|
611
|
+
duration: time (in secconds) for how long to hold the input."""
|
|
612
|
+
self.movement_count += 1
|
|
613
|
+
current_movement = self.movement_count
|
|
614
|
+
self.left_joystick_float(0.0, 1.0)
|
|
615
|
+
self.update()
|
|
616
|
+
await asyncio.sleep(duration)
|
|
617
|
+
if self.movement_count == current_movement:
|
|
618
|
+
self.left_joystick_float(0.0, 0.0)
|
|
619
|
+
self.update()
|
|
620
|
+
|
|
621
|
+
async def left_joystick_down(self, duration: int):
|
|
622
|
+
""" Simulates holding of the 'left joystick' on the controller downwards.
|
|
623
|
+
duration: time (in secconds) for how long to hold the input."""
|
|
624
|
+
self.movement_count += 1
|
|
625
|
+
current_movement = self.movement_count
|
|
626
|
+
self.left_joystick_float(0.0, -1.0)
|
|
627
|
+
self.update()
|
|
628
|
+
await asyncio.sleep(duration)
|
|
629
|
+
if self.movement_count == current_movement:
|
|
630
|
+
self.left_joystick_float(0.0, 0.0)
|
|
631
|
+
self.update()
|
|
632
|
+
|
|
633
|
+
async def left_joystick_right(self, duration: int):
|
|
634
|
+
""" Simulates holding of the 'left joystick' on the controller to the right.
|
|
635
|
+
duration: time (in secconds) for how long to hold the input."""
|
|
636
|
+
self.movement_count += 1
|
|
637
|
+
current_movement = self.movement_count
|
|
638
|
+
self.left_joystick_float(1.0, 0.0)
|
|
639
|
+
self.update()
|
|
640
|
+
await asyncio.sleep(duration)
|
|
641
|
+
if self.movement_count == current_movement:
|
|
642
|
+
self.left_joystick_float(0.0, 0.0)
|
|
643
|
+
self.update()
|
|
644
|
+
|
|
645
|
+
async def left_joystick_left(self, duration: int):
|
|
646
|
+
""" Simulates holding of the 'left joystick' on the controller to the left.
|
|
647
|
+
duration: time (in secconds) for how long to hold the input."""
|
|
648
|
+
self.movement_count += 1
|
|
649
|
+
current_movement = self.movement_count
|
|
650
|
+
self.left_joystick_float(-1.0, 0.0)
|
|
651
|
+
self.update()
|
|
652
|
+
await asyncio.sleep(duration)
|
|
653
|
+
if self.movement_count == current_movement:
|
|
654
|
+
self.left_joystick_float(0.0, 0.0)
|
|
655
|
+
self.update()
|
|
656
|
+
|
|
657
|
+
async def left_joystick_custom(self, x_axis: float, y_axis: float, duration: int):
|
|
658
|
+
""" Simulates moving of the 'left joystick' on the controller.\n
|
|
659
|
+
duration: time (in secconds) for how long to hold the input.\n
|
|
660
|
+
x_axis: float value range -1.0 to 1.0 to set x axis, 0 is resting position.\n
|
|
661
|
+
y_axis: float value range -1.0 to 1.0 to set y axis, 0 is resting position."""
|
|
662
|
+
self.movement_count += 1
|
|
663
|
+
current_movement = self.movement_count
|
|
664
|
+
if not (-1.0 <= x_axis <= 1.0 and -1.0 <= y_axis <= 1.0):
|
|
665
|
+
print(f"Custom joystick value error:\nGot x_axis={x_axis}, y_axis={y_axis}")
|
|
666
|
+
return
|
|
667
|
+
self.left_joystick_float(x_axis, y_axis)
|
|
668
|
+
self.update()
|
|
669
|
+
await asyncio.sleep(duration)
|
|
670
|
+
if self.movement_count == current_movement:
|
|
671
|
+
self.left_joystick_float(0.0, 0.0)
|
|
672
|
+
self.update()
|
|
673
|
+
|
|
674
|
+
async def right_joystick_up(self, duration: int):
|
|
675
|
+
""" Simulates holding of the 'right joystick' on the controller upwards.
|
|
676
|
+
duration: time (in secconds) for how long to hold the input."""
|
|
677
|
+
self.movement_count += 1
|
|
678
|
+
current_movement = self.movement_count
|
|
679
|
+
self.right_joystick_float(0.0, 1.0)
|
|
680
|
+
self.update()
|
|
681
|
+
await asyncio.sleep(duration)
|
|
682
|
+
if self.movement_count == current_movement:
|
|
683
|
+
self.right_joystick_float(0.0, 0.0)
|
|
684
|
+
self.update()
|
|
685
|
+
|
|
686
|
+
async def right_joystick_down(self, duration: int):
|
|
687
|
+
""" Simulates holding of the 'right joystick' on the controller downwards.
|
|
688
|
+
duration: time (in secconds) for how long to hold the input."""
|
|
689
|
+
self.movement_count += 1
|
|
690
|
+
current_movement = self.movement_count
|
|
691
|
+
self.right_joystick_float(0.0, -1.0)
|
|
692
|
+
self.update()
|
|
693
|
+
await asyncio.sleep(duration)
|
|
694
|
+
if self.movement_count == current_movement:
|
|
695
|
+
self.right_joystick_float(0.0, 0.0)
|
|
696
|
+
self.update()
|
|
697
|
+
|
|
698
|
+
async def right_joystick_right(self, duration: int):
|
|
699
|
+
""" Simulates holding of the 'right joystick' on the controller to the right.
|
|
700
|
+
duration: time (in secconds) for how long to hold the input."""
|
|
701
|
+
self.movement_count += 1
|
|
702
|
+
current_movement = self.movement_count
|
|
703
|
+
self.right_joystick_float(1.0, 0.0)
|
|
704
|
+
self.update()
|
|
705
|
+
await asyncio.sleep(duration)
|
|
706
|
+
if self.movement_count == current_movement:
|
|
707
|
+
self.right_joystick_float(0.0, 0.0)
|
|
708
|
+
self.update()
|
|
709
|
+
|
|
710
|
+
async def right_joystick_left(self, duration: int):
|
|
711
|
+
""" Simulates holding of the 'right joystick' on the controller to the right.
|
|
712
|
+
duration: time (in secconds) for how long to hold the input."""
|
|
713
|
+
self.movement_count += 1
|
|
714
|
+
current_movement = self.movement_count
|
|
715
|
+
self.right_joystick_float(-1.0, 0.0)
|
|
716
|
+
self.update()
|
|
717
|
+
await asyncio.sleep(duration)
|
|
718
|
+
if self.movement_count == current_movement:
|
|
719
|
+
self.right_joystick_float(0.0, 0.0)
|
|
720
|
+
self.update()
|
|
721
|
+
|
|
722
|
+
async def right_joystick_custom(self, x_axis: float, y_axis: float, duration: int):
|
|
723
|
+
""" Simulates moving of the 'right joystick' on the controller.\n
|
|
724
|
+
duration: time (in secconds) for how long to hold the input.\n
|
|
725
|
+
x_axis: float value range -1.0 to 1.0 to set x axis, 0 is resting position.\n
|
|
726
|
+
y_axis: float value range -1.0 to 1.0 to set y axis, 0 is resting position."""
|
|
727
|
+
self.movement_count += 1
|
|
728
|
+
current_movement = self.movement_count
|
|
729
|
+
if not (-1.0 <= x_axis <= 1.0 and -1.0 <= y_axis <= 1.0):
|
|
730
|
+
print(f"Custom joystick value error:\nGot x_axis={x_axis}, y_axis={y_axis}")
|
|
731
|
+
return
|
|
732
|
+
self.right_joystick_float(x_axis, y_axis)
|
|
733
|
+
self.update()
|
|
734
|
+
await asyncio.sleep(duration)
|
|
735
|
+
if self.movement_count == current_movement:
|
|
736
|
+
self.right_joystick_float(0.0, 0.0)
|
|
737
|
+
self.update()
|
|
738
|
+
|
|
739
|
+
async def press_left_thumb(self):
|
|
740
|
+
""" Simulates a tap of the 'left joystick' button on the controller."""
|
|
741
|
+
self.press_button(vg.XUSB_BUTTON.XUSB_GAMEPAD_LEFT_THUMB)
|
|
742
|
+
self.update()
|
|
743
|
+
await asyncio.sleep(0.05)
|
|
744
|
+
self.release_button(vg.XUSB_BUTTON.XUSB_GAMEPAD_LEFT_THUMB)
|
|
745
|
+
self.update()
|
|
746
|
+
|
|
747
|
+
async def press_right_thumb(self):
|
|
748
|
+
""" Simulates a tap of the 'right joystick' button on the controller."""
|
|
749
|
+
self.press_button(vg.XUSB_BUTTON.XUSB_GAMEPAD_RIGHT_THUMB)
|
|
750
|
+
self.update()
|
|
751
|
+
await asyncio.sleep(0.05)
|
|
752
|
+
self.release_button(vg.XUSB_BUTTON.XUSB_GAMEPAD_RIGHT_THUMB)
|
|
753
|
+
self.update()
|
|
754
|
+
|
|
755
|
+
async def hold_left_thumb(self, duration):
|
|
756
|
+
""" Simulates a holding of the 'left joystick' button on the controller.
|
|
757
|
+
duration: time (in secconds) for how long to hold the input."""
|
|
758
|
+
self.press_button(vg.XUSB_BUTTON.XUSB_GAMEPAD_LEFT_THUMB)
|
|
759
|
+
self.update()
|
|
760
|
+
await asyncio.sleep(duration)
|
|
761
|
+
self.release_button(vg.XUSB_BUTTON.XUSB_GAMEPAD_LEFT_THUMB)
|
|
762
|
+
self.update()
|
|
763
|
+
|
|
764
|
+
async def hold_right_thumb(self, duration):
|
|
765
|
+
""" Simulates holding of the 'right joystick' button on the controller.
|
|
766
|
+
duration: time (in secconds) for how long to hold the input."""
|
|
767
|
+
self.press_button(vg.XUSB_BUTTON.XUSB_GAMEPAD_RIGHT_THUMB)
|
|
768
|
+
self.update()
|
|
769
|
+
await asyncio.sleep(duration)
|
|
770
|
+
self.release_button(vg.XUSB_BUTTON.XUSB_GAMEPAD_RIGHT_THUMB)
|
|
771
|
+
self.update()
|
|
772
|
+
|
|
773
|
+
async def press_menu(self):
|
|
774
|
+
""" Simulates a tap of the 'options' button on the controller."""
|
|
775
|
+
self.press_button(vg.XUSB_BUTTON.XUSB_GAMEPAD_START)
|
|
776
|
+
self.update()
|
|
777
|
+
await asyncio.sleep(0.05)
|
|
778
|
+
self.release_button(vg.XUSB_BUTTON.XUSB_GAMEPAD_START)
|
|
779
|
+
self.update()
|
|
780
|
+
|
|
781
|
+
|
|
782
|
+
if __name__ == "__main__":
|
|
783
|
+
|
|
784
|
+
# Minimal working asynchronous example
|
|
785
|
+
|
|
786
|
+
def execute_async(command): #this is non-blocking
|
|
787
|
+
asyncio.create_task(command)
|
|
788
|
+
|
|
789
|
+
async def main():
|
|
790
|
+
execute_async(game.left_joystick_up(20))
|
|
791
|
+
execute_async(game.hold_dpad_up(3))
|
|
792
|
+
await asyncio.sleep(3)
|
|
793
|
+
execute_async(game.hold_dpad_down(3))
|
|
794
|
+
await asyncio.sleep(3)
|
|
795
|
+
execute_async(game.hold_dpad_left(3))
|
|
796
|
+
await asyncio.sleep(3)
|
|
797
|
+
execute_async(game.hold_dpad_right(3))
|
|
798
|
+
await asyncio.sleep(3)
|
|
799
|
+
execute_async(game.hold_left_thumb(3))
|
|
800
|
+
await asyncio.sleep(3)
|
|
801
|
+
execute_async(game.hold_right_thumb(3))
|
|
802
|
+
await asyncio.sleep(3)
|
|
803
|
+
|
|
804
|
+
time.sleep(5)
|
|
805
|
+
game = controller_async()
|
|
806
|
+
asyncio.run(main())
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: simplevgpad
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Simple wrapper around vgamepad for easier controller inputs
|
|
5
|
+
Author: Jakanon Clenkk
|
|
6
|
+
Requires-Python: >=3.8
|
|
7
|
+
Description-Content-Type: text/markdown
|
|
8
|
+
Requires-Dist: vgamepad
|
|
9
|
+
|
|
10
|
+
# simplevgpad
|
|
11
|
+
|
|
12
|
+
A Python helper library for simplified Xbox controller input using vgamepad.
|
|
13
|
+
|
|
14
|
+
Defines 2 classes which inherit the vgamepad.VX360Gamepad class, and adds methods to
|
|
15
|
+
slightly simplify controller input simulation for simple projects.
|
|
16
|
+
|
|
17
|
+
## Installation
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
pip install simplevgpad
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
## Examples
|
|
24
|
+
|
|
25
|
+
### controller
|
|
26
|
+
```py
|
|
27
|
+
from simplevgpad import controller
|
|
28
|
+
|
|
29
|
+
game = controller()
|
|
30
|
+
game.press_a()
|
|
31
|
+
game.hold_left_trigger(2)
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
### controller_async
|
|
35
|
+
```py
|
|
36
|
+
from simplevgpad import controller_async
|
|
37
|
+
import asyncio
|
|
38
|
+
|
|
39
|
+
async def main():
|
|
40
|
+
game = controller_async()
|
|
41
|
+
await game.press_a()
|
|
42
|
+
|
|
43
|
+
asyncio.run(main())
|
|
44
|
+
```
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
README.md
|
|
2
|
+
pyproject.toml
|
|
3
|
+
src/simplevgpad/__init__.py
|
|
4
|
+
src/simplevgpad/simplevgpad.py
|
|
5
|
+
src/simplevgpad.egg-info/PKG-INFO
|
|
6
|
+
src/simplevgpad.egg-info/SOURCES.txt
|
|
7
|
+
src/simplevgpad.egg-info/dependency_links.txt
|
|
8
|
+
src/simplevgpad.egg-info/requires.txt
|
|
9
|
+
src/simplevgpad.egg-info/top_level.txt
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
vgamepad
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
simplevgpad
|