Created
December 25, 2021 06:59
-
-
Save ko1nksm/a084d93ad5bcfbadf9278ebbce3d2b6f to your computer and use it in GitHub Desktop.
Display key code
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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