LinuxCommandLibrary

xev

Display X server event details

TLDR

Monitor all occurring X events

$ xev
copy

Monitor all X events of the root window instead of creating a new one
$ xev -root
copy

Monitor all X events of a particular window
$ xev -id [window_id]
copy

Monitor X events from a given category (can be specified multiple times)
$ xev -event [event_category]
copy

SYNOPSIS

xev [options]

PARAMETERS

-display display
    Specifies the X server to contact. Useful for connecting to a remote display.

-geometry geometry
    Sets the initial size and position of the created window (e.g., 200x100+10+10).

-id id
    Attaches to an existing window by its hexadecimal ID instead of creating a new one. Useful for monitoring other applications.

-event event_mask_name
    Selects specific event types to report. Can be used multiple times (e.g., -event KeyPress -event ButtonPress). If omitted, all events are reported.

-s
    Runs in synchronous mode, flushing the output buffer after each X request. Useful for debugging X protocol issues but can be slow.

-p
    Equivalent to -event MotionNotify, reporting pointer motion events. Can generate a large amount of output.

DESCRIPTION

xev (X Event Viewer) is a utility that creates a window and reports events received from the X server to standard output. It's an indispensable tool for debugging X applications, understanding window manager behavior, and observing how the X server handles user input like mouse clicks, keyboard presses, and window movements.

When launched, xev opens a small, empty window. As you interact with this window—moving the mouse cursor over it, clicking buttons, typing characters, or resizing/minimizing the window—xev prints detailed information about the corresponding X events (e.g., KeyPress, ButtonPress, ConfigureNotify) to your terminal. This real-time feedback helps developers and power users diagnose issues with event handling, verify input processing, and comprehend the low-level interactions within the X Window System.

CAVEATS

Be aware that xev can produce a very verbose output, especially when monitoring pointer motion or all event types. This can quickly fill the terminal buffer. It reports raw X events, which might be different from the events an application toolkit (like GTK or Qt) might process, as toolkits often abstract or filter events.

COMMON USAGE EXAMPLE

To observe keyboard and mouse button events only, you could run:
xev -event KeyPress -event KeyRelease -event ButtonPress -event ButtonRelease
To monitor all events of an existing window (e.g., your terminal window), you'd first find its ID using xwininfo, then run:
xev -id 0x400003 (replace with actual ID)

SEE ALSO

xwininfo(1), xprop(1), xdpyinfo(1), xdotool(1)

Copied to clipboard