Saturday, April 11, 2020

How to assign remote keys to key combinations in KODI / X

I have tried to use the chrome launcher on KODI and it was not so easy to exit the browser.

I decided to map CTRL-W to a previously unused button on the remote control.

The first step is to find out what the system sees when you press the button on the remote. I used xev for this purpose. However running it from shell directly did not lead to any results.

I had to create a startup script for KODI and first start openbox window manager. It was necessary to install openbox package anyway because the chrome plugin for KODI was using it so the browser can start full screen.

#!/bin/sh

/usr/bin/openbox &
/usr/bin/kodi &
wait %2

Then had to edit /usr/share/xsessions/kodi.desktop to execute this script. Only after that, I have been able to capture the input from my remote. However this setting can eventually be reversed.

KeyPress event, serial 44, synthetic NO, window 0x400001,
    root 0x4e0, subw 0x0, time 1226119813, (1262,603), root:(1263,623),
    state 0x0, keycode 72 (keysym 0xffc3, F6), same_screen YES,
    XLookupString gives 0 bytes:
    XmbLookupString gives 0 bytes:
    XFilterEvent returns: False

KeyRelease event, serial 47, synthetic NO, window 0x400001,
    root 0x4e0, subw 0x0, time 1226119885, (1262,603), root:(1263,623),
    state 0x0, keycode 72 (keysym 0xffc3, F6), same_screen YES,
    XLookupString gives 0 bytes:
    XFilterEvent returns: False


According to output, the remote sent F6 to the HTPC. Now we can repurpose F6. The easiest way is to use xbindkeys. For this purpose you need to create /home/kodi/.xbindkeysrc file and put the following in it.

"xdotool key --clearmodifiers ctrl+w"
    F6 + release

Then we can start xbindkeys from the .xprofile file by simply adding /usr/bin/xbindkeys into it.

Now, when I press the remote key, the chrome browser window closes and I return back to KODI.