| Gtk2-Ex-WidgetBits documentation | view source | Contained in the Gtk2-Ex-WidgetBits distribution. |
Gtk2::Ex::KeySnooper -- keyboard snooper as object
use Gtk2::Ex::KeySnooper; my $snooper = Gtk2::Ex::KeySnooper->new (\&myfunc, $mydata); # myfunc disconnected when object destroyed $snooper = undef;
A Gtk2::Ex::KeySnooper object installs a given function as a key snooper
in the Gtk main loop and when the KeySnooper object is destroyed it removes
that function. The idea is that it can be easier to manage the lifespan of
an object than to keep an integer ID safe somewhere and remember
Gtk2->key_snooper_remove at the right places.
$ks = Gtk2::Ex::KeySnooper->new ($func)$ks = Gtk2::Ex::KeySnooper->new ($func, $userdata)Create and return a KeySnooper object calling the given $func. The calls
made are the same as Gtk2->key_snooper_install, ie.
$stop = &$func ($widget,$event,$userdata)
where $func should return true if it wants to stop event processing,
ie. to consume the event, or false to let it propagate to other handlers
(the same as event signal handler returns, and you can use
Gtk2::EVENT_STOP and Gtk2::EVENT_PROPAGATE in Gtk2-Perl 1.220 and up).
For example,
my $snooper = Gtk2::Ex::KeySnooper->new (\&myfunc, $mydata);
sub myfunc {
my ($widget, $event, $userdata) = @_;
if ($event->type eq 'key-press') {
if ($event->keyval == MY_DESIRED_KEYVAL) {
do_something();
return 1; # don't propagate event further
}
} else {
# key release
...
}
return 0; # propagate event
}
$snooper->remove()Remove the snooper function, if not already removed. This is done
automatically when $snooper is destroyed, but you can do it explicitly
sooner if desired.
Gtk2::Widget, Gtk2::Ex::WidgetBits, Glib::Ex::SignalIds
Copyright 2008, 2009, 2010, 2011 Kevin Ryde
Gtk2-Ex-WidgetBits is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3, or (at your option) any later version.
Gtk2-Ex-WidgetBits is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with Gtk2-Ex-WidgetBits. If not, see http://www.gnu.org/licenses/.
| Gtk2-Ex-WidgetBits documentation | view source | Contained in the Gtk2-Ex-WidgetBits distribution. |