Mail Archives: djgpp/2002/05/18/02:58:25
> Date: Fri, 17 May 2002 20:28:32 +0200 (MEST)
> From: ahelm AT gmx DOT net
>
> I'm using kbhit() and getkey() for simple user interaction
> e.g. yes/no or "any key" questions. But this is very DJGPP
> specific. Is there a way to write these things more portable,
> especially for UNIX environments?
>
> There are 2 main functionalities:
> 1) empty the keyboard buffer:
> while(kbhit())
> {
> getkey();
> }
>
> 2) wait for and read a single key
> x = getkey();
The more portable way is to use termios and `select'. Set the
keyboard to raw mode using `tcsetattr', drain the keyboard queue by
calling `tcflush', and then read individual characters with `getc' and
friends. Should you need to avoid getting stuck inside `getc' while
it waits for the user to type something, use `select' to check if some
input is available.
Note that with this method, you gain portability to Posix systems, but
lose portability to DOS/Windows platforms other than DJGPP and Cygwin.
- Raw text -