I use evdev to wait for button key press on any joystick when displaying Image. Thing is my old code only worked for one joystick. Now I got two. This is about getting joystick device paths and using python and evdev to display image and wait for button key press to close image.
$lsusb
Bus 001 Device 004: ID 0079:0006 DragonRise Inc. PC TWIN SHOCK Gamepad
Bus 001 Device 005: ID 0079:0006 DragonRise Inc. PC TWIN SHOCK Gamepad
Bus 001 Device 006: ID 0424:7800 Standard Microsystems Corp.
Bus 001 Device 003: ID 0424:2514 Standard Microsystems Corp. USB 2.0 Hub
Bus 001 Device 002: ID 0424:2514 Standard Microsystems Corp. USB 2.0 Hub
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
$cd /dev/input
pi@finalfight:/dev/input $ ls -l
total 0
drwxr-xr-x 2 root root 80 Mar 14 19:10 by-id
drwxr-xr-x 2 root root 120 Mar 14 19:10 by-path
crw-rw----+ 1 root input 13, 64 Mar 14 19:10 event0
crw-rw----+ 1 root input 13, 65 Mar 14 19:10 event1
crw-rw----+ 1 root input 13, 0 Mar 14 19:10 js0
crw-rw----+ 1 root input 13, 1 Mar 14 19:10 js1
crw-rw---- 1 root input 13, 63 Mar 14 19:10 mice
pi@finalfight:~/py $ python3 listdevices.py
/dev/input/event1 DragonRise Inc. Generic USB Joystick usb-3f980000.usb-1 .1.3/input0
/dev/input/event0 DragonRise Inc. Generic USB Joystick usb-3f980000.usb-1 .2/input0
Real Path is
/dev/input/event1
/dev/input/event0
Python Code to wait for Key Press On two Joysticks
import asyncio, evdev, subprocess, sys
jstick1 = evdev.InputDevice('/dev/input/event0')
jstick2 = evdev.InputDevice('/dev/input/event1')
async def print_events(device):
async for event in device.async_read_loop():
if event.type == evdev.ecodes.EV_KEY:
keyevent = evdev.categorize(event)
if keyevent.keystate == evdev.KeyEvent.key_down:
print(device.path, evdev.categorize(event), sep=': ')
sys.exit(0)
for device in jstick1, jstick2 :
asyncio.ensure_future(print_events(device))
loop = asyncio.get_event_loop()
subprocess.Popen(["fbi","-a","/home/pi/RetroPie/roms/scripts/m/screen/dispAM.jpg"])
print('loop.run_forever()')
loop.run_forever()