How to get special keys to work

From ThinkWiki
Revision as of 12:26, 10 January 2008 by Kevmitch (Talk | contribs) (T60 (and possibly others))
Jump to: navigation, search

Overview

The following table gives an overview over the special keys found on ThinkPads and what is needed to make them work.

key standard function1 tools supporting key2 configurability3 remarks
Fn - xmodmap, tpb full on release without completed key combination
FnF1 - ibm-acpi, thinkpad-acpi full
FnF2 lock screen ibm-acpi, thinkpad-acpi full in models from T/X/Z 60 onwards
FnF3 blank screen ibm-acpi, thinkpad-acpi full
FnF4 suspend to ram ibm-acpi, thinkpad-acpi full may generate ACPI event when not enabled in the ibm-acpi hotkey mask
FnF5 switch bluetooth ibm-acpi, thinkpad-acpi full in models starting from 2002
FnF6 - ibm-acpi, thinkpad-acpi full
FnF7 toggle display ibm-acpi, thinkpad-acpi, tpb additional actions Sample Fn-F7 script
FnF8 toggle trackpoint/touchpad ibm-acpi, thinkpad-acpi, tpb additional actions
FnF9 eject from dock ibm-acpi, thinkpad-acpi full
FnF10 - ibm-acpi full
FnF11 - ibm-acpi, thinkpad-acpi full
FnF12 hibernate ibm-acpi, thinkpad-acpi full may generate ACPI event when not enabled in the ibm-acpi hotkey mask
FnHome / FnPos1 brightness up ibm-acpi, thinkpad-acpi, tpb, KMilo additional actions
FnEnd brightness down thinkpad-acpi, tpb, KMilo additional actions
FnPageUp toggle thinklight thinkpad-acpi, tpb, KMilo additional actions
FnSpace toggle zoom thinkpad-acpi, tpb, KMilo full
FnIns - ibm-acpi, thinkpad-acpi full
FnDel - ibm-acpi full
FnBackspace - ibm-acpi full
NumLock - xmodmap make working
Windows - xmodmap remapping
Access IBM or ThinkPad or ThinkVantage help application thinkpad-acpi,tpb, KMilo full
Home open web browser xmodmap, tpb, KMilo full only A30, A30p, A31, A31p and ext. keyboards
Search open search application xmodmap, tpb, KMilo full only A30, A30p, A31, A31p and ext. keyboards
Mail open mail application xmodmap, tpb, KMilo full only A30, A30p, A31, A31p and ext. keyboards
Favorites open favorites xmodmap, tpb full only A30, A30p, A31, A31p and ext. keyboards
Reload reload web page xmodmap, tpb full only A30, A30p, A31, A31p and ext. keyboards
Abort abort loading page xmodmap, tpb full only A30, A30p, A31, A31p and ext. keyboards
Backward previous page xmodmap, tpb full ext. keyboards and ThinkPads starting from 2002
Forward next page xmodmap, tpb full ext. keyboards and ThinkPads starting from 2002
Volume up volume up thinkpad-acpi, tpb, KMilo additional actions
Volume down volume down thinkpad-acpi, tpb, KMilo additional actions
Volume mute mute volume thinkpad-acpi, tpb, KMilo additional actions
Play/Pause start/pause playback xmodmap full X60s (Fn+Arrow Down)
Stop stop playback xmodmap full X60s (Fn+Arrow Up)
Next play next xmodmap full X60s (Fn+Arrow Right)
Previous play previous xmodmap full X60s (Fn+Arrow Left)
Power shutdown ibm-acpi,thinkpad-acpi full triggered on pressing 3secs, but notebook goes off on 5sec press
Display lid blank screen ibm-acpi, thinkpad-acpi full
Ultrabay lid announce ultrabay change ibm-acpi full
Dock eject eject from dock ibm-acpi full
Tablet power shutdown ibm-acpi full triggered on pressing 3secs, but notebook goes off on 5sec press
Tablet orientation rotates screen setkeycodes full
Tablet shortcut shortcut menu setkeycodes full
Tablet Esc esc key setkeycodes full
Tablet Enter enter key setkeycodes full
Tablet Up up key setkeycodes full
Tablet Down down key setkeycodes full
Tablet (unlabeled) down key setkeycodes full

Triggering key events

ibm-acpi/thinkpad-acpi events

Some of the following events require a # echo enable,0xffff >/proc/acpi/ibm/hotkey (when using ibm-acpi) in order to make acpi able to get information on them. Since the newer thinkpad-acpi has a larger number of bits that can be set in the mask, you might try # echo enable,0xffffffff >/proc/acpi/ibm/hotkey if you are using this driver. These events can be used to configure acpid.

events triggered by ibm-acpi for /etc/acpi/events files.
key event
FnF1 ibm/hotkey HKEY 00000080 00001001
FnF2 ibm/hotkey HKEY 00000080 00001002
FnF3 ibm/hotkey HKEY 00000080 00001003
FnF4 ibm/hotkey HKEY 00000080 00001004
FnF5 ibm/hotkey HKEY 00000080 00001005
FnF6 ibm/hotkey HKEY 00000080 00001006
FnF7 ibm/hotkey HKEY 00000080 00001007
FnF8 ibm/hotkey HKEY 00000080 00001008
FnF9 ibm/hotkey HKEY 00000080 00001009
FnF10 ibm/hotkey HKEY 00000080 0000100a
FnF11 ibm/hotkey HKEY 00000080 0000100b
FnF12 ibm/hotkey HKEY 00000080 0000100c
FnBackspace ibm/hotkey HKEY 00000080 0000100d
FnIns ibm/hotkey HKEY 00000080 0000100e
FnDel ibm/hotkey HKEY 00000080 0000100f
FnHome/FnPos1 ibm/hotkey HKEY 00000080 00001010
ThinkVantage ibm/hotkey HKEY 00000080 00001018
Power button/power PWRF 00000080 xxxxxxxx
Display lid button/lid LID 00000080 xxxxxxxx
Ultrabay eject ibm/bay MSTR 00000003 00000000
Ultrabay inserted ibm/bay MSTR 00000001 00000000
Dock eject ibm/dock GDCK 00000003 00000001
Wireless switch ibm/hotkey HKEY 00000080 00007000

By disassembling and editing the DSDT, more events can be added. HKEY events are triggered by calls to the MKHQ function, e.g. \_SB.PCI0.LPC.EC.HKEY.MHKQ(0×1007) will trigger "ibm/hotkey HKEY 00000080 00001007". Most of these can be found in _Qxx methods within the DSDT, which are executed on embedded controller events, e.g. _Q10 is triggered by pressing Fn-F7. You can add a call to MKHQ into an existing _Qxx method to get it recognized by ibm-acpi as well as creating new _Qxx methods, which if you're lucky will correspond to an EC event that IBM never used (e.g. A 770 will send Fn-Home/End/PgUp/PgDn to ibm-acpi if hacked in this fashion). For example, this is a modified block of DSDT for a G40.

Pure ACPI events

A few keys can generate ACPI events of their own on certain ThinkPads, as long as they are masked off in the ibm-acpi hotkey's mask (or the hotkey feature is disabled in ibm-acpi).

If you want the ThinkPad's BIOS and ACPI methods to know about these keys being pressed, you probably want to leave them masked out from ibm-acpi, and use their non-HKEY events listed below, instead.

events triggered by ACPI when hotkey is masked out or disabled.
key event
FnF4 button/sleep SLPB 00000080 00000001
FnF12 ibm/hotkey HKEY 00000080 0000100c

tpb configuration

configuration keywords for tpb (to put in /etc/tpbrc)
key config keyword
Access IBM or ThinkPad THINKPAD
Home HOME
Search SEARCH
Mail MAIL
Favorites FAVORITES
Reload RELOAD
Abort ABORT
Backward BACKWARD
Forward FORWARD
Fn FN
FnSpace CALLBACK (zoom on/off)
FnPageUp CALLBACK (thinklight on/off)
FnF7 CALLBACK (display lcd/crt/both)
FnF8 CALLBACK (expand on/off)
FnHome / FnPos1 CALLBACK (brightness <percent>)
FnEnd CALLBACK (brightness <percent>)
Volume up CALLBACK (volume <percent>)
Volume down CALLBACK (volume <percent>)
Volume mute CALLBACK (mute on/off)

To all parameter keywords should be assigned the full path to the executables supposed to be started on key press. The exectable provided for the CALLBACK keyword should take the parameters given in parentheses and act according to them. If you want to use xmodmap for the HOME, SEARCH, MAIL, FAVORITES, RELOAD, ABORT, BACKWARD, FORWARD and FN keys you should provide a XEVENTS OFF in your /etc/tpbrc. You can use an appropriate executable to inject fake keystrokes.

For Debian users, tpb is started from /etc/X11/Xsession.d/90tpb.

Sound Button configuration

Note: Tested on T60p with Ubuntu 6.06 LTS

Most Thinkpads have a hardware sound mixer, thus the volumes buttons should work without configuration. However, this change is not reflected in the software mixer. tpb has a switch to enable software mixer support via OSS. The manual recommends this only for devices without a hardware mixer, but it also works for other hadware mixer enabled devices, even with the ALSA system. Just put MIXER ON in your /etc/tpbrc file and you can see the effect immediately in any ALSA mixer (e.g. kmix). For this to work you need write permissions to /dev/nvram.

Note: Tested on X21 with Ubuntu 6.06 LTS

On the ThinkPad X21 (and maybe some other older models) ACPI causes problems with tpb. On an X21 using acpi the volume buttons would work occasionally, and the OSD for tpb functions would rarely work. If a volume buttons was pressed too often, sometimes the computer would enter a low power (unplugged state) and would require a reboot. The solution is to use APM instead of ACPI. Instructions can be found in How_to_make_APM_work.

KMilo configuration

The programs to be executed by KMilo are configured via the KDE Control Center (kcontrol), under System Administration --> IBM Thinkpad Laptop. Note that you can use appropriate commands to inject fake keystrokes.

xmodmap configuration

xmodmap enables you to edit the modifier map and keymap tables that are used to translate keycodes into keysyms. Understood? Well, basically it allows you to give the X server a dictionary for the translation of keycodes like "97" into more human readable synonyms like "Home". This way xmodmap allows you to make the special keys of your keyboard known to X applications.

To discover the keycode that a certain keypress produces, use the tool $ xev

Usually you should write your keycode-keysym associations into the file ~/.Xmodmap. This file is usually read by the X session startup scripts of your system, so that the mappings automatically get included everytime you run the X server.

The ~/.Xmodmap lines for our purpose are in the form of

keycode <keycode> = <keysym>

Load the assocation using the command

$ xmodmap ~/.Xmodmap

(some configurations do this automatically upon X startup).

The following table shows the keycodes generated by the ThinkPad special keys and sensible keysyms to assign them to.

keycodes and recommended keysyms
key keycode keysym
Access IBM or ThinkPad 159 XF86LaunchA
Backward 234 XF86Back or F19
Forward 233 XF86Forward or F20
Play/Pause 162 XF86AudioPlay
Stop 164 XF86AudioStop
Next 153 XF86AudioNext
Previous 144 XF86AudioPrev
Home 178 XF86HomePage
Search 229 XF86Search
Mail 236 XF86Mail
Favorites 230 XF86AddFavorite or XF86Favorites
Reload 231 XF86Reload
Abort 232 XF86Stop
Fn 227 F35

Note: You can also use xkeycaps (an X tool to display and edit the X keyboard mapping) to generate proper .Xmodmap.

Note: if you are running tpb you might need to add the line XEVENTS=off into your tpbrc to stop it from grabbing the key events and allow them to get through to X instead. See [[1]] for more detailed instruction on how to use tpb and xmodmap.

Note: XF86Forward and XF86Back do not work correctly in Firefox. You may want to map them to F19 and F20 instead if you use Firefox.

Note: The "XF86AudioPlay" etc. just works with a few programs. To make it work with more multimedia programs you have map the key to use something like ReMoot. ReMoot is a command line wrapper that control 18 of the most common multimedia applications.

Enabling the Windows and Menu Keys

On some systems the Windows and Menu keys may not be recognized. You can enable then by making the following changes:

       keycode 115 = F13
       keycode 227 = F35

F13 and F35 are used for the Windows and and Menu keys respectively. Labelling keycpode 227 as "Menu" may conflict with the right-mouse-click event.

Using Caps Lock as Super L (Windows key)

You can easily use Caps Lock as Win key by adding the following in your ~/.Xmodmap:

       ! No Caps Lock
       clear lock
       ! Caps Lock as Win key
       add mod4 = Caps_Lock
NumLock

On the ThinkPad 600, T20, T21, T22, T30, X20, X21, X31, X40, T42p, T43, R51, R52 and possibly other models, X does not recognize the keycode for NumLk = Shift+ScrLk. To fix this, add the following to ~/.Xmodmap in your home directory or /etc/X11/Xmodmap and run xmodmap, ex: xmodmap ~/.Xmodmap:

keycode 77 = Num_Lock

This configuration also enables the respective LED.

Please note, pressing the Shift+ScrLk key combination, without first following the above configuration, will start an accessibility feature, which will allow the numeric keypad to maneuver the mouse pointer. Starting this accessibility feature and subsequently running xmodmap, as described above, results in the accessibility feature and the numeric lock LED functioning simultaneously. As such, the above configuration should be completed before the accessibility feature is started in order to produce numbers.

T60 (and possibly others)

It seems that on the T60, PrtSc, ScrLk and Pause all generate the correct keycodes, however Fn-PrtSc (labelled as SysRq) generates keycode 64 (Alt_L) followed by the expected 111 (Sys_Req) on down and the same thing in the opposite order on release. Fn-ScrLk (labelled as NmLk) does indeed toggle the Numlock, but only seems to register as an X event the first time it is engaged. This is perhaps build into the firmware rather than controlled by the kernel. Finally, Fn-Pause (labelled as Break) generates keycode 37 (Control_L) followed by the expected keycode 110 (Break) on down and the same thing in reverse order on release.

Mapping keys with setkeycodes

You can use the setkeycodes command to remap certain keys. I.e. you can use # setkeycodes 6e 109 6d 104 69 28 6b 1 to map the Tablets Up and Down keys to the standard PageUp and PageDown keys and Tablet Escape and Enter to their respective keys.

The following table shows the keycodes generated by the ThinkPad keys.

keycodes
key keycode
Tablet orientation 0x6d
Tablet Shortcut 0x6e
Tablet Esc 0x6b
Tablet Enter 0x69
Tablet Up 0x68
Tablet Down 0x6c
Tablet (unlabeled) 0x67

Example Applications

Web Browsers

Firefox

There are various ways to assign actions to the browser keys. The easiest way is to install keyconfig.xpi from http://mozilla.dorando.at, which adds a menu entry Tools->Keyconfig. Then you can assign any action you want to the F19/F20 keys (you still need to create ~/.Xmodmap as explained above).

The remaining discussion gives you various more complicated ways to achieve the same thing. To have firefox make use of the browser keys you need to modify one of its files4. To do this you will first need to extract it from the browser.jar archive. Do...

# cd <firefox-directory>/chrome
# unzip browser.jar

The file of interest is content/browser/browser.xul. Edit it {and don't forget to make a backup copy first}...

# vi content/browser/browser.xul

Look for the <keyset id="mainKeyset"> section and add the following lines within...

<key id="goBackKb" keycode="VK_F19" command="Browser:Back" />
<key id="goForwardKb" keycode="VK_F20" command="Browser:Forward" />

The Command you need for Next Tab

<key id="goBackTabKb" keycode="VK_F19" oncommand="gBrowser.mTabContainer.advanceSelectedTab(-1)" />

For the Previous Tab

<key id="goForwardTabKb" keycode="VK_F20" oncommand="gBrowser.mTabContainer.advanceSelectedTab(1)" />

Now save the file and repackage the browser.jar archive...

# zip -rD0 browser.jar content/browser/

That's it.

Hint:
For Firefox 2.0, just edit <firefox-directory>/chrome/browser/content/browser/browser.xul
Hint:
Outdated: Another interesting Page on Firefox is http://dqd.com/~mayoff/notes/thinkpad/dqdnavkeys/ It uses different key mappings (F19 resp. F20) but a ready .xpi is provided which is pretty comfortable. However, this xpi file does not install on Firefox 1.5. or later.
Hint:
You can also use the keyconfig extension to configure custom keys. This extension works with Firefox 1.5 and also with Firefox 2.0. The Command you need for Next Tab is gBrowser.mTabContainer.advanceSelectedTab(1,true); For Previous Tab its gBrowser.mTabContainer.advanceSelectedTab(-1,true); You can alternatively install the functions for keyconfig and set the variable f4kc_NextTab to F20 and f4kc_PrevTab to F19.

.

Konqueror

KDE allows you set key mappings for KDE applications (Go to KMenu > System > Control Center > Regional & Accessibility > Keyboard Shortcuts). By default (at least in KDE 3.5), XF86Back and XF86Forward are set as alternatives to Alt-Left and Alt-Right, and are mapped to KDE Back and Forward navigation actions.

If you use Konqueror as your only browser, you only need to set up ~/.Xmodmap as described above to assign ThinkPad back/forward keys to the symbols XF86Back/XF86Forward. This also make these keys work for other KDE applications such as Quanta Plus, KPackage and so on (not all KDE applications honor this setting, e.g. KDE help system doesn't).

If you want to use Firefox, however, the above settings do not work. You will have to map ThinkPad back/forward keys to F19/F20 as described above, and change KDE navigation key settings to use F19/F20 instead of the default.

Opera

However this isn't a simple configration file, you can set your browser manually.
Go to Tool > Settings > Mouse and keyboard > Keyboard settings > Edit > Browser Window. There add F19 - Back and F20 - Forward. Now you can surf using your TP keys ;-)

Window Managers

fvwm

To get the Forward and Backward keys to cycle through pages in the virtual desktop, add this to your ~/.fvwmrc:

Key    XF86Back     A      A   Scroll     -100000   0
Key    XF86Forward  A      A   Scroll     +100000   0

If you use multiple virtual desktops, you could instead use the keys to flip between them by using GotoDesk.

fluxbox

To get the keys to cycle through pages in the virtual desktop, add this to your ~/.fluxbox/keys:

None F19 :PrevWorkspace
None F20 :NextWorkspace

pekwm configuration

You can make the two browser keys switch workspaces in pekwm, by adding the following two lines to the ~/.pekwm/keys file:

KeyPress = "Mod1 XF86Back" { Actions = "GoToWorkspace prev" }
KeyPress = "Mod1 XF86Forward" { Actions = "GoToWorkspace next" }

pwm

Another example how to use these two keys to switch between pwm tabs. These two lines should be added to ~/.pwm/keys-default.conf or /etc/pwm/keys-default.conf:

kbind "Back", "switch_rot", -1
kbind "Forward", "switch_rot", 1

IceWM

To make IceWM cycle workspaces using the Forward and Backward keys, change these two options in ~/.icewm/preferences (Provided you assigned keysyms F19 and F20 with xmodmap):

# "Previous workspace" shortcut
KeySysWorkspacePrev="F19"
# "Next workspace" shortcut
KeySysWorkspaceNext="F20"

Gnome/metacity

Follow the Ubuntu guide.

Other Uses

Console tools configuraton

To make the Forward and Backward keys useful in console, add this to your keymap (/etc/console/boottime.kmap.gz in Debian):

keycode 158 = Decr_Console
keycode 159 = Incr_Console

Alternatively you can load this script (perhaps on system startup) to enable Backward/Forward button console (VT) switch:

#!/bin/sh
echo keycode 158 = Decr_Console | loadkeys
echo keycode 159 = Incr_Console | loadkeys

It should work with any distro.

Cycling through tabs

In Gnome and Xfce4, Ctrl-PageUp/Ctrl-PageDown move to the previous/following open tab in all applications that have tabbed user interfaces (terminal emulator, web browser, ...). To make use of the Forward and Backward keys for this task, there're two possibilities.

For both ways, you should map the keycodes 233 and 234 to XF86Back and XF86Forward as described in xmodmap configuration.

Using xautomation

xautomation can be found here.

Create two files with permissions 755:

/usr/local/bin/tp_back: <bash>

  1. !/bin/bash

/usr/bin/xte 'keydown Control_L' 'keydown Page_Up' 'keyup Page_Up' 'keyup Control_L' </bash>

/usr/local/bin/tp_forward: <bash>

  1. !/bin/bash

/usr/bin/xte 'keydown Control_L' 'keydown Page_Down' 'keyup Page_Down' 'keyup Control_L' </bash>

Use your desktop's keyboard shortcut editor to assign XF86Back as a shortcut for tp_back and XF86Forward as a shortcut for tp_forward.

This should work in all distros and with all window managers (you might have to use other key combinations than Ctrl-PageUp and Ctrl-PageDown).

Redirecting XF86Back/XF86Forward

Create /etc/X11/xkb/compat/thinkpad:

// $XFree86$
//  XFree86 special keysyms
default partial xkb_compatibility "basic"  {
    interpret.repeat= True;

    interpret  XF86Back {
        action = Redirect(Key=<PGUP>, modifiers=Control);
    };
    interpret  XF86Forward {
        action = Redirect(Key=<PGDN>, modifiers=Control);
    };
};

Edit /etc/X11/xkb/compat/complete and add augment "thinkpad" so that it looks similar to the following:

// $XKeyboardConfig: xkbdesc/compat/complete,v 1.3 2005/10/17 00:42:11 svu Exp $
// $Xorg: complete,v 1.3 2000/08/17 19:54:34 cpqbld Exp $
default xkb_compatibility "complete"  {
    include "basic"
    augment "iso9995"
    augment "mousekeys"
    augment "accessx(full)"
    augment "misc"
    augment "xfree86"
    augment "level5"
    augment "thinkpad"
};

External Sources


FOOTNOTES [Δ]
  1. Note that the associated functionality for Fn-F* key combinations is not consistent amongst all ThinkPads. We are maintaining a table of associated meanings.
  2. if there are more than one tool listed, one is sufficient
  3. 'full' means you can completely reassign any action to be triggered by the key, 'additional actions' means you can trigger actions in addition to the standard function of the key, which can not be changed.
  4. Thanks go to Ryan Barrett for writing the little howto on his blog.