Xref: utzoo comp.unix.wizards:16834 comp.unix.questions:14180 Path: utzoo!utgpu!jarvis.csri.toronto.edu!rutgers!cs.utexas.edu!uunet!unisoft!tccc0!eric From: eric@tccc0.UUCP (Eric Smith) Newsgroups: comp.unix.wizards,comp.unix.questions Subject: Re: keyscan wanted Message-ID: <12@tccc0.UUCP> Date: 7 Jun 89 03:16:45 GMT References: <1006@twwells.uucp> <607@wn2.sci.kun.nl> Reply-To: eric@tccc0.UUCP (Eric Smith) Organization: TFS -- Berkeley, California Lines: 18 >int key_pressed() >{ > int mask=1; > struct timeval wait; > > wait.tv_sec=0; > wait.tv_usec=0; > return (select(1,&mask,0,0,&wait)); >} For that to work reliably, you must make sure the stdin buffer is empty before calling key_pressed, because the select call doesn't check for characters already in the stdin buffer. In some applications using raw mode this could be very hard to debug unless you had some hints (such as this one) because an undetected character in the stdin buffer might only happen very rarely and randomly. To check for characters in the stdin buffer, you can look at stdin->_cnt, which tells how many characters, so it should be 0 to proceed with the key_pressed call.