Xref: utzoo comp.unix.wizards:16676 comp.unix.questions:14048 Path: utzoo!utgpu!jarvis.csri.toronto.edu!rutgers!ukma!uflorida!novavax!twwells!bill From: bill@twwells.uucp (T. William Wells) Newsgroups: comp.unix.wizards,comp.unix.questions Subject: Re: keyscan wanted Message-ID: <1016@twwells.uucp> Date: 5 Jun 89 23:59:54 GMT References: <1006@twwells.uucp> <607@wn2.sci.kun.nl> Reply-To: bill@twwells.UUCP (T. William Wells) Organization: None, Ft. Lauderdale Lines: 46 Summary: Expires: Sender: Followup-To: Distribution: Keywords: In article <607@wn2.sci.kun.nl> medfys@wn2.sci.kun.nl (Victor Langeveld/Tjeerd Dijkstra) writes: : In article <1006@twwells.uucp>, bill@twwells.uucp (T. William Wells) : writes: : > In article <475@wn2.sci.kun.nl> medfys@wn2.sci.kun.nl (Victor Langeveld/Tjeerd Dijkstra) writes: : > : I am searching for a (small?) routine that informs me about a : > : possible pressed key. This routine should *not* wait for input, : > : but return immediately, wether succesfull or not. : > : Suggestions? : > : > Yes. Tell us what hardware and OS you are talking about. : > : > For example, this should be doable on my system, a '386 running : > Microport's Unix, by telling the driver to return scan codes and : > doing nonblocking reads. It's all in the relevant sections of the : > manual, under keyboard(7), open(2), and fcntl(2), and maybe a few : > other places I can't think of off hand. : > : > But on your system, who knows? We certainly don't, since we don't : > know the system. : > : > --- : > Bill { uunet | novavax } !twwells!bill : : 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) Leaving aside the possible interpretational problem (the solution I suggested *really* permits checking for key pressed, and key released, too), you're talking BSD. Your code won't work on my sysV 3.0 and on many others. --- Bill { uunet | novavax } !twwells!bill