Skip to content

Instantly share code, notes, and snippets.

@Hayao0819
Created October 19, 2022 04:04
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 Hayao0819/b524d9e25350f57bc8431fb67d3ae201 to your computer and use it in GitHub Desktop.
Save Hayao0819/b524d9e25350f57bc8431fb67d3ae201 to your computer and use it in GitHub Desktop.
シェルスクリプトで上下左右キーを検知する
#!/usr/bin/env bash
while IFS= read -r -n1 -s SELECTION && [[ -n "$SELECTION" ]]; do
if [[ $SELECTION == $'\x1b' ]]; then
read -r -n2 -s rest
SELECTION+="$rest"
fi
case $SELECTION in
$'\x1b\x5b\x41') #up arrow
echo "上"
;;
$'\x1b\x5b\x42') #down arrow
echo "下"
;;
$'\x1b\x5b\x43') #right arrow
echo "右"
;;
$'\x1b\x5b\x44') #left arrow
echo "左"
;;
$'\x20') #space
echo "スペース"
;;
esac
done
@Hayao0819
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment