Difference between revisions of "Keyboard configuration in console"

From ArchWiki
Jump to: navigation, search
m (Add zh_CN page.)
m (Temporary configuration: remove "of course")
 
(68 intermediate revisions by 15 users not shown)
Line 1: Line 1:
 
[[Category:Keyboards]]
 
[[Category:Keyboards]]
[[zh-CN:Keyboard Configuration in Console]]
+
[[es:Keyboard configuration in console]]
{{Article summary start}}
+
[[ja:コンソールでのキーボード設定]]
{{Article summary text|Basic configuration of keyboard layouts in [[Wikipedia:Virtual console|virtual console]].}}
+
[[pt:KEYMAP]]
{{Article summary heading|Related}}
+
[[zh-cn:Keyboard configuration in console]]
{{Article summary wiki|Keyboard Configuration in Xorg}}
+
{{Related articles start}}
{{Article summary wiki|Extra Keyboard Keys}}
+
{{Related|Keyboard configuration in Xorg}}
{{Article summary end}}
+
{{Related|Extra keyboard keys}}
 +
{{Related|Fonts#Console fonts}}
 +
{{Related articles end}}
  
{{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.}}
  
Keyboard mappings (keymaps) for [[Wikipedia:Virtual console|virtual console]], console fonts and console maps are provided by the {{Pkg|kbd}} package (it should already be installed), which also provides many low-level tools for managing virtual console.
+
Keyboard mappings (keymaps) for [[Wikipedia:Virtual console|virtual console]], console fonts and console maps are provided by the {{Pkg|kbd}} package (a dependency of [[systemd]]), which also provides many low-level tools for managing virtual console. In addition, ''systemd'' also provides the ''localectl'' tool, which can control both the system [[locale]] and keyboard layout settings for both the virtual console and Xorg.
  
 
== Viewing keyboard settings ==
 
== Viewing keyboard settings ==
  
You can use the following command to view keyboard configuration:
+
Use {{ic|localectl status}} to view the current keyboard configurations.
 
+
{{hc|$ localectl status|<nowiki>
+
  System Locale: LANG=en_GB.utf8
+
                  LC_COLLATE=C
+
      VC Keymap: cz-qwertz
+
      X11 Layout: cz
+
</nowiki>}}
+
  
 
== Setting keyboard layout ==
 
== Setting keyboard layout ==
  
Unlike [[XKB]] keyboard layout, which is composed of multiple components, the keyboard layout for virtual console has only one component. Usually one keymap file corresponds to one keyboard layout (the ''include'' statement can be used to share common parts and a keymap file can contain multiple layouts with some key combination used for switching). The keymap files are stored in {{ic|/usr/share/kbd/keymaps/}} directory tree. You can use the following command to list all available keymaps:
+
=== Keymap codes ===
 +
 
 +
Usually one keymap file corresponds to one keyboard layout (the {{ic|include}} statement can be used to share common parts and a keymap file can contain multiple layouts with some key combination used for switching). The keymap files are stored in the {{ic|/usr/share/kbd/keymaps/}} directory tree.
 +
 
 +
The naming conventions of console keymaps are somewhat arbitrary, but usually they are based on:
 +
 
 +
* [[wikipedia:ISO_639-1|Language codes]]: where the language code is the same as its country code (e.g. {{ic|de}} for German, or {{ic|fr}} for French).
 +
* [[wikipedia:Country_code|Country codes]]: where variations of the same language are used in different countries (e.g.{{ic|uk}} for United Kingdom English, or {{ic|us}} for United States English); a list of country codes can also be found in [[wikipedia:ISO 3166-1#Officially assigned code elements]].
 +
* [[wikipedia:Keyboard_layout|Keyboard layouts]]: where the layout is not related to a particular country or language (e.g. {{ic|dvorak}} for the [[wikipedia:Dvorak_Simplified_Keyboard|Dvorak keyboard layout]]).
 +
 
 +
For a list of all the available keymaps, use the command:
  
 
  $ localectl list-keymaps
 
  $ localectl list-keymaps
  
The naming conventions of console keymaps are not very strict, but usually the name consists of a [[Wikipedia:ISO_3166-1_alpha-2#Officially_assigned_code_elements|2-letter country code]] and a variant, separated by slash ({{ic|-}}) or underscore ({{ic|_}}).
+
To search for a keymap, use the following command, replacing {{ic|''search_term''}} with the code for your language, country, or layout:
 +
 
 +
$ localectl list-keymaps | grep -i ''search_term''
 +
 
 +
Alternatively, using find:
 +
 
 +
$ find /usr/share/kbd/keymaps/ -type f
  
 
=== Persistent configuration ===
 
=== Persistent configuration ===
  
High-level configuration can be done in {{ic|/etc/vconsole.conf}}, which is read by [[systemd]] on start-up. The {{ic|KEYMAP}} variable is used for specifying keymap. If the variable is empty or not set, the {{ic|us}} keymap is used as default value. See {{ic|man 5 vconsole.conf}} for all options. For example:
+
A persistent keymap can be set in {{ic|/etc/vconsole.conf}}, which is read by [[systemd]] on start-up. The {{ic|KEYMAP}} variable is used for specifying the keymap. If the variable is empty or not set, the {{ic|us}} keymap is used as default value. See {{ic|man 5 vconsole.conf}} for all options. For example:
  
 
{{hc|/etc/vconsole.conf|<nowiki>
 
{{hc|/etc/vconsole.conf|<nowiki>
KEYMAP=cz-qwertz
+
KEYMAP=uk
 
...
 
...
 
</nowiki>}}
 
</nowiki>}}
  
For convenience, ''localectl'' may be used to set console keymap. It will change the {{ic|KEYMAP}} variable in {{ic|/etc/vconsole.conf}} and set the keymap for current session. For example:
+
For convenience, ''localectl'' may be used to set console keymap. It will change the {{ic|KEYMAP}} variable in {{ic|/etc/vconsole.conf}} and also set the keymap for current session:
  
 
  $ localectl set-keymap --no-convert ''keymap''
 
  $ localectl set-keymap --no-convert ''keymap''
  
See {{ic|man 1 localectl}} for details.
+
The {{ic|--no-convert}} option can be used to prevent {{ic|localectl}} from automatically changing the [[Keyboard configuration in Xorg|Xorg keymap]] to the nearest match. See {{ic|man localectl}} for more information.
  
 
=== Temporary configuration ===
 
=== Temporary configuration ===
  
Of course it is possible to set a keymap just for current session. This is useful for testing different keymaps, solving problems etc.
+
It is possible to set a keymap just for current session. This is useful for testing different keymaps, solving problems etc.
  
 
The ''loadkeys'' tool is used for this purpose, it is used internally by [[systemd]] when loading the keymap configured in {{ic|/etc/vconsole.conf}}. It can be used very simply for this purpose:
 
The ''loadkeys'' tool is used for this purpose, it is used internally by [[systemd]] when loading the keymap configured in {{ic|/etc/vconsole.conf}}. It can be used very simply for this purpose:
Line 56: Line 67:
 
See {{ic|man 1 loadkeys}} details.
 
See {{ic|man 1 loadkeys}} details.
  
== Other settings ==
+
== Adjusting typematic delay and rate ==
  
=== Changing console font ===
+
The ''typematic delay'' indicates the amount of time (typically in miliseconds) a key needs to be pressed in order for the repeating process to begin. After the repeating process has been triggered, the character will be repeated with a certain frequency (usually given in Hz) specified by the ''typematic rate''. These values can be changed using the ''kbdrate'' command. Note that the typematic delay in the virtual console is different from the [[Keyboard_configuration_in_Xorg#Adjusting_typematic_delay_and_rate|typematic delay in Xorg]].
 
+
The {{Pkg|kbd}} package provides tools to change virtual console font and font mapping. The fonts are saved in {{ic|/usr/share/kbd/consolefonts/}} directory.
+
 
+
The configuration is done in {{ic|vconsole.conf}} using the {{ic|FONT}} and {{ic|FONT_MAP}} variables:
+
 
+
{{hc|/etc/vconsole.conf|<nowiki>
+
...
+
FONT=Lat2-Terminus16
+
FONT_MAP=8859-2
+
</nowiki>}}
+
 
+
If the {{ic|FONT}} variable is empty or not set, the kernel built-in font is used as default. See {{ic|man 5 vconsole.conf}} for details.
+
 
+
=== Adjusting typematic delay and rate ===
+
 
+
The ''typematic delay'' indicates the amount of time (typically in miliseconds) a key needs to be pressed in order for the repeating process to begin. After the repeating process has been triggered, the character will be repeated with a certain frequency (usually given in Hz) specified by the ''typematic rate''. These values can be changed using the ''kbdrate'' command:
+
  
 
  # kbdrate [-d ''delay''] [-r ''rate'']
 
  # kbdrate [-d ''delay''] [-r ''rate'']
Line 85: Line 80:
  
 
  # kbdrate
 
  # kbdrate
 +
 +
=== Systemd service ===
 +
 +
A systemd service can be used to set the keyboard rate. For example
 +
 +
{{hc|/etc/systemd/system/kbdrate.service|
 +
<nowiki>
 +
[Unit]
 +
Description=Keyboard repeat rate in tty.
 +
 +
[Service]
 +
Type=simple
 +
RemainAfterExit=yes
 +
StandardInput=tty
 +
StandardOutput=tty
 +
ExecStart=/usr/bin/kbdrate -s -d 450 -r 60
 +
 +
[Install]
 +
WantedBy=multi-user.target
 +
</nowiki>}}
 +
 +
Then [[start/enable]] the {{ic|kbdrate.service}} systemd service.

Latest revision as of 02:00, 10 July 2016

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

Keyboard mappings (keymaps) for virtual console, console fonts and console maps are provided by the kbd package (a dependency of systemd), which also provides many low-level tools for managing virtual console. In addition, systemd also provides the localectl tool, which can control both the system locale and keyboard layout settings for both the virtual console and Xorg.

Viewing keyboard settings

Use localectl status to view the current keyboard configurations.

Setting keyboard layout

Keymap codes

Usually one keymap file corresponds to one keyboard layout (the include statement can be used to share common parts and a keymap file can contain multiple layouts with some key combination used for switching). The keymap files are stored in the /usr/share/kbd/keymaps/ directory tree.

The naming conventions of console keymaps are somewhat arbitrary, but usually they are based on:

For a list of all the available keymaps, use the command:

$ localectl list-keymaps

To search for a keymap, use the following command, replacing search_term with the code for your language, country, or layout:

$ localectl list-keymaps | grep -i search_term

Alternatively, using find:

$ find /usr/share/kbd/keymaps/ -type f

Persistent configuration

A persistent keymap can be set in /etc/vconsole.conf, which is read by systemd on start-up. The KEYMAP variable is used for specifying the keymap. If the variable is empty or not set, the us keymap is used as default value. See man 5 vconsole.conf for all options. For example:

/etc/vconsole.conf
KEYMAP=uk
...

For convenience, localectl may be used to set console keymap. It will change the KEYMAP variable in /etc/vconsole.conf and also set the keymap for current session:

$ localectl set-keymap --no-convert keymap

The --no-convert option can be used to prevent localectl from automatically changing the Xorg keymap to the nearest match. See man localectl for more information.

Temporary configuration

It is possible to set a keymap just for current session. This is useful for testing different keymaps, solving problems etc.

The loadkeys tool is used for this purpose, it is used internally by systemd when loading the keymap configured in /etc/vconsole.conf. It can be used very simply for this purpose:

# loadkeys keymap

See man 1 loadkeys details.

Adjusting typematic delay and rate

The typematic delay indicates the amount of time (typically in miliseconds) a key needs to be pressed in order for the repeating process to begin. After the repeating process has been triggered, the character will be repeated with a certain frequency (usually given in Hz) specified by the typematic rate. These values can be changed using the kbdrate command. Note that the typematic delay in the virtual console is different from the typematic delay in Xorg.

# kbdrate [-d delay] [-r rate]

For example to set a typematic delay to 200ms and a typematic rate to 30Hz, use the following command:

# kbdrate -d 200 -r 30

Issuing the command without specifying the delay and rate will reset the typematic values to their respective defaults; a delay of 250ms and a rate of 11Hz:

# kbdrate

Systemd service

A systemd service can be used to set the keyboard rate. For example

/etc/systemd/system/kbdrate.service

[Unit]
Description=Keyboard repeat rate in tty.

[Service]
Type=simple
RemainAfterExit=yes
StandardInput=tty
StandardOutput=tty
ExecStart=/usr/bin/kbdrate -s -d 450 -r 60
 
[Install]
WantedBy=multi-user.target

Then start/enable the kbdrate.service systemd service.