Show keyboard layout linux

How do I get current keyboard layout?

I’m wondering if there is any command line tool that returns the current keyboard layout. I have XkbLayout set to us, ru . Update: setxkbmap returns layout settings, not selected layout. E.g.:

$ setxkbmap -print | grep xkb_symbols xkb_symbols < include "pc+us+ru:2+inet(evdev)+capslock(grouplock)+terminate(ctrl_alt_bksp)" >; 

I am not really good at D-Bus, but it should be easy to track the current keyboard layout using it I think. Although it may not be able to do so if there is no active switch.

15 Answers 15

Maybe this is version dependent, but on my machine that uses setxkbmap 1.3.0 the following command works:

setxkbmap -query | grep layout 

Note that depending on your need it may be useless to know only the layout : for instance the Dvorak variant of the US layout is quite different than the default QWERTY. The -query option of setxkbmap gives both the layout and the variant, as different fields :

$ setxkbmap -query rules: evdev model: default layout: fr variant: bepo options: grp:alt_shift_toggle 

To set it, for example both layouts cz and us, the latter with variant dvorak (for a 104 key keyboard), use setxkbmap -model pc104 -layout cz,us -variant ,dvorak

doesn’t let you know the active one for multiple layouts, which is what the OP asked. Bummer this got to the top.

Yes THERE IS a command line tool that does what you want! I just discovered it 10min ago 🙂

does exactly what you want (it doesn’t output an end of line, so add ; echo if you need). run the tool without parameters for the help.

There is xkb-switch which is described thus:

xkb-switch is a C++ program that allows to query and change the XKB layout state.

Or, following nozimica’s suggestion, you could use:

setxkbmap -print | awk -F"+" '/xkb_symbols/ '

Use this to get the code for the current layout:

This might needs to be converted to a form you want, like:

case "$(xset -q|grep LED| awk '< print $10 >')" in "00000002") KBD="English" ;; "00001002") KBD="Thai" ;; *) KBD="unknown" ;; esac 

It doesn’t help if there are three or more layouts. The second and the third layouts give the same value 00001004 on my machine.

Читайте также:  Линукс команда удалить пользователя

This will not work reliably — you need to use a mask since the LED indicates the status of the keyboard led buttons as well.

The answers so far did not work for me. I use setkbmap with two layouts english and czech so any -print or -query will always return the two. Grepping the LED status for xset -q does not work either since that one shows the status of all keyboard leds.

#include #include #include #include #include int main(int argc, char **argv) < Display *dpy = XOpenDisplay(NULL); if (dpy == NULL) < fprintf(stderr, "Cannot open display\n"); exit(1); >XkbStateRec state; XkbGetState(dpy, XkbUseCoreKbd, &state); XkbDescPtr desc = XkbGetKeyboard(dpy, XkbAllComponentsMask, XkbUseCoreKbd); char *group = XGetAtomName(dpy, desc->names->groups[state.group]); printf("Full name: %s\n", group); XkbRF_VarDefsRec vd; XkbRF_GetNamesProp(dpy, NULL, &vd); char *tok = strtok(vd.layout, ","); for (int i = 0; i < state.group; i++) < tok = strtok(NULL, ","); if (tok == NULL) < return 1; >> printf("Layout name: %s\n", tok); return 0; > 

gcc -I/usr/include getxkblayout.c -lX11 -lxkbfile

Источник

How to get keyboard layout (language) in terminal (console, command-line) [closed]

This question was closed because it is not about an official Ubuntu flavor. It is not currently accepting answers.

This is not about an official Ubuntu flavor. Questions about other Linux distributions can be asked on Unix & Linux, those about Windows on Super User, those about Apple products on Ask Different and generic programming questions on Stack Overflow.

  1. localectl ( status );
  2. cat /etc/default/locale ;
  3. cat /etc/default/keyboard ;
  4. setxkbmap -query ;
  5. gsettings . ;
  6. setxkbmap -print | grep xkb_symbols ( setxkbmap -v | awk -F «+» ‘/symbols/ ‘ );
  7. Tried to install xkblayout-state , but make failed on fresh OS install — skipped.

All of these output the same per each command with keyboard layout change — us layout.

uname -a shows Linux x4 4.4.0-97-generic #120-Ubuntu SMP Tue Sep 19 17:28:18 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux

The current distribution is KDE Neon 5.8 (based on Ubuntu) and window system is X11 .

The outputs of the above commands:

System Locale: LANG=en_US.UTF-8 LC_NUMERIC=lt_LT.UTF-8 LC_TIME=lt_LT.UTF-8 LC_MONETARY=lt_LT.UTF-8 LC_PAPER=lt_LT.UTF-8 LC_NAME=lt_LT.UTF-8 LC_ADDRESS=lt_LT.UTF-8 LC_TELEPHONE=lt_LT.UTF-8 LC_MEASUREMENT=lt_LT.UTF-8 LC_IDENTIFICATION=lt_LT.UTF-8 VC Keymap: n/a X11 Layout: us X11 Model: pc105 
# File generated by update-locale LANG="en_US.UTF-8" LC_NUMERIC="lt_LT.UTF-8" LC_TIME="lt_LT.UTF-8" LC_MONETARY="lt_LT.UTF-8" LC_PAPER="lt_LT.UTF-8" LC_NAME="lt_LT.UTF-8" LC_ADDRESS="lt_LT.UTF-8" LC_TELEPHONE="lt_LT.UTF-8" LC_MEASUREMENT="lt_LT.UTF-8" LC_IDENTIFICATION="lt_LT.UTF-8" 
# KEYBOARD CONFIGURATION FILE # Consult the keyboard(5) manual page. XKBMODEL="pc105" XKBLAYOUT="us" XKBVARIANT="" XKBOPTIONS="" BACKSPACE="guess" 
rules: evdev model: pc101 layout: us,lt options: grp:alt_shift_toggle 

$ setxkbmap -print | grep xkb_symbols :

$ setxkbmap -v | awk -F «+» ‘/symbols/ ‘ :

[Layout] DisplayNames=, LayoutList=us,lt LayoutLoopCount=-1 Model=pc101 Options=grp:alt_shift_toggle ResetOldOptions=true ShowFlag=false ShowLabel=true ShowLayoutIndicator=true ShowSingle=false SwitchMode=Global Use=true 

All of these commands were executed two times (before and after keyboard language/layout change) — no useful enough output.

Читайте также:  Root не видит файлы linux

$ xset -q | grep -A 0 ‘LED’ | cut -c59-67 (English language is enabled):

$ xset -q | grep -A 0 ‘LED’ | cut -c59-67 (Lithuanian language is enabled):

Considering it’s changing, is it a correct and reliable option?

Источник

Show keyboard layout chart from command line

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 .

3 Answers 3

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

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

To show US AltGr International keyboard variant:

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

The command gkbd-keyboard-display -l us,altgr-intl causes a segmentation fault for me. gkbd-keyboard-display -l «us(altgr-intl)» works, though.

(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.

Источник

How can I find out what the layout of my keyboard is?

I just bought a new keyboard. I love it, but some of the keys don’t map to the symbols they say they have. How can I find out what the layout of my keyboard is? Is there some sort of list of keyboards where I can find my keyboard? I’m using Xubuntu.

You’re right. Should’ve told you the OS: Xubuntu. And my keyboard is a Logitech MK365, layout unknown 🙂

Читайте также:  Смена домашней папки linux

5 Answers 5

If you are talking about your physical keyboard and which layout it has, there is no way to find that out using software, read the manual and find out.

If you are talking about which layout you are currently using you could run setxkbmap -query | grep layout .

Well, actually, that depends on the keyboard. Some keyboards store their layouts locally (for the purpose of having persistent custom layouts). In these cases, it’s possible that you might be able to query the keyboard for its layout.

If you use Ubuntu, you can follow this guide:

If you use a KDE based distribution (kubuntu):

Press the following keys: Alt + F2 , then run the executable:

in Debian/Ubuntu you can find in folders:

/usr/share/keymaps/i386/azerty /usr/share/keymaps/i386/dvorak /usr/share/keymaps/i386/fgGIod /usr/share/keymaps/i386/include /usr/share/keymaps/i386/qwerty /usr/share/keymaps/i386/qwertz 

a lot of files named NAME.kmap.gz — if you open the compressed file NAME.kmap with a text editor you’ll find the mapping of each keyboard-layout.

What should I do to change keyboard layout?

There are several options. One is to use xfce4-xkb-plugin, see http://goodies.xfce.org/projects/panel-plugins/xfce4-xkb-plugin . You can also use the setxkbmap command with the two letter keyboard code as argument; you can edit your X server configuration file to choose a different keyboard layout (change the value after Option “XkbLayout”, e.g.: Option “XkbLayout” “dvorak”).

Yes, this is nice. However, what I need is to know what my keyboard layout actually is, because I don’t know which one to select from the lists 🙁

Источник

How to get current gnome keyboard layout from terminal?

For usage in a bash script, I need to get the gnome keyboard layout the user is currently using. For example if the user sets its keyboard layout to en-us , I need a bash command that prints me this. How can I get that information?

Update:

setxkbmap -query is unfortunatelly not working. Below is the ouput with the en (first command) and the de (second command) layout activated. Switching keyboard layout seems to be have some relation with gnome session configuration

setxkbmap -query rules: evdev model: pc105 layout: us,de variant: , options: terminate:ctrl_alt_bksp,lv3:ralt_switch,grp:alts_toggle setxkbmap -query rules: evdev model: pc105 layout: us,de variant: , options: terminate:ctrl_alt_bksp,lv3:ralt_switch,grp:alts_toggle 

Update2:

setxkbmap -print #with en-us layout xkb_keymap < xkb_keycodes < include "evdev+aliases(qwerty)" >; xkb_types < include "complete" >; xkb_compat < include "complete" >; xkb_symbols < include "pc+us+de:2+inet(evdev)+level3(ralt_switch_for_alts_toggle):1+level3(ralt_switch_for_alts_toggle):2+group(alts_toggle)+level3(ralt_switch)+terminate(ctrl_alt_bksp)" >; xkb_geometry < include "pc(pc105)" >; >; setxkbmap -print #after switching to german layout xkb_keymap < xkb_keycodes < include "evdev+aliases(qwerty)" >; xkb_types < include "complete" >; xkb_compat < include "complete" >; xkb_symbols < include "pc+us+de:2+inet(evdev)+level3(ralt_switch_for_alts_toggle):1+level3(ralt_switch_for_alts_toggle):2+group(alts_toggle)+level3(ralt_switch)+terminate(ctrl_alt_bksp)" >; xkb_geometry < include "pc(pc105)" >; >; 

Источник

Оцените статью
Adblock
detector