Difference between revisions of "Keyboard configuration in Xorg"

From ArchWiki
Jump to: navigation, search
(added note - define scope of this page)
(Setting keyboard layout)
Line 1: Line 1:
 
{{Note|This article covers only basic configuration without modifying layouts, mapping extra keys etc. See [[Extra Keyboard Keys]] for these advanced topics.}}
 
{{Note|This article covers only basic configuration without modifying layouts, mapping extra keys etc. See [[Extra Keyboard Keys]] for these advanced topics.}}
  
Xorg may fail to detect your keyboard correctly. This might give problems with your keyboard layout or keyboard model not being set correctly.
+
== Setting keyboard layout ==
  
To see a full list of keyboard models, layouts, variants and options, open {{ic|/usr/share/X11/xkb/rules/xorg.lst}}.
+
Keyboard layout in Xorg can be set in multiple ways. Here is an explanation of used options:
  
To set the keymap for the current Xorg session:
+
* {{ic|XkbModel}} selects the keyboard model. This has an influence only for some extra keys your keyboard might have. The safe fallback are {{ic|pc104}} or {{ic|pc105}}. But for instance laptops usually have some extra keys, and sometimes you can make them work by simply setting a proper model.
 +
* {{ic|XkbLayout}} selects the keyboard layout. Multiple layouts may be specified in a comma-separated list, e.g. if you want to quickly switch between layouts.
 +
* {{ic|XkbVariant}} selects a specific layout variant. For instance, the default {{ic|sk}} variant is {{ic|qwertz}}, but you can manually specify {{ic|qwerty}} etc.
 +
: {{Warning|You must specify as many variants as the number of specified layouts. If you want the default variant, specify an empty string as the variant (the comma must stay). For example, to have the default {{ic|us}} layout as primary and the {{ic|dvorak}} variant of {{ic|us}} layout as secondary, specify {{ic|us,us}} as {{ic|XkbLayout}} and {{ic|,dvorak}} as {{ic|XkbVariant}}.}}
 +
* {{ic|XkbOptions}} contains some extra options. Used for specifying layout switching, notification LED, compose mode etc.
  
$ setxkbmap dvorak
+
To see a full list of keyboard models, layouts, variants and options, open {{ic|/usr/share/X11/xkb/rules/xorg.lst}}. Alternatively, you may use one of the following commands:
  
==== Key repeat delay and rate ====
+
Examples in the following subsections will have the same effect, they will set {{ic|pc104}} model, {{ic|cz}} as primary layout, {{ic|us}} as secondary layout, {{ic|dvorak}} variant for {{ic|us}} layout and the {{ic|Alt+Shift}} combination for switching between layouts.
 +
 
 +
=== Using setxkbmap ===
 +
 
 +
The tool ''setxkbmap'' sets the keyboard layout for an active X server and the setting is persistent only until the session ends. It is useful to override system-wide configuration specified by [[#Using X configuration files|X configuration files]].
 +
 
 +
The usage is as follows:
 +
 
 +
$ setxkbmap -model ''xkb_model'' -layout ''xkb_layout'' -variant ''xkb_variant'' -option ''xkb_options''
 +
 
 +
It is not necessary to specify all options, e.g. you can change just a layout:
 +
 
 +
$ setxkbmap -layout ''xkb_layout''
 +
 
 +
See {{ic|man 1 setxkbmap}} for a full list of command line arguments.
 +
 
 +
For example:
 +
 
 +
$ setxkbmap -model pc104 -layout cz,us -variant ,dvorak -option grp:alt_shift_toggle
 +
 
 +
=== Using X configuration files ===
 +
 
 +
The syntax of X configuration files is explained in [[Xorg#Configuration]]. This method creates system-wide configuration which is persistent across reboots.
 +
 
 +
Here is an example:
 +
 
 +
{{hc|/etc/X11/xorg.conf.d/10-keyboard.conf|
 +
Section "InputClass"
 +
        Identifier "system-keyboard"
 +
        MatchIsKeyboard "on"
 +
        Option "XkbLayout" "cz,us"
 +
        Option "XkbModel" "pc104"
 +
        Option "XkbVariant" ",dvorak"
 +
        Option "XkbOptions" "grp:alt_shift_toggle"
 +
EndSection
 +
}}
 +
 
 +
=== Using localectl ===
 +
 
 +
For convenience, the tool ''localectl'' may be used instead of manual editing of X configuration file. It will save the configuration in {{ic|/etc/X11/xorg.conf.d/00-keyboard.conf}}, this file should not be manually edited, because ''localectl'' will overwrite the changes on next start.
 +
 
 +
The usage is as follows:
 +
 
 +
$ localectl set-x11-keymap ''layout'' [''model''] [''variant''] [''options'']
 +
 
 +
The following command will create a file {{ic|/etc/X11/xorg.conf.d/00-keyboard.conf}} with pretty much the same content as the example above:
 +
 
 +
$ localectl set-x11-keymap cz,us pc104 ,dvorak grp:alt_shift_toggle
 +
 
 +
 
 +
 
 +
 
 +
 
 +
 
 +
== Key repeat delay and rate ==
  
 
Use {{ic|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.
 
Use {{ic|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 ====
+
== Viewing keyboard settings ==
  
 
{{hc|$ setxkbmap -print -verbose 10|<nowiki>
 
{{hc|$ setxkbmap -print -verbose 10|<nowiki>
Line 37: Line 95:
 
</nowiki>}}
 
</nowiki>}}
  
==== Setting keyboard layout ====
+
== 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]].}}
 
{{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 {{ic|''number''-*.conf}} file (e.g. {{ic|10-keyboard.conf}}) with the following content:
 
  
{{hc|/etc/X11/xorg.conf.d/10-keyboard.conf|
 
Section "InputClass"
 
    Identifier            "Keyboard Defaults"
 
    MatchIsKeyboard        "yes"
 
    Option                "XkbLayout" "us"
 
    Option                "XkbVariant" "colemak"
 
EndSection
 
}}
 
 
{{Note|Here is an example configurtion for setting the dvorak keyboard layout system-wide. It works on display managers such as slim and gdm.}}
 
 
{{hc|/etc/X11/xorg.conf.d/10-keyboard.conf|
 
Section "InputClass"
 
    Identifier            "Keyboard Defaults"
 
    MatchIsKeyboard        "yes"
 
    Option                "XkbLayout" "dvorak"
 
EndSection
 
}}
 
 
Alternatively, you can also combine {{ic|XkbLayout}} and {{ic|XkbVariant}}:
 
 
{{hc|/etc/X11/xorg.conf.d/10-keyboard.conf|
 
Section "InputClass"
 
    Identifier            "Keyboard Defaults"
 
    MatchIsKeyboard        "yes"
 
    Option                "XkbLayout" "us(colemak)"
 
EndSection
 
}}
 
  
==== Switching between keyboard layouts ====
+
== 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 {{ic|Caps Lock}} key, create a file {{ic|/etc/X11/xorg.conf.d/01-keyboard-layout.conf}} with the following content:
 
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 {{ic|Caps Lock}} key, create a file {{ic|/etc/X11/xorg.conf.d/01-keyboard-layout.conf}} with the following content:
Line 93: Line 122:
 
{{Tip|If you want to get a list of possible values for the layout and options, you can find them in {{ic|/usr/share/X11/xkb/rules/xorg.lst}}. They are under sections {{ic|! layout}} and {{ic|! option}} respectively. These values work for both the configuration file solution, and the command line alternative.}}
 
{{Tip|If you want to get a list of possible values for the layout and options, you can find them in {{ic|/usr/share/X11/xkb/rules/xorg.lst}}. They are under sections {{ic|! layout}} and {{ic|! option}} respectively. These values work for both the configuration file solution, and the command line alternative.}}
  
==== Enable pointerkeys ====
+
== Enable pointerkeys ==
  
 
[[Wikipedia:Mouse keys|Mouse keys]] is now disabled by default and has to be manually enabled:
 
[[Wikipedia:Mouse keys|Mouse keys]] is now disabled by default and has to be manually enabled:

Revision as of 16:13, 11 September 2013

Note: This article covers only basic configuration without modifying layouts, mapping extra keys etc. See Extra Keyboard Keys for these advanced topics.

Setting keyboard layout

Keyboard layout in Xorg can be set in multiple ways. Here is an explanation of used options:

  • XkbModel selects the keyboard model. This has an influence only for some extra keys your keyboard might have. The safe fallback are pc104 or pc105. But for instance laptops usually have some extra keys, and sometimes you can make them work by simply setting a proper model.
  • XkbLayout selects the keyboard layout. Multiple layouts may be specified in a comma-separated list, e.g. if you want to quickly switch between layouts.
  • XkbVariant selects a specific layout variant. For instance, the default sk variant is qwertz, but you can manually specify qwerty etc.
Warning: You must specify as many variants as the number of specified layouts. If you want the default variant, specify an empty string as the variant (the comma must stay). For example, to have the default us layout as primary and the dvorak variant of us layout as secondary, specify us,us as XkbLayout and ,dvorak as XkbVariant.
  • XkbOptions contains some extra options. Used for specifying layout switching, notification LED, compose mode etc.

To see a full list of keyboard models, layouts, variants and options, open /usr/share/X11/xkb/rules/xorg.lst. Alternatively, you may use one of the following commands:

Examples in the following subsections will have the same effect, they will set pc104 model, cz as primary layout, us as secondary layout, dvorak variant for us layout and the Alt+Shift combination for switching between layouts.

Using setxkbmap

The tool setxkbmap sets the keyboard layout for an active X server and the setting is persistent only until the session ends. It is useful to override system-wide configuration specified by X configuration files.

The usage is as follows:

$ setxkbmap -model xkb_model -layout xkb_layout -variant xkb_variant -option xkb_options

It is not necessary to specify all options, e.g. you can change just a layout:

$ setxkbmap -layout xkb_layout

See man 1 setxkbmap for a full list of command line arguments.

For example:

$ setxkbmap -model pc104 -layout cz,us -variant ,dvorak -option grp:alt_shift_toggle

Using X configuration files

The syntax of X configuration files is explained in Xorg#Configuration. This method creates system-wide configuration which is persistent across reboots.

Here is an example:

/etc/X11/xorg.conf.d/10-keyboard.conf
Section "InputClass"
        Identifier "system-keyboard"
        MatchIsKeyboard "on"
        Option "XkbLayout" "cz,us"
        Option "XkbModel" "pc104"
        Option "XkbVariant" ",dvorak"
        Option "XkbOptions" "grp:alt_shift_toggle"
EndSection

Using localectl

For convenience, the tool localectl may be used instead of manual editing of X configuration file. It will save the configuration in /etc/X11/xorg.conf.d/00-keyboard.conf, this file should not be manually edited, because localectl will overwrite the changes on next start.

The usage is as follows:

$ localectl set-x11-keymap layout [model] [variant] [options]

The following command will create a file /etc/X11/xorg.conf.d/00-keyboard.conf with pretty much the same content as the example above:

$ localectl set-x11-keymap cz,us pc104 ,dvorak grp:alt_shift_toggle




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.


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"
EndSection

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:

/etc/X11/xorg.conf.d/20-enable-pointerkeys.conf
Section "InputClass"
    Identifier             "Keyboard Defaults"
    MatchIsKeyboard        "yes"
    Option                 "XkbOptions" "keypad:pointerkeys"
EndSection

You can also run:

$ setxkbmap -option keypad:pointerkeys

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