1. Overview
Often, we need to understand and check the current keyboard layout to navigate our Linux system efficiently. This task is essential in different scenarios, such as verifying language preferences or troubleshooting input-related issues.
In this tutorial, we’ll see how to check the current keyboard layout using the setxkbmap, gkbd-keyboard-display, xkeycaps, and xkbprint commands, as well as the System Settings on both GNOME and KDE Plasma Desktop environments.
2. Using the setxkbmap Command
setxkbmap is used for configuring and querying the X keyboard extension (XKB) settings. In addition, we can also utilize it to change the keyboard layout or retrieve information related to the current layout.
Let’s check the current keyboard layout with the setxkbmap -query command:
$ setxkbmap -query
rules: evdev
model: pc105
layout: us
In the above output:
- rules represent current XKB rules
- model indicates the keyboard model
- layout represents the current keyboard layout
As a result, the output shows that our current keyboard layout is set to us.
3. Using the gkbd-keyboard-display Command
The gkbd-keyboard-display command is considered a part of the GNOME desktop environment. Moreover, we can use it to view the graphical representation of the current keyboard layout.
For this purpose, let’s run the gkbd-keyboard-display command in our terminal:
$ gkbd-keyboard-display -l us
Here, we’ve passed our current keyboard layout of “us” as the layout code to the -l option. Let’s check the result:
The output displays the graphical representation of our current keyboard layout, which is English (US).
4. Using the xkeycaps Command
xkeycaps provides a graphical interface for customizing X Windows keymaps. It is also used to view information related to key mapping.
However, in this case, we’ll use xkeycaps to check the current keyboard layout.
First, we’ll install xkeycaps utility on our system:
$ sudo apt install xkeycaps
Now, let’s run the xkeycaps command to check the current keyboard layout:
$ xkeycaps
As a result, we’ll see a graphical interface that displays the current keyboard layout and information related to key assignments:
5. Using the xkbprint Command
xkbprint is used to generate an encapsulated or printable PostScript description of the XKB keyboard defined by the source. In other words, this tool creates an image with the physical representation of our keyword according to XKB.
Before using xkbprint, we’ll install the x11-xkb-utils packages on our Linux system:
$ sudo apt-get install x11-xkb-utils
Now, let’s use the xkbprint command to get the current keyboard layout:
$ echo $DISPLAY
:0
$ xkbprint -color ":0" - | ps2pdf - > current_keyboard_layout.pdf
In the above script:
- echo retrieves and prints the current X server DISPLAY value on the terminal
- xkbprint creates a color-coded representation of the keyboard
- -color refers to the black-and-white output
- “:0” targets the default DISPLAY
- – at the end directs the output to the standard output
- pipe (|) operator redirects the output to ps2pdf
- ps2pdf converts the resultant PostScript to PDF format
- – specifies that the input is coming from the standard input
- > redirects the converted PDF content to the current_keyboard_layout.pdf file
In addition, we’ll see a visual representation of our current keyboard layout in the current_keyboard_layout.pdf file:
6. Using the System Settings
Let’s check out the methods to view the current keyboard layout using the GUI on GNOME and KDE Plasma desktop environments.
6.1. GNOME Desktop
In the GNOME desktop environment, we can check and configure the keyboard layout using the System Settings.
For this, we’ll open GNOME System Settings from the Applications menu. Then, navigate to the Keyboard settings, click on the three-dots menu, and select the View Keyboard Layout option from the drop-down menu:
As a result, we can see the current keyboard layout on our GNOME desktop environment:
6.2. KDE Plasma Desktop
Similarly, in the case of the KDE Plasma desktop environment, we can also view the current keyboard layout easily.
To do so, we’ll open System Settings and switch to Input Devices under the Hardware section:
Next, we’ll select Keyboard as our input device, switch to the Layouts tab, and double-click on the configured keyboard layout:
As a result, we can preview the current keyboard layout:
7. Conclusion
In this article, we explored several methods to check the current keyboard layout on our Linux system. These methods included the setxkbmap, gkbd-keyboard-display, xkeycaps, and xkbprint commands, and it also showed the use of the System Settings on both GNOME and KDE Plasma Desktop environments.
Naturally, we can use the setxkbmap command to view the name of the current keyboard layout on the terminal. Then, we can pass this name to the gkbd-keyboard-display command to view the graphical representation of the configured keyboard layout.
Moreover, the xkeycaps command shows the keyboard layout along with the key mapping information. Furthermore, the xkbprint command creates a drawing of the current layout according to the XKB keyboard description.
On the other hand, we can also use the System Settings of both GNOME and KDE Plasma desktop environments to view the current keyboard layout. Ultimately, we can select any of these methods according to our preferences.