Hello guys,
I installed OSMC on my raspperyPi model B2. I plan on making a jukebox kind of thing.
I need to configure some buttons to send messages to the interface (Up, Down, Left, Right and Enter) so I can navigate through it.
I wanted to map the physical buttons using python-uinput so that when I press a button it will send a certain signal.
The problem is that when I run the example that came with the uinput package it does nothing.
This is the keyboard.py example script:
import time
import uinput
def main():
events = (
uinput.KEY_E,
uinput.KEY_H,
uinput.KEY_L,
uinput.KEY_O,
)
with uinput.Device(events) as device:
time.sleep(1) # This is required here only for demonstration
# purposes. Without this, the underlying machinery might
# not have time to assign a proper handler for our device
# before the execution of this script reaches the end and
# the device is destroyed. At least this seems to be the
# case with X11 and its generic event device
# handlers. Without this magical sleep, "hello" might not
# get printed because this example exits before X11 gets
# its handlers ready for processing events from this
# device.
device.emit_click(uinput.KEY_H)
device.emit_click(uinput.KEY_E)
device.emit_click(uinput.KEY_L)
device.emit_click(uinput.KEY_L)
device.emit_click(uinput.KEY_O)
if __name__ == "__main__":
main()
And this is the mouse.py example script:
import time
import uinput
def main():
events = (
uinput.REL_X,
uinput.REL_Y,
uinput.BTN_LEFT,
uinput.BTN_RIGHT,
)
with uinput.Device(events) as device:
for i in range(20):
# syn=False to emit an "atomic" (5, 5) event.
device.emit(uinput.REL_X, 5, syn=False)
device.emit(uinput.REL_Y, 5)
# Just for demonstration purposes: shows the motion. In real
# application, this is of course unnecessary.
time.sleep(0.01)
if __name__ == "__main__":
main()