Xev - X Event Viewer Utility | Online Free DevTools by Hexmos

View X events with Xev, a command-line utility. Learn how to use Xev to print X event contents and keycodes. Free online tool for developers.

Xev - X Event Viewer

Understanding X Events with Xev

The xev command is a powerful utility for developers working with the X Window System. It allows you to capture and display events generated by the X server, providing insights into user interactions like keyboard presses, mouse movements, and window changes. This tool is invaluable for debugging graphical applications and understanding how the X server processes input and events.

Using Xev to Print Event Contents

Below are examples of how to use xev to view X events. The first example uses awk to filter and display only the relevant parts of the key press events, making the output more concise.

# xev
# Print contents of X events

# Start xev(1) and show only the relevant parts.
xev | awk -F'[ )]+' '
    /^KeyPress/ {
        a[NR+2]
    }
    NR in a {
        printf "%-3s %s\n", $5, $8
    }
'

Alternative Xev Keycode Display

This alternative approach also uses awk but employs process substitution (<(xev)) to achieve a similar result in displaying keycodes. Note that process substitution might not be available in all shell environments.

# Alternative approach to showing keycodes.
#
# Note that the use of `<(xev)` is process substitution, which is unavailable
# in the Bourne Shell and its standard derivatives, nor is it available in Bash
# with its own POSIX mode enabled.
awk '
    /^KeyPress/ {
        A[NR+2]
    }
    NR in A {
        B=substr($7, 0, length($7) - 2)
        printf("%3d %s\n", $4, B)
    }
' <(xev)

Further Resources on X Window System