Keyboard configuration in Xorg

From ArchWiki
Revision as of 14:29, 11 September 2013 by Lahwaacz (Talk | contribs) (merged from Xorg#Keyboard settings)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Xorg may fail to detect your keyboard correctly. This might give problems with your keyboard layout or keyboard model not being set correctly.

To see a full list of keyboard models, layouts, variants and options, open /usr/share/X11/xkb/rules/xorg.lst.

To set the keymap for the current Xorg session:

$ setxkbmap dvorak

Key repeat delay and rate

Use xset r rate delay rate to change them, then use xinitrc to make it permanent. Values 170 and 30 respectively are a good start point.

Viewing keyboard settings

$ setxkbmap -print -verbose 10
Setting verbose level to 10
locale is C
Applied rules from evdev:
model:      evdev
layout:     us
options:    terminate:ctrl_alt_bksp
Trying to build keymap using the following components:
keycodes:   evdev+aliases(qwerty)
types:      complete
compat:     complete
symbols:    pc+us+inet(evdev)+terminate(ctrl_alt_bksp)
geometry:   pc(pc104)
xkb_keymap {
        xkb_keycodes  { include "evdev+aliases(qwerty)" };
        xkb_types     { include "complete"      };
        xkb_compat    { include "complete"      };
        xkb_symbols   { include "pc+us+inet(evdev)+terminate(ctrl_alt_bksp)"    };
        xkb_geometry  { include "pc(pc104)"     };

Setting keyboard layout

Note: If you use GNOME, these settings will be ignored. You will have to set the keyboard layout from the GNOME Keyboard applet. Follow the Keyboard Layout link and add the layout you require and remove any you do not. For XkbOptions, see GNOME#Modify Keyboard with XkbOptions.

To change your keyboard layout, create a number-*.conf file (e.g. 10-keyboard.conf) with the following content:

Section "InputClass"
    Identifier             "Keyboard Defaults"
    MatchIsKeyboard        "yes"
    Option                 "XkbLayout" "us"
    Option                 "XkbVariant" "colemak"
Note: Here is an example configurtion for setting the dvorak keyboard layout system-wide. It works on display managers such as slim and gdm.
Section "InputClass"
    Identifier             "Keyboard Defaults"
    MatchIsKeyboard        "yes"
    Option                 "XkbLayout" "dvorak"

Alternatively, you can also combine XkbLayout and XkbVariant:

Section "InputClass"
    Identifier             "Keyboard Defaults"
    MatchIsKeyboard        "yes"
    Option                 "XkbLayout" "us(colemak)"

Switching between keyboard layouts

To be able to easily switch keyboard layouts, modify the Options used in either of the above two methods. For example, to switch between a US and a Swedish layout using the Caps Lock key, create a file /etc/X11/xorg.conf.d/01-keyboard-layout.conf with the following content:

Section "InputClass"
    Identifier             "keyboard-layout"
    MatchIsKeyboard        "on"
    Option "XkbLayout"     "us, se"
    Option "XkbOptions"    "grp:caps_toggle"

As an alternative, you can add the following to your .xinitrc:

$ setxkbmap -layout "us, se" -option "grp:caps_toggle"

This is mainly useful if you run a Desktop Environment which does not take care of keyboard layouts for you.

Tip: If you want to get a list of possible values for the layout and options, you can find them in /usr/share/X11/xkb/rules/xorg.lst. They are under sections ! layout and ! option respectively. These values work for both the configuration file solution, and the command line alternative.

Enable pointerkeys

Mouse keys is now disabled by default and has to be manually enabled:

Section "InputClass"
    Identifier             "Keyboard Defaults"
    MatchIsKeyboard        "yes"
    Option                 "XkbOptions" "keypad:pointerkeys"

You can also run:

$ setxkbmap -option keypad:pointerkeys

Both will make the Shift+Num Lock shortcut toggle mouse keys.