Subject: Re: Detecting keyboard press
To: Bruce Martin <brucem@cat.co.za>
From: Matthias Buelow <mkb@mukappabeta.de>
List: netbsd-help
Date: 12/04/2001 10:58:47
Bruce Martin writes:

>Very simple thing I'm sure - sorry if this isn't the correct group to ask! I 
>am writing some user space C++ code, and want to continuously perform a 
>number of instructions until a keyboard press takes place. On other O/Ses I 
>have done something like:
> while(!kbhit())
>  {
>     // determine the meaning of life
>  }
>  // display the meaning of life
>
>What is the _simplest_ way to do this under NetBSD/i386 (1.5.1)

The standard way of doing such things is to make use of the curses
library, which provides functions for interactive, full-screen
character-cell applications.  The curses functions you're looking
for are the *getch() family.  You might want to enable cbreak-mode
with the cbreak() function, otherwise the standard-input will remain
line-buffered.  See curses(3) for how to initialize curses in
an application and how to use the functions.
Alternatively, you could set the terminal in cbreak or raw mode
yourself, using ioctls.  I advise against doing this, though, when
curses can be used.

--mkb