1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77:
| library My_Hook;
uses Windows, Messages;
{$R *.res}
Const WM_HOOKMESSAGEID = WM_USER + 5000;
Type THookProc = function (nCode: Integer; wParam: WPARAM; lParam: LPARAM): LRESULT; stdcall;
var HookHandle : Cardinal = 0; WindowHandle : Cardinal = 0;
function KeyboardHookProc(nCode: Integer; wParam: WPARAM; lParam: LPARAM): LRESULT; stdcall; begin Result := CallNextHookEx(HookHandle, nCode, wParam, lParam); case nCode < 0 of TRUE : exit; FALSE : begin Postmessage(WindowHandle,WM_HOOKMESSAGEID,Integer(wParam),Integer(LPARAM)); end; end; end;
function InstallKeyboardHook(Hwnd: Cardinal): Boolean; stdcall; begin Result := False; if HookHandle = 0 then begin HookHandle := SetWindowsHookEx(WH_KEYBOARD, @KeyboardHookProc, HInstance, 0); WindowHandle := Hwnd; Result := TRUE; end; end;
function InstallHook( IDHook : integer; HookProc : THookProc ): Cardinal; stdcall; begin Result := 0; if (HookHandle = 0)AND(@HookProc<>NIL) then begin HookHandle := SetWindowsHookEx(IDHook, @HookProc, HInstance, 0); Result := HookHandle; end; end;
function UninstallHook: Boolean; stdcall; begin Result := UnhookWindowsHookEx(HookHandle); HookHandle := 0; end;
exports InstallKeyboardHook, InstallHook, UninstallHook;
begin
end. |