Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!uunet!seismo!mcnc!ece-csc!ncrcae!ncr-sd!hp-sdd!ucsdhub!jack!man!nu3b2!rwhite From: rwhite@nu3b2.UUCP (Robert C. White Jr.) Newsgroups: comp.lang.c,comp.unix.questions Subject: Re: Keyboard Input (Revised Question) ... Message-ID: <805@nu3b2.UUCP> Date: Tue, 14-Jul-87 00:38:55 EDT Article-I.D.: nu3b2.805 Posted: Tue Jul 14 00:38:55 1987 Date-Received: Fri, 17-Jul-87 01:18:09 EDT References: <1043@bucsb.bu.edu.UUCP> Organization: National University, San Diego Lines: 28 Keywords: Keyboard Summary: Read wiht O_NDELAY Xref: mnetor comp.lang.c:3049 comp.unix.questions:3197 In article <1043@bucsb.bu.edu.UUCP>, eap@bucsb.bu.edu.UUCP (Eric Pearce) writes: > > I used to be able to do this easily on my Apple ][. You could check a memory > location to see if a key had been pressed and which one it was, without having > the program wait for user input. (good for games) > > Is there a way to do this in C? Or maybe a different approach to the problem? > (this is intended for a program on a mainframe) It would apear that an apple ][ isnt a mainframe after all ;-) SERIOUSLY: use the function ioctl to set O_NDELAY on standard input, use read to read your character. if there are no characters waiting, and you are not at an EOF condition read will return -1 and errno will be set to EAGAIN. This is how it is on our machine, check read(2) in your programmers refrence [or wherever] for details. AND REMEMBER TO ALWAS CLEAN UP YOUR ioctl BEFORE BRANCHING/EXITING FROM THE LOOP OR GO UP IN FLAMES! Robert. Disclaimer: My mind is so fragmented by random excursions into a wilderness of abstractions and incipient ideas that the practical purposes of the moment are often submerged in my consciousness and I don't know what I'm doing. [my employers certainly have no idea]