showkey
Display scan codes and keycodes pressed
TLDR
View keycodes in decimal
Display scancodes in hexadecimal
Display keycodes in decimal (default)
Display keycodes in ASCII, decimal, and hexadecimal
Exit the program
SYNOPSIS
showkey [options]
PARAMETERS
-h
Display help information and exit.
-V
Display version information and exit.
-a
Show decimal, octal, and hexadecimal values of the keypresses. This mode displays the ASCII value if the key generates one, along with its numerical representations.
-s
Show raw scan codes. This is the lowest level of information, representing the raw data sent by the keyboard to the system.
-k
Show keycodes (default mode). Keycodes are generated by the kernel based on scan codes and are used by the keymap to determine characters or actions. This is the most commonly used mode for debugging.
-m
Show meta keypresses. This mode displays events related to meta keys like Alt, Ctrl, and Shift modifiers.
-p
Show only "press" events. By default, showkey displays both key press and key release events. This option filters out the release events.
DESCRIPTION
showkey is a utility used to display raw keyboard input on the Linux console. It monitors keystrokes and outputs either raw scan codes, interpreted keycodes, or ASCII values of the pressed keys. Its primary purpose is to aid in debugging keyboard layouts, custom keymaps, and general keyboard issues within the console (TTY) environment, as it reveals exactly what data the kernel receives from the keyboard hardware before any keyboard translation tables are applied. This makes it invaluable for understanding low-level keyboard behavior.
CAVEATS
showkey primarily operates on the Linux console (TTYs / virtual terminals) and typically does not work within graphical environments (like X11 or Wayland sessions). It requires appropriate permissions, often root privileges, to access the keyboard device. The command automatically exits after a few seconds of keyboard inactivity, preventing it from indefinitely blocking the console input.
USAGE FOR DEBUGGING
The main utility of showkey lies in its ability to reveal the exact keycodes or scan codes generated by a keypress. This is crucial when troubleshooting keyboard issues, especially when a key does not produce the expected character, or when mapping special keys. By comparing the output of showkey with the keymap definitions (viewable with dumpkeys), users can pinpoint discrepancies.
AUTOMATIC EXIT
One notable feature of showkey is its built-in timeout. If no keys are pressed for approximately 10 seconds, the command automatically terminates. This prevents a user from accidentally leaving showkey running indefinitely and thus capturing all keyboard input, which could make the console unusable without knowing how to kill the process from another terminal or SSH session.
HISTORY
showkey is a long-standing utility, part of the kbd package, which provides a collection of programs for controlling the Linux console's keyboard and font. Its development has closely tracked the evolution of the Linux kernel's console subsystem, serving as an essential tool for system administrators and developers to diagnose and configure keyboard behavior on console sessions since the early days of Linux.