This is the mail archive of the cygwin@sourceware.cygnus.com mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

RE: Porting getch() and kbdhit() ???


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 cygwin-unsubscribe@sourceware.cygnus.com


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]