Mapping the buttons on the remote control
Allright, time to make the remote controller work as I want it to. At this point I have a clean installation of OpenELEC and XBMC, the remote controller works, but the buttons on my remote do not work exactly as I would like. Luckily the XBMC is very flexible when it comes to mapping the buttons – it’s basically possibly to control fully how the system will function when a certain button is pressed. I’ve got an HP MCE-compatible remote controller and I’m using the inbuilt infrared receiver of my Haswell NUC. In order to make the inbuilt receiver work in OpenELEC, I first had to do a small trick described here. I also have an HP IR receiver that came with the remote (OVU400102/71). That works straight out of the box in OpenELEC.
Verify that the remote controller works
First, let’s make sure that the IR receiver is receiving something from the remote controller and that the keypresses are understood by the system. If you have an MCE-compatible remote and an IR receiver (such as the one inbuilt in the Haswell NUCs) this should be the case. Open an SSH connection to your NUC and run the command irw to see the keypresses recognized by the system. If you see lines on the screen when you press buttons on your remote, you’re good to go. Press Ctrl-C to stop irw.
MediaCenter:/ # irw
166 0 KEY_INFO devinput
166 0 KEY_INFO_UP devinput
174 0 KEY_ZOOM devinput
174 0 KEY_ZOOM_UP devinput
72 0 KEY_VOLUMEDOWN devinput
72 0 KEY_VOLUMEDOWN_UP devinput
73 0 KEY_VOLUMEUP devinput
73 0 KEY_VOLUMEUP_UP devinput
80 0 KEY_STOP devinput
80 0 KEY_STOP_UP devinput
Files for keymapping
There are two files that control how the buttons on your remote work and both are needed. The other one is called Lircmap.xml and the other one is remote.xml. If you want to modify these files, you should copy them under /storage/.xbmc/userdata. This way your settings will be retained, even if the system would be updated and the default files get overwritten with new versions. So copy the default files first using the cp command.
# cp /usr/share/xbmc/system/Lircmap.xml /storage/.xbmc/userdata
# cp /usr/share/xbmc/system/keymaps/remote.xml /storage/.xbmc/userdata/keymaps
The XBMC will first load the values from these files, and if they’re not present, then the default files will be used.
The Lircmap.xml is a text file that you can edit either inside the terminal using nano text editor, or you can transfer the file to another PC, edit it there and move it back. I’m using nano inside the terminal. The file contains several different types of devices. You only need to edit the section that is applicable for your device. The name of the device is shown in the irw printout above. In my case, it is devinput so I will need to edit only the section that is under <remote device=”devinput”>.
... clip ...
In this file, the key presses are mapped to XBMC button labels. For example, in the small clip above the key press KEY_LEFT has been mapped to XBMC button label left and key press KEY_OK has been mapped to XBMC label select. You can map several key presses to the same XBMC button label, but not the other way around. To see which physical button on your remote controller corresponds to which key press tag, use the irw command and press the buttons on your remote.
The other file, remote.xml binds the XBMC button labels with actual actions that take place when you press the button. There are a lot of comments in the beginning of the file that you can just skip. The first section starts by defining the global actions. These are valid in every different mode in XBMC.
... clip ...
Here you can see that the XBMC button label left has been tied to action Left. Not that surprising example maybe, but there are more complicated actions as well that you can define. If you scroll down further down in the file you can see that there are smaller lists of button labels and actions under various sections. This is a section called FullscreenLiveTV.
Here we can see that the button labels left, right, up and down have been redefined. This means that if you are watching live TV, the arrow up on your remote controller is tied to action ChannelUp instead of Up like it was in the global section. This is a way for you to fine tune the behaviour of the system according to your preferences.
But let’s take a concrete example. I’ve got a button Guide on my remote and I’d expect that when I press that I will see the EPG. Instead of EPG it seems to pop up the context menu. The first thing I need to do is to understand which key press takes place when I press the Guide button. I run the irw to find out that.
MediaCenter:~ # irw
16d 0 KEY_EPG devinput
16d 0 KEY_EPG_UP devinput
Allright, so the key press is called KEY_EPG and my device is called devinput. Good stuff. Now I will need to have a look at the Lircmap.xml file that is stored under /storage/.xbmc/userdata folder. I find that under the section for device devinput the KEY_EPG is defined like this:
This means that the actual key is bound to XBMC button label title. Now when I look at the remote.xml file that is stored under /storage/.xbmc/userdata/keymaps I find that the button label title is tied to action ContextMenu.
No wonder it pops up the context menu when I press the Guide button on the remote! I find that further down in this file, there is a button label guide that had been tied to a complex looking action that actually pops up the EPG.
<guide>XBMC.ActivateWindowAndFocus(MyPVR, 31,0, 10,0)</guide>
Now I would have two options. Either change the action for the XBMC button label title to XBMC.ActivateWindowAndFocus(MyPVR, 31,0, 10,0), or I can change the KEY_EPG to point to XBMC button label guide instead of title. I take another look at the Lircmap.xml and notice that under devinput section there’s not a single button tied to XBMC button guide, so I decide to change my Lircmap.
In order for the change to take place, I restart my system. After booting up, the button Guide on my remote now brings up the EPG for live TV. Yay!
List of button labels and actions
There’s a list of possible actions on the XBMC wiki page here. For different button labels that are available, it’s best to have a look at the existing remote.xml file. There’s also a page on the Keymap in the XBMC wiki, but I found that a little bit of confusing initially.