Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!watmath!clyde!caip!elbereth!rutgers!sri-spam!sri-unix!hplabs!pesnta!amd!amdcad!decwrl!sun!imagen!SofPasuk From: SofPasuk@imagen.UUCP (Munach Rvi'i) Newsgroups: net.unix,net.micro.att,net.unix-wizards Subject: Re: Keyboard check under UNIX Sys V? Message-ID: <592@imagen.UUCP> Date: Wed, 1-Oct-86 19:46:38 EDT Article-I.D.: imagen.592 Posted: Wed Oct 1 19:46:38 1986 Date-Received: Sat, 4-Oct-86 10:27:01 EDT References: <30896@arizona.UUCP> <224@BMS-AT.UUCP> Distribution: net Organization: Tohu VaVohu Lines: 38 Xref: watmath net.unix:9453 net.micro.att:1562 net.unix-wizards:19788 > In article <30896@arizona.UUCP>, sbw@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 > > { > 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!