Re: key bindings



Quoting Jaap Karssenberg <j g karssenberg student utwente nl>:
I would like to add custom key bindings to a widget, preferably
binding keys directly to perl subroutines. Now I found in the Gtk reference
this page <http://developer.gnome.org/doc/API/2.0/gtk/gtk-Bindings.html>
but this is totally unhelpful due to the lack of
descriptions/explanations.
Could someone show me how to bind a key to a perl sub ?

-- 
   )   (       Jaap Karssenberg || Pardus [Larus]
   :   :       http://pardus-larus.student.utwente.nl/~pardus
 )  \ /  (    
 ",.*'*.,"     Proud owner of "Perl6 Essentials" 1st edition :)
_______________________________________________

The first thing that comes to my mind is:

#!/usr/bin/perl

use Gtk2;
use Gtk2::Gdk::Keysyms;

my $window = Gtk2::Window->new;

$window->signal_connect('key_release_event' => \&keyrelease);
$window->signal_connect('destroy' => sub { Gtk2->main_quit } );

$window->show;

Gtk2->main;

sub keyrelease {
    my ($widget, $event) = @_;
    if ($event->keyval == $Gtk2::Gdk::Keysyms{q}) {
        Gtk2->main_quit;
    } else {
        print "key was ", chr($event->keyval), "\n";
    }
}



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