Custom GPIO buttons tied to keyboard events

Home Forums RetroPie Project GPIO Adapter, ControlBlock etc. Custom GPIO buttons tied to keyboard events

RetroPie has a new website and forum. Please visit for the new site. The new forum is located at This forum is left here as a read-only archive.

Tagged: , ,

This topic contains 1 reply, has 1 voice, and was last updated by Profile photo of vertpingouin vertpingouin 1 year, 8 months ago.

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
  • #105040
    Profile photo of vertpingouin

    Hi everyone !

    I try to add custom buttons in my project. Those button should allow access to save state, loadstate etc… function in retroarch. I plugge my buttons on the GPIO a like described here for example

    Then I wrote a little python script in order to map my buttons and trigger some uinput keyboard events.

    from time import sleep
    import RPi.GPIO as GPIO
    import uinput
    keypad = uinput.Device([uinput.KEY_N])
    GPIO.setup(4, GPIO.IN)
    pause = .1
    while True:
            if (GPIO.input(4)):

    I launch the script as admin (needed for GPIO python lib).
    The button press detection works without problem.
    When I’m in console, I can see ‘n’ ar input. ‘n’ key is mapped to the “next shader” function in retroarch, this works with a usb keyboard… But not with my buttons.

    Somehow, my script is only effective in console. As long as I launch emulstation or retroarch, it fails.

    Help would be much appreciated. I can’t figure it out and I really want to implement this with python which should bring a great flexibility to my project !

    Profile photo of vertpingouin

    I realize that the tty where my commands are sent is not the graphic tty (tty6). So i might be a clue, but I don’t know how to send uinput strokes to a specific tty.

    I anyone knows…

    Unless, Il just plug in my arduino micro and make it act like a keyboard, but it seems a bit too much.
    I would like to keep hardware side as simple as possible.

    Anyone ?

Viewing 2 posts - 1 through 2 (of 2 total)

Forums are currently read only - please visit the new RetroPie forums at

Skip to toolbar