Linux Commands Examples

A great documentation place for Linux commands

setxkbmap

set the keyboard using the X Keyboard Extension


see also : xkbcomp

Synopsis

setxkbmap [ args ] [ layout [ variant [ option ... ] ] ]


add an example, a script, a trick and tips

: email address (won't be displayed)
: name

Step 2

Thanks for this example ! - It will be moderated and published shortly.

Feel free to post other examples
Oops ! There is a tiny cockup. A damn 404 cockup. Please contact the loosy team who maintains and develops this wonderful site by clicking in the mighty feedback button on the side of the page. Say what happened. Thanks!

examples

20
source
            
setxkbmap us intl
18
source
            
setxkbmap -option ctrl:nocaps
9
source
            
setxkbmap no
8
source
            
setxkbmap -layout $1
8
source
            
setxkbmap -option 'ctrl:nocaps'
4
source
            
setxkbmap es
3
source
            
setxkbmap -option compose:caps
2
source
            
setxkbmap -layout dvorak
2
source
            
setxkbmap dvorak # uså°±å??ä¾?äº?
1
source

Using a custom keyboard map

Is it acceptable for you to do this by Xmodmap?

When you run xmodmap -pke > .Xmodmap it will generate a .Xmodmap file containing your current keyboard mapping in a format like keycode 57 = n N with a line for each keycode followed by the keysyms currently mapped to it by your layout and each column corresponing to a different modifier (so in this case 'n' with no modifier and 'N' when used with shift). You can edit your layout there and just run xmodmap .Xmodmap to activate it.

A short, helpful introduction can be found here

1
source

How to configure X kbmap for 4 languages while keeping two "main" languages easily switchable?

Have bound the following script to a hotkey:

#!/bin/sh
if setxkbmap -query | grep -q lang1,lang2 ; then 
    setxkbmap -model acer_laptop -layout lang3,lang4 -variant , ;
else 
    setxkbmap -model acer_laptop -layout lang1,lang2 -variant , ;
fi
1
source

Switching left alt and left win

I'm not completely sure whether or not I have understood what are you asking for but I suggest this link... Remapping Keys with AutoHotkey

0
source

Linux, Ubuntu & Apple Aluminium keyboard: remap greater/less with tilde

xmodmap Way

First, check this out.

Here's my version of .xsession:

#! /usr/bin/env sh
GTK_IM_MODULE=xim
QT_IM_MODULE=xim
xmodmap ~/.Xmodmap-Apple

and the corresponding ~/.Xmodmap-Apple (for the Russian version):

keycode 94 = grave asciitilde Cyrillic_io Cyrillic_IO
keycode 191 = Print Sys_Req Print Sys_Req Print Sys_Req
keycode 192 = Scroll_Lock NoSymbol Scroll_Lock NoSymbol Scroll_Lock
keycode 193 = Pause Break Pause Break Pause Break
keycode 49 = less greater less greater
keycode 108 = Multi_key Alt_L Multi_key Alt_L

setxkbmap way

In Linux, setxkbmap is used to switch keyboard layouts. Alas, setxkbmap & xmodmap can't work together: they reset each other's changes :( You'll have to pick one of:

  • Just don't switch layouts
  • Invoke xmodmap after every layout switching (or make a script replacing setxkbmap)
  • modify xkb key mappings for your keyboard.

We'll use the latter. First, check which layout you're using:

$ setxkbmap -print
xkb_keymap {
        xkb_keycodes  { include "evdev+aliases(qwerty)" };
        xkb_types     { include "complete+caps(internal)"       };
        xkb_compat    { include "complete"      };
        xkb_symbols   { include "pc+us+ru:2+inet(evdev)+altwin(meta_win)+group(alt_shift_toggle)+compose(ralt)+eurosign(e)+terminate(ctrl_alt_bksp)+macintosh_vndr/apple(alupckeys)"    };
        xkb_geometry  { include "pc(pc104)"     };
};

Here's your symbols map: xkb_symbols ... macintosh_vndr/apple(alupckeys)

In Ubuntu, we have a mapping for apple keyboards here: '/usr/share/X11/xkb/*symbols/macintosh_vndr/apple*'. First, backup this file. This file has several sections, each starts like this:

xkb_symbols "extended" {
xkb_symbols "laptop" {
xkb_symbols "laptop_bad_switch" {
xkb_symbols "alukbd" {
xkb_symbols "alupckeys" {

The latter mapping, "alupckeys", replaces F13-F15 with PrintScreen, ScrollLock, Pause. Use it if you lack these keys :)

Choose the section you've got from the command output above, and append the following, before the final } of the section:

    key <LSGT> { [ grave, asciitilde, grave, asciitilde ] };
};

Now, restart X. Yeehaw, enjoy having the tilde key on the correct place :)

This command can also help:

$ setxkbmap -option "apple:alupckeys" -print | xkbcomp - $DISPLAY

description

The setxkbmap command maps the keyboard to use the layout determined by the options specified on the command line.

An XKB keymap is constructed from a number of components which are compiled only as needed. The source for all of the components can be found in /usr/share/X11/xkb.

options

-help

Prints a message describing the valid input to setxkbmap.

-compat name

Specifies the name of the compatibility map component used to construct a keyboard layout.

-config file

Specifies the name of an XKB configuration file which describes the keyboard to be used.

-device device

Specifies the numeric device id of the input device to be updated with the new keyboard layout. If not specified, the core keyboard device of the X server is updated.

-display display

Specifies the display to be updated with the new keyboard layout.

-geometry name

Specifies the name of the geometry component used to construct a keyboard layout.

-I directory

Adds a directory to the list of directories to be used to search for specified layout or rules files.

-keycodes name

Specifies the name of the keycodes component used to construct a keyboard layout.

-keymap name

Specifies the name of the keymap description used to construct a keyboard layout.

-layout name

Specifies the name of the layout used to determine the components which make up the keyboard description. The -layout option may only be used once. Multiple layouts can be specified as a comma-separated list.

-model name

Specifies the name of the keyboard model used to determine the components which make up the keyboard description. Only one model may be specified on the command line.

-option name

Specifies the name of an option to determine the components which make up the keyboard description; multiple options may be specified, one per -option flag. Note that setxkbmap adds options specified in the command line to the options that were set before (as saved in root window properties). If you want to replace all previously specified options, use the -option flag with an empty argument first.

-print

With this option setxkbmap just prints component names in a format acceptable by xkbcomp (an XKB keymap compiler) and exits. The option can be used for tests instead of a verbose option and in cases when one needs to run both the setxkbmap and the xkbcomp in chain (see below).

-query

With this option setxkbmap just prints the current rules, model, layout, variant, and options, then exits.

-rules file

Specifies the name of the rules file used to resolve the requested layout and model to a set of component names.

-symbols name

Specifies the name of the symbols component used to construct a keyboard layout.

-synch

Force synchronization for X requests.

-types name

Specifies the name of the types component used to construct a keyboard layout.

-variant name

Specifies which variant of the keyboard layout should be used to determine the components which make up the keyboard description. The -variant option may only be used once. Multiple variants can be specified as a comma-separated list and will be matched with the layouts specified with -layout.

-verbose|-v [level]

Specifies level of verbosity in output messages. Valid levels range from 0 (least verbose) to 10 (most verbose). The default verbosity level is 5. If no level is specified, each -v or -verbose flag raises the level by 1.

files

/usr/share/X11/xkb

using with xkbcomp

If you have an Xserver and a client shell running on different computers and XKB configuration files on those machines are different you can get problems specifying a keyboard map by model, layout, options names. This is because setxkbcomp converts these names to names of XKB configuration files according to files that are on the client side computer, then it sends the file names to the server where the xkbcomp has to compose a complete keyboard map using files which the server has. Thus if the sets of files differ significantly the names that the setxkbmap generates can be unacceptable on the server side. You can solve this problem by running the xkbcomp on the client side too. With the -print option setxkbmap just prints the file names in an appropriate format to its stdout and this output can be piped directly to the xkbcomp input. For example, the command

setxkbmap us -print | xkbcomp - $DISPLAY

makes both steps run on the same (client) machine and loads a keyboard map into the server.


see also

xkbcomp , xkeyboard-config

How can this site be more helpful to YOU ?


give  feedback