Gtk2::Ex::KeySnooper -- keyboard snooper as object
use Gtk2::Ex::KeySnooper; my $snooper = Gtk2::Ex::KeySnooper->new (\&myfunc, $mydata); # calls &myfunc($widget,$event,$mydata) as usual # 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. 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.
Gtk2::Ex::KeySnooper
Gtk2->key_snooper_remove
$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.
$func
Gtk2->key_snooper_install
$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,
Gtk2::EVENT_STOP
Gtk2::EVENT_PROPAGATE
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.
$snooper
Gtk2::Widget, Gtk2::Ex::WidgetBits, Glib::Ex::SignalIds
http://user42.tuxfamily.org/gtk2-ex-widgetbits/index.html
Copyright 2008, 2009, 2010, 2011, 2012 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/.
To install Gtk2::Ex::WidgetBits, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Gtk2::Ex::WidgetBits
CPAN shell
perl -MCPAN -e shell install Gtk2::Ex::WidgetBits
For more information on module installation, please visit the detailed CPAN module installation guide.