
showkey Command in Linux
The showkey command in Linux is a specialized utility that captures and displays keycodes, scancodes, or ASCII values produced by your keyboard. This tool is especially beneficial for various tasks, such as troubleshooting keyboard-related issues, debugging hardware, or comprehending how your keyboard interacts with the operating system.
By using the showkey command, you can monitor and identify the unique codes linked to each key press on your keyboard. This information can be instrumental for a variety of purposes, including −
- Remapping Keys − If you want to reassign certain keys on your keyboard to perform different functions, knowing the specific keycodes or scancodes allows you to create custom key mappings or layouts.
- Creating Custom Keyboard Layouts − For users who require specialized keyboard layouts (e.g., for programming or gaming), the showkey command helps in identifying the necessary codes to configure these layouts accurately.
- Diagnosing Faulty Keys − If certain keys on your keyboard are malfunctioning or not responding as expected, the showkey command can help diagnose the issue by displaying the corresponding keycodes or scancodes when the keys are pressed.
Table of Contents
Here is a comprehensive guide to the options available with the showkey command â
Syntax of showkey Command
The basic syntax for the showkey command is −
sudo showkey [options]
Where,
- sudo − The command requires superuser privileges to access keyboard input/output information.
- [options] − Flags that modify the behavior of the showkey command.
showkey Command Options
Here are the commonly used options for the showkey command −
Option | Description |
---|---|
-s, --scancodes | Displays the scancodes of the keys in hexadecimal format. Scancodes represent the raw output from the keyboard hardware. |
-k, --keycodes | Explicitly displays keycodes in decimal format, similar to the default behavior. |
-a, --ascii | Displays the ASCII values of the keys pressed, along with their decimal, octal, and hexadecimal representations. |
Examples of the showkey Command in Linux
Letâs explore some practical examples to understand how the showkey command can be used effectively −
- Displaying Keycodes in Decimal Format
- Displaying Scancodes in Hexadecimal Format
- Displaying Keycodes Explicitly
- Displaying ASCII Values of Keys
Displaying Keycodes in Decimal Format
To display the keycodes of keys pressed and released, simply run −
sudo showkey
When you press a key, the terminal will output something like −

This example shows the keycode for the key pressed and released, which can be used for remapping or debugging.
Displaying Scancodes in Hexadecimal Format
If you want to see the raw scancodes generated by the keyboard, use the -s option −
sudo showkey -s
For example, pressing a key might produce output like −

This output represents the scancode for the key press (0x02) and release (0x82), which is useful for low-level hardware debugging.
Displaying Keycodes Explicitly
To ensure that keycodes are displayed in decimal format, use the -k option −
sudo showkey -k
This behaves similarly to the default mode but explicitly specifies that keycodes should be shown.

Displaying ASCII Values of Keys
To view the ASCII values of keys pressed, along with their decimal, octal, and hexadecimal representations, use the -a option −
sudo showkey -a
For example, pressing the A key might produce output like −

This output shows the ASCII value of the key in decimal (65), octal (101), and hexadecimal (0x41) formats.
Conclusion
The showkey command in Linux is a versatile tool for capturing and analyzing keyboard input. Whether youâre troubleshooting keyboard issues, debugging hardware, or configuring custom keymaps, this utility provides valuable insights into how your keyboard interacts with the system.
By mastering the showkey command and its options, you can efficiently diagnose and resolve keyboard-related problems, enhancing your overall Linux experience.