Keyboard Layout

From Manjaro Linux
Jump to: navigation, search

Keyboardctl

Keyboardctl is a simple tool to written by the Manjaro team, that makes it possible to change both the console and X11 keyboard layout at once. The two previous config files are fused together into /etc/keyboard.conf. You can change your keyboard layout by running the command:

sudo keyboardctl -l us

In case you're using a variant of a specific keyboard layout, then you can simply add it:

sudo keyboardctl -l us colemak

The changes take effect immediately and will be saved for future sessions as well. Unfortunately, more complex situations are not possible yet. If you're looking for something more complex such as customizing a keyboard layout or switching between keyboard layouts, then you can read on for other solutions.


X11 / Xorg

note: A list of all possible keyboard layouts and other parameters can be found in: /usr/share/X11/xkb/rules/xorg.lst

Change for 1 session

It's very easy to do this, all you have to do is open a terminal and type the following:

setxkbmap be

If you use a variant of a keyboard layout, then you have to add the -variant option:

setxbmap us -variant colemak

Change permanently

kbctl -l be

OR

This requires you to edit a config file. This can be found in /etc/X11/xorg.conf.d/ and is in most cases called 20-keyboard.conf or 10-evdev.conf on earlier version of Manjaro. You'll be looking for: Section "InputClass", under that section you can edit XkbLayout to your liking. For example if you want to use the Belgian keyboard layout:

Section "InputClass"
    Identifier "system-keyboard"
    MatchIsKeyboard "on"
    Option "XkbModel" "pc105"
    Option "XkbLayout" "be"
    Option "XkbVariant" ""
EndSection

If you use a variant of a keyboard layout, then you also have to include XkbVariant:

Section "InputClass"
    Identifier "system-keyboard"
    MatchIsKeyboard "on"
    Option "XkbModel" "pc105"
    Option "XkbLayout" "us"
    Option "XkbVariant" "colemak"
EndSection

Customize keyboard layout

You'll need 2 tools for this which are normally pre-installed: xmodmap and possibly xev. First we want to save our current keyboard layout in a config file.

xmodmap -pke > ~/.Xmodmap

Now you can open this document named .Xmodmap with your favorite text editor and change everything to your liking. When you're done, save and exit. If you're not sure what every button on your keyboard is called, then you can use xev to get all information about it. Open your terminal, type xev, then press the button of which you need more info, you'll be looking for the keycode. An example: My laptop for some reason detect my Return key as KP_Enter and that creates problems in several applications, so I replace that keycode.

keycode  36 = KP_Enter KP_Enter KP_Enter KP_Enter KP_Enter KP_Enter KP_Enter
..... This becomes the following .....
keycode  36 = Return Return Return Return Return Return Return

Now we have to apply the new keyboard layout, we do this by using the following command.

xmodmap .Xmodmap

Now we have to make sure that it uses this layout every time you start X11. In order to do that you have to add the following to the autostart script of your display manager. By default Manjaro uses LXDM, so then you'll have to add this to /etc/lxdm/PostLogin. For SLiM this is .xinitrc.

if [ -f $HOME/.Xmodmap ]; then
    xmodmap "$HOME/.Xmodmap"
fi

Switch between keyboard layouts

To switch between keyboard layouts you have to add the XkbOptions option to the InputClass section. There are 2 things you can use there: grp and grp_led. grp defines which key(s) you have to press to quickly switch between keyboard layouts. grp_led uses the LEDs on your keyboard to indicate a change, this is optional. The example below shows you how to change between the Belgian layout and the Colemak layout by pressing Alt+Shift, the Scroll Lock LED indicates the change. Note that if you for example want to use a variant in the second layout but not in the first one, you can just enter a comma to indicate that no variant is required for the first layout.

Section "InputClass"
    Identifier "system-keyboard"
    MatchIsKeyboard "on"
    Option "XkbModel" "pc105"
    Option "XkbLayout" "be,us"
    Option "XkbVariant" ",colemak"
    Option "XkbOptions" "grp:alt_shift_toggle,grp_led:scroll"
EndSection

Another way to work with variants is by including them between parentheses:

Option "XkbLayout" "be,us(colemak)"
note: Shortcut for switching layout could not work if Manjaro Hardware Detection tool was used for graphic card configuration. In that case it configured keyboard options in 90-mhwd.conf file. Comment or move the keyboard options to the section in 20-keyboard.conf file to make it work.

Console

note: Finding the name of your specific keyboard layout is a bit more difficult here. You have to go to a directory called /usr/share/kbd/keymaps/i386/, there you'll have to follow the right directory to your keyboard layout. The name of your keyboard is the name of the file without .map.gz.

Change for 1 session

Just like with X11/Xorg this can be done with a simple command. Note that these commands are not the same as the ones we used to specify our keyboard layout in X11.

loadkeys be-latin1

Variants have their own keymap now, there's no need for a special variant option:

loadkeys colemak

Change permanently

All you have to do is edit this file: /etc/vconsole.conf Change the KEYMAP line to your layout. For example:

KEYMAP=be-latin1


Links