On Jan 2, 2011, at 7:45 PM, Pawel Krol wrote: > Hello! > > This is my first message to this mailing list, so I would like to say "hi!" > to everyone. >
Welcome! > I am writing this e-mail, seeking for help from more experienced wxPerl > users. A problem I am dealing with is that I cannot get any key pressed > information while my program is running. It works fine for mouse events for > example, I have no luck with keyboard events however. > > Here is a simple example that best describes the issue I am dealing with: > > -------------------------------------------------- > > #!/usr/bin/perl > > my $myApp = MyApp->new(); > $myApp->MainLoop; > > package MyApp; > > use base qw(Wx::App); > use Wx; > use Wx::Event qw(EVT_LEFT_DOWN EVT_KEY_DOWN); > > sub OnInit { > my $frame = Wx::Frame->new(undef, -1, 'TEST'); > $frame->Show(); > EVT_LEFT_DOWN($frame, \&mouse); > EVT_KEY_DOWN($frame, \&keyboard); > return 1; > } > > sub mouse { > print "Success! Left mouse button pressed!\n" > } > > sub keyboard { > print "Failure! Why cannot ever get here?\n" > } > > 1; > > -------------------------------------------------- > > No matter what key I press on the keyboard, text from "keyboard" subroutine > never appears in the console output. If you could somehow direct me how to > get this to work, I would be very grateful. > > Thanks for help! > > Best regards, > Pawel Krol. > What platform and versions are you using? Your snippet works fine on my Mac OsX (10.6.5): perl : v5.8.9 built for darwin-2level wxPerl : 0.93 wxWidgets : wxWidgets 2.8.10 Not the latest & greatest but unless there's a bug in the version you're using I don't see why it won't work. Did you try EVT_CHAR or EVT_KEY_UP too? Also note that on most events you might want to call Skip() if you want it to propagate through to the native control(s): sub keyboard { my( $self, $event ) = @_; printf "code: %d\n", $event->GetKeyCode; $event->Skip(); } Cheers, Huub