Skip to content

Instantly share code, notes, and snippets.


egoebelbecker/ Secret

Created Dec 13, 2020
What would you like to do?
Python snippet reading gamepad from /dev/input
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:
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