delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/1999/08/18/11:37:14

Mailing-List: contact cygwin-help AT sourceware DOT cygnus DOT com; run by ezmlm
List-Unsubscribe: <mailto:cygwin-unsubscribe-archive-cygwin=delorie DOT com AT sourceware DOT cygnus DOT com>
List-Archive: <http://sourceware.cygnus.com/ml/cygwin/>
List-Post: <mailto:cygwin AT sourceware DOT cygnus DOT com>
List-Help: <mailto:cygwin-help AT sourceware DOT cygnus DOT com>,
<http://sourceware.cygnus.com/ml/#faqs>
Sender: cygwin-owner AT sourceware DOT cygnus DOT com
Delivered-To: mailing list cygwin AT sourceware DOT cygnus DOT com
Message-Id: <4.2.0.58.19990818104947.00a78dc0@dummy.mmrd.com>
X-Sender: dave AT 192 DOT 2 DOT 2 DOT 24
X-Mailer: QUALCOMM Windows Eudora Pro Version 4.2.0.58
Date: Wed, 18 Aug 1999 11:21:24 -0400
To: "Lincoln, W. Terry" <terryl AT ultimatetechnology DOT com>,
"'Philippe Noel'" <pnoel AT socoint DOT com>
From: "David W. Alderman" <dave AT mmrd DOT com>
Subject: RE: Porting getch() and kbdhit() ???
Cc: "'Cygwin Mailing List'" <cygwin AT sourceware DOT cygnus DOT com>
In-Reply-To: <B3953869CBF8D211A1E50004AC4C1B5402F436@ULTIMATE2>
Mime-Version: 1.0

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 AT socoint DOT 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 AT mmrd DOT com
Personal: dwa AT atlantic DOT net -or- dwa AT netcommander DOT com


--
Want to unsubscribe from this list?
Send a message to cygwin-unsubscribe AT sourceware DOT cygnus DOT com

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019