| 1 | #!/bin/bash |
| 2 | # keypress.sh: Detect a user keypress ("hot keys"). |
| 3 | |
| 4 | echo |
| 5 | |
| 6 | old_tty_settings=$(stty -g) # Save old settings (why?). |
| 7 | stty -icanon |
| 8 | Keypress=$(head -c1) # or $(dd bs=1 count=1 2> /dev/null) |
| 9 | # on non-GNU systems |
| 10 | |
| 11 | echo |
| 12 | echo "Key pressed was \""$Keypress"\"." |
| 13 | echo |
| 14 | |
| 15 | stty "$old_tty_settings" # Restore old settings. |
| 16 | |
| 17 | # Thanks, Stephane Chazelas. |
| 18 | |
| 19 | exit 0 |