Yo....So i'm still trying to get this hot key thing to work and i've gotten a little farther...maybe. I found the right API calls to hook a windows messages. I'm getting all sorts of messages about a Win32::GUI window I created, keystrokes etc. The problem is the hotkey message still isn't coming through. So i think there is a problem specificaly with either the hWnd returnd by Win32::GUI or the constants I've used, or my understanding of the problem at all. So if any Win32 gurus could lend me an eyeball and maybe a few brain cells i'd appreciate it.
use warnings;
use strict;
use Tk;
use Win32::API;
use Win32::GUI;
use Win32::API::Callback;
use constant WH_MSGFILTER => -1;
use constant WH_JOURNALRECORD => 0;
use constant WH_JOURNALPLAYBACK => 1;
use constant WH_KEYBOARD => 2;
use constant WH_GETMESSAGE => 3;
use constant WH_CALLWNDPROC => 4;
use constant WH_CBT => 5;
use constant WH_SYSMSGFILTER => 6;
use constant WH_MOUSE => 7;
use constant WH_HARDWARE => 8;
use constant WH_DEBUG => 9;
use constant WH_SHELL => 10;
use constant WH_FOREGROUNDIDLE => 11;
use constant WH_CALLWNDPROCRET => 12;
use constant WH_KEYBOARD_LL => 13;
use constant WH_MOUSE_LL => 14;
use constant MOD_CONTROL => 2;
use constant KEY_A => 65;
my $mw_win32 = new Win32::GUI::Window(
-title => 'This is a test!',
-width => 100,
-height => 100,
-name => 'MainWindow');
my $GetCurrentThreadId = new Win32::API('kernel32', 'GetCurrentThrea
+dId', '', 'N');
my $SetWindowsHookEx = new Win32::API('user32' , 'SetWindowsHookE
+x' , 'NKNN', 'N');
my $CallNextHookEx = new Win32::API('user32' , 'CallNextHookEx'
+ , 'PNNN', 'N');
Win32::API->Import('user32', 'BOOL RegisterHotKey(HWND hWnd, int id, U
+INT fsModifiers, UINT vk)')
or die "import RegisterHotKey: $! ($^W)";
sub KeyboardHook($$$) {
my ($nCode, $wParam, $lParam) = @_;
print "nCode=$nCode, wParam=$wParam, lParam=$lParam\n";
$CallNextHookEx->Call(0, $nCode, $wParam, $lParam);
}
# LRESULT CALLBACK CallWndProc(int nCode,WPARAM wParam, LPARAM lParam)
+;
sub WindowProc($$$) {
my ($nCode, $wParam, $lParam) = @_;
print "nCode=$nCode, wParam=$wParam, lParam=$lParam\n";
print "***************" if $wParam == 273;
$CallNextHookEx->Call(0, $nCode, $wParam, $lParam);
}
my $WinProc = new Win32::API::Callback(\&WindowProc , '
+NNN', 'N');
my $KeyboardHookCallback = new Win32::API::Callback(\&KeyboardHook, '
+NNN', 'N');
my $ThreadId = $GetCurrentThreadId->Call() or die;
my $Hook = $SetWindowsHookEx->Call(WH_KEYBOARD , $KeyboardHookC
+allback, 0 , $ThreadId) or die $^E;
my $ProcHook = $SetWindowsHookEx->Call(WH_GETMESSAGE , $WinProc, 0 , $
+ThreadId) or die $^E;
#WH_CALLWNDPROC
print $mw_win32->{-handle};
my $hotkey = RegisterHotKey ($mw_win32->{-handle}, 99, MOD_CONTROL,
+KEY_A) or die $^E;
$mw_win32->Show();
Win32::GUI::Dialog();