mirror of https://github.com/tLDP/LDP
22 lines
634 B
Bash
22 lines
634 B
Bash
#!/bin/bash
|
|
# dd-keypress.sh: Capture keystrokes without needing to press ENTER.
|
|
|
|
|
|
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)
|
|
# 'dd' uses stdin, if "if" (input file) not specified.
|
|
|
|
stty "$old_tty_setting" # Restore old terminal settings.
|
|
|
|
echo "You pressed the \"$keys\" keys."
|
|
|
|
# Thanks, Stephane Chazelas, for showing the way.
|
|
exit 0
|