Created
October 19, 2022 04:04
-
-
Save Hayao0819/b524d9e25350f57bc8431fb67d3ae201 to your computer and use it in GitHub Desktop.
シェルスクリプトで上下左右キーを検知する
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
#!/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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
参考
https://gist.github.com/shinyaoguri/782adf1c6765dba0717745578aa9c85f