Exemplo n.º 1
0
        /// <summary>
        /// 鼠标钩子处理方法
        /// </summary>
        /// <param name="nCode">指定是否需要处理该消息,消息类型WH_MOUSE_LL</param>
        /// <param name="wParam">该消息的附加消息 </param>
        /// <param name="lParam">该消息的附加消息 </param>
        /// <returns></returns>
        private int MouseHookProc(int nCode, Int32 wParam, IntPtr lParam)
        {
            if (Flag == HookFlag.IsRunning && (nCode >= 0) && (MouseEvent != null))
            {
                //将数据从非托管内存块封送到新分配的指定类型的托管对象。
                MouseHookStruct mouseHookStruct = (MouseHookStruct)Marshal.PtrToStructure(lParam, typeof(MouseHookStruct));
                MouseButtons    mousebutton     = MouseButtons.None;
                short           mouseDelta      = 0;
                switch (wParam)
                {
                case (int)WM_MOUSE.WM_LBUTTONDOWN:
                    mousebutton = MouseButtons.Left;
                    break;

                case (int)WM_MOUSE.WM_RBUTTONDOWN:
                    mousebutton = MouseButtons.Right;
                    break;

                case (int)WM_MOUSE.WM_MBUTTONDOWN:
                    mousebutton = MouseButtons.Middle;
                    break;

                case (int)WM_MOUSE.WM_MOUSEWHEEL:
                    mouseDelta = (short)((mouseHookStruct.MouseData >> 16) & 0xffff);
                    break;

                case (int)WM_MOUSE.WM_XBUTTONDOWN:
                    if (mouseHookStruct.MouseData == (uint)WM_MOUSE.MD_XBUTTON1)
                    {
                        mousebutton = MouseButtons.XButton1;
                    }
                    else if (mouseHookStruct.MouseData == (uint)WM_MOUSE.MD_XBUTTON2)
                    {
                        mousebutton = MouseButtons.XButton2;
                    }
                    break;
                }
                MouseHookEventArgs e = new MouseHookEventArgs(mousebutton, mouseHookStruct.Point, mouseDelta);
                if (MouseEvent(this, e))
                {
                    return(1);
                }
            }
            return(CallNextHookEx(this._hookHandle, nCode, wParam, lParam));
        }
Exemplo n.º 2
0
 /// <summary>
 /// 鼠标钩子处理方法
 /// </summary>
 /// <param name="nCode">指定是否需要处理该消息,消息类型WH_MOUSE_LL</param>
 /// <param name="wParam">该消息的附加消息 </param>
 /// <param name="lParam">该消息的附加消息 </param>
 /// <returns></returns>
 private int MouseHookProc(int nCode,Int32 wParam,IntPtr lParam)
 {
     if(Flag==HookFlag.IsRunning&&(nCode>=0)&&(MouseEvent!=null))
     {
         //将数据从非托管内存块封送到新分配的指定类型的托管对象。
         MouseHookStruct mouseHookStruct = (MouseHookStruct)Marshal.PtrToStructure(lParam, typeof(MouseHookStruct));
         MouseButtons mousebutton=MouseButtons.None;
         short mouseDelta = 0;
         switch(wParam)
         {
             case (int)WM_MOUSE.WM_LBUTTONDOWN:
                 mousebutton=MouseButtons.Left;
                 break;
             case(int)WM_MOUSE.WM_RBUTTONDOWN:
                 mousebutton=MouseButtons.Right;
                 break;
             case(int)WM_MOUSE.WM_MBUTTONDOWN:
                 mousebutton=MouseButtons.Middle;
                 break;
             case (int)WM_MOUSE.WM_MOUSEWHEEL:
                 mouseDelta = (short)((mouseHookStruct.MouseData >> 16) & 0xffff);
                 break;
             case(int)WM_MOUSE.WM_XBUTTONDOWN:
                 if(mouseHookStruct.MouseData==(uint)WM_MOUSE.MD_XBUTTON1)
                 {
                     mousebutton=MouseButtons.XButton1;
                 }
                 else if(mouseHookStruct.MouseData==(uint)WM_MOUSE.MD_XBUTTON2)
                 {
                     mousebutton=MouseButtons.XButton2;
                 }
                 break;
         }
         MouseHookEventArgs e = new MouseHookEventArgs(mousebutton,mouseHookStruct.Point,mouseDelta);
         if(MouseEvent(this,e))
         {
             return 1;
         }
     }
     return CallNextHookEx(this._hookHandle, nCode, wParam, lParam);
 }
Exemplo n.º 3
0
 private bool MouseButtonEventProc(object sender, MouseHookEventArgs e)
 {
     if(e.ChangedButton==MouseButtons.Right)
     {
         keyBoardHook.Flag=HookFlag.IsRunning;
     }
     if (e.ChangedButton == MouseButtons.XButton1)
     {
         IntPtr war3 = FindWindow(null, "Warcraft III");
         SendMessage(war3, (uint)WM_KEYBOARD.WM_KEYDOWN, (int)_myKeys.XButton1, 0);
         SendMessage(war3, (uint)WM_KEYBOARD.WM_KEYUP, (int)_myKeys.XButton1, 0);
         return true;
     }
     else if (e.ChangedButton == MouseButtons.XButton2)
     {
         IntPtr war3 = FindWindow(null, "Warcraft III");
         SendMessage(war3, (uint)WM_KEYBOARD.WM_KEYDOWN, (int)_myKeys.XButton2, 0);
         SendMessage(war3, (uint)WM_KEYBOARD.WM_KEYUP, (int)_myKeys.XButton2, 0);
         return true;
     }
     else if (e.ChangedButton ==MouseButtons.Middle)
     {
         IntPtr war3 = FindWindow(null, "Warcraft III");
         SendMessage(war3, (uint)WM_KEYBOARD.WM_KEYDOWN, (int)_myKeys.MiddleButton, 0);
         SendMessage(war3, (uint)WM_KEYBOARD.WM_KEYUP, (int)_myKeys.MiddleButton, 0);
         return true;
     }
     return false;
 }