开发者

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' }
);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜