Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Hi: In a number of posts, we've

Status
Not open for further replies.

olded

Programmer
Oct 27, 1998
1,065
US
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
 
or recognizing that the value returned by getkey indicates that it's a function key, and recalling getkey appropriately.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top