Keyboard check under UNIX Sys V?
Stuart D. Gathman
stuart at BMS-AT.UUCP
Mon Sep 29 05:40:30 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>
More information about the Comp.unix.wizards
mailing list