Xref: utzoo comp.unix.wizards:16663 comp.unix.questions:14042 Path: utzoo!utgpu!jarvis.csri.toronto.edu!rutgers!apple!amdahl!kucharsk From: kucharsk@uts.amdahl.com (William Kucharski) Newsgroups: comp.unix.wizards,comp.unix.questions Subject: Re: keyscan wanted Message-ID: <1d5J02BR328401@amdahl.uts.amdahl.com> Date: 5 Jun 89 17:53:43 GMT References: <1006@twwells.uucp> <607@wn2.sci.kun.nl> Reply-To: kucharsk@amdahl.uts.amdahl.com (William Kucharski) Organization: Amdahl Coup, UTS Products Hen House Lines: 28 In article <607@wn2.sci.kun.nl> medfys@wn2.sci.kun.nl (Victor Langeveld/Tjeerd Dijkstra) writes: >There is no need to know what hardware this should be working on. >Mr Charles Thayer (Thanks again, Charles!) gave me a perfect solution: > >int key_pressed() >{ > int mask=1; > struct timeval wait; > > wait.tv_sec=0; > wait.tv_usec=0; > return (select(1,&mask,0,0,&wait)); >} > >This can be used as e.g. if(!key_pressed) { do stuff} else { key >handling}. Works fine! (As is should (?) on any unix machine) As long as the machine in question has select(2), which automatically assumes a UNIX with some BSD extensions - SYSV hacks will have to use poll(2) instead. -- William Kucharski ARPA: kucharsk@uts.amdahl.com UUCP: ...!{ames,decwrl,sun,uunet}!amdahl!kucharsk Disclaimer: The opinions expressed above are my own, and may not agree with those of any other sentient being, not to mention those of my employer. So there.