-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgamepad.py
More file actions
53 lines (40 loc) · 1.18 KB
/
Copy pathgamepad.py
File metadata and controls
53 lines (40 loc) · 1.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
"""
Gamepad Module
Daniel J. Gonzalez
dgonz@mit.edu
Based off code from: http://robots.dacloughb.com/project-1/logitech-game-pad/
"""
import pygame
class GamepadCtrl:
j = None
pygame.init()
j = pygame.joystick.Joystick(0)
j.init()
print('Initialized Joystick : %s' % j.get_name())
def __init__(self):
pass
"""
Returns a vector of the following form:
[LThumbstickX, LThumbstickY, Unknown Coupled Axis???,
RThumbstickX, RThumbstickY,
Button 1/X, Button 2/A, Button 3/B, Button 4/Y,
Left Bumper, Right Bumper, Left Trigger, Right Triller,
Select, Start, Left Thumb Press, Right Thumb Press]
Note:
No D-Pad.
Triggers are switches, not variable.
Your controller may be different
"""
def get(self):
out = [0] * 17
it = 0 # iterator
pygame.event.pump()
# Read input from the two joysticks
for i in range(0, self.j.get_numaxes()):
out[it] = self.j.get_axis(i)
it += 1
# Read input from buttons
for i in range(0, self.j.get_numbuttons()):
out[it] = self.j.get_button(i)
it += 1
return out[0], out[2], out[5]