Re: Move the focus along ( Tab keypress? )



On Fri, 03 Feb 2006 12:03:50 +1100
Daniel Kasak <dkasak nusconsulting com au> wrote:

Greetings.

I'm trying to trap an Enter keypress and create a Tab keypress ( or 
otherwise move the focus along ).

Try this:
$window->child_focus('tab-forward');


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

my $window = Gtk2::Window->new('toplevel');
$window->signal_connect( 'key_press_event' => \&process_entry_keypress );
$window->signal_connect( 'destroy' => sub { Gtk2->main_quit } );

$window->set_border_width(10);
#->set_size_request(300,200);
$window->set_default_size(300,200);

my $vbox = Gtk2::VBox->new( FALSE, 6 );
$vbox->set_size_request(0,0);

$window->add($vbox);
$vbox->set_border_width(2);

my $hbox= Gtk2::HBox->new( FALSE, 6 );
$vbox->pack_end($hbox,FALSE,FALSE,0);
$hbox->set_border_width(2);

$vbox->pack_end (Gtk2::HSeparator->new, FALSE, FALSE, 0);

my $button = Gtk2::Button->new_from_stock('gtk-quit');
$hbox->pack_end( $button, FALSE, FALSE, 0 );
$button->signal_connect( clicked => sub { Gtk2->main_quit } );

for(1..3){
my $button = Gtk2::Button->new ("Action$_");
$vbox->pack_start($button,0,0,0);
}

$window->show_all();
Gtk2->main;
#####################################
sub process_entry_keypress {
 
    my ( $widget, $event ) = @_;
      if (
        $event->keyval == $Gtk2::Gdk::Keysyms{ Return } ||
        $event->keyval == $Gtk2::Gdk::Keysyms{ KP_Enter }
       ) {
        my $new_event = Gtk2::Gdk::Event::Key->new('key-press');
        $event->keyval($Gtk2::Gdk::Keysyms{'Tab'});
        $window->propagate_key_event($new_event);
        $window->child_focus('tab-forward');
        return TRUE;    #prevents the Exit button from triggering
     }
   
    if ( $event->keyval == $Gtk2::Gdk::Keysyms{ Tab } ){
            print "An Tab key has been pressed!\n";
          }   
    return FALSE;
}
__END__

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



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