How do I get current keyboard layout?
Clash Royale CLAN TAG#URR8PPP
I'm wondering is there any command line tool, that returns 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)" ;
It will return same result no matter what current layout is.
xorg keyboard xkb
add a comment |
I'm wondering is there any command line tool, that returns 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)" ;
It will return same result no matter what current layout is.
xorg keyboard xkb
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.
– Benjamin
Dec 26 '11 at 18:16
add a comment |
I'm wondering is there any command line tool, that returns 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)" ;
It will return same result no matter what current layout is.
xorg keyboard xkb
I'm wondering is there any command line tool, that returns 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)" ;
It will return same result no matter what current layout is.
xorg keyboard xkb
xorg keyboard xkb
edited Dec 26 '11 at 17:12
Stéphane Gimenez
19.4k25074
19.4k25074
asked Apr 26 '11 at 21:08
AndrewAndrew
5522513
5522513
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.
– Benjamin
Dec 26 '11 at 18:16
add a comment |
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.
– Benjamin
Dec 26 '11 at 18:16
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.
– Benjamin
Dec 26 '11 at 18:16
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.
– Benjamin
Dec 26 '11 at 18:16
add a comment |
11 Answers
11
active
oldest
votes
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
3
-query
was added in setxkbmap 1.2.0
– alanc
Apr 6 '13 at 1:49
You get the current layouts and variants and many additional info withsetxkbmap -print -verbose 10
– erik
May 13 '16 at 20:22
To set it, for example both layouts cz and us, the latter with variant dvorak (for a 104 key keyboard), usesetxkbmap -model pc104 -layout cz,us -variant ,dvorak
– erik
May 13 '16 at 20:27
add a comment |
There is xkb-switch which is described thus:
xkb-switch is a C++ program that
allows to query and change the XKB
layout state.
https://github.com/ierton/xkb-switch
Or, following nozimica's suggestion, you could use:
setxkbmap -print | awk -F"+" '/xkb_symbols/ print $2'
From this thread on the Arch Linux boards: https://bbs.archlinux.org/viewtopic.php?pid=539406
1
Thanks,xkb-switch
works fine, but I hope that there was more portable solution
– Andrew
Apr 28 '11 at 16:34
1
@Andrew: yes it's kind of odd there is no simple way to get the current layout.
– Benjamin
Dec 26 '11 at 17:38
6
Yoursetxkbmap
doesn't show the currently active layout when more than one layout is defined.
– terdon♦
Oct 22 '15 at 12:51
add a comment |
Yes THERE IS a command line tool that does what you want!
I just discovered it 10min ago :)
Look at here: https://github.com/nonpop/xkblayout-state
xkblayout-state print "%s"
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.
add a comment |
Use this to get the code for the current layout:
$(xset -q|grep LED| awk ' print $10 ')
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
3
I get00000002
even though my layout is "USA Dvorak international". Language is not enough...
– l0b0
Jan 5 '12 at 11:42
4
It doesn't help if there are three or more layouts. The second and the third layouts give the same value00001004
on my machine.
– sastanin
Dec 19 '12 at 8:37
problem: toggle your numlock and start this command again ;)
– andras.tim
Jul 6 '16 at 16:19
This will not work reliably - you need to use a mask since the LED indicates the status of the keyboard led buttons as well.
– fikovnik
Feb 7 '18 at 9:26
add a comment |
Another simpler approach, because of fixed positions of the output of the xset -q
command, is this:
xset -q | grep -A 0 'LED' | cut -c59-67
It prints 00000002
or 00001002
depending on your current keyboard layout.
I like this one, I think you can narrow it down to 8 chars.c59-66
.
– xlembouras
Jul 31 '14 at 13:23
add a comment |
On newer systems, you can use
localectl status
It will for instance show you the following:
System Locale: LANG=en_US.UTF-8
VC Keymap: us
X11 Layout: us
add a comment |
From Goosfrabaa in the Arch Linux forums:
setxkbmap -v | awk -F "+" '/symbols/ print $2'
This works correctly here, and prints us(dvorak-intl)
(displayed as "USA Dvorak international" in the GNOME keyboard selection menu).
7
It prints only the first layout in the list, not the current one.
– sastanin
Dec 19 '12 at 8:38
How can I detect my keymap, when I use language toggle by setxkbmap?$ setxkbmap -v
>>Trying to build keymap using the following components: | keycodes: evdev+aliases(qwerty) | types: complete | compat: complete+ledscroll(group_lock) | symbols: pc+us+hu:2+inet(evdev)+group(alt_shift_toggle)+compose(rwin)+terminate(ctrl_alt_bksp) | geometry: pc(pc105)
in this case I got everytime "us"
– andras.tim
Jul 6 '16 at 16:29
add a comment |
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.
The best so far was to quickly write this small utility:
https://gist.github.com/fikovnik/ef428e82a26774280c4fdf8f96ce8eeb
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <X11/XKBlib.h>
#include <X11/extensions/XKBrules.h>
int main(int argc, char **argv)
Display *dpy = XOpenDisplay(NULL);
if (dpy == NULL)
fprintf(stderr, "Cannot open displayn");
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: %sn", 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: %sn", tok);
return 0;
and compile using
gcc -I/usr/include getxkblayout.c -lX11 -lxkbfile
add a comment |
Partial answer: On KDE, you can apparently get the current keyboard layout through the qdbus
command:
$ qdbus org.kde.keyboard /Layouts getCurrentLayout
gb(intl)
I have several layouts configured, but it only shows the one that is currently in use.
Tested on Kubuntu 18.04 (qdbus version 4.8.7). There may be other d-bus based solutions for non-Qt environments, but I do not know about them.
add a comment |
#! /bin/bash
# (GPL3+) Alberto Salvia Novella (es20490446e)
keyboardLayout ()
layout=$(variableInFile "KEYMAP" "/etc/vconsole.conf")
echo $layout
variableInFile ()
variable=$1
file=$2
source $file
eval value=$$variable
echo $value
keyboardLayout
add a comment |
You can use:
setxkbmap -print | grep xkb_symbols
5
it returns overall keyboard settings, not current layout (us or ru)
– Andrew
Apr 28 '11 at 11:17
Execute it well, as @jasonwryan states if you analyze carefully that line, into it resides your layout. In my case it islatam
.
– nozimica
Apr 28 '11 at 14:10
5
jasonwryan version just output a part of string after '+',xkb_symbols
value doesn't depend on selected layout, I always get 'us'
– Andrew
Apr 28 '11 at 16:33
add a comment |
Your Answer
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "106"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f12072%2fhow-do-i-get-current-keyboard-layout%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
11 Answers
11
active
oldest
votes
11 Answers
11
active
oldest
votes
active
oldest
votes
active
oldest
votes
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
3
-query
was added in setxkbmap 1.2.0
– alanc
Apr 6 '13 at 1:49
You get the current layouts and variants and many additional info withsetxkbmap -print -verbose 10
– erik
May 13 '16 at 20:22
To set it, for example both layouts cz and us, the latter with variant dvorak (for a 104 key keyboard), usesetxkbmap -model pc104 -layout cz,us -variant ,dvorak
– erik
May 13 '16 at 20:27
add a comment |
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
3
-query
was added in setxkbmap 1.2.0
– alanc
Apr 6 '13 at 1:49
You get the current layouts and variants and many additional info withsetxkbmap -print -verbose 10
– erik
May 13 '16 at 20:22
To set it, for example both layouts cz and us, the latter with variant dvorak (for a 104 key keyboard), usesetxkbmap -model pc104 -layout cz,us -variant ,dvorak
– erik
May 13 '16 at 20:27
add a comment |
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
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
edited Jul 15 '13 at 11:11
Skippy le Grand Gourou
1,0521122
1,0521122
answered Sep 22 '12 at 14:18
marsmars
29732
29732
3
-query
was added in setxkbmap 1.2.0
– alanc
Apr 6 '13 at 1:49
You get the current layouts and variants and many additional info withsetxkbmap -print -verbose 10
– erik
May 13 '16 at 20:22
To set it, for example both layouts cz and us, the latter with variant dvorak (for a 104 key keyboard), usesetxkbmap -model pc104 -layout cz,us -variant ,dvorak
– erik
May 13 '16 at 20:27
add a comment |
3
-query
was added in setxkbmap 1.2.0
– alanc
Apr 6 '13 at 1:49
You get the current layouts and variants and many additional info withsetxkbmap -print -verbose 10
– erik
May 13 '16 at 20:22
To set it, for example both layouts cz and us, the latter with variant dvorak (for a 104 key keyboard), usesetxkbmap -model pc104 -layout cz,us -variant ,dvorak
– erik
May 13 '16 at 20:27
3
3
-query
was added in setxkbmap 1.2.0– alanc
Apr 6 '13 at 1:49
-query
was added in setxkbmap 1.2.0– alanc
Apr 6 '13 at 1:49
You get the current layouts and variants and many additional info with
setxkbmap -print -verbose 10
– erik
May 13 '16 at 20:22
You get the current layouts and variants and many additional info with
setxkbmap -print -verbose 10
– erik
May 13 '16 at 20:22
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
– erik
May 13 '16 at 20:27
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
– erik
May 13 '16 at 20:27
add a comment |
There is xkb-switch which is described thus:
xkb-switch is a C++ program that
allows to query and change the XKB
layout state.
https://github.com/ierton/xkb-switch
Or, following nozimica's suggestion, you could use:
setxkbmap -print | awk -F"+" '/xkb_symbols/ print $2'
From this thread on the Arch Linux boards: https://bbs.archlinux.org/viewtopic.php?pid=539406
1
Thanks,xkb-switch
works fine, but I hope that there was more portable solution
– Andrew
Apr 28 '11 at 16:34
1
@Andrew: yes it's kind of odd there is no simple way to get the current layout.
– Benjamin
Dec 26 '11 at 17:38
6
Yoursetxkbmap
doesn't show the currently active layout when more than one layout is defined.
– terdon♦
Oct 22 '15 at 12:51
add a comment |
There is xkb-switch which is described thus:
xkb-switch is a C++ program that
allows to query and change the XKB
layout state.
https://github.com/ierton/xkb-switch
Or, following nozimica's suggestion, you could use:
setxkbmap -print | awk -F"+" '/xkb_symbols/ print $2'
From this thread on the Arch Linux boards: https://bbs.archlinux.org/viewtopic.php?pid=539406
1
Thanks,xkb-switch
works fine, but I hope that there was more portable solution
– Andrew
Apr 28 '11 at 16:34
1
@Andrew: yes it's kind of odd there is no simple way to get the current layout.
– Benjamin
Dec 26 '11 at 17:38
6
Yoursetxkbmap
doesn't show the currently active layout when more than one layout is defined.
– terdon♦
Oct 22 '15 at 12:51
add a comment |
There is xkb-switch which is described thus:
xkb-switch is a C++ program that
allows to query and change the XKB
layout state.
https://github.com/ierton/xkb-switch
Or, following nozimica's suggestion, you could use:
setxkbmap -print | awk -F"+" '/xkb_symbols/ print $2'
From this thread on the Arch Linux boards: https://bbs.archlinux.org/viewtopic.php?pid=539406
There is xkb-switch which is described thus:
xkb-switch is a C++ program that
allows to query and change the XKB
layout state.
https://github.com/ierton/xkb-switch
Or, following nozimica's suggestion, you could use:
setxkbmap -print | awk -F"+" '/xkb_symbols/ print $2'
From this thread on the Arch Linux boards: https://bbs.archlinux.org/viewtopic.php?pid=539406
edited Apr 18 '13 at 8:46
answered Apr 26 '11 at 21:21
jasonwryanjasonwryan
49.8k14134188
49.8k14134188
1
Thanks,xkb-switch
works fine, but I hope that there was more portable solution
– Andrew
Apr 28 '11 at 16:34
1
@Andrew: yes it's kind of odd there is no simple way to get the current layout.
– Benjamin
Dec 26 '11 at 17:38
6
Yoursetxkbmap
doesn't show the currently active layout when more than one layout is defined.
– terdon♦
Oct 22 '15 at 12:51
add a comment |
1
Thanks,xkb-switch
works fine, but I hope that there was more portable solution
– Andrew
Apr 28 '11 at 16:34
1
@Andrew: yes it's kind of odd there is no simple way to get the current layout.
– Benjamin
Dec 26 '11 at 17:38
6
Yoursetxkbmap
doesn't show the currently active layout when more than one layout is defined.
– terdon♦
Oct 22 '15 at 12:51
1
1
Thanks,
xkb-switch
works fine, but I hope that there was more portable solution– Andrew
Apr 28 '11 at 16:34
Thanks,
xkb-switch
works fine, but I hope that there was more portable solution– Andrew
Apr 28 '11 at 16:34
1
1
@Andrew: yes it's kind of odd there is no simple way to get the current layout.
– Benjamin
Dec 26 '11 at 17:38
@Andrew: yes it's kind of odd there is no simple way to get the current layout.
– Benjamin
Dec 26 '11 at 17:38
6
6
Your
setxkbmap
doesn't show the currently active layout when more than one layout is defined.– terdon♦
Oct 22 '15 at 12:51
Your
setxkbmap
doesn't show the currently active layout when more than one layout is defined.– terdon♦
Oct 22 '15 at 12:51
add a comment |
Yes THERE IS a command line tool that does what you want!
I just discovered it 10min ago :)
Look at here: https://github.com/nonpop/xkblayout-state
xkblayout-state print "%s"
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.
add a comment |
Yes THERE IS a command line tool that does what you want!
I just discovered it 10min ago :)
Look at here: https://github.com/nonpop/xkblayout-state
xkblayout-state print "%s"
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.
add a comment |
Yes THERE IS a command line tool that does what you want!
I just discovered it 10min ago :)
Look at here: https://github.com/nonpop/xkblayout-state
xkblayout-state print "%s"
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.
Yes THERE IS a command line tool that does what you want!
I just discovered it 10min ago :)
Look at here: https://github.com/nonpop/xkblayout-state
xkblayout-state print "%s"
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.
answered Apr 5 '13 at 23:41
Pablo SaratxagaPablo Saratxaga
1,6781115
1,6781115
add a comment |
add a comment |
Use this to get the code for the current layout:
$(xset -q|grep LED| awk ' print $10 ')
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
3
I get00000002
even though my layout is "USA Dvorak international". Language is not enough...
– l0b0
Jan 5 '12 at 11:42
4
It doesn't help if there are three or more layouts. The second and the third layouts give the same value00001004
on my machine.
– sastanin
Dec 19 '12 at 8:37
problem: toggle your numlock and start this command again ;)
– andras.tim
Jul 6 '16 at 16:19
This will not work reliably - you need to use a mask since the LED indicates the status of the keyboard led buttons as well.
– fikovnik
Feb 7 '18 at 9:26
add a comment |
Use this to get the code for the current layout:
$(xset -q|grep LED| awk ' print $10 ')
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
3
I get00000002
even though my layout is "USA Dvorak international". Language is not enough...
– l0b0
Jan 5 '12 at 11:42
4
It doesn't help if there are three or more layouts. The second and the third layouts give the same value00001004
on my machine.
– sastanin
Dec 19 '12 at 8:37
problem: toggle your numlock and start this command again ;)
– andras.tim
Jul 6 '16 at 16:19
This will not work reliably - you need to use a mask since the LED indicates the status of the keyboard led buttons as well.
– fikovnik
Feb 7 '18 at 9:26
add a comment |
Use this to get the code for the current layout:
$(xset -q|grep LED| awk ' print $10 ')
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
Use this to get the code for the current layout:
$(xset -q|grep LED| awk ' print $10 ')
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
edited Jan 5 '12 at 11:41
l0b0
28.1k17119246
28.1k17119246
answered Dec 26 '11 at 15:44
PepaPepa
10912
10912
3
I get00000002
even though my layout is "USA Dvorak international". Language is not enough...
– l0b0
Jan 5 '12 at 11:42
4
It doesn't help if there are three or more layouts. The second and the third layouts give the same value00001004
on my machine.
– sastanin
Dec 19 '12 at 8:37
problem: toggle your numlock and start this command again ;)
– andras.tim
Jul 6 '16 at 16:19
This will not work reliably - you need to use a mask since the LED indicates the status of the keyboard led buttons as well.
– fikovnik
Feb 7 '18 at 9:26
add a comment |
3
I get00000002
even though my layout is "USA Dvorak international". Language is not enough...
– l0b0
Jan 5 '12 at 11:42
4
It doesn't help if there are three or more layouts. The second and the third layouts give the same value00001004
on my machine.
– sastanin
Dec 19 '12 at 8:37
problem: toggle your numlock and start this command again ;)
– andras.tim
Jul 6 '16 at 16:19
This will not work reliably - you need to use a mask since the LED indicates the status of the keyboard led buttons as well.
– fikovnik
Feb 7 '18 at 9:26
3
3
I get
00000002
even though my layout is "USA Dvorak international". Language is not enough...– l0b0
Jan 5 '12 at 11:42
I get
00000002
even though my layout is "USA Dvorak international". Language is not enough...– l0b0
Jan 5 '12 at 11:42
4
4
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.– sastanin
Dec 19 '12 at 8:37
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.– sastanin
Dec 19 '12 at 8:37
problem: toggle your numlock and start this command again ;)
– andras.tim
Jul 6 '16 at 16:19
problem: toggle your numlock and start this command again ;)
– andras.tim
Jul 6 '16 at 16:19
This will not work reliably - you need to use a mask since the LED indicates the status of the keyboard led buttons as well.
– fikovnik
Feb 7 '18 at 9:26
This will not work reliably - you need to use a mask since the LED indicates the status of the keyboard led buttons as well.
– fikovnik
Feb 7 '18 at 9:26
add a comment |
Another simpler approach, because of fixed positions of the output of the xset -q
command, is this:
xset -q | grep -A 0 'LED' | cut -c59-67
It prints 00000002
or 00001002
depending on your current keyboard layout.
I like this one, I think you can narrow it down to 8 chars.c59-66
.
– xlembouras
Jul 31 '14 at 13:23
add a comment |
Another simpler approach, because of fixed positions of the output of the xset -q
command, is this:
xset -q | grep -A 0 'LED' | cut -c59-67
It prints 00000002
or 00001002
depending on your current keyboard layout.
I like this one, I think you can narrow it down to 8 chars.c59-66
.
– xlembouras
Jul 31 '14 at 13:23
add a comment |
Another simpler approach, because of fixed positions of the output of the xset -q
command, is this:
xset -q | grep -A 0 'LED' | cut -c59-67
It prints 00000002
or 00001002
depending on your current keyboard layout.
Another simpler approach, because of fixed positions of the output of the xset -q
command, is this:
xset -q | grep -A 0 'LED' | cut -c59-67
It prints 00000002
or 00001002
depending on your current keyboard layout.
edited Jan 28 '12 at 5:18
Kevin
27.3k1062100
27.3k1062100
answered Jan 5 '12 at 5:11
nikospagnikospag
9912
9912
I like this one, I think you can narrow it down to 8 chars.c59-66
.
– xlembouras
Jul 31 '14 at 13:23
add a comment |
I like this one, I think you can narrow it down to 8 chars.c59-66
.
– xlembouras
Jul 31 '14 at 13:23
I like this one, I think you can narrow it down to 8 chars.
c59-66
.– xlembouras
Jul 31 '14 at 13:23
I like this one, I think you can narrow it down to 8 chars.
c59-66
.– xlembouras
Jul 31 '14 at 13:23
add a comment |
On newer systems, you can use
localectl status
It will for instance show you the following:
System Locale: LANG=en_US.UTF-8
VC Keymap: us
X11 Layout: us
add a comment |
On newer systems, you can use
localectl status
It will for instance show you the following:
System Locale: LANG=en_US.UTF-8
VC Keymap: us
X11 Layout: us
add a comment |
On newer systems, you can use
localectl status
It will for instance show you the following:
System Locale: LANG=en_US.UTF-8
VC Keymap: us
X11 Layout: us
On newer systems, you can use
localectl status
It will for instance show you the following:
System Locale: LANG=en_US.UTF-8
VC Keymap: us
X11 Layout: us
answered Dec 12 '16 at 13:56
oLenoLen
15115
15115
add a comment |
add a comment |
From Goosfrabaa in the Arch Linux forums:
setxkbmap -v | awk -F "+" '/symbols/ print $2'
This works correctly here, and prints us(dvorak-intl)
(displayed as "USA Dvorak international" in the GNOME keyboard selection menu).
7
It prints only the first layout in the list, not the current one.
– sastanin
Dec 19 '12 at 8:38
How can I detect my keymap, when I use language toggle by setxkbmap?$ setxkbmap -v
>>Trying to build keymap using the following components: | keycodes: evdev+aliases(qwerty) | types: complete | compat: complete+ledscroll(group_lock) | symbols: pc+us+hu:2+inet(evdev)+group(alt_shift_toggle)+compose(rwin)+terminate(ctrl_alt_bksp) | geometry: pc(pc105)
in this case I got everytime "us"
– andras.tim
Jul 6 '16 at 16:29
add a comment |
From Goosfrabaa in the Arch Linux forums:
setxkbmap -v | awk -F "+" '/symbols/ print $2'
This works correctly here, and prints us(dvorak-intl)
(displayed as "USA Dvorak international" in the GNOME keyboard selection menu).
7
It prints only the first layout in the list, not the current one.
– sastanin
Dec 19 '12 at 8:38
How can I detect my keymap, when I use language toggle by setxkbmap?$ setxkbmap -v
>>Trying to build keymap using the following components: | keycodes: evdev+aliases(qwerty) | types: complete | compat: complete+ledscroll(group_lock) | symbols: pc+us+hu:2+inet(evdev)+group(alt_shift_toggle)+compose(rwin)+terminate(ctrl_alt_bksp) | geometry: pc(pc105)
in this case I got everytime "us"
– andras.tim
Jul 6 '16 at 16:29
add a comment |
From Goosfrabaa in the Arch Linux forums:
setxkbmap -v | awk -F "+" '/symbols/ print $2'
This works correctly here, and prints us(dvorak-intl)
(displayed as "USA Dvorak international" in the GNOME keyboard selection menu).
From Goosfrabaa in the Arch Linux forums:
setxkbmap -v | awk -F "+" '/symbols/ print $2'
This works correctly here, and prints us(dvorak-intl)
(displayed as "USA Dvorak international" in the GNOME keyboard selection menu).
answered Jan 5 '12 at 11:50
l0b0l0b0
28.1k17119246
28.1k17119246
7
It prints only the first layout in the list, not the current one.
– sastanin
Dec 19 '12 at 8:38
How can I detect my keymap, when I use language toggle by setxkbmap?$ setxkbmap -v
>>Trying to build keymap using the following components: | keycodes: evdev+aliases(qwerty) | types: complete | compat: complete+ledscroll(group_lock) | symbols: pc+us+hu:2+inet(evdev)+group(alt_shift_toggle)+compose(rwin)+terminate(ctrl_alt_bksp) | geometry: pc(pc105)
in this case I got everytime "us"
– andras.tim
Jul 6 '16 at 16:29
add a comment |
7
It prints only the first layout in the list, not the current one.
– sastanin
Dec 19 '12 at 8:38
How can I detect my keymap, when I use language toggle by setxkbmap?$ setxkbmap -v
>>Trying to build keymap using the following components: | keycodes: evdev+aliases(qwerty) | types: complete | compat: complete+ledscroll(group_lock) | symbols: pc+us+hu:2+inet(evdev)+group(alt_shift_toggle)+compose(rwin)+terminate(ctrl_alt_bksp) | geometry: pc(pc105)
in this case I got everytime "us"
– andras.tim
Jul 6 '16 at 16:29
7
7
It prints only the first layout in the list, not the current one.
– sastanin
Dec 19 '12 at 8:38
It prints only the first layout in the list, not the current one.
– sastanin
Dec 19 '12 at 8:38
How can I detect my keymap, when I use language toggle by setxkbmap?
$ setxkbmap -v
>> Trying to build keymap using the following components: | keycodes: evdev+aliases(qwerty) | types: complete | compat: complete+ledscroll(group_lock) | symbols: pc+us+hu:2+inet(evdev)+group(alt_shift_toggle)+compose(rwin)+terminate(ctrl_alt_bksp) | geometry: pc(pc105)
in this case I got everytime "us"– andras.tim
Jul 6 '16 at 16:29
How can I detect my keymap, when I use language toggle by setxkbmap?
$ setxkbmap -v
>> Trying to build keymap using the following components: | keycodes: evdev+aliases(qwerty) | types: complete | compat: complete+ledscroll(group_lock) | symbols: pc+us+hu:2+inet(evdev)+group(alt_shift_toggle)+compose(rwin)+terminate(ctrl_alt_bksp) | geometry: pc(pc105)
in this case I got everytime "us"– andras.tim
Jul 6 '16 at 16:29
add a comment |
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.
The best so far was to quickly write this small utility:
https://gist.github.com/fikovnik/ef428e82a26774280c4fdf8f96ce8eeb
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <X11/XKBlib.h>
#include <X11/extensions/XKBrules.h>
int main(int argc, char **argv)
Display *dpy = XOpenDisplay(NULL);
if (dpy == NULL)
fprintf(stderr, "Cannot open displayn");
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: %sn", 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: %sn", tok);
return 0;
and compile using
gcc -I/usr/include getxkblayout.c -lX11 -lxkbfile
add a comment |
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.
The best so far was to quickly write this small utility:
https://gist.github.com/fikovnik/ef428e82a26774280c4fdf8f96ce8eeb
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <X11/XKBlib.h>
#include <X11/extensions/XKBrules.h>
int main(int argc, char **argv)
Display *dpy = XOpenDisplay(NULL);
if (dpy == NULL)
fprintf(stderr, "Cannot open displayn");
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: %sn", 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: %sn", tok);
return 0;
and compile using
gcc -I/usr/include getxkblayout.c -lX11 -lxkbfile
add a comment |
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.
The best so far was to quickly write this small utility:
https://gist.github.com/fikovnik/ef428e82a26774280c4fdf8f96ce8eeb
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <X11/XKBlib.h>
#include <X11/extensions/XKBrules.h>
int main(int argc, char **argv)
Display *dpy = XOpenDisplay(NULL);
if (dpy == NULL)
fprintf(stderr, "Cannot open displayn");
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: %sn", 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: %sn", tok);
return 0;
and compile using
gcc -I/usr/include getxkblayout.c -lX11 -lxkbfile
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.
The best so far was to quickly write this small utility:
https://gist.github.com/fikovnik/ef428e82a26774280c4fdf8f96ce8eeb
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <X11/XKBlib.h>
#include <X11/extensions/XKBrules.h>
int main(int argc, char **argv)
Display *dpy = XOpenDisplay(NULL);
if (dpy == NULL)
fprintf(stderr, "Cannot open displayn");
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: %sn", 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: %sn", tok);
return 0;
and compile using
gcc -I/usr/include getxkblayout.c -lX11 -lxkbfile
answered Feb 7 '18 at 9:46
fikovnikfikovnik
1212
1212
add a comment |
add a comment |
Partial answer: On KDE, you can apparently get the current keyboard layout through the qdbus
command:
$ qdbus org.kde.keyboard /Layouts getCurrentLayout
gb(intl)
I have several layouts configured, but it only shows the one that is currently in use.
Tested on Kubuntu 18.04 (qdbus version 4.8.7). There may be other d-bus based solutions for non-Qt environments, but I do not know about them.
add a comment |
Partial answer: On KDE, you can apparently get the current keyboard layout through the qdbus
command:
$ qdbus org.kde.keyboard /Layouts getCurrentLayout
gb(intl)
I have several layouts configured, but it only shows the one that is currently in use.
Tested on Kubuntu 18.04 (qdbus version 4.8.7). There may be other d-bus based solutions for non-Qt environments, but I do not know about them.
add a comment |
Partial answer: On KDE, you can apparently get the current keyboard layout through the qdbus
command:
$ qdbus org.kde.keyboard /Layouts getCurrentLayout
gb(intl)
I have several layouts configured, but it only shows the one that is currently in use.
Tested on Kubuntu 18.04 (qdbus version 4.8.7). There may be other d-bus based solutions for non-Qt environments, but I do not know about them.
Partial answer: On KDE, you can apparently get the current keyboard layout through the qdbus
command:
$ qdbus org.kde.keyboard /Layouts getCurrentLayout
gb(intl)
I have several layouts configured, but it only shows the one that is currently in use.
Tested on Kubuntu 18.04 (qdbus version 4.8.7). There may be other d-bus based solutions for non-Qt environments, but I do not know about them.
answered Jul 22 '18 at 16:46
QeoleQeole
464510
464510
add a comment |
add a comment |
#! /bin/bash
# (GPL3+) Alberto Salvia Novella (es20490446e)
keyboardLayout ()
layout=$(variableInFile "KEYMAP" "/etc/vconsole.conf")
echo $layout
variableInFile ()
variable=$1
file=$2
source $file
eval value=$$variable
echo $value
keyboardLayout
add a comment |
#! /bin/bash
# (GPL3+) Alberto Salvia Novella (es20490446e)
keyboardLayout ()
layout=$(variableInFile "KEYMAP" "/etc/vconsole.conf")
echo $layout
variableInFile ()
variable=$1
file=$2
source $file
eval value=$$variable
echo $value
keyboardLayout
add a comment |
#! /bin/bash
# (GPL3+) Alberto Salvia Novella (es20490446e)
keyboardLayout ()
layout=$(variableInFile "KEYMAP" "/etc/vconsole.conf")
echo $layout
variableInFile ()
variable=$1
file=$2
source $file
eval value=$$variable
echo $value
keyboardLayout
#! /bin/bash
# (GPL3+) Alberto Salvia Novella (es20490446e)
keyboardLayout ()
layout=$(variableInFile "KEYMAP" "/etc/vconsole.conf")
echo $layout
variableInFile ()
variable=$1
file=$2
source $file
eval value=$$variable
echo $value
keyboardLayout
edited Jan 18 at 10:52
answered Jan 18 at 10:45
Alberto Salvia NovellaAlberto Salvia Novella
1185
1185
add a comment |
add a comment |
You can use:
setxkbmap -print | grep xkb_symbols
5
it returns overall keyboard settings, not current layout (us or ru)
– Andrew
Apr 28 '11 at 11:17
Execute it well, as @jasonwryan states if you analyze carefully that line, into it resides your layout. In my case it islatam
.
– nozimica
Apr 28 '11 at 14:10
5
jasonwryan version just output a part of string after '+',xkb_symbols
value doesn't depend on selected layout, I always get 'us'
– Andrew
Apr 28 '11 at 16:33
add a comment |
You can use:
setxkbmap -print | grep xkb_symbols
5
it returns overall keyboard settings, not current layout (us or ru)
– Andrew
Apr 28 '11 at 11:17
Execute it well, as @jasonwryan states if you analyze carefully that line, into it resides your layout. In my case it islatam
.
– nozimica
Apr 28 '11 at 14:10
5
jasonwryan version just output a part of string after '+',xkb_symbols
value doesn't depend on selected layout, I always get 'us'
– Andrew
Apr 28 '11 at 16:33
add a comment |
You can use:
setxkbmap -print | grep xkb_symbols
You can use:
setxkbmap -print | grep xkb_symbols
answered Apr 26 '11 at 21:27
nozimicanozimica
709519
709519
5
it returns overall keyboard settings, not current layout (us or ru)
– Andrew
Apr 28 '11 at 11:17
Execute it well, as @jasonwryan states if you analyze carefully that line, into it resides your layout. In my case it islatam
.
– nozimica
Apr 28 '11 at 14:10
5
jasonwryan version just output a part of string after '+',xkb_symbols
value doesn't depend on selected layout, I always get 'us'
– Andrew
Apr 28 '11 at 16:33
add a comment |
5
it returns overall keyboard settings, not current layout (us or ru)
– Andrew
Apr 28 '11 at 11:17
Execute it well, as @jasonwryan states if you analyze carefully that line, into it resides your layout. In my case it islatam
.
– nozimica
Apr 28 '11 at 14:10
5
jasonwryan version just output a part of string after '+',xkb_symbols
value doesn't depend on selected layout, I always get 'us'
– Andrew
Apr 28 '11 at 16:33
5
5
it returns overall keyboard settings, not current layout (us or ru)
– Andrew
Apr 28 '11 at 11:17
it returns overall keyboard settings, not current layout (us or ru)
– Andrew
Apr 28 '11 at 11:17
Execute it well, as @jasonwryan states if you analyze carefully that line, into it resides your layout. In my case it is
latam
.– nozimica
Apr 28 '11 at 14:10
Execute it well, as @jasonwryan states if you analyze carefully that line, into it resides your layout. In my case it is
latam
.– nozimica
Apr 28 '11 at 14:10
5
5
jasonwryan version just output a part of string after '+',
xkb_symbols
value doesn't depend on selected layout, I always get 'us'– Andrew
Apr 28 '11 at 16:33
jasonwryan version just output a part of string after '+',
xkb_symbols
value doesn't depend on selected layout, I always get 'us'– Andrew
Apr 28 '11 at 16:33
add a comment |
Thanks for contributing an answer to Unix & Linux Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f12072%2fhow-do-i-get-current-keyboard-layout%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
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.
– Benjamin
Dec 26 '11 at 18:16