-
Notifications
You must be signed in to change notification settings - Fork 0
/
controller.py
36 lines (29 loc) · 1011 Bytes
/
controller.py
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
# Utility file for figuring out the input axis's on the controller
import pygame
# Initialize Pygame
pygame.init()
# Initialize the joystick
pygame.joystick.init()
try:
# Attempt to setup the joystick
joystick = pygame.joystick.Joystick(0)
joystick.init()
print("Joystick initialized")
except pygame.error:
print("No joystick found.")
# Game loop to keep the window open
running = True
while running:
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
elif event.type == pygame.JOYAXISMOTION:
# Print the values of the axes
print("Joystick Axis", event.axis, "value:", event.value)
elif event.type == pygame.JOYBUTTONDOWN:
print("Joystick Button", event.button, "pressed.")
elif event.type == pygame.JOYBUTTONUP:
print("Joystick Button", event.button, "released.")
# Update loop runs at a manageable pace
pygame.time.Clock().tick(60)
pygame.quit()