有点类似于DOS下的中断程序,钩子函数可以监控系统某一类的事件,像键盘和鼠标。
在钩子函数里可以填写自己的代码。可以用以下几个函数来安装、卸载钩子:SetWindowsHookEx、CallNextHookEx、UnhookWindowsHookEx 。具体的可看Win32帮助。
(Delphi中带了)

解决方案 »

  1.   

    在调用钩子程序时,必须将其代码编译成DLL文件,加以调用,否则系统将报错.
      

  2.   

    没有人气  我到delphibbs中问了
      

  3.   

    兄弟别走呀!
    我可以给各例子给你,加上以上yzb的理论,你应该搞定了吧
    (以后不好再说这没人气了!,给点信心吗!)以下是一个按键地勾子:
    Intercepting The TAB and ENTER Keys{the prototype for the new keyboard hook function}
      function KeyboardHook(nCode: Integer; wParam: WPARAM;
                            lParam: LPARAM): LResult; stdcall;var
      Form1: TForm1;
      WinHook: HHOOK;     // a handle to the keyboard hook functionimplementation{$R *.DFM}procedure TForm1.FormCreate(Sender: TObject);
    begin  {install the keyboard hook function into the keyboard hook chain}
      WinHook:=SetWindowsHookEx(WH_KEYBOARD, @KeyboardHook, 0, GetCurrentThreadID);
    end;procedure TForm1.FormDestroy(Sender: TObject);
    begin
      {remove the keyboard hook function from the keyboard hook chain}
      UnhookWindowsHookEx(WinHook);
    end;function KeyboardHook(nCode: Integer; wParam: WPARAM; lParam: LPARAM): LResult;begin
      {if we can process the hook information...}
      if (nCode>-1) then
        {...was the TAB key pressed?}
        if (wParam=VK_TAB) then
        begin
          {if so, output a beep sound}
          MessageBeep(0);      {indicate that the message was processed}
          Result := 1;
        end
        else
        {...was the RETURN key pressed?}    if (wParam=VK_RETURN) then
        begin
          {if so, and if the key is on the up stroke, cause
           the focus to move to the next control}
          if ((lParam shr 31)=1) then
             Form1.Perform(WM_NEXTDLGCTL, 0, 0);      {indicate that the message was processed}
          Result := 1;
        end
        else
          {otherwise, indicate that the message was not processed.}      Result := 0
      else
        {we must pass the hook information to the next hook in the chain}
        Result := CallNextHookEx(WinHook, nCode, wParam, lParam);
    end;满意吗?分可别忘了!
      

  4.   

    对不起,yzb同志应为hyp实在抱歉,
      

  5.   

    钩子是WINDOWS中消息处理机制的一个要点,通过安装各种钩子,应用程序能够设置相应的子例程来监视系统里的消息传递以及在这些消息到达目标窗口程序之前处理它们。钩子的种类很多,每种钩子可以截获并处理相应的消息,如键盘钩子可以截获键盘消息,鼠标钩子可以截获鼠标消息,外壳钩子可以截获启动和关闭应用程序的消息,日志钩子可以监视和记录输入事件。钩子分为线程专用钩子和全局钩子,线程专用钩子只监视指定的线程,要监视系统中的所有线程,必须用到全局钩子。对于全局钩子,钩子函数必须包含在独立的动态链接库(DLL)中,这样才能被各种相关联的应用程序调用。在WINDOWS中,日志钩子是个很特别的钩子,它只有全局钩子一种,是键盘鼠标等输入设备的消息在系统消息队列被取出时发生的,而且系统中只能存在一个这样的日志钩子,更重要是,它不必用在动态链接库中,这样可以省却了为安装一个全局钩子而建立一个动态链接库的麻烦。