HKProc.pas
上传用户:mjqmds
上传日期:2022-05-05
资源大小:2827k
文件大小:3k
- unit HKProc;
- interface
- uses
- Windows, Messages,SysUtils,SyncObjs,Classes,Variants, Registry;
- Const
- WM_MYBACK=WM_USER+102;
- WM_SHOWAPP=WM_USER+1108;
- WM_HIDEAPP=WM_USER+1109;
- WM_KILLAPP=WM_USER+1110;
-
- function MessageHookProc(iCode: Integer;
- wParam: WPARAM;
- lParam: LPARAM): LRESULT; stdcall; export;
- function EnableHotKeyHook: BOOL; export;
- function DisableHotKeyHook: BOOL; export;
- procedure HotKeyHookExit; far;
- var
- hNextHookProc: HHook;
- procSaveExit: Pointer;
- vHandle:THandle;
- CriticalSetion:TCriticalSection;
- implementation
- uses Information;
- function ReadReg(Key: String; DefaultValue: Variant): Variant;
- Var
- Reg:TRegistry;
- begin
- Result:=NULL;
- Reg:=TRegistry.Create;
- Try
- Reg.RootKey:=HKEY_CURRENT_USER;
- if Reg.OpenKey('/WHSUPPERPLAYER/RUN',false) then
- begin
- Result:=Reg.ReadString(Key);
- if VarIsNull(Result) or VarIsEmpty(Result) then
- Result:=DefaultValue;
- end
- else
- Result:=DefaultValue;
- Finally
- Reg.Free;
- end;
- end;
- function MessageHookProc(iCode: Integer;
- wParam: WPARAM;
- lParam: LPARAM): LRESULT; stdcall; export;
- const
- _KeyPressMask = $80000000;
- Var
- v:Variant;
- begin
- Result := 0;
- If iCode < 0 Then
- begin
- Result := CallNextHookEx(hNextHookProc, iCode, wParam, lParam);
- Exit;
- end;
- // 侦测 Ctrl + B 组合键
- if ((lParam and _KeyPressMask) = 0) and (GetKeyState(vk_Control) < 0) then
- begin
- v:=ReadReg('MsgHandle',null);
- if VarIsNull(v) then
- Exit;
- Result := 1;
- if wParam = Ord('R') then
- begin
- begin
- PostMessage(v,WM_SHOWAPP,0,0);
- end;
- end
- else if wParam=Ord('Q') then
- begin
- PostMessage(v,WM_KILLAPP,0,0);
- end
- end
- end;
- function EnableHotKeyHook: BOOL; export;
- begin
- Result := False;
- if hNextHookProc <> 0 then Exit;
- hNextHookProc := SetWindowsHookEx(WH_KEYBOARD,
- MessageHookProc,
- HInstance,
- 0);
- Result := hNextHookProc <> 0;
- end;
- function DisableHotKeyHook: BOOL; export;
- begin
- if hNextHookProc <> 0 then
- begin
- UnhookWindowshookEx(hNextHookProc);
- hNextHookProc := 0;
- end;
- Result := hNextHookProc = 0;
- end;
- procedure HotKeyHookExit;
- begin
- if hNextHookProc <> 0 then DisableHotKeyHook;
- ExitProc := procSaveExit;
- end;
- begin
- CriticalSetion:=TCriticalSection.Create;
- end.