how to poll keyboard

Guy Harris guy at gorodish.Sun.COM
Thu Aug 4 11:20:05 AEST 1988


> 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.

No need to open "/dev/tty", just use the same descriptor you would use for the
"read".

> 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.

Only if your tty driver is streams-based; the only generally-available
system I know of that has no *non*-streams-based ttys is SunOS - S5R3 as
distributed by AT&T still has non-streams-based ttys.

However, both 4.[23]BSD and S5 support non-blocking mode on ttys; in this mode,
a "read" doesn't block when no data is available, it returns -1 and sets
"errno" to EWOULDBLOCK in 4.[23]BSD and returns 0 in S5.  See FCNTL(2) in the
BSD documentation, or FCNTL(2) and READ(2) in the S5 documentation.



More information about the Comp.unix.questions mailing list