Customizing the Keyboard Layout under Linux


  • Access Umlauts from an international keyboard.
  • Keyboard-settings should work also in a terminal (Control-Alt-F1 kind of Terminal).
  • Keyboard-shortcuts should continue to work in Gnome.

Important files, programs

  • xev
  • setxkbmap
  • /usr/share/X11/xkb/keycodes/xfree86
  • /usr/share/X11/xkb/symbols/us
  • /etc/default/console-setup
  • /usXxs/altwin
  • /usXxs/capslock
  • /usXxs/compose
  • /usXxs/ctrl
  • /usXxs/eurosign
  • /usXxs/group
  • /usXxs/level3

Setup & Background information

I have an Ubuntu Linux 9.10, Karmic Koala. The xorg.conf is not to be used any more.

Key assignments of the modifiers on a normal keyboard

going from left to right on the Keyboard

Label on Keyboard Keycode (xev) xfree86 Symbol Name (xev)
Control 37 LCTL Control_L
Win 115 LWIN Meta_L
Alt 64 LALT Alt_L
Alt 113 RALT ISO_Level3_Shift
Win 116 RWIN Multi_key
Menu 117 MENU Menu
Control 109 RCTL Control_R

Key assignments of the modifiers on a Mac keyboard

going from left to right on the Keyboard

Label on Keyboard Keycode (xev) xfree86 Symbol Name (xev)
Control 37 LCTL Control_L
Alt 64 LALT Alt_L
Apple 133 LWIN Super_L
Apple 134 RALT Super_R
Numpad Enter 104 KPEN KP_ENTER


There are eight modifiers accessible in Linux, shown here together with their normal bindings:

Apple’s Command key (place of interest sign) corresponds to the windows key. Apples Option Key corresponds to the Alt Key.

GNOME and KDE use the Windows key as modifier, called “super”

Either have ` etc as dead keys or use a Compose key.

EMACS has Alt, Meta, Super, Hyper.

Mod1 Alt
Mod2 NumLock
Mod3 CapsLock
Mod4 Win = Meta
Mod5 Scroll

You can see the current setup with

> xmodmap -pm

Each modifier bit (i.e. mod?) has to be associated with at most one modifier (Alt, Meta, Hyper, Super).

Some toolkits (e.g. GTK) blindly treat mod1 as “the Alt/Meta modifier”, while Xt and XEmacs handle modifier bits according to which keysyms are bound to them (as dictated by the ICCCM).

Note that you cannot have all six of the Alt, Meta, Hyper, Super, Num_Lock and Mode_switch/ISO_Level3_Shift modifiers; there simply aren’t enough bits (the Shift, Control and Lock modifiers are restricted to specific keysyms: Shift_L/R, Control_L/R and either Shift_Lock or Caps_Lock; binding them to other keysyms won’t work).

Defining the new layout

sudo gedit /usr/share/X11/xkb/symbols/de_us

de_us is just a name. it is mainly due to the fact that this is somehow based on us_de, see link section. the file de_us is based on /usr/share/X11/xkb/symbols/macintosh_vndr/us which seems to be the keymap used by default. my de_us looks like:

// $XConsortium: macintosh /main/10 1996/01/29 19:54:54 kaleb $
// based on $XFree86: xc/programs/xkbcomp/symbols/macintosh/us,v 1.8 2003/08/04 10:32:31 eich Exp $
// $XFree86: xc/programs/xkbcomp/symbols/de_us,v 1.8 2003/08/04 10:32:31 eich Exp $

// symbols definition for a Macintosh "Extended" keyboard
// edited for umlauts, switched keys, and modifiers

partial default alphanumeric_keys
xkb_symbols "extended" {

    include "macintosh_vndr/us"

    name[Group1]= "DE_US";

    // Alphanumeric section
    key  {	[   section,	plusminus	]	};
    key  {	[	  0,	parenright,	degree	]	};

    key  {        [         e,    E, EuroSign               ]       };
    key  {	[	  u,	U,	udiaeresis, 	Udiaeresis		]	};
    key  {	[	  o,	O,	odiaeresis,	Odiaeresis		]	};

    key  {	[	  a,	A,	adiaeresis,	Adiaeresis 		]	};
    key  {	[	  s,	S,	ssharp,	ssharp		]	};

    key  {	[ quoteleft,	asciitilde		]	};
    key  {	[     comma,	less,	guillemotleft		]	};
    key  {	[    period,	greater,	guillemotright		]	};
    // End alphanumeric section

    // Begin "Modifier" section
    key  {	[  Multi_key	]	}; // compose key
    // replace KP_ENTER
    replace key  { [ ISO_Level3_Shift ] }; // access tho third/forth column
    modifier_map Mod5  { ISO_Level3_Shift };     
    // End "Modifier" section

Activating the new layout

setxkbmap -layout de_us

making a small script containing exactly this line and adding that to the session-startup thing will then always load the changed keyboard. note that the keys are not changed before login into your window manager. this means that they are not active in the "real" terminals and also not when entering the password.

To get this working, edit


and give your XKBLAYOUT. then run

sudo /etc/init.d/console-setup restart

It seems that this is buggy in the moment. If you need your setup in the TTYs, you can run

sudo setupcon


Leave a Reply