Hi, I wanted to modify the response of my program based upon keyboard entry. Thus I would like the key_press_event to capture which key was entered.
Now I saw some of the example code in the examples section, such as histogram.pl do not set up a key-press-mask. 1. Is that event automatic for a Gtk2::DrawingArea, and only needed for a Gtk2::Window? (also I notice that Gtk2::DrawingArea isn't in object-browser) 2. I tried the following code in my application and I got no output. :( $drawing_area->set_events ([qw/exposure-mask leave-notify-mask button-press-mask pointer-motion-mask key-press-mask pointer-motion-hint-mask/]); $drawing_area->signal_connect (key_press_event => \&key_press_event); sub key_press_event { my $widget=shift ; my $event=shift; print "we got called \n"; my $keyval= $event->keyval; if ($keyval == $Gtk2::Gdk::KeySyms{Up}) { print "we got an up arrow yay!!! \n"; } } and nothing happened with any key press events :(. Here is a simple example: ----------drawingarea.pl-------------- #!/usr/bin/perl -w use strict; use Gtk2 '-init'; my $window = Gtk2::Window->new ('toplevel'); my $button= Gtk2::VBox->new; my $draw = Gtk2::DrawingArea->new; $draw->add_events ([qw/exposure-mask leave-notify-mask button-press-mask pointer-motion-mask pointer-motion-hint-mask key-press-mask /]); $draw->signal_connect (motion_notify_event => \&motion_notify_event); $draw->signal_connect (key_press_event => \&key_press_event); sub key_press_event { my $widget=shift ; my $event=shift; print "we got called \n"; my $keyval= $event->keyval; if ($keyval == $Gtk2::Gdk::KeySyms{Up}) { print "we got an up arrow yay!!! \n"; } } sub motion_notify_event { my $widget=shift; my $event=shift; my ($x, $y, $state); if ($event->is_hint) { (undef, $x, $y, $state) = $event->window->get_pointer; } else { $x = $event->x; $y = $event->y; $state = $event->state; } if ($state >= "button1-mask" ) { print "value of x and y and button1 are $x and $y \n" ; } if ($state >= "button2-mask" ) { print "value of x and y and button2 are $x and $y \n" ; } return 1; #was TRUE in source (was scribble.pl) } $button->add($draw); $window->add($button); $window->signal_connect (delete_event => sub {Gtk2->main_quit; 1}); $window->show_all; Gtk2->main; ----------------- here is output ./toggle2.pl Name "Gtk2::Gdk::KeySyms" used only once: possible typo at ./toggle2.pl line 23. value of x and y and button1 are 85 and 64 value of x and y and button1 are 85 and 65 value of x and y and button1 are 85 and 67 value of x and y and button1 are 85 and 69 value of x and y and button1 are 84 and 71 value of x and y and button1 are 84 and 72 value of x and y and button1 are 84 and 74 value of x and y and button1 are 84 and 76 value of x and y and button1 are 84 and 77 value of x and y and button1 are 84 and 78 value of x and y and button1 are 84 and 80 value of x and y and button1 are 84 and 82 value of x and y and button1 are 84 and 84 value of x and y and button1 are 84 and 8 nothing when i press a key :(. Thank you, Mitchell Laks _______________________________________________ gtk-perl-list mailing list gtk-perl-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-perl-list