in reply to Re^2: Problem with multiple windows and drop down menus
in thread Problem with multiple windows and drop down menus
To demonstrate the problem, look at the following and google for "perl tk grabGlobal". You can do mouse grabs, keyboard grabs, or global grabs. Your focus cannot shift until the grab is released.
There may be a clever trick to override it, but I don't know it offhand.
I would try something like $top->bind( '<Leave>',sub { $top->grabRelease } );
#!/usr/bin/perl use warnings; use strict; use Tk; my $mw = MainWindow->new; # the window must be mapped for a global grab # so make a 1 pixel window in lower right corner # for invisible grabs $mw->geometry('200x200+50+50'); $mw->overrideredirect(1); $mw->bind("<Key>", [ \&process_key_press , Ev('K') ] ); $mw->bind("<KeyRelease>", [ \&process_key_release , Ev('K') ] ); $mw->Label(-text=>"Press escape to exit")->pack(); $mw->after(100,sub{$mw->grabGlobal;}); $mw->focusForce; MainLoop; sub process_key_press{ my ($caller, $key) = @_; print "Press $key\n"; if ($key eq 'Escape'){exit} } sub process_key_release{ my ($caller, $key) = @_; print "Release $key\n"; }
|
|---|