uhookcode.pas

来自「Delphi编写的Cs1.6中文输入软件 支持CS游戏全屏下的中文输入;但只支」· PAS 代码 · 共 67 行

PAS
67
字号
unit UHookCode;

interface

uses windows, QStrings, Classes, Sysutils{, UShowWin};

function HookOn:Boolean;stdcall;
procedure HookOff;stdcall;

implementation

uses Controls, StdCtrls, Messages, UKeyInput;

var
  HookH:HHook;    //钩子句柄
  ifOpen:Boolean;
  iH:Integer;

procedure GetCSHandle;
begin
  iH:=FindWindow(nil,'Counter-Strike');
  if iH=0 then iH:=FindWindow(nil,'strike');
  if iH=0 then iH:=FindWindow(nil,'HL');
  if iH=0 then iH:=FindWindow(nil,'Condition Zero');
  if iH=0 then iH:=FindWindow('Valve001',nil);
end;

procedure ShowInput;

begin
  if frmKeyInput=nil then
     frmKeyInput:=TfrmKeyInput.Create(nil)
  else frmKeyInput.Show;
end;

function keyhook(Code:Integer;wParam:WPARAM;lParam:LPARAM):LRESULT;stdcall;
begin
  if ifOpen then
  begin
    Result:=CallNextHookEx(HookH,code,Wparam,lParam);
    Exit;
  end;
  Result:=1;
  ifOpen:=True;
  if (code=HC_ACTION) and (wParam=123) then  ShowInput;
  Result:=CallNextHookEx(HookH,code,Wparam,lParam);
  ifOpen:=False;
end;

function HookOn:Boolean;
var
  iP:Cardinal;
begin
  GetCSHandle;
  iP:=GetWindowThreadProcessId(iH,nil);
  HooKH:=SetWindowsHookEx(WH_KEYBOARD,keyHook,HInstance,iP);
  Result:=HookH<>0;
  ifOpen:=False;
end;

procedure HookOff;
begin
  UnHookWindowsHookEx(HookH);
end;

end.

⌨️ 快捷键说明

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