Special Keys on your Keyboard

              ·

In order to use the special keys on your keyboard or laptop like audio control or the “ThinkVantage” Button it is sometimes necessary to do some tweaks on your system. Not all window managers directly know how to deal with these keys.

This article is written because of my IBM/Lenovo ThinkPad I installed Ubuntu on. First of all I am a fan of the fluxbox window manager which doesn’t offer a feature to configure the special keys. While the volume control in the upper left worked fine, the ThinkVantage Button and some other Fn- Keys like hibernate or suspend didn’t do what I expected. So I found out that there is a way through the XServer.

The keyword is “Xmodmap” which binds keycodes coming from the hardware to particular key “names” you can use in the Xserver Environment. To define these patterns you must first find out the keycode of the given button. This can be done with xev. If you start xev in a terminal it opens a little window and produces some messages in the terminal itself. To find out the key codes focus the external xev window and press the key on your keyboard. In the terminal will be something like this:

KeyRelease event, serial 32, synthetic NO, window 0x2200001,
root 0xa1, subw 0x0, time 1355270960, (119,75), root:(164,143),
state 0x10, keycode 67 (keysym 0xffbe, F1), same_screen YES,
XLookupString gives 0 bytes:
XFilterEvent returns: False

As you can see the keycode here is 67 (it was the F1 key as you can see, too ;-) ). Now take it and open the file ~/.Xmodmap. This file is used to declare the keynames in the Xserver Environment. Type

keycode 67 = XF86Launch1

for every key you want to bind, where XF86Launch1 must be different for every single keybinding. Here is a list of XF86-Keys you can use:

XF86AddFavorite
XF86ApplicationLeft
XF86ApplicationRight
XF86AudioMedia
XF86AudioMute
XF86AudioNext
XF86AudioPause
XF86AudioPlay
XF86AudioPrev
XF86AudioLowerVolume
XF86AudioRaiseVolume
XF86AudioRecord
XF86AudioRewind
XF86AudioStop
XF86Away
XF86Back
XF86Book
XF86BrightnessAdjust
XF86CD
XF86Calculator
XF86Calendar
XF86Clear
XF86ClearGrab
XF86Close
XF86Community
XF86ContrastAdjust
XF86Copy
XF86Cut
XF86DOS
XF86Display
XF86Documents
XF86Eject
XF86Excel
XF86Explorer
XF86Favorites
XF86Finance
XF86Forward
XF86Game
XF86Go
XF86History
XF86HomePage
XF86HotLinks
XF86Launch0
XF86Launch1
XF86Launch2
XF86Launch3
XF86Launch4
XF86Launch5
XF86Launch6
XF86Launch7
XF86Launch8
XF86Launch9
XF86LaunchA
XF86LaunchB
XF86LaunchC
XF86LaunchD
XF86LaunchE
XF86LaunchF
XF86LightBulb
XF86LogOff
XF86Mail
XF86MailForward
XF86Market
XF86Meeting
XF86Memo
XF86MenuKB
XF86MenuPB
XF86Messenger
XF86Music
XF86MyComputer
XF86MySites
XF86New
XF86News
XF86Next_VMode
XF86Prev_VMode
XF86OfficeHome
XF86Open
XF86OpenURL
XF86Option
XF86Paste
XF86Phone
XF86Pictures
XF86PowerDown
XF86PowerOff
XF86Next_VMode
XF86Prev_VMode
XF86Q
XF86Refresh
XF86Reload
XF86Reply
XF86RockerDown
XF86RockerEnter
XF86RockerUp
XF86RotateWindows
XF86RotationKB
XF86RotationPB
XF86Save
XF86ScreenSaver
XF86ScrollClick
XF86ScrollDown
XF86ScrollUp
XF86Search
XF86Send
XF86Shop
XF86Sleep
XF86Spell
XF86SplitScreen
XF86Standby
XF86Start
XF86Stop
XF86Support
XF86Switch_VT_1
XF86Switch_VT_10
XF86Switch_VT_11
XF86Switch_VT_12
XF86Switch_VT_2
XF86Switch_VT_3
XF86Switch_VT_4
XF86Switch_VT_5
XF86Switch_VT_6
XF86Switch_VT_7
XF86Switch_VT_8
XF86Switch_VT_9
XF86TaskPane
XF86Terminal
XF86ToDoList
XF86Tools
XF86Travel
XF86Ungrab
XF86User1KB
XF86User2KB
XF86UserPB
XF86VendorHome
XF86Video
XF86WWW
XF86WakeUp
XF86WebCam
XF86WheelButton
XF86Word
XF86XF86BackForward
XF86Xfer
XF86ZoomIn
XF86ZoomOut
XF86iTouch

After editing the file, type
xmodmap ~/.Xmodmap
Now you are able to use the keys in your preferred Desktop Environment or window manager.

To give you a little example here is a part of my ~/.fluxbox/keys file:

None XF86Launch1 :ExecCommand xterm -vb -fg grey -bg black -fs 9 -fa "Lucida Console"
#notebook extras
None XF86Standby :ExecCommand sudo /etc/acpi/sleep.sh

Finally if we follow our example the F1 key would now open an xterm with the given options.