From: Nat Pryce Date: 2001-08-07T19:36:07+09:00 Subject: [ruby-talk:19278] Re: Ruby/Tk: how to discard excess messages Ignore any other presses and scroll the window with a timer callback. E.g. rough pseudocode: @key_pressed = Hash.new; key_pressed.default = false @scroll_timers = Hash.new # timers indexed by key def on_key_press( key ) if not @key_pressed[key] @key_pressed[key] = true start_scroll( key ) end end def on_key_release( key ) @key_pressed[key] = false if @scroll_timers.has_key? key cancel_timer @scroll_timers[key] end end def start_scroll( key ) do_scroll( key ) @scroll_timers[key] = after( 0.25, proc {continue_scroll( key ) } ) end def continue_scroll( key ) if @key_pressed[key] do_scroll( key ) @scroll_timers[key] = after( 0.25, proc { continue_scroll( key ) } ) else @scroll_timers.delete( key ) end end ----- Original Message ----- From: "Albert Wagner" To: "ruby-talk ML" 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. > > On Monday 06 August 2001 16:41, you wrote: > > From: "Albert L. Wagner" > > > > > 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. >