Skip to content

Instantly share code, notes, and snippets.

@adamency
Created November 6, 2023 09:30
Show Gist options
  • Save adamency/4830e35da4e54c3d71e388dc03c5a22c to your computer and use it in GitHub Desktop.
Save adamency/4830e35da4e54c3d71e388dc03c5a22c to your computer and use it in GitHub Desktop.
CheckKeys: Pretty-Print Key Presses & Releases
#!/bin/bash
### DEPENDENCIES
# `rg`: https://github.com/BurntSushi/ripgrep/
# `awk`
# `xev`
# `--line-buffered` because ripgrep uses a block buffer in piped
# and so doesn't provide instant output by default when redirected
# after to stdout (related: https://unix.stackexchange.com/questions/200235/how-to-use-sed-to-manipulate-continuously-streaming-output)
echo
xev |\
rg --line-buffered -o '(KeyPress|KeyRelease|\(keysym.*\))' |\
rg --line-buffered --passthru -e '\(keysym.*, ' -e '\)' -r '' |\
awk 'ORS=NR%2-1?"\n":": "'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment