Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!watmath!clyde!cbatt!ihnp4!qantel!lll-lcc!lll-crg!seismo!vrdxhq!BMS-AT!stuart From: stuart@BMS-AT.UUCP (Stuart D. Gathman) Newsgroups: net.unix,net.micro.att,net.unix-wizards Subject: Re: Keyboard check under UNIX Sys V? Message-ID: <224@BMS-AT.UUCP> Date: Sun, 28-Sep-86 15:40:30 EDT Article-I.D.: BMS-AT.224 Posted: Sun Sep 28 15:40:30 1986 Date-Received: Tue, 30-Sep-86 19:47:17 EDT References: <30896@arizona.UUCP> Distribution: net Organization: Business Management Systems, Inc., Fairfax, VA Lines: 34 Xref: watmath net.unix:9397 net.micro.att:1547 net.unix-wizards:19718 Summary: VMIN and VTIME in SysV 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>