Re: Gtk2::Entry catching a keypress?



On Wed, 30 Jul 2008 09:58:23 -0400
Dominik <theoniq gmail com> wrote:

Hi,

I did some searching for about an hour and couldn't find what I was looking
for.  I was wondering if there is a signal to catch a Gtk2::Entry keypress
(for instance, the up arrow on the keyboard).  Or if there is a way to work
around the lack of one.

#! /usr/bin/perl -w
use strict;
use Gtk2::Gdk::Keysyms;
use Glib qw/TRUE FALSE/;
use Gtk2 -init;

my $window = Gtk2::Window->new;
$window->signal_connect (delete_event => sub { Gtk2->main_quit });
my $vbox = new Gtk2::VBox( FALSE, 0 );
my $entry = Gtk2::Entry->new();

$vbox->pack_start( $entry, FALSE, FALSE, FALSE );
$vbox->set_focus_child ($entry); # works
$window->add ($vbox);

$entry->signal_connect ('key-press-event' => sub {
         my ($widget,$event)= @_;
         print  $event->keyval(),"\n";

        #let the event propagate, so entry will still work
        return FALSE;

   });

$window->show_all;

Gtk2->main;

__END__


zentara

-- 
I'm not really a human, but I play one on earth.
http://zentara.net/Remember_How_Lucky_You_Are.html 



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