Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!purdue!mentor.cc.purdue.edu!j.cc.purdue.edu!pur-ee!hankd From: hankd@pur-ee.UUCP (Hank Dietz) Newsgroups: comp.lang.c Subject: Re: WANTED: do while no key pressed (in portable code) Summary: It is possible... but not easy Message-ID: <11119@pur-ee.UUCP> Date: 27 Mar 89 20:15:04 GMT References: <22064@agate.BERKELEY.EDU> <16535@mimsy.UUCP> <796@vector.UUCP> Reply-To: hankd@pur-ee.UUCP (Hank Dietz) Distribution: usa Organization: Purdue University Engineering Computer Network Lines: 34 In article <796@vector.UUCP> chip@vector.UUCP (Chip Rosenthal) writes: >In article <16535@mimsy.UUCP> chris@mimsy.UUCP (Chris Torek) writes: >>In article <22064@agate.BERKELEY.EDU> air@anableps.berkeley.edu writes: ...[lots of stuff as to foolishness of key press testing and how it could never be done portably].... I think he's just looking for a way to do things like update the screen incrementally, only performing update until a new keyboard command makes the yet-to-be-drawn portion of the screen image be out-of-date (e.g., as in editors like emacs) -- a very sane thing to want to do. Unfortunately, you can't do it portably because a non-blocking read was not one of those things designed into unix (or CP/M). It could only be done under v6pwb unix by using two processes: one does a raw mode read, spits out the char on a pipe, and signals the other process that a char has arrived so that it can read the pipe and not block. Yuck. In v7, it was added as empty(fd) (actually read(fd,NULL,0)) to test if a char could be read without actually reading it. Then you got an ioctl mode for non-blocking input. Then you got cbreak mode. Etc. I think the only thing that works on all unix systems is the raw mode v6pwb two-process hack. In most cases, under unix, you probably also want no echo mode set. As for other OS, in later versions of CP/M (v2), non-blocking input of a char became bdos(6,0xff) (as raw mode with no echo). The problem is that a return value of zero represented either no input available or that the NUL char was input -- you couldn't tell which. I am blissfully ignorant of the situation relative to MSDOS (but it probably follows the CP/M convention). I too would really like a package which uses the BEST POSSIBLE IMPLEMENTATION for each OS... anyone out there want to write and post one? -hankd@ee.ecn.purdue.edu