Code: Select all
library KeyHandler;
uses Windows, Messages, madCodeHook;
type
TParam = record
WParam: WPARAM;
LParam: LPARAM;
end;
var PeekMessageCallNext: function (lpMsg: TMsg; hWnd: HWND; wMsgFilterMin, wMsgFilterMax, wRemoveMsg: UINT): BOOL; stdcall;
function PeekMessageCallBack(lpMsg: TMsg; hWnd: HWND; wMsgFilterMin, wMsgFilterMax, wRemoveMsg: UINT): BOOL; stdcall;
var
Param: TParam;
begin
case lpMsg.message of
WM_KEYFIRST..WM_KEYLAST: begin
Param.WParam := lpMsg.wParam;
Param.LParam := lpMsg.lParam;
SendIpcMessage('KYHNDLR', @Param, SizeOf(Param));
end;
end;
Result := PeekMessageCallNext(lpMsg, hWnd, wMsgFilterMin, wMsgFilterMax, wRemoveMsg);
end;
begin
HookAPI(user32, 'PeekMessageA', @PeekMessageCallBack, @PeekMessageCallNext);
HookAPI(user32, 'PeekMessageW', @PeekMessageCallBack, @PeekMessageCallNext);
end.
What am I doing wrong?
PS. I'm not using SetWindowsHookEx because I want to be able to inject/uninject and delete the DLL at any time. I suppose I could write a keyhook with SetWindowsHookEx, then use madRemote to execute a function in each remote process to force them to unload the DLL. Dunno if this would work though.