Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10 5/3/83; site bbncca.ARPA Path: utzoo!linus!bbncca!keesan From: keesan@bbncca.ARPA (Morris Keesan) Newsgroups: net.lang.c Subject: Re: Need Help: 1-char input in C Message-ID: <415@bbncca.ARPA> Date: Thu, 22-Dec-83 18:07:50 EST Article-I.D.: bbncca.415 Posted: Thu Dec 22 18:07:50 1983 Date-Received: Fri, 23-Dec-83 01:40:52 EST References: <464@ihuxn.UUCP> Organization: Bolt, Beranek and Newman, Cambridge, Ma. Lines: 28 ---------------------------- > I want to have it so that the program can key an ASCII value for the key > from the VT100 terminal without having to have the user type RETURN. > > I tried using getchar() but inputs an entire line up to the RETURN, returns > the first letter, and shoves the rest in a buffer that is emptied the next > time getchar() is called. > > I just read that CP/M's version of C returns the value of the key as soon > as the key is typed, but UNIX C (which I am using) waits for a newline. > Yet, I know that many C utilities do accept a key as soon as I type it. -------------------------------------------------------- This is very simple, and it's nothing to do with C, but rather a UNIX(tm) feature. In normal modes, the UNIX terminal driver will do just this, hold the input until a newline is input, and then make it available to the program. What you want to do is set CBREAK mode, which will make each character available as it's typed. Try setting in from the command line by typing stty cbreak to see if it behaves the way you want it to, and then put it into your program using gtty() and stty(), or ioctl(). See ioctl(2) and tty(4). You should get the mode settings first, remember them, then set CBREAK, and restore the original modes when you're through. Note that CBREAK will effectively disable any line editing (such as erase and line-kill). -- Morris M. Keesan {decvax,linus,wjh12}!bbncca!keesan keesan @ BBN-UNIX.ARPA