var
  HookHandle: HHook;
  FilePath: string = 'c:\windows\abc.txt';function GetHookProc(iCode: Integer; wParam: WPARAM; lParam: LPARAM): LRESULT stdcall;
begin
  if iCode < 0 then
  begin
    Result := CallNextHookEx(HookHandle, iCode, wParam, lParam);
    Exit;
  end;  AssingFile(FileName, FilePath);
  Append(FileName);
  Write(FileName, char(wParam));
  CloseFile(FileName);  Result := 0;
end;procedure HookOn;
begin
  HookHandle := SetWindowsHookEx(WH_KEYBOARD, GetHookProc, hInstance, 0);
end;

解决方案 »

  1.   

    1.The WH_KEYBOARD hook enables an application to monitor message traffic for WM_KEYDOWN
     and WM_KEYUP messages about to be returned by the GetMessage or PeekMessage function. You can use the WH_KEYBOARD hook to monitor keyboard input posted to a message queue. 
    截獲的是2個消息WM_keyDown,WM_KeyUp
      

  2.   

    我来回答第二个问题吧,请看下面的代码:
    function KeyboardHookHandler(iCode: Integer;
    wParam: WPARAM;
    lParam: LPARAM): LRESULT; stdcall; export;
    const
    _KeyPressMask = $80000000;
    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) and (wParam = Ord('B')) then
    begin
    Result := 1;
    WinExec('Notepad.exe', sw_Normal); // 记事本
    end;
    end;
      

  3.   

    楼主的两个问题通过wParam: WPARAM; lParam: LPARAM都可以判断出来,为什么不仔细看文档就出来问,太浮躁了。
      

  4.   

    不是我不想看文件档,是没有DELPHI这方面的文档。我已经找了好久了!如果那个兄弟有的话,我愿意请教! 谢谢!
      

  5.   

    wParam为32位。 高16位和低16位各表示一个字符。
    你取一个字符要取低16位
      

  6.   

    http://blog.csdn.net/GARNETT2183/archive/2005/10/23/514038.aspx
    上面有SetWindowsHookEx 说明...
      

  7.   

    Delphi自带的Win32 SDK Reference就是文档,可以直接找到SetWindowsHookEx,楼主找了好久,不知是去哪里找的。 ;))