Re: Gtk3::Gdk::EventKey mappings
- From: Terence Ferraro <terencejferraro gmail com>
- To: Daniel Kasak <d j kasak dk gmail com>
- Cc: gtk-perl mailing list <gtk-perl-list gnome org>
- Subject: Re: Gtk3::Gdk::EventKey mappings
- Date: Tue, 3 Mar 2015 03:14:56 -0500
I previously used the global snooper in Gtk2, but due to removed functionality, I added some code myself into Gtk3.pm to essentially provide the same functionality.
It looks like I locally define near the beginning of Gtk3.pm:
my $key_snooper_subroutine;
With a subroutine further below:
sub Gtk3::key_snooper_install
{
my ($gtk,$sub) = @_;
$key_snooper_subroutine = $sub;
}
Then I call in the application initialization directly: Gtk3->key_snooper_install(\&key_hook);
I've also got a modified Gtk3::Window::new function that includes:
if(defined($key_snooper_subroutine)) { $window->signal_connect(key_press_event => $key_snooper_subroutine); }
Among other things that are processed within the sub, I also save the last key data, for processing of delayed or redirected events, etc:
sub key_hook
{
my ($widget,$event,$data) = @_;
# ...stuff...
$main::global_last_key_state = $state;
$main::global_last_key_keyval = $event->keyval;
$main::global_last_key_type = $event->type;
}
In any case, one of the things I think you're looking for is the state mask, e.g. I check for: if($state =~ /shift-mask/) { ... }
And I think your L key should just be: Gtk3::Gdk::KEY_L or Gtk3::Gdk::KEY_l
Here's a snippet I use to ensure a given field can only accept numbers and decimals:
if($event->keyval != Gtk3::Gdk::KEY_BackSpace && $event->keyval != Gtk3::Gdk::KEY_0 && $event->keyval != Gtk3::Gdk::KEY_1 && $event->keyval != Gtk3::Gdk::KEY_2 && $event->keyval != Gtk3::Gdk::KEY_3 && $event->keyval != Gtk3::Gdk::KEY_4 && $event->keyval != Gtk3::Gdk::KEY_5 && $event->keyval != Gtk3::Gdk::KEY_6 && $event->keyval != Gtk3::Gdk::KEY_7 && $event->keyval != Gtk3::Gdk::KEY_8 && $event->keyval != Gtk3::Gdk::KEY_9 && $event->keyval != Gtk3::Gdk::KEY_Tab && $event->keyval != Gtk3::Gdk::KEY_Left && $event->keyval != Gtk3::Gdk::KEY_Right && $event->keyval != Gtk3::Gdk::KEY_period && $event->keyval != Gtk3::Gdk::KEY_KP_0 && $event->keyval != Gtk3::Gdk::KEY_KP_1 && $event->keyval != Gtk3::Gdk::KEY_KP_2 && $event->keyval != Gtk3::Gdk::KEY_KP_3 && $event->keyval != Gtk3::Gdk::KEY_KP_4 && $event->keyval != Gtk3::Gdk::KEY_KP_5 && $event->keyval != Gtk3::Gdk::KEY_KP_6 && $event->keyval != Gtk3::Gdk::KEY_KP_7 && $event->keyval != Gtk3::Gdk::KEY_KP_8 && $event->keyval != Gtk3::Gdk::KEY_KP_9) { return(1); }
Hope this helps!
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]