in reply to Re^3: Windows Hotkey
in thread Windows Hotkey
"Doesn't work to set a non-local hook without a modulereferense (handle) at globalKeysWin32.pl line 79, <DATA> line 164."#!/usr/bin/env perl use Data::Dumper; use strict; use warnings; #use diagnostics; use Win32::API; use Win32::API::Callback; sub FILE_FLAG_BACKUP_SEMANTICS { 0x02000000 } sub WH_KEYBOARD { 2 } sub WH_KEYBOARD_LL { 13 } sub DWORD_SIZE { 4 } #my $kernel32 = 'kernel32.dll'; #my $advapi32 = 'advapi32.dll'; # HHOOK SetWindowsHookEx( # # int idHook, # HOOKPROC lpfn, # HINSTANCE hMod, # DWORD dwThreadId # ); # lpfn # [in] Pointer to the hook procedure. If the dwThreadId parameter +is zero or specifies # the identifier of a thread created by a different process, +the lpfn parameter must point # to a hook procedure in a dynamic-link library (DLL). Otherw +ise, lpfn can point to a hook # procedure in the code associated with the current process. # hMod # [in] Handle to the DLL containing the hook procedure pointed to +by the lpfn parameter. # The hMod parameter must be set to NULL if the dwThreadId pa +rameter specifies a thread # created by the current process and if the hook procedure is + within the code associated # with the current process. # dwThreadId # [in] Specifies the identifier of the thread with which the hook +procedure is to be associated. # If this parameter is zero, the hook procedure is associated + with all existing threads # running in the same desktop as the calling thread. # LRESULT CALLBACK LowLevelKeyboardProc( # int nCode, # WPARAM wParam, # LPARAM lParam # ); my $user32 = 'user32.dll'; my $callback = Win32::API::Callback->new( sub { my($a, $b) = @_; return $a+$b; }, "INN", "N", ); my $SetWindowsHookEx = new Win32::API($user32, 'SetWindowsHookEx', 'IPNN', 'I'); print Dumper($SetWindowsHookEx); if (!$SetWindowsHookEx) { print $^E . "\n"; print Win32::GetLastError(); exit; } my $idHook = WH_KEYBOARD_LL; my $lpfn = \&hello; #pack("L", 0); my $hMod = 0; my $dwThreadId = 0; my $ok = $SetWindowsHookEx->Call( $idHook, $lpfn, $hMod, $dwThreadId ) or die $^E; print Win32::GetLastError(); sub hello { }
|
---|