Keyboard check under UNIX Sys V?

Munach Rvi'i SofPasuk at imagen.UUCP
Thu Oct 2 09:46:38 AEST 1986


> In article <30896 at arizona.UUCP>, sbw at arizona.UUCP (stephen wampler) writes:
> > What is the preferred way to determine if a key has been pressed
> > on the keyboard when running UNIX Sys V?  I know that some UN*X
> 
> #include <sys/termio.h>
> 
> {
>   struct termio tty, save;
>   char c;
> 
>   ioctl(0,TCGETA,&tty);
>   save = tty;				/* save current tty definitions */
>   tty.c_lflag &= ~(ECHO|ICANON);	/* enter raw mode */
>   tty.c_cc[VMIN]=0;		/* wait for at least VMIN chars on read */
>   tty.c_cc[VTIME]=0;		/* wait at least VTIME seconds/10 on read */
>   ioctl(0,TCSETA,&tty);
> 
>   saved = read(0,&c,1);
>   if (saved)
>     printf("You typed a '%c'.\n",c);
>   else
>     printf("You haven't typed anything yet.\n");
> 
> /*
>   Note, you will have to save 'c' yourself if you need it!
>   Perhaps stdio would work (using ungetc()).
> */
> 
> /* restore tty state */
> 
>   ioctl(0,TCSETA,&save);
> }
> -- 
> Stuart D. Gathman	<..!seismo!{vrdxhq|dgis}!BMS-AT!stuart>

Don't assume that this works for all System V UNIX implementations.
For example, Convergent Technologies CTIX on MegaFrame and MiniFrame will block
on the read!



More information about the Comp.unix.wizards mailing list