Murray G. Gamble (gamblem++at++home.com)
Thu, 24 Jun 1999 06:54:28 -0400
If you're working on NT, you can test _kbhit() in your main loop to check
for input at the console (ref. "conio.h") and _getch() to determine which
key was pressed.
I use it like so:
// check for console input
if (_kbhit())
{
switch (_getch())
{
case 'q': // exit
case 'Q':
done = true;
break;
etc....
}
}
'Hope this helps!
Mur.
----- Original Message -----
From: Thom DeCarlo <trdecarlo++at++tasc.com>
To: Don Hatch <hatch++at++sgi.com>
Cc: info-vega <info-vega++at++paradigmsim.com>; info-performer
<info-performer++at++sgi.com>
Sent: Wednesday, June 23, 1999 11:13 PM
Subject: Re: WOT: Testing stdin
> Hi,
>
> Don Hatch wrote:
>
> > On Jun 23, 9:21pm, Thom DeCarlo wrote:
> > > Subject: WOT: Testing stdin
> > > Hi,
> > > I apologize for this message being Way Off Topic, but I'm at a loss
for
> > > how to continue.
> > >
> > > The problem is, how do I test whether anything has been typed to stdin
> > > without blocking the program if the input buffer is empty? Of course,
> > > the simple things don't work. I've tried getc(), fgetc(), gets(),
> > > scanf(), .... They all block until a '\n' is typed. I just want the
test
> > > to fail and continue if nothing is waiting in the buffer.
> > >
> > > Any ideas from you C++ gurus out there?
> > >
> > > TIA,
> > > Thom
> > >
> > >
> >
> -----------------------------------------------------------------------
> > > List Archives, FAQ, FTP: http://www.sgi.com/software/performer/
> > > Submissions: info-performer++at++sgi.com
> > > Admin. requests: info-performer-request++at++sgi.com
> > >-- End of excerpt from Thom DeCarlo
> >
> > Not off topic at all! You need to know how to do this
> > to get keyboard input in any Performer simulation loop.
> >
> > Use select() to query whether stdin (fileno = 0) has characters
> > waiting to be read.
> > If it says yes, then you should be able to call getc()
> > or fgets() to get a line of input without it blocking.
> >
> > You'll have to experiment with the details of stdio buffering
> > (e.g. what happens when there's more than one line of input waiting?
> > I suspect the second line might get buffered and so you'll get fooled
> > into thinking it's not there).
> > You can probably avoid this issue by calling setbuf(stdin, NULL),
> > or use read() directly instead of the buffered stdio calls.
> >
> > Don
> >
> > --
> > Don Hatch hatch++at++sgi.com (650) 933-5150 Silicon Graphics, Inc.
>
> Well, I guess I have to admit it. I'm not writing this on an SGI. I'm on
WinNT
> using VC++ 6.0 and VegaNT.
>
> I can't find anything on this machine that defines the select() function.
And
> the read() function still blocks until '\n' is entered. I did find an
> _filelength() function which I thought might work, but it just returns an
> error whether anything is on the input buffer or not.
>
> Thom
>
>
>
This archive was generated by hypermail 2.0b2 on Thu Jun 24 1999 - 03:54:04 PDT