Re: Do something clever on a keypress with Gtk2-0.92?
- From: "muppet" <scott asofyet org>
- To: gtk-perl-list gnome org
- Subject: Re: Do something clever on a keypress with Gtk2-0.92?
- Date: Thu, 7 Aug 2003 16:39:38 -0400 (EDT)
Tom Cross said:
Either I want to make an accelgroup without the
menu, or just trap certain key-press events.
I'm lost on how to do either.
disclaimer: i have no experience with creating accel groups. they may be more
appropriate than what i'm about to describe, but this works for me.
connect a callback to either key-press-event or key-release-event, then switch
on the keyval in the event structure you get. return true if you handle it,
otherwise false lets the rest of the processing happen. that sounds pretty
basic, but in general i have had a really hard time catching key events for
specific widgets, probably because the widgets i create do a lot of drawing
and charting and are usually plain DrawingAreas, which by default don't take
key events. so, i tend to have the best results when i hook to the
key-press-event on the *toplevel* *window* containing the widgets i'm using.
others may have the wisdom to correct me.
here's how i would hook up something to stop loading something from a remote
host when you get bored and hit escape (watch out, untested code!):
# there's another module which contains all the keycodes!!!
use Gtk2::Gdk::Keysyms;
$win->signal_connect (key_press_event => sub {
my ($widget, $event) = @_;
return unless $event->keyval ==
$Gdk2::Gdk::Keysyms{Escape};
abort_some_long_running_process ();
return 1;
});
there's also the key snoopers, which i have never used, and which may or may
not be bound to perl. as i understand it, a key snooper is a function you
install to the event loop to filter key events globally, and catch things
application-wide rather than just for one window. this may do what you want.
--
muppet <scott at asofyet dot org>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]