Can't get Kodi to accept keys emitted from python-uinput?

330 Views Asked by At

I'm emitting keys from a python script using python-uinput. Basic stuff such as up / down / enter / esc.

As far as I can see this works fine on my desktop, in the terminal, and with the browser. But when I run Kodi, it doesn't seem to respond at all. Is this something to do with it being a fullscreen application?

NB: I'm running Raspbian on model 3 Raspberry Pi.

1

There are 1 best solutions below

1
Jeroen On BEST ANSWER

Maybe you need to do: sudo modprobe uinput

The following script works for me to send Function key 12 to vice (a C64 emulator) based on a button press on a GPIO:

import uinput 
import RPi.GPIO as GPIO
import time

GPIO.setmode(GPIO.BCM)
GPIO.setup(21, GPIO.IN, pull_up_down=GPIO.PUD_UP)

wasPressed=False

# set up keystroke input
device = uinput.Device([uinput.KEY_F12])
while True:
    button_inactive = GPIO.input(21)
    if not button_inactive and not wasPressed:
        device.emit_click(uinput.KEY_F12)
        print "sending F12"
        wasPressed=True
    if button_inactive: 
        wasPressed=False
    time.sleep(0.1)

Note that I used uinput.KEY_F12 twice. The script should be run as root.