comp.lang.ada
 help / color / mirror / Atom feed
* Keyboard input time out routine
@ 1999-11-09  0:00 Ray
  0 siblings, 0 replies; 6+ messages in thread
From: Ray @ 1999-11-09  0:00 UTC (permalink / raw)


I am trying to allow a max time for keyboard (math speed test program),
but the following code only sort of works.  It times out, but waits for
an input (unused) before printing out the message.  I want the message
to print as soon as the time allotted for input has passed.  Hints? Is
select even the right way to go (pulled the code from the help docs)?

win 98, intel, AdaGIDE.

with Ada.Text_Io, Ada.Integer_Text_IO;

procedure InputDelay is
X: Integer;

begin
X:=1;
select
  delay 5.0;
  Ada.Text_Io.Put_Line("No data entered");
then abort
  Ada.Integer_Text_IO.Get (X);
end select;
Ada.Integer_Text_IO.Put (X);
end InputDelay;
-- 
"I'm not lost, I just don't know where I am!"
In the interest of anti-spam, I have added numerics to my email address

Ray




^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Keyboard input time out routine
       [not found] <11FADB0F359D6AC2.1F52588FCDAC2F80.5B1126BE5AE8CD31@lp.airnews. net>
@ 1999-11-11  0:00 ` Matthew Heaney
  1999-11-11  0:00   ` Ray
  0 siblings, 1 reply; 6+ messages in thread
From: Matthew Heaney @ 1999-11-11  0:00 UTC (permalink / raw)


In article 
<11FADB0F359D6AC2.1F52588FCDAC2F80.5B1126BE5AE8CD31@lp.airnews.net> ,
Ray <crwhite12@airmail7.net>  wrote:

> I am trying to allow a max time for keyboard (math speed test program),
> but the following code only sort of works.  It times out, but waits for
> an input (unused) before printing out the message.  I want the message
> to print as soon as the time allotted for input has passed.  Hints? Is
> select even the right way to go (pulled the code from the help docs)?

I don't think your ATC example will work.  You could try polling the
input using Get_Immediate:

declare
  C : Character;
  Available : Boolean;
begin
  for I in 1 .. 50 loop
    Get_Immediate (C, Available);
    exit when Available;
    delay 0.1;
  end loop;

  if Available then
    <do whatever>
  else
    Put_Line ("No data entered.");
  end if;
end;


--
Science is, foremost, a method of interrogating reality: proposing
hypotheses that seem true and then testing them -- trying, almost
perversely, to negate them, elevating only the handful that survive to
the status of a theory. Creationism is a doctrine, whose adherents are
interested only in seeking out data that support it.

George Johnson, NY Times, 15 Aug 1999




^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Keyboard input time out routine
  1999-11-11  0:00 ` Keyboard input time out routine Matthew Heaney
@ 1999-11-11  0:00   ` Ray
  1999-11-11  0:00     ` Matthew Heaney
  0 siblings, 1 reply; 6+ messages in thread
From: Ray @ 1999-11-11  0:00 UTC (permalink / raw)


Thanks Matthew, I was able to expand your information to get a working idea of
what to do.  Looks like I need to write a procedure (like I did in C++ using
kbhit and getch) to process any keystrokes and build the number, and time out if
the enter key is not hit in the allotted time.

Matthew Heaney wrote:
> Ray <crwhite12@airmail7.net>  wrote:
> 
> > I am trying to allow a max time for keyboard (math speed test program),
> > but the following code only sort of works.  It times out, but waits for
> > an input (unused) before printing out the message.  I want the message
> > to print as soon as the time allotted for input has passed.  Hints? Is
> > select even the right way to go (pulled the code from the help docs)?
> 
> I don't think your ATC example will work.  You could try polling the
> input using Get_Immediate:
> 
> declare
>   C : Character;
>   Available : Boolean;
> begin
>   for I in 1 .. 50 loop
>     Get_Immediate (C, Available);
>     exit when Available;
>     delay 0.1;
>   end loop;
> 
>   if Available then
>     <do whatever>
>   else
>     Put_Line ("No data entered.");
>   end if;
> end;


-- 
"I'm not lost, I just don't know where I am!"
In the interest of anti-spam, I have added numerics to my email address

Ray




^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Keyboard input time out routine
  1999-11-11  0:00   ` Ray
@ 1999-11-11  0:00     ` Matthew Heaney
  1999-11-11  0:00       ` Ray
  0 siblings, 1 reply; 6+ messages in thread
From: Matthew Heaney @ 1999-11-11  0:00 UTC (permalink / raw)


In article 
<B94C2AACE5FD49E5.F586390D9ABF88C3.A2C5492FFC18140C@lp.airnews.net> ,
Ray <crwhite12@airmail7.net>  wrote:

> Thanks Matthew, I was able to expand your information to get a working idea of
> what to do.  Looks like I need to write a procedure (like I did in C++ using
> kbhit and getch) to process any keystrokes and build the number, and time out
> if the enter key is not hit in the allotted time.

That's right.  Predefined I/O packages are "potentially blocking," so
you don't really know whether they'll abort right away.  For example,
Get could be implemented like this:

  procedure Get (Item : out Num) is
    pragma Abort_Deferred;  -- GNAT-specific pragma
  begin
    ...
  end Get;

in which case Get won't abort, even if the delay expires.

In your example, Get didn't abort.  I coded your example using Get_Line,
and it did abort.  But you can't depend on this.

The best thing to do is as you suggest: assemble the lexeme yourself by
consuming one character at a time using Get_Immediate, and terminate
when you consume the line terminator (or too much time passes).

You don't need ATC at all (for this problem).

--
Science is, foremost, a method of interrogating reality: proposing
hypotheses that seem true and then testing them -- trying, almost
perversely, to negate them, elevating only the handful that survive to
the status of a theory. Creationism is a doctrine, whose adherents are
interested only in seeking out data that support it.

George Johnson, NY Times, 15 Aug 1999




^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Keyboard input time out routine
  1999-11-11  0:00     ` Matthew Heaney
@ 1999-11-11  0:00       ` Ray
  1999-11-11  0:00         ` David C. Hoos, Sr.
  0 siblings, 1 reply; 6+ messages in thread
From: Ray @ 1999-11-11  0:00 UTC (permalink / raw)


Thanks for the insight, I think have a handle on the process now.

BTW, the reference to ATC is throwing me, I think I should know what it means
but it is not clicking.

Matthew Heaney wrote:
> 
> 
> You don't need ATC at all (for this problem).

-- 
"I'm not lost, I just don't know where I am!"
In the interest of anti-spam, I have added numerics to my email address

Ray




^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Keyboard input time out routine
  1999-11-11  0:00       ` Ray
@ 1999-11-11  0:00         ` David C. Hoos, Sr.
  0 siblings, 0 replies; 6+ messages in thread
From: David C. Hoos, Sr. @ 1999-11-11  0:00 UTC (permalink / raw)



Ray <crwhite12@airmail7.net> wrote in message
news:B0C8FE9D400F6087.66CD428C51706C9B.9AE35DA51148E4AA@lp.airnews.net...
> Thanks for the insight, I think have a handle on the process now.
>
> BTW, the reference to ATC is throwing me, I think I should know what it
means
> but it is not clicking.
Asynchronous Transfer of Control -- RM-95 9.7.4






^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~1999-11-11  0:00 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <11FADB0F359D6AC2.1F52588FCDAC2F80.5B1126BE5AE8CD31@lp.airnews. net>
1999-11-11  0:00 ` Keyboard input time out routine Matthew Heaney
1999-11-11  0:00   ` Ray
1999-11-11  0:00     ` Matthew Heaney
1999-11-11  0:00       ` Ray
1999-11-11  0:00         ` David C. Hoos, Sr.
1999-11-09  0:00 Ray

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox