Ruby/Tk: how to discard excess messages 
Author Message
 Ruby/Tk: how to discard excess messages

An auto-repeat key is sending additional messages while method is
still processing first message.  How can I discard the excess
messages?

--
"It requires wisdom to understand wisdom:
 the music is nothing if the audience is deaf."
 - Walter Lippman



Sat, 24 Jan 2004 03:52:38 GMT  
 Ruby/Tk: how to discard excess messages

Quote:
> An auto-repeat key is sending additional messages while method is
> still processing first message.  How can I discard the excess
> messages?

This does not work:

   def do_it(widget)
       widget.bind("Any-Key") {}
       really_do_it()
       widget.bind("Any-Key") { do_it(widget) }
   end
   widget.bind("Any-Key") { do_it(widget) }

Because of the single thread queueing the events
until after do_it() returns :(

Perhaps you could look at the event timestamp?


|  Don't split your mentality without thinking twice       |
|                          Proud like a God -- Guano Apes  |
+--- M38c ------- http://members.chello.nl/~k.vangelder ---+



Sat, 24 Jan 2004 05:27:03 GMT  
 Ruby/Tk: how to discard excess messages

Quote:
> An auto-repeat key is sending additional messages while method is
> still processing first message.  How can I discard the excess
> messages?

Once you have received a KeyPressed event for a particular key, ignore
further KeyPressed events for the same key until you receive a KeyReleased
event for that key.  An auto-repeating key sends multiple KeyPressed events
without any KeyReleased events until the user actually releases the key.


Sat, 24 Jan 2004 05:41:25 GMT  
 Ruby/Tk: how to discard excess messages
You're right, Kero.  I tried that:  it doesn't work.


Quote:
> > An auto-repeat key is sending additional messages while method is
> > still processing first message.  How can I discard the excess
> > messages?

> This does not work:

>    def do_it(widget)
>        widget.bind("Any-Key") {}
>        really_do_it()
>        widget.bind("Any-Key") { do_it(widget) }
>    end
>    widget.bind("Any-Key") { do_it(widget) }

> Because of the single thread queueing the events
> until after do_it() returns :(

> Perhaps you could look at the event timestamp?


> |  Don't split your mentality without thinking twice       |
> |                          Proud like a God -- Guano Apes  |

> +--- M38c ------- http://members.chello.nl/~k.vangelder ---+



Sat, 24 Jan 2004 09:00:21 GMT  
 Ruby/Tk: how to discard excess messages
Thanks, Nat.  That's useful to know.  I didn't realise that no releases were
being sent.  However, I still have a problem:  I am using the up/down arrow
keys to scroll.  I want to be able to hold the key down; I just don't want
presses any faster than I can redraw the  window.


Quote:

> > An auto-repeat key is sending additional messages while method is
> > still processing first message.  How can I discard the excess
> > messages?

> Once you have received a KeyPressed event for a particular key, ignore
> further KeyPressed events for the same key until you receive a KeyReleased
> event for that key.  An auto-repeating key sends multiple KeyPressed events
> without any KeyReleased events until the user actually releases the key.



Sat, 24 Jan 2004 09:06:14 GMT  
 Ruby/Tk: how to discard excess messages
Hi, Nat.
Just checked on my linux box and I get a keypressed/keyrelease combo sent
continuously while the key is depressed.  Perhaps you are on Windows?  If so,
then we have discovered yet another reason why Ruby/Tk scripts aren't
portable.
Quote:

> Once you have received a KeyPressed event for a particular key, ignore
> further KeyPressed events for the same key until you receive a KeyReleased
> event for that key.  An auto-repeating key sends multiple KeyPressed events
> without any KeyReleased events until the user actually releases the key.



Sat, 24 Jan 2004 10:09:02 GMT  
 Ruby/Tk: how to discard excess messages
Ignore any other presses and scroll the window with a timer callback.

E.g. rough pseudocode:

def on_key_press( key )


        start_scroll( key )
    end
end

def on_key_release( key )



    end
end

def start_scroll( key )
    do_scroll( key )

end

def continue_scroll( key )

        do_scroll( key )

    else

    end
end

Quote:
----- Original Message -----


Sent: Tuesday, August 07, 2001 2:06 AM
Subject: [ruby-talk:19266] Re: Ruby/Tk: how to discard excess messages

> Thanks, Nat.  That's useful to know.  I didn't realise that no releases
were
> being sent.  However, I still have a problem:  I am using the up/down
arrow
> keys to scroll.  I want to be able to hold the key down; I just don't want
> presses any faster than I can redraw the  window.



> > > An auto-repeat key is sending additional messages while method is
> > > still processing first message.  How can I discard the excess
> > > messages?

> > Once you have received a KeyPressed event for a particular key, ignore
> > further KeyPressed events for the same key until you receive a
KeyReleased
> > event for that key.  An auto-repeating key sends multiple KeyPressed
events
> > without any KeyReleased events until the user actually releases the key.



Sat, 24 Jan 2004 18:36:07 GMT  
 
 [ 7 post ] 

 Relevant Pages 

1. test message please discard

2. interactive ruby/tk app (was: ruby/tk internals)

3. Ruby/Tk - never did Tcl/Tk or Perl/Tk

4. Ruby: Ruby/Tk widget demo

5. Ruby/Tk update (for Ruby 1.8.x)

6. Tk under Ruby [newbie to ruby]

7. Tk message box without tk main window?

8. Q.Message box in Ruby-FXRuby

9. Ruby on Apple Newton Message Pad?

10. ruby-talk reaches message 60000

11. gtk-ruby error messages/ feature request

12. ruby-talk message 40K

 

 
Powered by phpBB® Forum Software