20

I'm looking for a way to display the current keyboard layout chart from the command line.

Unfortunately xkbprint does not display utf-8 characters correctly (AFAICT).

In gnome, it is possible to click on the keyboard layout indicator applet and then "Show Layout Chart", which does the same thing as going through the menus of gnome-control-center (btw, gnome-control-center keyboard is not an acceptable solution), so there must be a way to trigger an event that would pop up this window, right?

Note that most of the time I don't use gnome-panel.

Metaxal
  • 373
  • 3
  • 8

3 Answers3

25
gkbd-keyboard-display -l keyboard_layout[(variant)]

For example, to show Greek keyboard layout chart from command line:

gkbd-keyboard-display -l gr

To show US AltGr International keyboard variant:

gkbd-keyboard-display -l "us(altgr-intl)"

For a complete list of layouts, see https://manpages.ubuntu.com/manpages/impish/en/man7/xkeyboard-config.7.html#layouts

karel
  • 110,292
  • 102
  • 269
  • 299
Radu Rădeanu
  • 166,822
  • 48
  • 327
  • 400
  • 1
    Fantastic, thanks a lot! I've been looking for this for several hours! – Metaxal May 03 '14 at 14:58
  • +1 I had to install `gkbd-keyboard-display` from package `gkbd-capplet`.. – Håkon Hægland May 19 '14 at 22:20
  • nice and simple :) – A.B. Apr 22 '15 at 07:49
  • 6
    The command `gkbd-keyboard-display -l us,altgr-intl` causes a segmentation fault for me. `gkbd-keyboard-display -l "us(altgr-intl)"` works, though. – Guildenstern Nov 06 '17 at 22:40
  • 1
    Is there a way to show the currently selected input method instead? – To Do Jan 31 '22 at 11:36
  • 1
    I think I found out how: `gkbd-keyboard-display -g 1` – To Do Jan 31 '22 at 21:20
  • @ToDo - what that does is to show the first/default kb image. `2` shows the second, `3` the third and so forth. Useful, but it doesn't *show* the already selected kb, it *selects* the kb in numerical order. – cipricus Jun 25 '22 at 07:54
  • @ToDo - looking up the help there isn't a way to show the already selected layout, we have to specify the layout or the number: `-g, --group=group number (1, 2, 3, 4) Group to display` – cipricus Jun 25 '22 at 08:01
1

(Mis-)interpreting the requirement "from the command line" as "without touching the mouse", a convenient way in a casual Gnome environment is to create a desktop file that starts the "gkdb-keyboard-tool" from the activities overview.

As setup, create the following file:

~/.local/share/applications/show-keyboard-layout.desktop

With the following content:

[Desktop Entry]
Type=Application
Name=Show keyboard layout
Comment=
Icon=/usr/share/icons/Yaru/256x256/devices/input-keyboard.png
Exec=gkbd-keyboard-display -l "us(altgr-intl)"
Terminal=false
Categories=Utility

Press ALT-F2, and enter 'r' to restart the Gnome desktop if you use X11, otherwise restart your session.

To open the layout window, press the Super key (e.g. Windows key), and then enter the first letters of "Show keyboard layout" until the proper entry is shown. Finally, press enter.

The layout shown is hard coded. You can query the keyboard currently used with the following command and adapt the .desktop file accordingly.

setxkbmap -query
ocroquette
  • 111
  • 3
  • To change layout, variant, option etc, you need to know what you can select with what. Try `localectl list-x11-keymaps-models`, `localectl list-x11-keymaps-layouts`, `localectl list-x11-keymaps-variants us` etc. Then use `setxkbmap` to test until it work as you want. Then you can use `localectl set-x11-keymap ...` to set it "permanently" so it work at next login. Use `man` pages to see more options. – Anders Jul 16 '21 at 18:23
0

Current keyboard layout chart onliner (using awk and localectl):

gkbd-keyboard-display -l $(localectl status | awk '/X11 Layout/ {print $3}')$'\t'$(localectl status | awk '/X11 Variant/ {print $3}')

On an alias, using string literal syntax:

alias current_keyboard_layout_chart=$'gkbd-keyboard-display -l $(localectl status | awk \'/X11 Layout/ {print $3}\')$\'\t\'$(localectl status | awk \'/X11 Variant/ {print $3}\')'

Also, you can generate a PDF or use xkeycaps.

Pablo Bianchi
  • 14,308
  • 4
  • 74
  • 117