Keyboard layout switching

Keyboard layout maps scancodes from a keyboard into characters sent to application. Keyboard layout can also do more complex transformations via so called dead keys which do not output characters on their own but modify output of subsequent keys. An appropriate keyboard layout is required to support both non-QWERTY keyboards as well as QWERTY keyboards used to enter characters outside of ASCII set.

OpenRC
Edit which is documented but not very understandable. It appears that one should choose appropriate keyboard map likely from as the value for keymap and then optionally also pick files from appropriate include directory such as  other locations might or might not work as values for the extended_keymaps variable.

Lastly add to the boot run level.

Custom keymap
To make a custom keymap look at the provided keymaps in for examples.

Here is an example custom keymap which is the same as the U.S. QWERTY keymap except the forward slash and apostrophe keys are swapped:

To find the keycodes mapped to keys view the output of :

If the key cannot me found using the above command, run:

Just press the key and its keycode will be shown. When finished wait a few seconds and will close.

systemd
systemd uses and includes both tty font and keyboard layout settings but lacks advanced settings found in OpenRC. Valid values should match what OpenRC supports for the corresponding variable.

X11
Modern X11 applications usually use libXklavier (das Klavier being German for keyboard so it has nothing to do with a certain K DE) and can be configured by using. Furthermore X11 supports much broader set of keyboard layouts than virtual terminal. It should be kept in mind that proper desktop environment will do its own keyboard layout management and there's no need to directly use aforementioned application but it can come in handy when dealing with broken or lacking keyboard layout management.

KDE4
Open and navigate to  module.

Generic desktop environment
Edit and call  from there (see below for an example on using it).

lxpanel's keyboard layout handler
provides a keyboard layout handler as panel item.



Using setxkbmap
These changes are non-permanent and will persist only as long as user does not restart X11. Naturally the command can be called from a startup script to set the appropriate parameters on every start of the X server.

Querying existing configuration:

Setting a keyboard layout:

Setting a keyboard layout, its variant and model:

Finding the supported layouts and variants or values of other xkb properties does not appear to be possible with this application and the only generic way to determine supported values is by examining. For sake of sanity use of a proper desktop environment with its own keyboard layout management is advised.

Enhancing an X keyboard layout
This is necessary if you want to make more far-reaching changes to your keyboard layout, such as adding key assignments, or adding actions to function keys. Since such changes are actually enhancements to the source files of a package, you are recommended to use the epatch_user mechanism to preserve these amendments when the package is next updated.

The fundamentals
The relevant Gentoo package is. Configuring a keyboard under X is more complicated than the doing the same for a virtual console. The pertinent configuration files can be found in in these subdirectories:


 * keycodes
 * These files associate key codes with symbolic names - you're unlikely to want to change this.


 * geometry
 * This is the physical shape of the keyboard, used by some software for drawing diagrams of it - you'll not want to change this either.


 * types
 * The files here create "types". Used in a key declaration, a type specifies which combinations of shift keys can be used with the key.


 * symbols
 * These files specify the actual key assignments.


 * compat
 * The files here specify "actions" (such as switching to a virtual terminal), giving them names, which can be assigned to keys.


 * rules
 * These files, given parameters such as the keyboard type, and a language, activate the appropriate specifications in the other directories.

A fuller description of the files in these directories can be found at An Unreliable Guide to XKB Configuration by Doug Palmer. It is a lot better than its name suggests. Further documentation can be found at xkeyboard-config's home page at freedesktop.org.

Xkb gives keys names like "" which means "key in the Alphanumeric area, in row C (i.e. third row from the bottom, the row CapsLock is on), and key number 01, the first key at the left of the row. This key is A in an English layout. Keys in other areas have other names, such as "" for F5, or "" for the left control key. The keys we want to enhance are A (), O () and U ().

Adding key assignments
As an example, we wish to enhance the British English keyboard layout such that typing a, o, or u with AltGr will generate the German umlaut letters ä, ö, and ü. It should also do the Right Thing for the upper case versions.

The names of the umlauted letters in xkb are "adiaeresis" and so on. These names can be found in the file, though you have to remove the leading "XK_"s to get the names.

Identify the pertinent file in the symbols directory. Most of these files are named as two letter country codes, e.g. "gb" for Great Britain, so guess the one which matches the keyboard layout you've selected in X. Here, we enhance symbols/gb.

With the information above, we can now create our new entries by copying the existing scheme in symbols/gb. We guess that these entries should be added into the section called "basic". We can also easily guess that the four items in the braces and brackets within the entry for each key:

key 	{ [        2,   quotedbl,  twosuperior,    oneeighth]	};

are for unshifted, shift, AltGr, and shift-AltGr respectively.

After making the additions, the section looks like this:

Having saved this file, restart your X Windows. A typical desktop environment, XFCE, re-reads the above configuration files each time it starts. Should there be errors, error messages will be written to the normal stderr - if you start your X Windows from the command line, stderr will be the virtual tty you started it from.

Adding Actions to Function Keys
As an example, we wish to add the actions "switch to virtual terminal n" (where n > 12) to the function keys F1 - F12 when control, alt, and shift are all depressed. We also want the same effect when AltGr and Fn are depressed.

First, we find the file in the symbols directory which handles the existing assignments for the Fn keys. It is symbols/srvr_ctrl. The entry in this file for F1, that we intend to modify, is:

key  { type="CTRL+ALT", symbols[Group1]= [ F1, F1, F1, F1, XF86_Switch_VT_1 ] };

There are two things to note with this entry:
 * It is of type "CTRL+ALT"; it thus takes the standard four shift key settings with and , plus a fifth setting of + . Since we wish to use + +, and there is no suitable existing type, we will need to create a new one.
 * The "action" XF86_Switch_VT_1 is just a defined symbol in the xkb system. It's semantics are given to it by an entry in a file in the compat directory, namely compat/xfree86.  There is no symbol XF86_Switch_VT_13 (or higher), so we will purloin the otherwise unused existing symbols F13, F14, ..., F24.

Creating the new type CTRL+ALT+SHIFT
Having located "CTRL+ALT" in types/pc, it is easy enough to copy it, rename the copy to "CTRL+ALT+SHIFT" and extend this to allow the modifier key combination ctrl+alt+shift. The result looks like this:

Activating the symbols F13, ..., F24
The symbol XF86_Switch_VT_1 is swifly located in compat/xfree86. It is a simple matter to copy its form, creating assignments for the symbols F13, ..., F24. The definition for the first of these symbols, F13, in compat/xfree86 then looks like:

Amending the entries in symbols for keys F1, ..., F12
Now that we have the new type CTRL+ALT+SHIFT and definitions for the symbols F13, ..., F24, we can amend the key definitions for the function keys in symbols/srvr_ctrl. That for F1 is as below, analogous definitions also need to be inserted for the other function keys.

After making these changes to types/pc, compat/xfree86, and symbols/srvr_ctrl, and restarting your X server, you should be able to switch from X directly to virtual terminals 13 and above - provided that you have configured them in your (or systemd equivalent), of course. :-)

Enhancing an X keyboard layout
This is necessary if you want to make more far-reaching changes to your keyboard layout, such as adding key assignments, or adding actions to function keys.

The fundamentals
The relevant Gentoo package is. Configuring a keyboard under X is more complicated than the doing the same for a virtual console. The pertinent configuration files can be found in in these subdirectories:


 * keycodes
 * These files associate key codes with symbolic names - you're unlikely to want to change this.


 * geometry
 * This is the physical shape of the keyboard, used by some software for drawing diagrams of it - you'll not want to change this either.


 * types
 * The files here create "types". Used in a key declaration, a type specifies which combinations of shift keys can be used with the key.


 * symbols
 * These files specify the actual key assignments.


 * compat
 * The files here specify "actions" (such as switching to a virtual terminal), giving them names, which can be assigned to keys.


 * rules
 * These files, given parameters such as the keyboard type, and a language, activate the appropriate specifications in the other directories.

A fuller description of the files in these directories can be found at An Unreliable Guide to XKB Configuration by Doug Palmer. It is a lot better than its name suggests. Further documentation can be found at xkeyboard-config's home page at freedesktop.org.

Xkb gives keys names like "" which means "key in the Alphanumeric area, in row C (i.e. third row from the bottom, the row CapsLock is on), and key number 01, the first key at the left of the row. This key is A in an English layout. Keys in other areas have other names, such as "" for F5, or "" for the left control key. The keys we want to enhance are A (), O () and U ().

Adding key assignments
As an example, we wish to enhance the British English keyboard layout such that typing a, o, or u with AltGr will generate the German umlaut letters ä, ö, and ü. It should also do the Right Thing for the upper case versions.

The names of the umlauted letters in xkb are "adiaeresis" and so on. These names can be found in the file, though you have to remove the leading "XK_"s to get the names.

Identify the pertinent file in the symbols directory. Most of these files are named as two letter country codes, e.g. "gb" for Great Britain, so guess the one which matches the keyboard layout you've selected in X. Here, we enhance symbols/gb.

With the information above, we can now create our new entries by copying the existing scheme in symbols/gb. We guess that these entries should be added into the section called "basic". We can also easily guess that the four items in the braces and brackets within the entry for each key:

key 	{ [        2,   quotedbl,  twosuperior,    oneeighth]	};

are for unshifted, shift, AltGr, and shift-AltGr respectively.

After making the additions, the section looks like this:

Having saved this file, restart your X Windows. A typical desktop environment, XFCE, re-reads the above configuration files each time it starts. Should there be errors, error messages will be written to the normal stderr - if you start your X Windows from the command line, stderr will be the virtual tty you started it from.