[comp.os.msdos.programmer] reading stdin one character at the time

fs-info@sbsvax.cs.uni-sb.de (c/o Peter Gaal) (08/17/90)

HiHo!

I hope someone may help me with the following problem:

Asume this C fragment:

int dev_ready(int handle)
/* does an ioctl() call on handle to get an input-ready status
 * This should work, assume it does.
 */
{ some code... }

...
setraw(fileno(stdin));
while (!dev_ready(fileno(stdin)) { /* do something 'til a key is hit */ }
c=fgetc(stdin); /* read ONE character */

The task is: query if a character is present on some handle, if not, do
something else, and if it is, read exactly this character.

The Problem is the function setraw() above, which should set a CON: device
(normally associated with stdin) into a raw mode.
All experiments 'til now failed to force the CON: device to read the
keyboard one character at the time - it allways reads a complete line
which breaks the nonblocking intention of the above.

Important: I do not want code reading the keyboard directly (via BIOS or so),
I need the possibility to continue working with the handle only.

Please E-Mail suggestions, and only post code if it's tested...

Thanx in advance
  Patrick