how to poll keyboard

Scott Wilson swilson%thetone at Sun.COM
Thu Aug 4 11:12:45 AEST 1988


In article <5065 at husc6.harvard.edu> nakada at husc8.UUCP (Paul Nakada) writes:
>I am in need of a way to read a terminal keyboard without
>stopping if there is no keypress...  this is the scenario..

If you are using a UNIX that has the select(2) system call try
opening /dev/tty then calling select with a timeout of zero.  That
is not a NULL pointer for the timeout struct but a struct with
the time fields set to zero.  This is effectively a poll of
the process' controlling terminal to see if any characters have
been typed.  I have found some select man pages to be less than
obvious about its features.

If your UNIX is sys5 based and has streams you can probably do
the same thing with poll(2) but I have never used it.

--
Scott Wilson		arpa: swilson at sun.com		"Why do dogs lick
Sun Microsystems	uucp: ...!sun!swilson		their balls?  Because
Mt. View, CA						they can!"



More information about the Comp.unix.questions mailing list