I’ve had a Microsoft Wireless Comfort Keyboard for years, however I have somehow managed to ignore most of the extra keys that don’t work out of the box until now (I got them working at one point, but something happened and I lost all of that again). The tipping point was that, as a bonus, this keyboard sends what are possibly power status notifications with scancodes ‘e059′ and ‘e001′ randomly, which end up flooding the kernel message buffer to the point that its hard to read other things in it. Anyway, long story short, its not too difficult to get them to work. Note: to get them to work under Windows or Mac, you need to install the Microsoft Intellitype drivers, so Linux isn’t _that_ much worse.
The basic idea is we need to find out what scancodes (the raw messages sent to the computer by the keyboard) are being generated by the extra keys, and then map them to suitable keycodes (generic codes that are used by application programs) so that the system can make use of them. To figure out what the scancodes for each of the nonworking keys is, fire up a terminal and run the following command:
tail -f /var/log/messages
Now, press the keys one at a time and write down the values that are reported. For instance, when I press the ‘log off’ button i get the following messages:
Oct 9 01:15:32 matt-desktop kernel: [61716.586807] atkbd.c: Unknown key pressed (translated set 2, code 0x96 on isa0060/serio0). Oct 9 01:15:32 matt-desktop kernel: [61716.586812] atkbd.c: Use 'setkeycodes e016' to make it known. Oct 9 01:15:32 matt-desktop kernel: [61716.659007] atkbd.c: Unknown key released (translated set 2, code 0x96 on isa0060/serio0). Oct 9 01:15:32 matt-desktop kernel: [61716.659012] atkbd.c: Use 'setkeycodes e016 ' to make it known.
There will most likely be two messages, one for when the key is pressed down and one for when it is released. In this case, the value we are looking for is e016. Once you have made a list of all the keys and the scancodes that correspond to them, the next step is to figure out what keycodes they should be mapped to. There is a good list of the existing keycodes in the file /usr/include/linux/input.h. For our example, I did not find a log out key defined, so I mapped the log out key to keycode 183 ( KEY_F13). This is rather arbitrary, but since I don’t have an F13 function key on my keyboard, at least it will not conflict with anything. The final step is to put these mappings into a state that the system can use them. The way to do this in Ubuntu is to add some commands to the /etc/rc.local file. I’ll leave you with the the file I am using as an example. If you have any questions or comments please let me know.
Following is the contents of my rc.local file:
#!/bin/sh -e # # rc.local # # This script is executed at the end of each multiuser runlevel. # Make sure that the script will "exit 0" on success or any other # value on error. # # In order to enable or disable this script just change the execution # bits. # # By default this script does nothing. # These are supposedly power state messages from the MS Wireless Comfort # Keyboard. But, I dont know how to read them so kill them off for now. setkeycodes e059 254 setkeycodes e001 254 # These codes are for the unrecognized multimedia keys on the keyboard # (target keycode values taken from include/linux/input.h) setkeycodes e073 188 # Favorites #1 -> F18 setkeycodes e074 189 # Favorites #2 -> F19 setkeycodes e075 190 # Favorites #3 -> F20 setkeycodes e076 191 # Favorites #4 -> F21 setkeycodes e077 192 # Favorites #5 -> F22 setkeycodes e078 193 # Favorites 'star' -> F23 setkeycodes e005 216 # Messenger -> KEY_CHAT setkeycodes e015 184 # Calendar -> F14 setkeycodes e00b 103 # Zoom + -> KEY_UP setkeycodes e011 108 # Zoom - -> KEY_DOWN setkeycodes e016 183 # Log Off -> F13 # These codes are for the alternate identities of the function keys. # (target keycode values taken from include/linux/input.h) setkeycodes e03b 138 # Help setkeycodes e008 131 # Undo setkeycodes e007 182 # Redo setkeycodes e03e 181 # New setkeycodes e03f 134 # Open setkeycodes e040 206 # Close setkeycodes e041 232 # Reply setkeycodes e042 233 # Fwd setkeycodes e043 231 # Send #setkeycodes e023 ??? # Spell (not sure?) setkeycodes e057 234 # Save setkeycodes e058 210 # Print exit 0 |