
One of the great features of RaspBMC is the ability to control it using your existing TV remote when connected via HDMI. It accomplishes this task by making use of CEC to pass control codes from the TV to the Raspberry Pi.
While most of the important buttons on my Samsung TV pass happily through to XMBC (such as navigation arrows, play, pause, stop, etc) one of the controls which is sorely missing is the ability to access the context menu. Which means that every time I need to alter a setting I need to plug in a usb keyboard. I would also like to be able to adjust the XBMC volume using the remote.
Thankfully XMBC is designed in such a way that you can set up your own custom keymaps to alter the behaviour of the existing remote buttons or add new ones.
The first step is to work out which of the buttons on your remote actually get passed through to the Raspi. Not all buttons on a remote are CEC enabled, which seems to be at the whim of the TV manufacturer as is the name that each button appears as. My volume buttons are not enabled so I want to remap Channel Up/Down to perform this function when video is playing.
If we connect to Raspi via SSH (using a terminal program such as putty) then we examine the status updates recorded in xbmc.log in response to each key press…
tail -F /home/pi/.xbmc/temp/xbmc.log
This then shows the name of each button (in this case I pressed the ‘green’ button). The response was to bring up the Videos screen.
22:00:43 T:1182790720 DEBUG: CecLogMessage – key pressed: F3 (green) (73)
22:00:43 T:1182790720 DEBUG: PushCecKeypress – received key fc duration 0
22:00:43 T:1102835712 DEBUG: OnKey: 252 (fc) pressed, action is XBMC.ActivateWindow(MyVideos)
(You may find that key presses are not being logged. If this is the case then you need to create /home/pi/.xbmc/userdata/advancedsettings.xml and add the lines <advancedsettings> <loglevel>1</loglevel> </advancedsettings>)
Then the final step is to make an entry in /home/pi/.xbmc/userdata/keymaps/remote.xml to bind the key to a new action (such as XBMC.ActivateWindow(VideoLibrary,MovieTitles). The list of actions can be found the XBMC wiki (ButtonTranslator.cpp).
However things get more complicated with my Samsung remote because many of the buttons do not come up with their actual name…
12:10:10 T:1183839296 DEBUG: CecLogMessage – key pressed: channel up (30)
12:10:10 T:1183839296 DEBUG: PushCecKeypress – received key d2 duration 0
12:10:10 T:1075412992 DEBUG: OnKey: leftshift (d2) pressed, action is PageUp
Above is what happens when I press the Channel Up button. From the above log you would expect this to respond to something like a <channel up> or <d2> tag. But it doesn’t. The tag you want is inexplicably <pageplus>. The way I found this out was that this button already had a behaviour associated with it in /opt/xbmc-bcm/xbmc-bin/share/xmbc/system/keymaps/remote.xml, so I could trace it back. However there are buttons on the remote that do pass CEC codes through but aren’t already defined with a behaviour and it seems at this point in time I have no way of finding out what their tag should be!
This is a real pain, because of all the buttons that pass through CEC only half of mine I can work out the correct tag for. Grr!
So anyway my volume fix ends up looking something like this…
<keymap>
<global>
</global>
<FullScreenVideo>
<remote>
<pageplus>volumeup</pageplus>
<pageminus>volumedown</pageminus>
</remote>
</FullScreenVideo>
</keymap>
UPDATE: work-in-progress listing of codes