Subject: RE: Porting getch() and kbdhit() ???
From: "Philippe Noel" <[email-masked]>
To: "David W. Alderman" <[email-masked]>
Cc: "Cygwin-List" <[email-masked]>
Date: Wed, 18 Aug 1999 16:56:05 -0400

Hi,

>
> I suspect you  (Philippe?) have a program loop like this:
>
> while ( TRUE )
> {
>      if kbhit()
>      {
>          inchar = getch();
>          <Put entered character in its place>
>      }
>
>      <Most of program's real work>
> }
>

Exactly.  :)

What I want to do is, in my mind, extremely simple and common.  In fact, I
need the application catch any characters typed on the keyboard if there is
any.  For example, if the user wants to quit during the process is running,
he press Q, the application catch the character and quit.  So, a function
like getchar() don't do the job because this function waits for a keypress
before returning...

> Under ioctl(), this could be implemented as:
>
> ioctl(<Save current settings>)  // So we can restore later
> ioctl(<RAW mode>)  //  So read will return if no key has been pressed
>
> while (TRUE)
> {
>      if (read(0, inbuf, 1)  // Returns 0 if no key pressed
>      {
>          <Put entered character in its place>
>      }
>
>      <Most of program's real work>
> }
> ioctl(<Restore current settings>)  //  Be nice to your parent shell!
>

Yes great, but I really don't find any actions in ioctl (or tcsetattr :) )
that allowed to switch to a kind of "RAW MODE".  So, the question about
read() stay unresolved (for me): It seems the read function waits for a
character infinitly and there's no way to make it returns if no character is
catched on STDIN.

P.S.: The kbhit() function I was searching for is exaclty the one Warren
found in is "M$-C book" (?) :

<snip>
the function kbhit() should return a 0 if no characters have been struck
otherwise the character-code of the struck key (without removing the key
from the KB queue).
<snip>

PN

--
Want to unsubscribe from this list?
Send a message to [email-masked]