Steve Loughran wrote:
> I have seen several programs that have installed some
> kind of "hotkey" event handler that the controlling program
> is sent when triggered, even if the window is minimized,
> or in the system tray, or does not currently have
> keyboard/system focus. All the keyboard related items I can
> find in the Win32::GUI docs only appear to work when the
> program's window is active. How have these other programs
> done this? Just a pointer to the correct call would would
> be enough to keep me quiet for another week.. honest :)
I stumbled across this today. See the MSDN documentation for
WM_SETHOTKEY and (if you want to do something other than activate the
window) RegisterHotKey() - Hook()ing the WM_HOTKEY message. Note the
comment in the code below about setting the modifiers.
Regards,
Rob.
#!perl -w
use strict;
use warnings;
use Win32::GUI 1.03_04, qw( WM_SETHOTKEY VK_A );
sub HOTKEYF_SHIFT() {0x01}
sub HOTKEYF_CONTROL() {0x02}
sub HOTKEYF_ALT() {0x04}
sub HOTKEYF_EXT() {0x08}
my $mw = Win32::GUI::Window->new(
-size => [400,300],
);
# $key: any virtual key except Esc, TAB, SPACE and a few others.
my $key = VK_A;
# $modifier: any combination of the HOTKEYF_* constants (or 0 for no
modifier)
my $modifier = HOTKEYF_CONTROL;
# Watch out. Despite what the MS documentation says the modifier
# goes in the upper byte of a short, not the upper WORD of a
# DWORD. I.e. the left shift is 8 bits, not 16 bits
my $wParam = ($modifier << 8) + $key;
# Run this script and minimise the window. Ctrl-A will restore the
# window and make it the foreground window
my $ret = $mw->SendMessage(WM_SETHOTKEY, $wParam, 0);
print "$ret \n";
$mw->Show();
Win32::GUI::Dialog();
__END__