7

One can use

loadkeys

command to set appropriate keyboard layout. My question is how can I check the currently selected layout (in the console mode)?

0

7 Answers 7

6

You can check keyboard file for keyboard layout information...

nano /etc/default/keyboard

OUTPUT:

# KEYBOARD CONFIGURATION FILE
# Consult the keyboard(5) manual page.
XKBMODEL="pc105"
XKBLAYOUT="us"
XKBVARIANT=""
XKBOPTIONS=""
BACKSPACE="guess"

Value of XKBLAYOUT is the layout of keyboard. Change it to another possible value and reboot the machine to take effects.

5
  • 3
    Sorry but have no keyboard file on my system...
    – Ringger81
    Mar 4, 2018 at 11:58
  • Which OS are you exactly using? Mar 4, 2018 at 17:02
  • It's Slackware 14.2
    – Ringger81
    Mar 4, 2018 at 19:04
  • Slackware doesn't use /etc/default/keyboard, it uses /etc/rc.d/rc.keymap instead.
    – bormant
    Feb 24, 2019 at 15:00
  • The question doesn't ask for a partircular distro and this response is very distro specific. Indeed the cited file didn't ever exist in any of the RedHate related distros (Fedora, RHEL, Centos, Suse, Rocky Linux, etc) May 9 at 23:07
3

This is a workaround but...it works

xset -q | grep LED | awk '{ print $10 }')

the output is a number made of 8 digits corresponding to.. something related to the layout (in my case 00000000 for gb and 00001000 for it). Care to the fact that this number changes if you have CAPS LOCK enabled (the same number but +1).
If you want it as a string you can edit my simple script.

#!/bin/sh
COMMAND=$(xset -q | grep LED | awk '{ print $10 }')

case "$COMMAND" in

 "00000000"|"00000001") LAYOUT="uk" ;;

 "00001000"|"00001001") LAYOUT="it" ;;

  *) LAYOUT="??" ;;

esac

echo $LAYOUT
3

Command:

localectl status

Output:

  System Locale: LANG=en_US.UTF-8
  VC Keymap: us
  X11 Layout: us
2
  • This doesn't show the current locale if you have several enabled, e.g. se,us. It just shows se,us.
    – Victor
    Feb 11 at 12:46
  • This worked for me in both Debian/Ubuntu and RedHat based distros, and the comand is part of the general systemd package, so it seems to be available in any modern Linux distribution. So this seems the most appropriate answer to me. May 9 at 23:10
1

As referenced by the man page for setfont, you could use showconsolefont. As referenced by the manpage for loadkeys, you could use dumpkeys.

1

I think you are looking for the command dumpkeys

1
  • 3
    Couldn't get a file descriptor referring to the console Nov 9, 2020 at 23:03
0

This is way with one direction.

loadkeys modify kernel keyboard driver's translation table by loadind keyboard keymap file.

If nobody issue loadkeys you can check /etc/rc.d/rc.keymap file for loaded keymap.

You can check content of kernel keyboard driver's translation table using dumpkeys. There are no tool to find from which keymap file data was loaded into table.

-1

You can use this script to find out which keyboard layout you are using:

#!/bin/bash
var=" $(xset -q | grep -i "led mask" | grep -o "....1...")"
if [ -z $var ]
then
    echo "Using the first layout"
else
    echo "Using the second one"
fi

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .