Skip to content

Instantly share code, notes, and snippets.

@mdawaffe
Created December 2, 2013 02:42
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 mdawaffe/7744141 to your computer and use it in GitHub Desktop.
Save mdawaffe/7744141 to your computer and use it in GitHub Desktop.
Terminal Arrow Keys Experiment
#!/bin/bash
ENTER=$(printf "%b" "\n")
ESCAPE=$(printf "%b" "\e")
UP_SUFFIX="A"
DOWN_SUFFIX="B"
RIGHT_SUFFIX="C"
LEFT_SUFFIX="D"
while true; do
read -sn1 a
case "$a" in
$ENTER) echo "ENTER";;
$ESCAPE)
read -sn1 b
test "$b" == "[" || continue
read -sn1 b
case "$b" in
$UP_SUFFIX) echo "UP";;
$DOWN_SUFFIX) echo "DOWN";;
$LEFT_SUFFIX) echo "LEFT";;
$RIGHT_SUFFIX) echo "RIGHT";;
*) continue;;
esac
;;
*) echo "$a";;
esac
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment