Using Keypad for Xbmc Navigation on Raspi
Finally, a new Raspberry Pi is mine.
I love this little small computer. Installing Raspbmc was really easy and it plays videos without any problems.
For several reasons I want to use a keypad to navigate XBMC user interface. I found a keypad with USB at an online auction. It is a Targus keypad, Model: PAUK10E.
First tests revealed that it is not working out of the box the way I thought. The main problem is that arrow keys are not recognized in XBMC. Searching for a solution the following links are of interest:
But why are the arrow keys not working? When pressing “arrow left” on keypad the log prints :
DEBUG: Keyboard: scancode: 4b, sym: 0104, unicode: 0000, modifier: 0
DEBUG: OnKey: numpadfour (f074) pressed, screen saver/dpms woken up
Even when NumLock is activated this message is received from keypad. A simple solution is to map this key to the action “arrow left”. Same for other keys.
As a result we get a keyboard.xml looking like:
<keymap>
<global>
<keyboard>
<numpadfour>left</numpadfour>
<numpadsix>right</numpadsix>
<numpadeight>up</numpadeight>
<numpadtwo>down</numpadtwo>
</keyboard>
</global>
</keymap>
This did the first part of our job. Arrow keys are working now.
One problem remains. The Enter key is not working in non-NumLock mode. This could be ignored but I wanted to have a consistent behavior independent of NumLock. Pressing Enter key shows following debug messages:
DEBUG: Keyboard: scancode: 45, sym: 012c, unicode: 0000, modifier: 1000
DEBUG: OnKey: numlock (f0da) pressed, action is
DEBUG: Keyboard: scancode: 38, sym: 0134, unicode: 0000, modifier: 1100
DEBUG: OnKey: alt-leftalt (4f0d4) pressed, action is
DEBUG: Keyboard: scancode: 4d, sym: 0106, unicode: 0000, modifier: 1100
DEBUG: OnKey: alt-numpadsix (4f076) pressed, action is
DEBUG: Keyboard: scancode: 4f, sym: 0101, unicode: 0000, modifier: 1100
DEBUG: OnKey: alt-numpadone (4f071) pressed, action is
DEBUG: Keyboard: scancode: 45, sym: 012c, unicode: 0000, modifier: 0
DEBUG: OnKey: numlock (f0da) pressed, action is
This means pressing Enter generated five key events. Anybody out there knowing why especially those events are generated? Ignoring this problem, one solution is to take one of these generated key events and assigning them a “pressing enter”-event. I chose alt-leftalt (4f0d4) key event.
The problem here is that key event alt-leftalt (4f0d4) is not predefined. Regarding to XBMC Wiki keycode has to be used for assigning a new keys any action. The hex value 0x4f0d4 is 323796 in decimal. This is the keycode we need. This keycode has to be connected with “Select” event. Enhancing the file above results in:
<keymap>
<global>
<keyboard>
<numpadfour>left</numpadfour>
<numpadsix>right</numpadsix>
<numpadeight>up</numpadeight>
<numpadtwo>down</numpadtwo>
<key id="323796">Select</key>
</keyboard>
</global>
</keymap>
That’s it. Yeah!