前提:
用SetWindowsHookEx注入到游戏进程。SetWindowsHookEx的第2个参数为回调函数 内容是按HOME呼出dll里面封装的Form.SetWindowsHookEx最后一个参数先用FindWindow获取游戏标题 然后GetWindowThreadProcessId获取该标题的id. Hook Mutex实现游戏多开。问题:
在游戏为焦点的时候按一次热键可以呼出form.再按一次热键form消失,前景美好。但是再按没反映。请问各位高手能否帮我改下代码。达到一个dll可以注入到多个游戏,而且不是游戏的时候按热键注入不了。代码:var
keyhhk: HHOOK ;Function keyproc(nCode: Integer; wParam: WPARAM; lParam: LPARAM): DWORD; stdcall; //键盘HOOK回调函数
var
game:hwnd;
cn : Array[0..255] of char;
begin
game:=0;
  if nCode = HC_ACTION then
  begin
    if (wParam = VK_F9) and ((1 shl 31) and lParam = 0) then
    begin
      if form1 = nil then
      game:=GetForegroundWindow();
      getclassname(game ,cn,255);
       if lstrcmpi(cn,'StartUpDlgClass') = 0 then begin
        form1 := Tform1.Create(Application);
        form1.Visible := True;
       end
      else
        form1.Visible := False;
      end;
  end;
  Result := CallNextHookEx(keyhhk, nCode, wParam, lParam);
end;Function installKeyProc():boolean;stdcall;
begin
    Result:=false;
    keyhhk:=SetWindowsHookEx(WH_KEYBOARD,@Keyproc,HInstance,0);
    if keyhhk>0 then Result:=true;
end;

解决方案 »

  1.   

    : Function keyproc(nCode: Integer; wParam: WPARAM; lParam: LPARAM): DWORD; stdcall; //键盘HOOK回调函数
    var
    game:hwnd;
    cn : Array[0..255] of char;
    begin
    game:=0;
      if nCode = HC_ACTION then
      begin
        if (wParam = VK_F9) and ((1 shl 31) and lParam = 0) then
        begin
          if form1 = nil then
          game:=GetForegroundWindow();
          getclassname(game ,cn,255);
           if lstrcmpi(cn,'StartUpDlgClass') = 0 then
            form1 := Tform1.Create(nil);
            form1.Visible:=not form1.Visible;
         end;
      end;
      Result := CallNextHookEx(keyhhk, nCode, wParam, lParam);
    end;改为这样的话 如果当前焦点的类名不是StartUpDlgClass你按热键是呼不出 但是 你焦点为游戏类名的话再按热键就呼不出了 请问怎么处理?