Keyboard Special Keys

From MythTV Official Wiki
Jump to: navigation, search

A great many keyboards are available with "special" keys, many of which are of interest to MythTV users with functions printed on them like "Vol +", "Vol -". There are more keyboards out there than are likely to ever be documented in a wiki like this... So, if you have a keyboard with the "special" keys that you would like to put to use, how do you do that, with examples drawn from Muthbuntu 11.04 "Natty Narwhal". Further while the focus here is on keyboards, the same rules/instructions apply to other devices that look to the system as "keyboards", such as PC cases with media buttons.

First program we need is "xev" which you can get through the package manager or by pulling up a terminal under X-windows and running "sudo apt-get install xev". You will want pen and paper (or maybe a second computer) to make notes for the next step. We run "xev" this will display in the terminal window what events it sees. Events to xev include keyboard keys being pressed, keyboard keys being release, mouse movements, etc.. Once xev is running pressing and releasing one of the special keys will generate something like the following on screen:

 KeyPress event, serial 36, synthetic NO, window 0x4a00001,
     root 0x1ad, subw 0x0, time 20577657, (1029,913), root:(1033,938),
     state 0x10, keycode 164 (keysym 0x1008ff30, XF86Favorites), same_screen YES,
     XLookupString gives 0 bytes: 
     XmbLookupString gives 0 bytes: 
     XFilterEvent returns: False
 KeyRelease event, serial 36, synthetic NO, window 0x4a00001,
     root 0x1ad, subw 0x0, time 20577669, (1029,913), root:(1033,938),
     state 0x10, keycode 164 (keysym 0x1008ff30, XF86Favorites), same_screen YES,
     XLookupString gives 0 bytes: 
     XFilterEvent returns: False

In our case all we care about is the number that follows the word "keycode", in the above example 164. Once you have your list of keys (or while your collecting your list if you are using a second computer) you can create the /home/{mythtv user}/.Xmodmap file. In the .Xmodmap file you will tie the special keys to what you want them to mean, so, for the above we might do something like:

 ! Keymap for Brand XYZ Model 123 keyboard
 ! Skip Back
 keycode 164 = Left

Any line that starts with an exclamation mark is treated as a comment and ignored. A full list of the codes that xmodmap knows about (like "Left" as in left arrow key) can be seen in the file keysymdef.h (which you will likely have to dig-up on line). When looking through the keysymdef.h file remember to ignore "XK_". A typical .Xmodmap file when done will look something along the likes of the following:

 ! Keymap for Brand XYZ Model 123 keyboard  
 ! Skip Back
 keycode 999 = Left
 ! Skip Forward
 keycode 999 = Right
 ! Stop
 keycode 999 = Escape
 ! PlayPause
 keycode 999 = P
 ! VolUp
 keycode 999 = bracketright
 ! VolDn
 keycode 999 = bracketleft
 ! Mute
 keycode 999 = bar

To start the above immediately type:

 xmodmap /home/{mythtv user}/.Xmodmap

Otherwise, the script /etc/gdm/Xsession is run during the the Mythbuntu start-up and if it sees the file "/home/{user name}/.Xmodmap" it will auto-run "xmodmap /home/{user name}/.Xmodmap".

Once the above is up and running satisfactorily, the last step is to add what you have learned back to this wiki, so nobody else will have to go through the same grunt work of mapping keys if they have the same make / model of keyboard as you.