LDP/LDP/guide/docbook/abs-guide/dd-keypress.sh

22 lines
634 B
Bash
Raw Normal View History

2001-07-10 14:25:50 +00:00
#!/bin/bash
2005-05-08 20:09:31 +00:00
# dd-keypress.sh: Capture keystrokes without needing to press ENTER.
2001-07-10 14:25:50 +00:00
keypresses=4 # Number of keypresses to capture.
old_tty_setting=$(stty -g) # Save old terminal settings.
echo "Press $keypresses keys."
stty -icanon -echo # Disable canonical mode.
# Disable local echo.
keys=$(dd bs=1 count=$keypresses 2> /dev/null)
2005-05-08 20:09:31 +00:00
# 'dd' uses stdin, if "if" (input file) not specified.
2001-07-10 14:25:50 +00:00
stty "$old_tty_setting" # Restore old terminal settings.
echo "You pressed the \"$keys\" keys."
2005-05-08 20:09:31 +00:00
# Thanks, Stephane Chazelas, for showing the way.
2001-07-10 14:25:50 +00:00
exit 0