John,
It is possible to capture keyboard input by using the -onKeyDown or -onKeyUp
events. Here is an example:
my $winMain = Win32::GUI::Window->new(
-name => 'winMain',
-text => 'Keyboard Capture',
-size => [320,240],
-onKeyDown => sub {
my($self, $flags, $key) = @_;
#do processing here
return 1;
},
);
__END__
The $key param contains the virtual key code, and the $flags param contains
flags for the event, such as repeat count. See the Microsoft SDK docs for more
information.
One problem is that the window will only report key press events when it has
focus. This means that if any of the controls in the window have focus, the
keypress events won't trigger. An alternative is to use one of the
GetAsyncKeyState / GetKeyboardState / GetKeyState methods instead to poll the
keyboard when you need input, such as every timer event.
Hope this helps,
Kevin.
> From: j...@johnwhitney.com
> To: perl-win32-gui-users@lists.sourceforge.net
> Date: Sun, 11 Oct 2009 23:25:52 -0700
> Subject: [perl-win32-gui-users] How to capture keyboard key presses
>
> Hello,
>
> I have a timer application that uses Win32::GUI, version 1.06, and all works
> quite nicely.
>
> I would like add a capability so that my $window_main can capture keyboard
> events when certain keys are pressed, for example space bar (\x20), esc
> (\x1b) if possible, enter (\x0d), or one of the keyboard function keys (F1 -
> F12). Users want to be able to start and stop my timer using the space bar
> for example. Is this possible? My $window_main has no input text fields,
> just images and Hyperlinks.
>
> John
> j...@johnwhitney.com
> 801 815 9265
>
>
> ------------------------------------------------------------------------------
> Come build with us! The BlackBerry(R) Developer Conference in SF, CA
> is the only developer event you need to attend this year. Jumpstart your
> developing skills, take BlackBerry mobile applications to market and stay
> ahead of the curve. Join us from November 9 - 12, 2009. Register now!
> http://p.sf.net/sfu/devconference
> _______________________________________________
> Perl-Win32-GUI-Users mailing list
> Perl-Win32-GUI-Users@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/perl-win32-gui-users
> http://perl-win32-gui.sourceforge.net/
_________________________________________________________________
Use Messenger in your Hotmail inbox Find out how here
http://windowslive.ninemsn.com.au/article.aspx?id=823454
------------------------------------------------------------------------------
Come build with us! The BlackBerry(R) Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay
ahead of the curve. Join us from November 9 - 12, 2009. Register now!
http://p.sf.net/sfu/devconference
_______________________________________________
Perl-Win32-GUI-Users mailing list
Perl-Win32-GUI-Users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/perl-win32-gui-users
http://perl-win32-gui.sourceforge.net/