Xref: utzoo comp.lang.c:28446 comp.unix.questions:21964 Path: utzoo!utgpu!news-server.csri.toronto.edu!mailrus!uflorida!mephisto!gatech!kd4nc!n4hgf!wht From: wht@n4hgf.uucp (Warren Tucker) Newsgroups: comp.lang.c,comp.unix.questions Subject: Re: Testing if keystrokes are waiting in the buffer (solution) Keywords: kbhit, UNIX, keypressed Message-ID: <684@n4hgf.uucp> Date: 3 May 90 20:15:34 GMT References: <1990Apr25.000456.25048@cunixf.cc.columbia.edu> <24107@mimsy.umd.edu> Reply-To: wht@n4hgf.UUCP (Warren Tucker) Followup-To: comp.lang.c Organization: Amateur Radio Station N4HGF Lines: 53 In article <24107@mimsy.umd.edu> chris@mimsy.umd.edu (Chris Torek) writes: >(First, an obligatory note to comp.lang.c readers: the notion of a `key' >is found nowhere in the C language, therefore the notion of testing for >... well said >Readers not interested in Unix details can skip the rest of >this followup. ditto BSD: ioctl(0,FIONREAD,&number_of_chars_waiting_to_be_read); XENIX V, SCO UNIX, UNIX Sys V Rel 4: if(rdchk(0)) /* if ICANON is on, rdchk will report nothing until * newline or whatever is typed */ { data is waiting ... } else { no data is waiting ... } Sys V Rel 2, standard Rel 3: (tricky; this is just a clue) ioctl(0,TCGETA,&termio_struct_at_beginning); ioctl(0,TCGETA,&termio_struct); termio_struct.c_lflags ~= ~(ICANON); termio_struct.c_cc[VMIN] = 0; termio_struct.c_cc[VTIME] = 0; ioctl(0,TCSETA,&termio_struct); if((i = read(0,&input_char,1) == 0) { no input } else if(i < 0) { read error } else { 'input_character' has a charcter } /* before program terminates */ ioctl(0,TCSETA,&termio_struct_at_beginning); V7: horrible /dev/kmem munging you dont want to hear about ------------------------------------------------------------------ Warren Tucker, TuckerWare gatech!n4hgf!wht or wht%n4hgf@gatech.edu McCarthyism did to cinema what ANSI did to C, cast a great number of characters into the void.