Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!utgpu!water!watnot!watmath!clyde!rutgers!seismo!rochester!pt.cs.cmu.edu!ius2.cs.cmu.edu!edw From: edw@ius2.cs.cmu.edu.UUCP Newsgroups: comp.lang.c Subject: Re: boolean function to tell if a key has been pressed Message-ID: <1073@ius2.cs.cmu.edu> Date: Sat, 21-Mar-87 16:37:57 EST Article-I.D.: ius2.1073 Posted: Sat Mar 21 16:37:57 1987 Date-Received: Sun, 22-Mar-87 17:38:14 EST References: <10260@topaz.RUTGERS.EDU> <523@thumper.UUCP> Organization: Carnegie-Mellon University, CS/RI Lines: 31 In article <10260@topaz.RUTGERS.EDU>, whoffman@topaz.UUCP writes: > > Hello, > > I am seeking a way to tell whether or not a key has been pressed on > a keyboard. i.e something like this: > > while (1) > { ...statements.... > if "a key has been pressed" {...statements} > ...statements...} > > the problem i keep running into is that getc,getchar etc..all WAIT for > a key to be pressed. I would just like to see IF one has been pressed. > Any help on this would be greatly appreciated. Thanks in advance... > > William R. Hoffman If you are on a unix os you can make a call to "select" and it will tell you whether a file descriptor or list of files descriptor are ready to read from, write to, or have excecption pending (See manual entry for select for more details.) Note also you can get the file descriptor for a pointer to a file (FILE *fp) with the macro fileno which is defined in stdio.h. Also, if you are on a Unix os, you will want to make the appropriate call to ioctl or stty so that characters are made available to your process as soon as they are type, instead of buffering them until a new line is type from the terminal (cbreak on or off, one of the two). Eddie Wyatt