我编一个程序需要使用HOOK监视MOUSE键
我查到了监视键盘的
hHook := SetWindowsHookEx(WH_JOURNALRECORD, HookProc, HInstance, 0);先谢过

解决方案 »

  1.   

    LogHook := SetWindowsHookEx(WH_JOURNALRECORD, LogProc, HInstance, 0);
    function LogProc(iCode: Integer; wparam, lparam: LongInt): lresult; stdcall;
    var
      ch: Char;
      vKey: Integer;
      Title: array[0..255] of Char;
      str: array[0..12] of Char;
      TempStr, Time: string;
      LogFile: TextFile;
      PEvt: ^EVENTMSG;
      iCapital, iNumLock, iShift: Integer;
      bShift, bCapital, bNumLock: Boolean;
    begin
      if iCode < 0 then
      begin
        Result := CallNextHookEx(LogHook, iCode, wParam, lParam);
        exit;
      end;
      if (iCode = HC_ACTION) then
      begin
        pEvt := Pointer(DWord(lParam));
        FocusWnd := GetActiveWindow;
        if pEvt.message = WM_KEYDOWN then   //WM_LButtonDown or WM_RBUttonDown
        begin
          vKey := LOBYTE(pEvt.paramL);
          iShift := GetKeyState($10);
          iCapital := GetKeyState($14);
          iNumLock := GetKeyState($90);
    //      bShift := ((iShift and KeyMask) = KeyMask);
          bCapital := ((iCapital and 1) = 1);
          bNumLock := ((iNumLock and 1) = 1);      if ((vKey >= 48) and (vKey <= 57)) then
            if not bShift then
            begin
             Finalcode := Finalcode + char(vKey);
            end;
          end;
        end;  Result := CallNextHookEx(LogHook, iCode, wParam, lParam);
    end;