Subject: RE: Porting getch() and kbdhit() ???
From: "David W. Alderman" <[email-masked]>
To: "Lincoln, W. Terry" <[email-masked]>, "'Philippe Noel'" <[email-masked]>
Cc: "'Cygwin Mailing List'" <[email-masked]>
Date: Wed, 18 Aug 1999 11:21:24 -0400

Hi guys,

kbhit and getch were defined in Xenix, I believe.  They were included to 
allow greater compatibility with DOS  :-)
Unfortunately, both functions do not fit well with a mode-oriented 
ioctl-based input stream, although I guess you could do a kbhit() 
equivalent in cbreak mode, which is appropriate mode for getch().

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>
}

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!

The correct settings for ioctl() under cygwin are left as an exercise for 
the implementer  :-)

Please forgive any obvious errors (or any non-obvious ones).

At 06:11 PM 8/17/1999 -0400, Lincoln, W. Terry wrote:
>Those two functions are not POSIX now, are they?  Sounds DOS/WINDOZISH to me
>;-)
>Cygwin is for porting Unix(POSIX) apps to Win32.

<deleted>

> > -----Original Message-----
> > From: Philippe Noel [mailto:[email-masked]]

<deleted>

> > I'm currently trying to port a source code that use getch()
> > and kbdhit()
> > under Linux.
> > It really do not seems to be supported by Cygwin.  Is there a
> > reason for
> > this?
> >
> > And, is there a way to do the same thing as this (very
> > common) code under
> > Cygwin?
> >
> > if( kbdhit() )
> >    key = getch();
> >

Dave Alderman - Democracy should not be capital intensive.
Business: [email-masked]
Personal: [email-masked] -or- [email-masked]

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