Extra keyboard keys in Xorg

From ArchWiki
Revision as of 13:47, 3 June 2011 by CSosa (Talk | contribs) (Map keycodes to actions)

Jump to: navigation, search

This template has only maintenance purposes. For linking to local translations please use interlanguage links, see Help:i18n#Interlanguage links.

Local languages: Català – Dansk – English – Español – Esperanto – Hrvatski – Indonesia – Italiano – Lietuviškai – Magyar – Nederlands – Norsk Bokmål – Polski – Português – Slovenský – Česky – Ελληνικά – Български – Русский – Српски – Українська – עברית – العربية – ไทย – 日本語 – 正體中文 – 简体中文 – 한국어

External languages (all articles in these languages should be moved to the external wiki): Deutsch – Français – Română – Suomi – Svenska – Tiếng Việt – Türkçe – فارسی


When we are in a graphical environment we may want a key to print a special character or execute a command. There are some ways of doing that and they are covered in this HOWTO.

Template:Box Note

Map keycodes to symbols


The most traditional and proficient way to make a key output a character when you are in X is to use xmodmap. Xmodmap is roughly the X equivalent of loadkeys: it reads a file containing some directives. As loadkeys, it can be used to modify many aspects of the behaviour of your keyboard (such as modifiers, etc.), but I will not cover these aspects in this article. The only kind of directive I am interested in here associates an X keycode to a keysym. xmodmap is included in the xorg-server-utils package.

# pacman -S xorg-server-utils

Step 1: Create the xmodmap file

In this file, you have to list the keycode directives, with the following syntax:

keycode <Xkeycode> = <keysym>

The list of X keysyms can be read in Template:Filename. Anyway, most of them are intuitive. Let us say that the X keycode of my hotkey is 239. If I want it to output a literal 'e', I will write the following directive:

keycode 239 = e

If I want it to output the symbol of the American currency, I will write the following directive:

keycode 239 = dollar

This can also be used to assign functions to multimedia keys. Special functions can be found in Template:Filename.

An example Template:Filename:

keycode 160 = XF86AudioMute
keycode 176 = XF86AudioRaiseVolume
keycode 174 = XF86AudioLowerVolume

Multimedia programs such as Rhythmbox and Exaile are designed to work with keys assigned to XF86 Symbols out-of-the-box, without the need to configure a third-party application.

Step 2: Testing

Finally I have to source the file with xmodmap:

$ xmodmap ~/.Xmodmap

Step 3: Making it permanent

Obviously, this will work only for the current X session, use xprofile to make it permanent.

Map keycodes to actions


KeyTouch is a program which allows you to easily configure the extra function keys of your keyboard. This means that you can define, for every individual function key, what to do if it is pressed.

See the detailed article: keytouch.

Using xbindkeys

xbindkeys (available in the extra repository) allows advanced mapping of keycodes to actions independently of the Desktop Environment.

A GUI called xbindkeys_config is available in AUR.

Using actkbd

From actkbd home page:

actkbd (available in AUR) is a simple daemon that binds actions to keyboard events. It recognises key combinations and can handle press, repeat and release events. Currently it only supports the linux-2.6 evdev interface. It uses a plain-text configuration file which contains all the bindings.

A sample configuration and guide is available here.

Using your Desktop Environment tools


Gnome Control Center is quite complete for the extra keyboard keys management. In fact it can directly detect scancodes which means that he can map any key seen by the kernel.


In KDE 4.1, Input Actions use the KHotKeys daemon but it doesn't work.

In KDE 4.2, Input Actions are configurable from the systemsettings program.


You can change the keyboard shortcuts in Keyboard Settings, which can be run using Template:Codeline.


You can set keyboard shortcuts and actions in the keyboard section of your Template:Filename file. For example, the following will lower the volume with a media key:

<keybind key="XF86AudioLowerVolume">
<action name="Execute">
<execute>amixer set Master 5- unmute</execute>

For more information, please visit urukrama's Openbox Guide or the Openbox Wiki.


Setting keys in PekWM is accomplished by editing your Template:Filename file. For example, adding the following at the bottom of the Global section will lower the volume with a media key:

KeyPress = "XF86AudioLowerVolume" { Actions = "exec amixer set Master 5- unmute &" }


If you use Xmonad as a stand alone window manager, you can edit the xmonad.hs to add unbinded keyboard keys. You just need to find the Xf86 name of the key (such as XF86PowerDown) and look it up in Template:Codeline it will give you a keycode like 0x1008FF2A. than using that keycode you can just add a line like the following in the keybindings section of your xmonad.hs

((0,               0x1008FF2A), spawn "sudo pm-suspend")