comp.lang.ada
 help / color / mirror / Atom feed
* Keyboard Polling Solution
@ 2004-02-18 21:37 Me
  2004-02-18 23:10 ` Preben Randhol
  2004-02-20 21:38 ` Warren W. Gay VE3WWG
  0 siblings, 2 replies; 14+ messages in thread
From: Me @ 2004-02-18 21:37 UTC (permalink / raw)


Yes, "Get_Immediate" seems to do the trick.  Thanks for the tip.

Test Example :




with Text_IO;  use Text_IO;

procedure Test is

  My_Char          : CHARACTER := ' ';
  Character_Exists : BOOLEAN   := FALSE;
  Loop_Counter     : INTEGER   := 0;

procedure Take_A_Break is begin put_line ("Taking a break from
polling..."); end Take_A_Break;

begin

  loop
    Loop_Counter := Loop_Counter + 1;
    for X in 1..10000 loop
      Get_Immediate (Item      => My_Char,
                     Available => Character_Exists);
      if (Character_Exists) then
        put_line ("Character entered.  Done.");
        return;
      end if;
    end loop;
    Take_A_Break;
  end loop;

end;





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

* Re: Keyboard Polling Solution
  2004-02-18 21:37 Keyboard Polling Solution Me
@ 2004-02-18 23:10 ` Preben Randhol
  2004-02-19  0:30   ` Bruce or Tracy Jacobs
  2004-02-19 11:47   ` Marin David Condic
  2004-02-20 21:38 ` Warren W. Gay VE3WWG
  1 sibling, 2 replies; 14+ messages in thread
From: Preben Randhol @ 2004-02-18 23:10 UTC (permalink / raw)


On 2004-02-18, Me <me@me.org> wrote:
> Yes, "Get_Immediate" seems to do the trick.  Thanks for the tip.
>
> Test Example :
>
>
>
>
> with Text_IO;  use Text_IO;
>
> procedure Test is
>
>   My_Char          : CHARACTER := ' ';
>   Character_Exists : BOOLEAN   := FALSE;
>   Loop_Counter     : INTEGER   := 0;
>
> procedure Take_A_Break is begin put_line ("Taking a break from
> polling..."); end Take_A_Break;
>
> begin
>
>   loop
>     Loop_Counter := Loop_Counter + 1;
>     for X in 1..10000 loop
>       Get_Immediate (Item      => My_Char,
>                      Available => Character_Exists);
>       if (Character_Exists) then
>         put_line ("Character entered.  Done.");
>         return;
>       end if;
>     end loop;
>     Take_A_Break;
>   end loop;
>
> end;
>
>

Hmm, to me this looks like you want to read about tasks in Ada.

-- 
"Saving keystrokes is the job of the text editor, not the programming
 language."



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

* Re: Keyboard Polling Solution
  2004-02-18 23:10 ` Preben Randhol
@ 2004-02-19  0:30   ` Bruce or Tracy Jacobs
  2004-02-19 11:47   ` Marin David Condic
  1 sibling, 0 replies; 14+ messages in thread
From: Bruce or Tracy Jacobs @ 2004-02-19  0:30 UTC (permalink / raw)


As I get deeper in to my application implementation, there is a good
chance
I will have to take a look into tasking.  Thank you.  

Bruce 


Preben Randhol wrote:
> 
> On 2004-02-18, Me <me@me.org> wrote:
> > Yes, "Get_Immediate" seems to do the trick.  Thanks for the tip.
> >
> > Test Example :
> >
> >
> >
> >
> > with Text_IO;  use Text_IO;
> >
> > procedure Test is
> >
> >   My_Char          : CHARACTER := ' ';
> >   Character_Exists : BOOLEAN   := FALSE;
> >   Loop_Counter     : INTEGER   := 0;
> >
> > procedure Take_A_Break is begin put_line ("Taking a break from
> > polling..."); end Take_A_Break;
> >
> > begin
> >
> >   loop
> >     Loop_Counter := Loop_Counter + 1;
> >     for X in 1..10000 loop
> >       Get_Immediate (Item      => My_Char,
> >                      Available => Character_Exists);
> >       if (Character_Exists) then
> >         put_line ("Character entered.  Done.");
> >         return;
> >       end if;
> >     end loop;
> >     Take_A_Break;
> >   end loop;
> >
> > end;
> >
> >
> 
> Hmm, to me this looks like you want to read about tasks in Ada.
> 
> --
> "Saving keystrokes is the job of the text editor, not the programming
>  language."



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

* Re: Keyboard Polling Solution
  2004-02-18 23:10 ` Preben Randhol
  2004-02-19  0:30   ` Bruce or Tracy Jacobs
@ 2004-02-19 11:47   ` Marin David Condic
  2004-02-19 22:57     ` Bruce or Tracy Jacobs
  1 sibling, 1 reply; 14+ messages in thread
From: Marin David Condic @ 2004-02-19 11:47 UTC (permalink / raw)


An observation would be that this is not truly "polling" in the sense 
that Get_Immediate is going to block waiting for a keystroke. It does 
get one keystroke at a time - which is often what you want, but Preben 
is right about tasks. If you want to test for a keystroke being 
available and otherwise go on about some other business, you should look 
at building a task around Get_Immediate that would queue up keystrokes.

MDC

Preben Randhol wrote:
>>
>>with Text_IO;  use Text_IO;
>>
>>procedure Test is
>>
>>  My_Char          : CHARACTER := ' ';
>>  Character_Exists : BOOLEAN   := FALSE;
>>  Loop_Counter     : INTEGER   := 0;
>>
>>procedure Take_A_Break is begin put_line ("Taking a break from
>>polling..."); end Take_A_Break;
>>
>>begin
>>
>>  loop
>>    Loop_Counter := Loop_Counter + 1;
>>    for X in 1..10000 loop
>>      Get_Immediate (Item      => My_Char,
>>                     Available => Character_Exists);
>>      if (Character_Exists) then
>>        put_line ("Character entered.  Done.");
>>        return;
>>      end if;
>>    end loop;
>>    Take_A_Break;
>>  end loop;
>>
>>end;
>>
>>
> 
> 
> Hmm, to me this looks like you want to read about tasks in Ada.
> 


-- 
======================================================================
Marin David Condic
I work for: http://www.belcan.com/
My project is: http://www.jsf.mil/NSFrames.htm

Send Replies To: m   o   d   c @ a   m   o   g
                    c   n   i       c   .   r

     "Face it ladies, its not the dress that makes you look fat.
     Its the FAT that makes you look fat."

         --  Al Bundy

======================================================================




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

* Re: Keyboard Polling Solution
  2004-02-19 11:47   ` Marin David Condic
@ 2004-02-19 22:57     ` Bruce or Tracy Jacobs
  2004-02-20 12:15       ` Marin David Condic
  0 siblings, 1 reply; 14+ messages in thread
From: Bruce or Tracy Jacobs @ 2004-02-19 22:57 UTC (permalink / raw)


A version of Get_Immediate does this.  If there is nothing in the
buffer, it returns
FALSE and lets you continue on.  

Marin David Condic wrote:
> 
> An observation would be that this is not truly "polling" in the sense
> that Get_Immediate is going to block waiting for a keystroke. It does
> get one keystroke at a time - which is often what you want, but Preben
> is right about tasks. If you want to test for a keystroke being
> available and otherwise go on about some other business, you should look
> at building a task around Get_Immediate that would queue up keystrokes.
> 
> MDC
> 
> Preben Randhol wrote:
> >>
> >>with Text_IO;  use Text_IO;
> >>
> >>procedure Test is
> >>
> >>  My_Char          : CHARACTER := ' ';
> >>  Character_Exists : BOOLEAN   := FALSE;
> >>  Loop_Counter     : INTEGER   := 0;
> >>
> >>procedure Take_A_Break is begin put_line ("Taking a break from
> >>polling..."); end Take_A_Break;
> >>
> >>begin
> >>
> >>  loop
> >>    Loop_Counter := Loop_Counter + 1;
> >>    for X in 1..10000 loop
> >>      Get_Immediate (Item      => My_Char,
> >>                     Available => Character_Exists);
> >>      if (Character_Exists) then
> >>        put_line ("Character entered.  Done.");
> >>        return;
> >>      end if;
> >>    end loop;
> >>    Take_A_Break;
> >>  end loop;
> >>
> >>end;
> >>
> >>
> >
> >
> > Hmm, to me this looks like you want to read about tasks in Ada.
> >
> 
> --
> ======================================================================
> Marin David Condic
> I work for: http://www.belcan.com/
> My project is: http://www.jsf.mil/NSFrames.htm
> 
> Send Replies To: m   o   d   c @ a   m   o   g
>                     c   n   i       c   .   r
> 
>      "Face it ladies, its not the dress that makes you look fat.
>      Its the FAT that makes you look fat."
> 
>          --  Al Bundy
> 
> ======================================================================



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

* Re: Keyboard Polling Solution
  2004-02-19 22:57     ` Bruce or Tracy Jacobs
@ 2004-02-20 12:15       ` Marin David Condic
  2004-02-20 20:59         ` Chad R. Meiners
  2004-02-22 21:26         ` Bruce or Tracy Jacobs
  0 siblings, 2 replies; 14+ messages in thread
From: Marin David Condic @ 2004-02-20 12:15 UTC (permalink / raw)


Well, there you go! I have not messed with any keyboard input in so long 
I'd completely forgotten about that. But yes, that looks like it would 
do the job.

I'd be curious why you want to poll. Usually, one tries to avoid that, 
but I know I've wanted something going on in the background that might 
stop when the user hit a key. The usual trick would be to have a task 
looking at keyboard input with another task doing the background job. 
Sometimes this wouldn't work with some implementations because the I/O 
operation didn't flag the task as "blocked", so the background would 
starve. Then you might want to resort to some kind of polling.

MDC

Bruce or Tracy Jacobs wrote:
> A version of Get_Immediate does this.  If there is nothing in the
> buffer, it returns
> FALSE and lets you continue on.  
> 

-- 
======================================================================
Marin David Condic
I work for: http://www.belcan.com/
My project is: http://www.jsf.mil/NSFrames.htm

Send Replies To: m   o   d   c @ a   m   o   g
                    c   n   i       c   .   r

     "Face it ladies, its not the dress that makes you look fat.
     Its the FAT that makes you look fat."

         --  Al Bundy

======================================================================




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

* Re: Keyboard Polling Solution
  2004-02-20 12:15       ` Marin David Condic
@ 2004-02-20 20:59         ` Chad R. Meiners
  2004-02-22 21:26         ` Bruce or Tracy Jacobs
  1 sibling, 0 replies; 14+ messages in thread
From: Chad R. Meiners @ 2004-02-20 20:59 UTC (permalink / raw)



"Marin David Condic" <nobody@noplace.com> wrote in message
news:4035FA69.1060301@noplace.com...
> I'd be curious why you want to poll. Usually, one tries to avoid that,
> but I know I've wanted something going on in the background that might
> stop when the user hit a key. The usual trick would be to have a task
> looking at keyboard input with another task doing the background job.
> Sometimes this wouldn't work with some implementations because the I/O
> operation didn't flag the task as "blocked", so the background would
> starve. Then you might want to resort to some kind of polling.

When writing a keyboard task, I usually poll the keyboard and then delay or
sleep on a select statement.   This way I can send commands to the keyboard
task if need be.

-CRM





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

* Re: Keyboard Polling Solution
  2004-02-18 21:37 Keyboard Polling Solution Me
  2004-02-18 23:10 ` Preben Randhol
@ 2004-02-20 21:38 ` Warren W. Gay VE3WWG
  2004-02-22 21:30   ` Bruce or Tracy Jacobs
  1 sibling, 1 reply; 14+ messages in thread
From: Warren W. Gay VE3WWG @ 2004-02-20 21:38 UTC (permalink / raw)


Me wrote:

> Yes, "Get_Immediate" seems to do the trick.  Thanks for the tip.
> 
> Test Example :
...

One annoying thing about it however is that for w2k use,
Control-D causes "End_of_File" to occur, whether or not
it was the first character entered on a line or not.

Under *NIX/*BSD, the end of file character is only special
at the start of the line (or not active at all). This
means that Get_Immediate cannot return ^D when you want
it to :<  AFAIK, under w2k.  Note however, that ^Z _is_
readable, which usually causes EOF to windoze/DOS progs.

-- 
Warren W. Gay VE3WWG
http://ve3wwg.tk




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

* Re: Keyboard Polling Solution
  2004-02-20 12:15       ` Marin David Condic
  2004-02-20 20:59         ` Chad R. Meiners
@ 2004-02-22 21:26         ` Bruce or Tracy Jacobs
  2004-02-23 10:40           ` Preben Randhol
  1 sibling, 1 reply; 14+ messages in thread
From: Bruce or Tracy Jacobs @ 2004-02-22 21:26 UTC (permalink / raw)


I am playing with an Ada OpenGL graphics program that allows the user to 
manipulate output graphics (zoom in, out, move around, etc) but I 
didn't want the entire program to stop and wait for input because it
needs to stay busy doing things.  


Marin David Condic wrote:
> 
> Well, there you go! I have not messed with any keyboard input in so long
> I'd completely forgotten about that. But yes, that looks like it would
> do the job.
> 
> I'd be curious why you want to poll. Usually, one tries to avoid that,
> but I know I've wanted something going on in the background that might
> stop when the user hit a key. The usual trick would be to have a task
> looking at keyboard input with another task doing the background job.
> Sometimes this wouldn't work with some implementations because the I/O
> operation didn't flag the task as "blocked", so the background would
> starve. Then you might want to resort to some kind of polling.
> 
> MDC
> 
> Bruce or Tracy Jacobs wrote:
> > A version of Get_Immediate does this.  If there is nothing in the
> > buffer, it returns
> > FALSE and lets you continue on.
> >
> 
> --
> ======================================================================
> Marin David Condic
> I work for: http://www.belcan.com/
> My project is: http://www.jsf.mil/NSFrames.htm
> 
> Send Replies To: m   o   d   c @ a   m   o   g
>                     c   n   i       c   .   r
> 
>      "Face it ladies, its not the dress that makes you look fat.
>      Its the FAT that makes you look fat."
> 
>          --  Al Bundy
> 
> ======================================================================



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

* Re: Keyboard Polling Solution
  2004-02-20 21:38 ` Warren W. Gay VE3WWG
@ 2004-02-22 21:30   ` Bruce or Tracy Jacobs
  0 siblings, 0 replies; 14+ messages in thread
From: Bruce or Tracy Jacobs @ 2004-02-22 21:30 UTC (permalink / raw)


Lots of good info and advice from everyone - thanks for the response.  

I had a similar experience with output to a printer once.  One of the
patterns I was sending to the bit-mapping in the printer just happened
to be a CTL-D or something very similar which had a pre-defined meaning
to the printer.  Had to explicitly check for that joker everytime from
then on.  That does get to be a pain from time to time, and it isn't
exactly intuitive to debug.  


"Warren W. Gay VE3WWG" wrote:
> 
> Me wrote:
> 
> > Yes, "Get_Immediate" seems to do the trick.  Thanks for the tip.
> >
> > Test Example :
> ...
> 
> One annoying thing about it however is that for w2k use,
> Control-D causes "End_of_File" to occur, whether or not
> it was the first character entered on a line or not.
> 
> Under *NIX/*BSD, the end of file character is only special
> at the start of the line (or not active at all). This
> means that Get_Immediate cannot return ^D when you want
> it to :<  AFAIK, under w2k.  Note however, that ^Z _is_
> readable, which usually causes EOF to windoze/DOS progs.
> 
> --
> Warren W. Gay VE3WWG
> http://ve3wwg.tk



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

* Re: Keyboard Polling Solution
  2004-02-22 21:26         ` Bruce or Tracy Jacobs
@ 2004-02-23 10:40           ` Preben Randhol
  2004-02-25  0:44             ` Bruce or Tracy Jacobs
  0 siblings, 1 reply; 14+ messages in thread
From: Preben Randhol @ 2004-02-23 10:40 UTC (permalink / raw)


On 2004-02-22, Bruce or Tracy Jacobs <bljacobs2@mchsi.com> wrote:
> I am playing with an Ada OpenGL graphics program that allows the user to 
> manipulate output graphics (zoom in, out, move around, etc) but I 
> didn't want the entire program to stop and wait for input because it
> needs to stay busy doing things.  

Don't the GUI have rutines for getting the keys you press? I don't know
what you use though.

-- 
"Saving keystrokes is the job of the text editor, not the programming
 language."



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

* Re: Keyboard Polling Solution
  2004-02-23 10:40           ` Preben Randhol
@ 2004-02-25  0:44             ` Bruce or Tracy Jacobs
  2004-02-25  2:05               ` Chad R. Meiners
  0 siblings, 1 reply; 14+ messages in thread
From: Bruce or Tracy Jacobs @ 2004-02-25  0:44 UTC (permalink / raw)


I am using GLUT (Ada - to - OpenGL) Interface.  Not sure whether it has
such 
or not.  I think that version of Get_Immediate will get the job done. 
The
test case worked so well that I am anxious to get it implemented into
the
package and see what happens.  

Thanks.  

Bruce 

Preben Randhol wrote:
> 
> On 2004-02-22, Bruce or Tracy Jacobs <bljacobs2@mchsi.com> wrote:
> > I am playing with an Ada OpenGL graphics program that allows the user to
> > manipulate output graphics (zoom in, out, move around, etc) but I
> > didn't want the entire program to stop and wait for input because it
> > needs to stay busy doing things.
> 
> Don't the GUI have rutines for getting the keys you press? I don't know
> what you use though.
> 
> --
> "Saving keystrokes is the job of the text editor, not the programming
>  language."



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

* Re: Keyboard Polling Solution
  2004-02-25  0:44             ` Bruce or Tracy Jacobs
@ 2004-02-25  2:05               ` Chad R. Meiners
  2004-03-03 16:20                 ` Me
  0 siblings, 1 reply; 14+ messages in thread
From: Chad R. Meiners @ 2004-02-25  2:05 UTC (permalink / raw)


For keyboard events in GLUT, GLUT provide a keyboard event function handler
http://www.opengl.org/documentation/specs/glut/spec3/node49.html#SECTION00084000000000000000

-CRM

"Bruce or Tracy Jacobs" <bljacobs2@mchsi.com> wrote in message
news:403BF0A5.5676A1E5@mchsi.com...
> I am using GLUT (Ada - to - OpenGL) Interface.  Not sure whether it has
> such
> or not.  I think that version of Get_Immediate will get the job done.
> The
> test case worked so well that I am anxious to get it implemented into
> the
> package and see what happens.
>
> Thanks.
>
> Bruce
>
> Preben Randhol wrote:
> >
> > On 2004-02-22, Bruce or Tracy Jacobs <bljacobs2@mchsi.com> wrote:
> > > I am playing with an Ada OpenGL graphics program that allows the user
to
> > > manipulate output graphics (zoom in, out, move around, etc) but I
> > > didn't want the entire program to stop and wait for input because it
> > > needs to stay busy doing things.
> >
> > Don't the GUI have rutines for getting the keys you press? I don't know
> > what you use though.
> >
> > --
> > "Saving keystrokes is the job of the text editor, not the programming
> >  language."





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

* Re: Keyboard Polling Solution
  2004-02-25  2:05               ` Chad R. Meiners
@ 2004-03-03 16:20                 ` Me
  0 siblings, 0 replies; 14+ messages in thread
From: Me @ 2004-03-03 16:20 UTC (permalink / raw)


Thanks.

"Chad R. Meiners" wrote:

> For keyboard events in GLUT, GLUT provide a keyboard event function handler
> http://www.opengl.org/documentation/specs/glut/spec3/node49.html#SECTION00084000000000000000
>
> -CRM
>
> "Bruce or Tracy Jacobs" <bljacobs2@mchsi.com> wrote in message
> news:403BF0A5.5676A1E5@mchsi.com...
> > I am using GLUT (Ada - to - OpenGL) Interface.  Not sure whether it has
> > such
> > or not.  I think that version of Get_Immediate will get the job done.
> > The
> > test case worked so well that I am anxious to get it implemented into
> > the
> > package and see what happens.
> >
> > Thanks.
> >
> > Bruce
> >
> > Preben Randhol wrote:
> > >
> > > On 2004-02-22, Bruce or Tracy Jacobs <bljacobs2@mchsi.com> wrote:
> > > > I am playing with an Ada OpenGL graphics program that allows the user
> to
> > > > manipulate output graphics (zoom in, out, move around, etc) but I
> > > > didn't want the entire program to stop and wait for input because it
> > > > needs to stay busy doing things.
> > >
> > > Don't the GUI have rutines for getting the keys you press? I don't know
> > > what you use though.
> > >
> > > --
> > > "Saving keystrokes is the job of the text editor, not the programming
> > >  language."




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

end of thread, other threads:[~2004-03-03 16:20 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-02-18 21:37 Keyboard Polling Solution Me
2004-02-18 23:10 ` Preben Randhol
2004-02-19  0:30   ` Bruce or Tracy Jacobs
2004-02-19 11:47   ` Marin David Condic
2004-02-19 22:57     ` Bruce or Tracy Jacobs
2004-02-20 12:15       ` Marin David Condic
2004-02-20 20:59         ` Chad R. Meiners
2004-02-22 21:26         ` Bruce or Tracy Jacobs
2004-02-23 10:40           ` Preben Randhol
2004-02-25  0:44             ` Bruce or Tracy Jacobs
2004-02-25  2:05               ` Chad R. Meiners
2004-03-03 16:20                 ` Me
2004-02-20 21:38 ` Warren W. Gay VE3WWG
2004-02-22 21:30   ` Bruce or Tracy Jacobs

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