Hook.pas
上传用户:mjqmds
上传日期:2022-05-05
资源大小:2827k
文件大小:2k
- unit Hook;
- interface
- uses Windows,Messages,Dialogs,Sysutils;
- var
- hNextHookProc: HHook;
- procSaveExit: Pointer;
- function sethook:bool;export;
- function hookproc(iCode:Integer;wParam: WPARAM;lParam: LPARAM):LRESULT; stdcall;
- function endhook:bool;export;
- procedure HotKeyHookExit;far;
- implementation
- uses Controller;
- function HookProc(iCode: integer; wParam: wParam; lParam: lParam):
- LResult; stdcall;
- var
- hwnd:dword;
- AppRect:TRect;
- title:pchar;
- begin
- result:=0;
- if iCode<0 then
- begin
- CallNextHookEx(hnexthookproc,iCode,wParam,lParam);
- result:=0;
- Exit;
- end;
- if ((lParam and $80000000)=0) and (wParam=$6a) then
- begin
- hwnd:=getforegroundwindow;
- try
- GetWindowRect(hwnd,AppRect);
- CForm.Left:=(AppRect.Right-AppRect.Left) div 2;
- CForm.Top:=(AppRect.Bottom-AppRect.Top) div 2;
- CForm.Show;
- finally
- end;
- result:=1;
- end;
- end;
- function sethook:bool;export;
- begin
- result:=false;
- if hnexthookproc<>0 then exit;
- hNextHookProc := SetWindowsHookEx(WH_KEYBOARD,hookproc,HInstance,0);
- Result := hNextHookProc <> 0;
- end;
- procedure hotkeyhookexit;
- begin
- if hNextHookProc <> 0 then endHook;
- ExitProc := procSaveExit;
- end;
- function endhook:bool;export;
- begin
- if hNextHookProc <> 0 then
- begin
- UnhookWindowshookEx(hNextHookProc); // 解除 Keyboard Hook
- hNextHookProc := 0;
- end;
- Result := hNextHookProc = 0;
- end;
- end.