-
-
Save egoebelbecker/e78c33fa3b1fb1dfa24963ea8d14847c to your computer and use it in GitHub Desktop.
Python snippet reading gamepad from /dev/input
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from evdev import InputDevice, categorize, ecodes, KeyEvent | |
gamepad = InputDevice('/dev/input/event0') | |
for event in gamepad.read_loop(): | |
if event.type == ecodes.EV_KEY: | |
keyevent = categorize(event) | |
if keyevent.keystate == KeyEvent.key_down: | |
if keyevent.scancode == 305: | |
print('Back') | |
elif keyevent.scancode == 304: | |
print ('Left') | |
elif keyevent.scancode == 307: | |
print ('Forward') | |
elif keyevent.scancode == 306: | |
print ('Right') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment