Skip to content

Instantly share code, notes, and snippets.

@ko1nksm
Created December 25, 2021 06:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ko1nksm/a084d93ad5bcfbadf9278ebbce3d2b6f to your computer and use it in GitHub Desktop.
Save ko1nksm/a084d93ad5bcfbadf9278ebbce3d2b6f to your computer and use it in GitHub Desktop.
Display key code
#!/bin/sh
set -euf
stty=$(stty -g)
trap 'stty "$stty"' EXIT
stty -echo -icanon
tpid=""
while :; do
key=$(dd bs=1 count=1 2>/dev/null | od -An -a)
set -- $key && key=$1
hex=$(printf "%s" "$key" | od -An -tx1)
set -- $hex && hex=$1
case $hex in
[a-f]?) printf "%s " "$hex" ;;
*) printf "%s " "$key" ;;
esac
[ "$tpid" ] && { kill "$tpid" 2>/dev/null ||:; }
( trap exit TERM; sleep 0.1; echo ) & tpid=$!
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment