Hi:
In a number of posts, we've discussed in shell how to manipulate the terminal driver to return one character without pressing return.
This particular function was posted by Nate, the Bigoldbulldog:
#!/bin/sh
getkey() {
TTYSTATE=`stty -g`
stty raw
key=`dd if=/dev/tty bs=1 count=1 2>/dev/null`
stty "$TTYSTATE"
echo "\nkey is ${key}" | cat -vu
}
echo "Press any key to continue: "
xx=`getkey`
echo "xx: "$xx
I've just had a user complain when they inadvertly press a function key. A function key returns more than one character which breaks the script above.
Does anybody have any ideas on how to handle this? I guess what I need is the ability of flushing standard output when returning from getkey.
Any help is appreciated.
Ed
In a number of posts, we've discussed in shell how to manipulate the terminal driver to return one character without pressing return.
This particular function was posted by Nate, the Bigoldbulldog:
#!/bin/sh
getkey() {
TTYSTATE=`stty -g`
stty raw
key=`dd if=/dev/tty bs=1 count=1 2>/dev/null`
stty "$TTYSTATE"
echo "\nkey is ${key}" | cat -vu
}
echo "Press any key to continue: "
xx=`getkey`
echo "xx: "$xx
I've just had a user complain when they inadvertly press a function key. A function key returns more than one character which breaks the script above.
Does anybody have any ideas on how to handle this? I guess what I need is the ability of flushing standard output when returning from getkey.
Any help is appreciated.
Ed