⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 hook.pas

📁 墨香外挂源码!!有兴趣的人下载来研究研究巴
💻 PAS
字号:
unit Hook;

interface

uses Windows, Messages, Dialogs, Sysutils, Unit1, IniFiles, Registry;

var
  hNextHookProc: HHook;
  procSaveExit: Pointer;
  IniFile: TIniFile;
  FTitle: pchar;
  IsRun, IsWindowMode, IsShow: Boolean;
  FilePath: string;
  Style: Longint;
  OldProc: FARPROC;
  swl: longint;
function sethook: bool; export;
function MyProc(Hwnd: HWND; iCode: UINT; wParam: WPARAM; lParam: LPARAM): integer; stdcall;
function hookproc(iCode: Integer; wParam: WPARAM; lParam: LPARAM): LRESULT; stdcall;
function endhook: bool; export;
procedure HotKeyHookExit; far;

implementation

function MyProc(Hwnd: HWND; iCode: UINT; wParam: WPARAM; lParam: LPARAM): integer; stdcall;
begin
  if (iCode = WM_ACTIVATEAPP) or (iCode = WM_ACTIVATE) or (iCode = WM_KILLFOCUS) or (iCode = WM_SETFOCUS) then
  begin
    result := 0;
    Exit;
  end;
  result := CallWindowProc(oldproc, hwnd, iCode, wparam, lparam);
end;

function HookProc(iCode: integer; wParam: wParam; lParam: lParam): LResult; stdcall;
var
  hwnd: dword;
  AppRect: TRect;
  title: pchar;
  Reg: TRegistry;
  Pos: TPoint;
  Handle: dword;
  Buf: array[0..1024] of Char;
begin
  Reg := TRegistry.Create;
  with Reg do begin
    RootKey := HKEY_CURRENT_USER;
    OpenKey('\Software\PPSSoft\MXTools', True);
    FilePath := ReadString('FilePath');
    CloseKey;
    Free;
  end;
  result := 0;
  title := '';
  if iCode < 0 then
  begin
    CallNextHookEx(hnexthookproc, iCode, wParam, lParam);
    result := 0;
    Exit;
  end;
  IniFile := TiniFile.Create(FilePath + 'Config.ini');
  with IniFile do begin
    FTitle := Pchar(ReadString('CONFIG', 'GameTitle', 'Pigeon'));
    Free;
  end;
  hwnd := getforegroundwindow;
  GetMem(title, 255);
  getwindowtext(hwnd, title, 255);
  if ((lParam and $80000000) = 0) and (wParam = $6F) then begin
    GetCursorPos(Pos);
    Handle := WindowFromPoint(Pos);
    GetClassName(Handle, Buf, 1024);
    SendMessage(Handle, WM_GETTEXT, 1024, Integer(@Buf));
    IniFile := TiniFile.Create(FilePath + 'Config.ini');
    with IniFile do begin
      WriteString('CONFIG', 'GameTitle', Buf);
      Free;
    end;
  end;
  if ((lParam and $80000000) = 0) and (wParam = vk_Home) and (IsRun) then begin
    Form1.BeginGJ;
  end;
  if ((lParam and $80000000) = 0) and (wParam = $C0) and (IsRun) then begin
    Form1.BeginAutoGJ;
  end;
  if ((lParam and $80000000) = 0) and (wParam = $7A) and (not IsWindowMode) then
  begin
    if (Trim(title) = Trim(FTitle)) or (Trim(Title) = Trim(FTitle + '-F11窗口化,F10隐藏/显示 鸽子作品,www.vifo.cn')) then
    begin
      ShowWindow(hwnd, SW_SHOW);
      style := getwindowlong(hwnd, GWL_STYLE);
      style := WS_CAPTION;
      setwindowlong(hwnd, GWL_STYLE, style);
      SetWindowPos(hwnd, HWND_TOP, 0, 0, 1029, 793, SWP_SHOWWINDOW);
     // SendMessage(hWnd, WM_SETTEXT, length(title), LongInt(PChar(Trim(title + '-F11窗口化,F10隐藏/显示 鸽子作品,www.vifo.cn'))));
      oldproc := FARPROC(getwindowlong(hwnd, GWL_WNDPROC));
      swl := setwindowlong(hwnd, GWL_WNDPROC, longint(@MyProc));
      IsWindowMode := True;
    end;
  end;
  if ((lParam and $80000000) = 0) and (wParam = $6A) then
  begin
    try
      if (Trim(title) = Trim(FTitle)) or (Trim(Title) = Trim(FTitle + '-F11窗口化,F10隐藏/显示 鸽子作品,www.vifo.cn')) then
      begin
        try
          Messagebeep(0);
          if not IsRun then
            Form1 := TForm1.CreateParented(hwnd);
          IsRun := True;
          GetWindowRect(hwnd, AppRect);
          Form1.FPath := FilePath;
          if (IsRun) and (Form1.Showing) then Form1.Close else
            Form1.Show;
        finally

        end;
      end;
    finally
    end;
    result := 1;
  end;
  hwnd := FindWindow(nil, pchar(FTitle));
  if ((lParam and $80000000) = 0) and (wParam = $79) then
  begin
    //if (Trim(title) = Trim(FTitle)) or (Trim(Title) = Trim(FTitle + '-F11窗口化,F10隐藏/显示 鸽子作品,www.vifo.cn')) then
    begin
      if not IsShow then begin
        ShowWindow(hwnd, SW_HIDE);
        IsShow := True;
      end else begin
        ShowWindow(hwnd, SW_SHOW);
        IsShow := False;
      end;
    end;
    result := 1;
  end;
  FreeMem(title);
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;
  Form1.Free;
end;

end.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -