检测用户按键脚本

1 #!/bin/bash
2 old_tty_settings=$(stty -g)   # 保存老的设置(为什么?). 
3 stty -icanon
4 Keypress=$(head -c1)          # 或者使用$(dd bs=1 count=1 2> /dev/null)
5 echo "Key pressed was \""$Keypress"\"."
6 stty "$old_tty_settings"      # 恢复老的设置. 
7 exit 0

 

posted @ 2019-09-17 11:02  凌空a  阅读(252)  评论(0编辑  收藏  举报