Retropie Game Controller using evdev python module

43 Views Asked by At

I programmed the following script to simulate a game controller evaluating the gpio pins of raspberry pi in retropie os:

from evdev import UInput, ecodes as e
from gpiozero import Button
from time import sleep

buttons = {e.BTN_A:Button(21),
           e.BTN_B:Button(4),
           e.BTN_START:Button(2),
           e.BTN_SELECT:Button(3),
           e.BTN_DPAD_LEFT:Button(22),
           e.BTN_DPAD_RIGHT:Button(17),
           e.BTN_DPAD_UP:Button(20),
          e.BTN_DPAD_DOWN:Button(27)}

ui = UInput(name="Custom Game Controller")
while True:
  for code, button in buttons.items():
      ui.write(e.EV_KEY, code, button.value)
      ui.syn()
  sleep(0.01)

Playing with it works fine, but when i press what i configured as hotkey (in python the select key) and start only the start key is evaluated ingame, but it doenst go back to menu. What do I have to do, to make it possible to use the retropie/es hotkey?

Can someone help?

0

There are 0 best solutions below