Path: utzoo!mnetor!uunet!tektronix!cae780!leadsv!pyramid!altera!frank From: frank@altera.UUCP (Frank Heile) Newsgroups: comp.sys.amiga Subject: Need help reading single character from keyboard without waiting Message-ID: <273@altera.UUCP> Date: 28 Jan 88 02:20:55 GMT Organization: Altera Corporation, Santa Clara, CA Lines: 55 Keywords: need simple no-wait unbuffered keyboard input method Problem: How to read a single character from the keyboard without blocking the task to wait for input, and WITHOUT REQUIRING THE USER TO TYPE A TERMINATING . My Current Solution: (using Manx 3.4b) ----------------------------------------------------------------- #include struct FileHandle * Input(); main() { struct FileHandle * InHandle; char ch; InHandle = Input(); /* get the input file handle from DOS */ setbuf(stdin,NULL); /* don't let the stdio package buffer the input */ while (1) { /* this returns true if a character is available */ if (WaitForChar(InHandle,1L)) /* I'm afraid to use 0L */ { /* because of the Delay(0L) bug */ ch = getchar(); ...do something with this character... ...like change the mode...or like EXIT... } else { ...continue to do something else... } } } ----------------------------------------------------------------- (This is from memory...please excuse any errors) THE PROBLEM: Apparently WaitForChar() and the DOS Read() function will NOT recognise keyboard input until a has been typed by the user. The above code works just fine except that no characters are returned by getchar() until after a return is typed. DOS must be buffering up the input till a is typed. The getchar() eventually calls the DOS library Read() routine (I know because looked at the source since I bought the commercial package with library source included). So it appears that the DOS WaitForChar() and Read() are the culprits. I can't find anywhere in the RKM about how to make DOS not buffer the input - can anyone help? What I need is a simple technique to read a single character from the keyboard. This is for a very simple CLI type task that doesn't use intuition. I am sure that by using the intuition IDCMP port it could be done. But I would like a simpler method which doesn't require opening a window or interfacing to intuition.