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.


HP MediaCenter Remote

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
^C

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.

Editing Lircmap.xml

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”>.

<remote device="devinput">
<left>KEY_LEFT</left>
<right>KEY_RIGHT</right>
<up>KEY_UP</up>
<down>KEY_DOWN</down>
<select>KEY_OK</select>
... 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.

Editing remote.xml

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.

<keymap>
<global>
<remote>
<play>Play</play>
<pause>Pause</pause>
<stop>Stop</stop>
<forward>FastForward</forward>
<reverse>Rewind</reverse>
<left>Left</left>
<right>Right</right>
<up>Up</up>
<down>Down</down>
<select>Select</select>
... 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.

  <FullscreenLiveTV>
<remote>
<left>PreviousChannelGroup</left>
<right>NextChannelGroup</right>
<up>ChannelUp</up>
<down>ChannelDown</down>
</remote>
</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.

Concrete example

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
^C

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:

                <title>KEY_EPG</title>

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.

      <title>ContextMenu</title>

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.

                <guide>KEY_EPG</guide>

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.

10 Responses

  1. What did you map the context command to? I was wondering why they had mapped the context menu to the guide button…

    • OT says:

      I’m currently using a remote that has ‘Options’ button. I mapped the context command to that one.

  2. shaulian says:

    Nice article. Do you know whats the substitute for irw in windows ?

  3. Vern says:

    I am totally flummoxed by this, even with the concrete example. In my case I want to remap a button to change audio track in a video file. Assuming I want to change the Pictures button on my remote (which I do not use) to change the audio track on a video (so I can change to the commentary track on a video), what would I change in each file? I have no problems editing the files. I just don’t understand what changes to make.

    • Juraj says:

      I didn’t edit any file. I use “Keymap Editor” addon.

      • Vern says:

        I’m sorry, this is not very helpful. First, the article here talks about editing the Lircmap.xml and remote.xml files. Second, using the Keymap Editor addon does edit (what about “editor” doesn’t mean edit?) the keymap.xml file. Third, you don’t post any details about how you solved the problem. It’s akin to writing, “I didn’t turn at the traffic light,” when I was asking for directions to the pizza place.

        • Juraj says:

          I tried to tell you, that if you “want to remap a button to change audio track in a video file” you don’t have to edit “remote.xml” file it self, but can use something, that does it for you.
          I’m sorry I bother you with my post.
          That’s true I didn’t read the article just your last post – my fault.

  4. martin says:

    Oh Jesus! Finally! Thank You Soo Much!

    I got it working now. In my case, to use the info from irw for setting up was the last missing bit !

    I’ve put it all together here (note: this is work-in-progress!):
    https://gist.github.com/glitterkitty/9554d88aff011e73b02ccd67b944f7c9

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.