User Tools

Site Tools


How to modify keybindings under X11

Task: Adapt an xorg/X11 keymap to your personal needs. To be specific, let us add European special characters (German umlauts, accent dead keys, euro sign) to the standard ASCII keyboard us. The modified keymap shall be called us_de.

Solution: (1) Create a difference file us_de_diff. (2) Create an overarching file us_de that calls in both us and us_de_diff. (3) Test with setxkbmap. (4) Make us_de permanently known to the operating system.

Step 1: Create a difference file ''us_de_diff''

The following example extends the US ASCII keyboard by the following ALT keys:

  • ALT-a, ALT-o, ALT-u produce the German umlauts äöü.
  • ALT-A, ALT-O, ALT-U produce the uppercase umlauts ÄÖÜ.
  • ALT-s produces the German ligature ß.
  • ALT-e produces the Euro sign €.
  • ALT-1 to ALT-6 are various dead keys (accents, diaeresis, cedilla).
  • ALT-7 produces the section symbol (German “Paragraph”) §.
  • ALT-z and ALT-x produce guillemots «».

Save the following as /usr/share/X11/xkb/symbols/us_de_diff:

default partial 
xkb_symbols "basic" {
    key <AE01> {  [  1,   exclam      , dead_grave             ] };
    key <AE02> {  [  2,   at          , dead_circumflex        ] };
    key <AE03> {  [  3,   numbersign  , dead_acute             ] };
    key <AE04> {  [  4,   dollar      , dead_diaeresis         ] };
    key <AE05> {  [  5,   percent     , dead_cedilla           ] };
    key <AE06> {  [  6,   asciicircum , dead_caron             ] };
    key <AE07> {  [  7,   ampersand   , section                ] };
    key <AD03> {  [  e,   E           , EuroSign               ] };
    key <AD07> {  [  u,   U           , udiaeresis, Udiaeresis ] };
    key <AD09> {  [  o,   O           , odiaeresis, Odiaeresis ] };
    key <AC01> {  [  a,   A           , adiaeresis, Adiaeresis ] };
    key <AC02> {  [  s,   S           , ssharp                 ] };
    key <AB03> {  [  c,   C           , ccedilla               ] };
    key <AB01> {  [  z,   Z           , guillemotleft          ] };
    key <AB02> {  [  x,   X           , guillemotright         ] };
};

Step 2: Create a master file ''us_de''

Save the following as /usr/share/X11/xkb/symbols/us_de:

partial default alphanumeric_keys
xkb_symbols "basic" {
    include "us"
    include "us_de_diff"
    name[Group1]="en_US";
    key <RALT>  { type[Group1]="TWO_LEVEL",
                  [ ISO_Level3_Shift, Multi_key ]   };
    modifier_map Mod5   { <RALT> };
};
xkb_symbols "nodeadkeys" {
    include "pc/en_US(basic)"
    include "pc/latin(nodeadkeys)"
    include "us_de_diff"
};

Step 3: Test

Use the command

setxkbmap -layout us_de

to test the new key binding.

Step 4: Make changes permanent

Edit the appropriate config file. Changes will become effective with the next upstart of the X11 server.

Current X11 versions: Modify the XKBLAYOUT entry in /etc/default/keyboard.

Old X11 versions: Modify the following section in /etc/X11/xorg.conf:

Section "InputDevice"
        [...]
        Option      "XkbLayout" "us_de"
EndSection

Please inform me if other distribution need to be configured in different ways.

Changelog

Maintained by Joachim Wuttke.

First published in the German Linux-Magazin 10/2003, under the title “Deutsch-Amerikanische Freundschaft”.

Revised version for X11R7 published online 2006.

Revised version for X.Org versions without xorg.conf, 3 March 2012.