RPi GPIO Controls

Probably been asked before, But is there a way to Hook up some Tact Buttons as Up, Down, Left Right, Enter, Esc on Keyboard on the Raspberry Pi GPIO?
I’m Running Offline as a Portable Media, so Any Internet Required Addons for this will not work, I Can take any Workaround that is Offline. Any Feedback is appreciated, Thanks! :wink:

Or a USB Teensy Setup? I’m Using the A+, But i can Hack a USB Hub If needed! :smile:

I’m not sure I understand your requirement, but I run a pi1A with a powered USB hub and keyboard, ethernet etc plugged into it

1 Like

Just wondering if you can hook up Some Buttons to register as a Keyboard Press.


There is probably a way to do it, but it’s well outside the support scope for OSMC - if someone here knew the answer they would have replied by now.

I would search for a way to do this on Raspbian first as there are a lot of projects out there for connecting up various sensors, buttons etc to Raspberry Pi’s via GPIO - depending on their software requirements the same is likely to work on OSMC as it is based on Raspbian (Pi 1) or Debian Jessie (Pi 2) as the underlying operating system, with apt-get available to install everything you’re likely to need.

1 Like

I’ll Try that. I’m Just trying to work solely with OSMC Software now. But I’ll see what Raspbian can handle. :smile:


Been a while since you requested this, but I have had success connecting a small joypad (xbox360/ps3 style thumbstick) and also buttons using gpio. lt me know if you still want some info. I used a cheap adc (analogue to digital converter) for the thumbstick, and it also is great for creating resistance based button arrays like tactile buttons without the need to tie up several gpio pins (I use just 4 pins for the adc using spi)

Anyway let me know


Thanks for replying. I actually began tinkering with Arduino Micro for my buttons. :slight_smile:

No worries but if u change your mind give me a shout I be happy to help!


Stewart: I’d love to know more about how you got GPIO buttons to work as controls for OSMC. I’ve hooked up a gesture sensor via I2C to my Pi2 and want to use it to control the picture slide show. I have a C++ prog that interprets the sensor readings. But I’m not sure how to then pass virtual keystrokes to the picture viewer process (it’s not even clear to me what process it is!)

Any suggestions you can offer would be most appreciated.


The picture viewer in Kodi is just part of the main kodi.bin process.

To pass virtual key strokes to Kodi you could either emulate a linux input device and send uinput events which will be picked up by eventlircd and passed to Kodi, or you could use the xbmc json interface either directly using the bindings for the language you’re writing in:

Or by using xbmc-send. Have a look at xbmc-send and the following page to see what kinds of things you can do with this API:


There are a number of picture and slideshow related commands there which you can try out from the command line with xbmc-send. If you can do what you want via xbmc-send then you can use the c++ bindings directly within your program to send the commands.

Thanks so much, DBMandrake, for these awesome leads! I will try these approaches and report back on what I get working.

Thanks to the lead suggested by DBMandrake, I got an APDS-9960 gesture sensor working as a controller for a Raspberry Pi 2-driven slideshow – in my case, a digital art frame (in which the Pi is hidden behind an HD monitor, which hangs on the wall).

xbmc-send provides all the functionality I need to intercept the six gestures generated by the sensor (using code generously provided by Justin Woodman) and turn them into Kodi commands for OSMC. Here is the script I wrote, which I run from /etc/rc.local on boot:

    #! /bin/bash

ROOT_UID=0     # Only users with $UID 0 have root privileges.
E_NOTROOT=67   # Non-root exit error.

if [ "$UID" -ne "$ROOT_UID" ]
  echo "Must be root to run this script."
  exit $E_NOTROOT

./GestureTest | {
    while read command
        echo $command

        case "$command" in
            UP    ) action=BACK;;
            DOWN    ) action=SELECT;;
            LEFT    ) action=LEFT;;
            RIGHT    ) action=RIGHT;;
            FAR    ) action="RecursiveSlideShow(/home/osmc/Pictures/Art)";;
            NEAR    ) action=SHUTDOWN;;
            NONE    ) action="Notification('ALERT','Unrecognized gesture.',2000)"
                  action="Notification('ALERT','Valid gestures are swipes L/R/U (sends BACK), and D (SELECT)...',5000)"
                  action="Notification('ALERT','Also push in & pull out (START SLIDESHOW); push in & move left (SHUTDOWN).',5000)"
            *    ) action=NULL;;

        xbmc-send --action="$action"

exit 0

Hi Wayt

Sorry for the delay replying.

I gather the picture process viewer is within osmc itself?

If so what you need is package called xbmcclient.py
Its written in python and shows how the commands are sent which you could maybe interpret to C++ code?

The may already exist a version written in c++ I haven’t had time to check tbh.

The process for sending keys is simple and all the commands are available in the XBMC/KODI/OSMC development information for skins and addons.

Sorry its just a quick response I’m a little busy but if you want any further info give me a shout I try explain things a little more.


There is already sample C++ code for using the kodi events client interface, I linked to it a few posts ago:

Yeah sorry was too busy rushing a reply I didn’t read up properly.thanks for that.

I may have use for the c++ code myself as the python gpio code im using for my thumb stick and now a rotary encoder are using valuable CPU cycles especially as to get my touch screen working I had to create a virtual kernel event using cython hidapi and uevent as the driver didn’t create an event* just a hidraw2 device and hiddev0 device so I’m using too many CPU cycles with python code I think c++ may work out better any thoughts?