in reply to Tk bind KeyPress KeyRelease Problem

Hi again, I think I have something that works. I couldn't give up on this, because something in my subconcious mind told me it had to be possible. It was just a question of "pulling it out" with all it's multiple feedback complexities. So the code below does it with a counter and 2 timers. The first timer will set and reset itself as the key auto repeats, and it will reset the counter to 0 after 300 ms. If the key is held down, the counter should never hit 0. The second timer, waits for the counter to hit 0, and will call the stop function, and reset the bindings. I have it setup with 300 and 400 milliseconds, and that seems to work on my machine. If you go too low, like to 50 and 100 ms, you will get a single repeat sneaking thru, before the counter can setup. So this timer has to be set higher than the repeat rate on your machine. I'm sure this code can be refined, but it's good enough for a "proof of concept".
#!/usr/bin/perl use warnings; use strict; use Tk; my $counter = 0; my $timer; my $timer1; my $timerrunning = 0; my $mw = MainWindow->new; $mw->geometry('+250+250'); $mw->bind("<Key>", sub { &pressed } ); $mw->bind("<KeyRelease>", sub { } ); MainLoop; #----------------------------------- sub pressed{ my($widget) = @_; my $e = $widget->XEvent; # get reference to X11 event structure if($timerrunning == 1){ $timer->cancel; &start_timer} else{&start_timer} $counter++; print "$counter\n"; &do_function( $e->K.'-pressed' ); } #----------------------------------- sub start_timer{ $timerrunning = 1; $counter++; $timer = $mw->after(300, sub{$counter = 0; $timerrunning = 0; &start_timer1; $timer->cancel; }); } #------------------------------------- sub start_timer1{ $timer1 = $mw->after(400, sub { if($counter == 0){&stop_function} }); } #-------------------------------------- sub do_function{ my $key = shift; print "$key\n"; } #---------------------------------------- sub stop_function{ print "Stopping\n"; $mw->bind("<Key>", sub { &pressed } ); $timerrunning = 0; $counter = 0; } #----------------------------------------

I'm not really a human, but I play one on earth. flash japh