-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinput_test.py
More file actions
51 lines (40 loc) · 1.14 KB
/
input_test.py
File metadata and controls
51 lines (40 loc) · 1.14 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
#!/usr/bin/env python3
"""
Background input tester
"""
__author__ = "Stephen Ancona"
__version__ = "0.1.0"
__license__ = "The Unlicense"
import os
import pygame
def start_pygame():
os.environ["SDL_JOYSTICK_ALLOW_BACKGROUND_EVENTS"] = "1"
os.environ["SDL_VIDEODRIVER"] = "dummy"
pygame.init()
joysticks = [
pygame.joystick.Joystick(x)
for x in range(pygame.joystick.get_count())
]
def input_loop():
while True:
for event in pygame.event.get():
if event.type == pygame.JOYDEVICEADDED:
joysticks = [
pygame.joystick.Joystick(x)
for x in range(pygame.joystick.get_count())
]
if (
event.type == pygame.JOYBUTTONUP or
event.type == pygame.JOYHATMOTION or
event.type == pygame.JOYAXISMOTION
):
print('input seen')
def main():
start_pygame()
input_loop()
if __name__ == "__main__":
""" This is executed when run from the command line """
try:
main()
except KeyboardInterrupt:
print("Ending!")