delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/1999/08/18/17:00:44

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
From: "Philippe Noel" <pnoel AT socoint DOT com>
To: "David W. Alderman" <dave AT mmrd DOT com>
Cc: "Cygwin-List" <cygwin AT sourceware DOT cygnus DOT com>
Subject: RE: Porting getch() and kbdhit() ???
Date: Wed, 18 Aug 1999 16:56:05 -0400
Message-ID: <003d01bee9bc$16d90f40$400010ac@philippe.socoint.com>
MIME-Version: 1.0
X-Priority: 3 (Normal)
X-MSMail-Priority: Normal
X-Mailer: Microsoft Outlook 8.5, Build 4.71.2377.0
In-Reply-To: <4.2.0.58.19990818104947.00a78dc0@dummy.mmrd.com>
X-MimeOLE: Produced By Microsoft MimeOLE V4.72.3110.3
Importance: Normal

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 AT sourceware DOT cygnus DOT com

- Raw text -


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