loadkeys Command in Linux



The loadkeys command in Linux is used to load a new keyboard map. This map defines the mapping between physical keys on your keyboard and the characters they produce. This is particularly useful when you're working with different keyboard layouts or want to customize your keyboard's behavior.

Table of Contents

Here is a comprehensive guide to the options available with the loadkeys command −

Understanding loadkeys Command

The loadkeys command in Linux is used to load keyboard translation tables. Here are the options you can use with loadkeys. The loadkeys command offers several options to fine-tune keyboard mapping and behavior. Here's a breakdown of the most common options −

Options Description
-c, --clearcompose Clears the kernel compose table.
-d, --default Loads the default keymap.
-h, --help Displays help information.
-m, --mktable Creates a kernel source table.
-s, --clearstrings Clears the kernel string table.
-b, --bkeymap Creates a binary keymap.
-C, --console Specifies the console device to use.
-q, --quiet Suppresses all output.
-v, --verbose Enables verbose mode, providing more detailed output.
Core Options
-a or --ascii Forces the conversion of the keymap to ASCII.
-h or --help Prints a brief help message.
-p or --parse Parses the keymap without applying it. Parses the keymap without taking any action.
-q or --quiet Suppresses most output.
-u or --unicode Forces the conversion of the keymap to Unicode.
-V or --version Prints the version information.

These options allow you to manage and customize your keyboard layout effectively. You can find more details on the Linux man page.

How to Use loadkeys Command in Linux?

The loadkeys command in Linux is used to load or change the keyboard layout for the console. This command is particularly useful when you need to switch between different keyboard layouts or customize your keyboard settings. Here's a detailed explanation −

Syntax of loadkeys Command

The basic syntax for the loadkeys command is −

loadkeys [options] [keymap]
  • keymap − This is the name of the keymap file you want to load. Keymap files are usually located in /usr/share/keymaps/.
  • Options

    -c, --clearcompose − Clears the kernel compose table. This is useful if you want to reset any custom compose key sequences.

Examples of loadkeys Command in Linux

Load the Default Keymap

This command loads the default keymap for the console.

loadkeys --default
loadkeys Command in Linux1

This command loads the default keymap for the console. It's useful if you want to reset the keyboard layout to its default state1.

Load a Specific Keymap

This command loads the US QWERTY keymap.

loadkeys /usr/share/keymaps/i386/qwerty/us.map.gz
loadkeys Command in Linux2

Create a Binary Keymap

This command creates a binary keymap from the specified keymap file.

loadkeys --bkeymap /usr/share/keymaps/i386/qwerty/us.map.gz
loadkeys Command in Linux3

Load a Keymap Silently

This command loads the specified keymap without any output messages.

loadkeys --quiet /usr/share/keymaps/i386/qwerty/us.map.gz
loadkeys Command in Linux4

Specify Console Device

This command loads the specified keymap for the console device /dev/tty1.

loadkeys --console /dev/tty1 /usr/share/keymaps/i386/qwerty/us.map.gz
loadkeys Command in Linux5

These examples should give you a good starting point for using loadkeys in various scenarios. You can find more details on the Linux man page.

Here are some detailed examples of how you can use the loadkeys command in Linux −

Load Default Keymap When an Unusual Keymap is Loaded

This command is handy when an unusual keymap is loaded, and you can't find the - sign on the keyboard. It resets the keymap to the default1.

loadkeys defmap
loadkeys Command in Linux6

Create a Kernel Source Table

This command generates a kernel source table for the keymap. It's useful for developers who need to create or modify keymaps at the kernel level1.

loadkeys --mktable
loadkeys Command in Linux7

Create a Binary Keymap

This command creates a binary keymap. Binary keymaps are more efficient for the system to load and use1.

loadkeys --bkeymap
loadkeys Command in Linux8

Search and Parse Keymap Without Action

This command searches and parses the keymap without taking any action. It's useful for testing and debugging keymaps1.

loadkeys --parse
loadkeys Command in Linux9

Load the Keymap Suppressing All Output

This command loads the keymap but suppresses all output. It's useful when you want to load a keymap silently without any messages1.

loadkeys --quiet
loadkeys Command in Linux10

Load a Keymap from a Specified File for the Console

This command loads a specific keymap from a file for the console. Replace /dev/ttyN with the appropriate console device and /path/to/file with the path to the keymap file1.

loadkeys --console /dev/ttyN /path/to/file
loadkeys Command in Linux11

Use Standard Names for Keymaps of Different Locales

This command loads a keymap with standard names for different locales. Replace /dev/ttyN with the appropriate console device and uk with the locale name1.

loadkeys --console /dev/ttyN uk
loadkeys Command in Linux12

These examples should give you a good starting point for using loadkeys in various scenarios. You can find more details on the Linux man page.

loadkeys <keyboard_map_file>

Replace <keyboard_map_file> with the path to the desired keyboard map file. These files are typically located in the /usr/share/keymaps directory.

Switching Keyboard Layouts

Switching to a US Keyboard Layout −

loadkeys us

Switching to a German Keyboard Layout −

loadkeys de

Switching to a French Keyboard Layout −

loadkeys fr

Customizing Key Mappings

Creating a Custom Keyboard Map −

Create a new file (e.g., my_custom_map) in the /usr/share/keymaps directory.

Define the key mappings using a specific syntax. For example, to swap the Caps Lock and Control keys −

keycode 58 = Control
keycode 29 = Caps_Lock

Loading the Custom Map −

loadkeys my_custom_map

Restoring Default Keyboard Map

Restoring the Default Map −

loadkeys <default_map>

The specific default map depends on your system's configuration.

  • Persistent Changes − To make changes persistent across reboots, you'll need to modify your system's configuration files, such as /etc/default/keyboard.
  • Keyboard Map Files − Keyboard map files are typically named according to the language or region they represent, such as us for US English or de for German.
  • Testing Keyboard Maps − You can test a new keyboard map without making it permanent by using the setkeymap This command allows you to temporarily switch to a different keyboard map.

Creating a Custom Keyboard Map to Swap Caps Lock and Control Keys

Create a new file −

sudo nano /usr/share/keymaps/my_custom_map

Add the following lines to the file −

keycode 58 = Control
keycode 29 = Caps_Lock

Save the file and load the new map −

sudo loadkeys my_custom_map

Conclusion

The loadkeys command in Linux is used to load a new keyboard map. This map defines the mapping between physical keys on your keyboard and the characters they produce. This is particularly useful when you're working with different keyboard layouts or want to customize your keyboard's behavior.

Advertisements