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 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:pnoel@socoint.com]

<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: dave@mmrd.com
Personal: dwa@atlantic.net -or- dwa@netcommander.com


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