i want gui react on single key strokes.
this works fine -keydown option long windows object has focus.
to feedback keystrokes without focus want use win32::gui::acceleratortable.
in docs took code snippets can see in code. i'm confused syntax use. once docs win32::gui::accelerator , in others there mentioned win32::acceleratortable (even though there no such package on cpan). same options -accel, -accelerators , -acceleratortable.
how has code feedback keycode of keystroke?
here (not working) code:
use strict; use warnings; use win32::gui(); # define main window $window = win32::gui::window->new( -name => 'mainwindow', -width => 250, -height => 200, -text => 'keys', -accel => win32::gui::acceleratortable, # ???? # or -accelerator, or -acceleratortable # ???? ); $window->addlabel( -name => 'lblstatus', -top => 5, -left => 5, -text => "pressed key", ); # text field give feedback key press $window->addtextfield( -name => 'txtstatus', -width => 80, -height => 20, -top => 20, -left => 5, -tip => "displays value of key", ); # took cpan win32::gui::acceleratortable should @ least print # "hello" on console if 1 presses lowercase letter "b" on keyboard $a = win32::gui::acceleratortable->new( "ctrl-x" => "close", "shift-n" => "new", "ctrl-alt-del" => "reboot", "b" => sub { print "hello\n"; }, ); # display app $window->show(); # start of event handler win32::gui::dialog(); exit (0);
i changed code according ikegami's hint solved problem. thank ikegami!
# first initialize acceleratortable... $a = new win32::gui::acceleratortable( "ctrl-x" => "close", "shift-n" => "new", "ctrl-alt-del" => "reboot", "b" => sub { print "hello\n"; }, ); # ...and define main window using -accel option $window = win32::gui::window->new( -name => 'mainwindow', -width => 250, -height => 200, -text => 'keys', -accel => $a, );
...and voilĂ - works :-)
Comments
Post a Comment