shell中怎么捕捉用户输入的上下左右
答案:1 悬赏:70 手机版
解决时间 2021-03-23 17:32
- 提问者网友:回忆在搜索
- 2021-03-23 08:32
就比如 用户按了上键 然后我就在屏幕上echo a
最佳答案
- 五星知识达人网友:罪歌
- 2021-03-23 09:23
#!/bin/bash
KEY=()
echo "Press a direction Key:"
while :
do
#echo "Press a direction Key:"
read -s -n 1 KEY
#echo ${KEY[@]}
#echo "Length:`expr ${#KEY}`"
#echo ${KEY[0]}
case ${KEY[0]} in
"B")
echo "Down key pressed"
;;
"A")
echo "UP key pressed"
;;
"D")
echo "Left key pressed"
;;
"C")
echo "Right key pressed"
;;
*)
continue
#echo "Unknown key"
;;
esac
done
KEY=()
echo "Press a direction Key:"
while :
do
#echo "Press a direction Key:"
read -s -n 1 KEY
#echo ${KEY[@]}
#echo "Length:`expr ${#KEY}`"
#echo ${KEY[0]}
case ${KEY[0]} in
"B")
echo "Down key pressed"
;;
"A")
echo "UP key pressed"
;;
"D")
echo "Left key pressed"
;;
"C")
echo "Right key pressed"
;;
*)
continue
#echo "Unknown key"
;;
esac
done
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯