How to avoid magic Gtk2 accel_key numbers?
I'm want an accelerator for a subroutine in my GTK application, using the Gtk2
bindings for Perl. Gtk2::AccelGroup
->connect()
takes an $accel_key
as argument, which seems to be an int开发者_StackOverfloweger representing a key. Can Gtk2
export constants or a function to use in place of this magic number?
Use Gtk2::Accelerator->parse():
use Gtk2;
my ( $key, $mods ) = Gtk2::Accelerator->parse( '<control><alt>a' );
# $key is 97
# $mods is '[ control-mask mod1-mask ]'
my $ag = Gtk2::AccelGroup->new();
$ag->connect(
Gtk2::Accelerator->parse( '<control><alt><a>' ),
[qw/visible/], sub { say 'hi' }
);
精彩评论