Monday, March 10, 2014

Remap the buttons of your remote to use with XBMC/MythTV/Media_Player

Because of the Vestel TV that I purchased, I had an airmouse lying around which I did not have any use for it until today. I decided to use it for XBMC. It turned out to be perfect.

First, test your remote mouse/keyboard/device by plugging in to the computer. If it is USB you can check through lsusb devices. As you can see below, in my case,  the dongle of the remote is recognized by the kernel.

$ lsusb
Bus 002 Device 003: ID 4853:4b66  




You can search for the device in 

$ ls /dev/input/by-id/usb-4853_4b66-event-kbd

Your connected device will probably be have a similar name. Next you need the codes of the buttons that you want to remap. For this purpose we use ir-keytable from v4l-utils package.

$ equo install v4l-utils

then try, 

$ ir-keytable -d /dev/input/by-id/usb-4853_4b66-event-kbd -t

The command above will let you to test the buttons. When you hit buttons on your remote, you will see entries similar to the lines shown below.

1394490580.520636: event type EV_MSC(0x04): scancode = 0xc0041
1394490580.520636: event type EV_KEY(0x01) key_down: KEY_ENTER(0x0001)

The scancode (highlighted as green) is what we are looking for. Write down all the scancodes and their actual purpose on the remote. If the list is long, things can get easily mixed up.

Now we want to match the scancodes with their new purposes. For example I want to assign the scancode 0xc0041 to ENTER key. Open up a file preferably named remap.keys.

$ nano remap.keys

add lines with your scancodes and some explanation for debugging purposes. 

scancode 0xc0041 = KEY_ENTER # Actually it was OK button
scancode 0xc0011 = KEY_SPACE # Actually it was P+ button

If you are looking for the word of a key you can run the command below

$ irrecord -l | grep ENTER

or you can list all keys 

$ irrecord -l

Save the file with your scancodes and it is time for magic. 

$ ir-keytable -d /dev/input/by-id/usb-4853_4b66-event-kbd --write=/path/to/remap.keys

Now you can test and enjoy your perfect remote for XBMC. You have to run this command in every boot so it would be a good idea to add it in your .bashrc.


Here is my remote.keys if you have a similar airmouse.

scancode 0xc0041 = KEY_ENTER # OK            # Select in XBMC
scancode 0xc0196 = KEY_MEDIA # WWW       # Open XBMC
scancode 0xc0040 = KEY_ESC      # MENU       # ESC
scancode 0xc009c = KEY_I             # P+              # Info
scancode 0xc00a0 = KEY_S            # SOURCE  # Shutdown Menu
scancode 0xc009d = KEY_SPACE # P-               # Play/Pause
# 0xc0224 # BACK #back is back nothing changed
# Volume buttons are not changed


No comments:

Post a Comment