LinuxCommandLibrary

evtest

Test input devices (e.g., keyboard, mouse)

TLDR

List all detected input devices

$ sudo evtest
copy

Display events from a specific input device
$ sudo evtest /dev/input/event[number]
copy

Grab the device exclusively, preventing other clients from receiving events
$ sudo evtest --grab /dev/input/event[number]
copy

Query the state of a specific key or button on an input device
$ sudo evtest --query /dev/input/event[number] [event_type] [event_code]
copy

SYNOPSIS

evtest [options] device

PARAMETERS

device
    The path to the input event device file, e.g., /dev/input/event0.

-s, --show-v_values
    Show specific value details for known event types (e.g., key names for EV_KEY events).

-S, --show-v_values-all
    Show all known value details, including for EV_SYN and EV_MSC events.

-g, --grab
    Grab the device, preventing other applications (like the desktop environment) from receiving events from it until evtest exits. Use with caution.

-q, --quiet
    Suppress the initial device information output, showing only events.

-r, --raw
    Show raw event values (numeric type, code, and value) instead of their descriptive names.

-e, --event-codes
    Show event codes (e.g., KEY_A) instead of their numeric values.

-c, --capabilities
    Only show device capabilities (supported event types, codes, and values), then exit.

-C, --codes
    Only show event codes for a given event type, then exit.

-h, --help
    Display a help message and exit.

-v, --version
    Display version information and exit.

DESCRIPTION

The evtest command is a crucial diagnostic utility for Linux systems, designed to test input devices that utilize the evdev (event device) interface. It opens a specified input device file, typically found under /dev/input/eventX, and then continuously prints the raw events generated by that device.

This tool is invaluable for debugging issues with keyboards, mice, touchpads, joysticks, gamepads, touchscreens, and other input peripherals. It displays detailed information about the device's capabilities, supported event types (e.g., key presses, relative movements, absolute positions), and then logs each event as it occurs, including its type, code, and value. This allows users and developers to verify if a device is recognized by the kernel, if it's sending the expected events, and to diagnose unresponsive or misbehaving input hardware. Because it accesses device files directly, evtest typically requires root privileges to run.

CAVEATS

evtest typically requires superuser (root) privileges to open and read from input device files in /dev/input/.

Using the --grab option will prevent other applications from receiving input from the specified device, potentially making your system unresponsive to that input until evtest is terminated. It should be used carefully, especially on critical input devices like your primary keyboard or mouse.

The output can be very verbose, especially for active devices, making it challenging to parse without specific knowledge of the evdev event structure.

FINDING DEVICE PATHS

Before running evtest, you need to identify the correct device path. Common methods include listing files in /dev/input/by-id/ or /dev/input/by-path/ which provide persistent symbolic links, or by examining the output of cat /proc/bus/input/devices which lists all detected input devices and their event numbers (e.g., event0, event1).

For example, to list devices: ls -l /dev/input/ or sudo lsinput (if lsinput is installed).

INTERPRETING OUTPUT

The output of evtest consists of event triplets: Type, Code, and Value.

  • Type: Specifies the category of event (e.g., EV_KEY for key presses/releases, EV_REL for relative movements like mouse deltas, EV_ABS for absolute positions like touchscreens or joystick axes, EV_SYN for synchronization events).
  • Code: Identifies the specific event within its type (e.g., KEY_A for the 'A' key, REL_X for X-axis movement, ABS_X for absolute X coordinate).
  • Value: The actual data for the event (e.g., 1 for key press, 0 for key release, -1 or +1 for mouse scroll, the coordinate value for absolute position).
Synchronization events (EV_SYN) typically mark the end of a report, indicating that all preceding events form a consistent set of changes.

HISTORY

evtest is part of the input-tools suite, which provides user-space utilities for interacting with the Linux evdev (event device) interface. The evdev interface itself was introduced early in the Linux kernel's development to standardize the way input devices communicate raw events to user-space applications. evtest emerged as the primary diagnostic tool for this interface, providing a direct window into the raw event stream from any evdev-compatible input device. Its development has closely tracked the evolution of Linux input device support.

SEE ALSO

lsinput(1), libinput-debug-events(1), xinput(1), udevadm(8), dmesg(1)

Copied to clipboard