Re: DEL as an accelerator




On Jun 12, 2006, at 7:44 AM, Beast wrote:

Hi,

How do I use  "DEL" and "ENTER" as an accelerator key?

Presently I use:
...
_Delete  => { accelerator => 'Del'},

...

But its not works, whilst using 'F8' is fine.


Try using "Delete" instead of "Del".

The "Enter" keys are actually "Return" and "KP_Enter".

A full listing of the available key code names can be found in Gtk2::Gdk::Keysyms. (e.g. perldoc -m Gtk2::Gdk::Keysyms)

This code shows you the name of the key you pressed, and also hooks up a few accelerators by hand to make sure they work.

--=-=-=-=---
#!/usr/bin/perl -w

use strict;
use Gtk2 -init;
use Gtk2::Gdk::Keysyms;


my $window = Gtk2::Window->new;
$window->signal_connect (destroy => sub { Gtk2->main_quit });
$window->set_default_size (200, 200);

my $label = Gtk2::Label->new;
$window->add ($label);

$window->signal_connect (key_press_event => sub {
        my ($widget, $event) = @_;
        $label->set_text (Gtk2::Gdk->keyval_name ($event->keyval));
        return 0;
});

my $group = Gtk2::AccelGroup->new;

$group->connect ($Gtk2::Gdk::Keysyms{F1}, [], [], \&callback);
#$group->connect ($Gtk2::Gdk::Keysyms{Delete}, [], [], \&callback);
$group->connect (Gtk2::Gdk->keyval_from_name ('Delete'), [], [], \&callback); $group->connect ($Gtk2::Gdk::Keysyms{Delete}, ['control-mask'], [], \&callback);
$group->connect ($Gtk2::Gdk::Keysyms{Return}, [], [], \&callback);
$group->connect ($Gtk2::Gdk::Keysyms{Return}, ['control-mask'], [], \&callback);
$group->connect ($Gtk2::Gdk::Keysyms{KP_Enter}, [], [], \&callback);
$group->connect ($Gtk2::Gdk::Keysyms{KP_Enter}, ['control-mask'], [], \&callback);


$window->add_accel_group ($group);

$window->show_all;
Gtk2->main;

sub callback {
        print "@_\n";
}



--
She's obviously your child. She looks like you, she talks a lot, and most of it is gibberish.
  -- Elysse, to me, of Zella.




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]