求一个HOOK住鼠标左右中键的代码?

解决方案 »

  1.   

    function MsgHookProc(Code: Integer; WParam: Longint;Msg:Longint): LRESULT;stdcall;
    begin
    if (Code = HC_ACTION) then     if wparam = WM_LBUTTONDOWN then
         begin             Result := 1;      end;
        if PMsg(Msg)^.Message = WM_MOUSEWHEEL then //鼠标滚动
        begin
          if HIWORD(PMsg(Msg)^.wParam)=120 then        // 上滚
          begin
                 //做你想做的。
                 //showmessage('d2d');
                 //Result := 1;
               ShowWindow (pmsg(msg)^.hwnd,SW_MAXIMIZE );
          end;      if HIWORD(PMsg(Msg)^.wParam)<>120 then        // 下滚
          begin
                 //做你想做的。
                 //showmessage('dd');
                 //Result := 1;
                 ShowWindow (pmsg(msg)^.hwnd,SW_RESTORE );
          end;
          PMsg(Msg)^.Message := 0;
        end;
        Result :=CallNextHookEx(HookHandle, Code, WParam, Longint(@Msg));
    end;
    中轮可以hook,左右键没有办法实现,哪位朋友帮看看,上面的hook左键的怎么改一下?
      

  2.   

    鼠标钩子,连DLL都可以不要。20分只能给你这么多提示。
      

  3.   

    左键右键也有消息的,不然MFC里面哪里有onmouseclick事件
      

  4.   

     WH_MOUSE_LL这种低级钩子不用单写DLL,直接在主程序中即可function MouseHook(nCode: Integer; wParam: WPARAM; lParam: LPARAM): LRESULT; stdcall;begin  case wParam of    WM_LBUTTONDOWN  ,
        WM_LBUTTONUp   :
        begin    end;
      end;
      Result := CallNextHookEx(hook, nCode, wParam, lParam);
    end;function SetHook: Boolean; stdcall;
    const
      WH_MOUSE_LL =14;
    begin
      hook := SetWindowsHookEx(WH_MOUSE_LL, @MouseHook, HInstance, 0);
      Result := hook <> 0;
    end;function DelHook: Boolean; stdcall;
    begin
      Result := UnhookWindowsHookEx(hook);
    end;
      

  5.   


    case wParam of    WM_LBUTTONDOWN  ,
        WM_LBUTTONUp   :    if wparam = WM_LBUTTONDOWN then
        begin            Result := 1;
                  showmessage('dd');
          end; 
    没有禁用左键呢?怎么用这个?
      

  6.   

    unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls, TntStdCtrls;type
      TForm1 = class(TForm)
        btn1: TTntButton;
        btn2: TTntButton;
        procedure btn1Click(Sender: TObject);
        procedure btn2Click(Sender: TObject);
      private
        { Private declarations }
      public
        { Public declarations }
      end;
      
    const
      WH_MOUSE_LL = 14; var
      Form1: TForm1;
      Hook: HHOOK;implementation{$R *.dfm}
    function MouseHookProc(nCode: integer; wParam: WPARAM;
      lParam: LPARAM): LRESULT; stdcall;
    begin
      Result := 0;
      if nCode = HC_ACTION then
      begin
        case wParam of
          WM_LBUTTONDOWN, WM_LBUTTONUP:
            Result := -1;
          else
            Result := CallNextHookEx(Hook, nCode, wParam, lParam);
        end;
      end;
    end;//启动或者停止底层鼠标钩子
    function StartHook(Enable: Boolean): Boolean;
    begin
      if Enable then
      begin
        if Hook <> 0 then
        begin
          Result:=False
        end
        else
        begin
          Hook:=SetWindowsHookEx(WH_MOUSE_LL, MouseHookProc, HInstance, 0);
          Result := Hook <> 0;
        end;
      end
      else
      begin
        Result:=UnhookWindowsHookEx(Hook);
      end;
    end;procedure TForm1.btn1Click(Sender: TObject);
    begin
      StartHook(True);
    end;procedure TForm1.btn2Click(Sender: TObject);
    begin
      StartHook(False);
    end;end.
      

  7.   


    楼主在begin里面加上 result := -1 和 exit