Exemple #1
0
 private static void HookManager_MouseDown(object sender, MouseEventExtArgs e)
 {
     if (e.Button == MouseButtons.Right)
     {
         ZmMouseRightIsDown = true;
         e.Handled = true;
     }
 }
Exemple #2
0
 private static void HookManager_MouseUp(object sender, MouseEventExtArgs e)
 {
     if (e.Button == MouseButtons.Right)
     {
         ZmMouseRightIsDown = false;
         e.Handled = true;
         if (ZmVirtualControlIsDown)
         {
             ZmInSim.Keyboard.KeyUp(WindowsInput.Native.VirtualKeyCode.RCONTROL);
             ZmVirtualControlIsDown = false;
         }
         else
         {
             ZmTimerSendRightClick.Start();
         }
     }
 }
        /// <summary>
        /// A callback function which will be called every Time a mouse activity detected.
        /// </summary>
        /// <param name="nCode">
        /// [in] Specifies whether the hook procedure must process the message. 
        /// If nCode is HC_ACTION, the hook procedure must process the message. 
        /// If nCode is less than zero, the hook procedure must pass the message to the 
        /// CallNextHookEx function without further processing and must return the 
        /// value returned by CallNextHookEx.
        /// </param>
        /// <param name="wParam">
        /// [in] Specifies whether the message was sent by the current thread. 
        /// If the message was sent by the current thread, it is nonzero; otherwise, it is zero. 
        /// </param>
        /// <param name="lParam">
        /// [in] Pointer to a CWPSTRUCT structure that contains details about the message. 
        /// </param>
        /// <returns>
        /// If nCode is less than zero, the hook procedure must return the value returned by CallNextHookEx. 
        /// If nCode is greater than or equal to zero, it is highly recommended that you call CallNextHookEx 
        /// and return the value it returns; otherwise, other applications that have installed WH_CALLWNDPROC 
        /// hooks will not receive hook notifications and may behave incorrectly as a result. If the hook 
        /// procedure does not call CallNextHookEx, the return value should be zero. 
        /// </returns>
        private static int MouseHookProc(int nCode, int wParam, IntPtr lParam)
        {
            if (nCode >= 0)
            {
                //Marshall the data from callback.
                MouseLLHookStruct mouseHookStruct = (MouseLLHookStruct)Marshal.PtrToStructure(lParam, typeof(MouseLLHookStruct));

                //detect button clicked
                MouseButtons button = MouseButtons.None;
                short mouseDelta = 0;
                int clickCount = 0;
                bool mouseDown = false;
                bool mouseUp = false;

                switch (wParam)
                {
                    case WM_LBUTTONDOWN:
                        mouseDown = true;
                        button = MouseButtons.Left;
                        clickCount = 1;
                        break;
                    case WM_LBUTTONUP:
                        mouseUp = true;
                        button = MouseButtons.Left;
                        clickCount = 1;
                        break;
                    case WM_LBUTTONDBLCLK:
                        button = MouseButtons.Left;
                        clickCount = 2;
                        break;
                    case WM_RBUTTONDOWN:
                        mouseDown = true;
                        button = MouseButtons.Right;
                        clickCount = 1;
                        break;
                    case WM_RBUTTONUP:
                        mouseUp = true;
                        button = MouseButtons.Right;
                        clickCount = 1;
                        break;
                    case WM_RBUTTONDBLCLK:
                        button = MouseButtons.Right;
                        clickCount = 2;
                        break;
                    case WM_MOUSEWHEEL:
                        //If the message is WM_MOUSEWHEEL, the high-order word of MouseData member is the wheel delta.
                        //One wheel click is defined as WHEEL_DELTA, which is 120.
                        //(value >> 16) & 0xffff; retrieves the high-order word from the given 32-bit value
                        mouseDelta = (short)((mouseHookStruct.MouseData >> 16) & 0xffff);

                    //TODO: X BUTTONS (I havent them so was unable to test)
                        //If the message is WM_XBUTTONDOWN, WM_XBUTTONUP, WM_XBUTTONDBLCLK, WM_NCXBUTTONDOWN, WM_NCXBUTTONUP,
                        //or WM_NCXBUTTONDBLCLK, the high-order word specifies which X button was pressed or released,
                        //and the low-order word is reserved. This value can be one or more of the following values.
                        //Otherwise, MouseData is not used.
                        break;
                }

                //generate event
                MouseEventExtArgs e = new MouseEventExtArgs(
                                                   button,
                                                   clickCount,
                                                   mouseHookStruct.Point.X,
                                                   mouseHookStruct.Point.Y,
                                                   mouseDelta);

                //Mouse up
                if (s_MouseUp!=null && mouseUp)
                {
                    s_MouseUp.Invoke(null, e);
                }

                //Mouse down
                if (s_MouseDown != null && mouseDown)
                {
                    s_MouseDown.Invoke(null, e);
                }

                //If someone listens to click and a click is heppened
                if (s_MouseClick != null && clickCount>0)
                {
                    s_MouseClick.Invoke(null, e);
                }

                //If someone listens to click and a click is heppened
                if (s_MouseClickExt != null && clickCount > 0)
                {
                    s_MouseClickExt.Invoke(null, e);
                }

                //If someone listens to double click and a click is heppened
                if (s_MouseDoubleClick != null && clickCount == 2)
                {
                    s_MouseDoubleClick.Invoke(null, e);
                }

                //Wheel was moved
                if (s_MouseWheel!=null && mouseDelta!=0)
                {
                    s_MouseWheel.Invoke(null, e);
                }

                //If someone listens to move and there was a change in coordinates raise move event
                if ((s_MouseMove!=null || s_MouseMoveExt!=null) && (m_OldX != mouseHookStruct.Point.X || m_OldY != mouseHookStruct.Point.Y))
                {
                    m_OldX = mouseHookStruct.Point.X;
                    m_OldY = mouseHookStruct.Point.Y;
                    if (s_MouseMove != null)
                    {
                        s_MouseMove.Invoke(null, e);
                    }

                    if (s_MouseMoveExt != null)
                    {
                        s_MouseMoveExt.Invoke(null, e);
                    }
                }

                if (e.Handled)
                {
                    return -1;
                }
            }

            //call next hook
            return CallNextHookEx(s_MouseHookHandle, nCode, wParam, lParam);
        }
        /// <summary>
        /// A callback function which will be called every Time a mouse activity detected.
        /// </summary>
        /// <param name="nCode">
        /// [in] Specifies whether the hook procedure must process the message.
        /// If nCode is HC_ACTION, the hook procedure must process the message.
        /// If nCode is less than zero, the hook procedure must pass the message to the
        /// CallNextHookEx function without further processing and must return the
        /// value returned by CallNextHookEx.
        /// </param>
        /// <param name="wParam">
        /// [in] Specifies whether the message was sent by the current thread.
        /// If the message was sent by the current thread, it is nonzero; otherwise, it is zero.
        /// </param>
        /// <param name="lParam">
        /// [in] Pointer to a CWPSTRUCT structure that contains details about the message.
        /// </param>
        /// <returns>
        /// If nCode is less than zero, the hook procedure must return the value returned by CallNextHookEx.
        /// If nCode is greater than or equal to zero, it is highly recommended that you call CallNextHookEx
        /// and return the value it returns; otherwise, other applications that have installed WH_CALLWNDPROC
        /// hooks will not receive hook notifications and may behave incorrectly as a result. If the hook
        /// procedure does not call CallNextHookEx, the return value should be zero.
        /// </returns>
        private static int MouseHookProc(int nCode, int wParam, IntPtr lParam)
        {
            if (nCode >= 0)
            {
                //Marshall the data from callback.
                MouseLLHookStruct mouseHookStruct = (MouseLLHookStruct)Marshal.PtrToStructure(lParam, typeof(MouseLLHookStruct));

                //detect button clicked
                MouseButtons button     = MouseButtons.None;
                short        mouseDelta = 0;
                int          clickCount = 0;
                bool         mouseDown  = false;
                bool         mouseUp    = false;

                switch (wParam)
                {
                case WM_LBUTTONDOWN:
                    mouseDown  = true;
                    button     = MouseButtons.Left;
                    clickCount = 1;
                    break;

                case WM_LBUTTONUP:
                    mouseUp    = true;
                    button     = MouseButtons.Left;
                    clickCount = 1;
                    break;

                case WM_LBUTTONDBLCLK:
                    button     = MouseButtons.Left;
                    clickCount = 2;
                    break;

                case WM_RBUTTONDOWN:
                    mouseDown  = true;
                    button     = MouseButtons.Right;
                    clickCount = 1;
                    break;

                case WM_RBUTTONUP:
                    mouseUp    = true;
                    button     = MouseButtons.Right;
                    clickCount = 1;
                    break;

                case WM_RBUTTONDBLCLK:
                    button     = MouseButtons.Right;
                    clickCount = 2;
                    break;

                case WM_MOUSEWHEEL:
                    //If the message is WM_MOUSEWHEEL, the high-order word of MouseData member is the wheel delta.
                    //One wheel click is defined as WHEEL_DELTA, which is 120.
                    //(value >> 16) & 0xffff; retrieves the high-order word from the given 32-bit value
                    mouseDelta = (short)((mouseHookStruct.MouseData >> 16) & 0xffff);

                    //TODO: X BUTTONS (I havent them so was unable to test)
                    //If the message is WM_XBUTTONDOWN, WM_XBUTTONUP, WM_XBUTTONDBLCLK, WM_NCXBUTTONDOWN, WM_NCXBUTTONUP,
                    //or WM_NCXBUTTONDBLCLK, the high-order word specifies which X button was pressed or released,
                    //and the low-order word is reserved. This value can be one or more of the following values.
                    //Otherwise, MouseData is not used.
                    break;
                }

                //generate event
                MouseEventExtArgs e = new MouseEventExtArgs(
                    button,
                    clickCount,
                    mouseHookStruct.Point.X,
                    mouseHookStruct.Point.Y,
                    mouseDelta);

                //Mouse up
                if (s_MouseUp != null && mouseUp)
                {
                    s_MouseUp.Invoke(null, e);
                }

                //Mouse down
                if (s_MouseDown != null && mouseDown)
                {
                    s_MouseDown.Invoke(null, e);
                }

                //If someone listens to click and a click is heppened
                if (s_MouseClick != null && clickCount > 0)
                {
                    s_MouseClick.Invoke(null, e);
                }

                //If someone listens to click and a click is heppened
                if (s_MouseClickExt != null && clickCount > 0)
                {
                    s_MouseClickExt.Invoke(null, e);
                }

                //If someone listens to double click and a click is heppened
                if (s_MouseDoubleClick != null && clickCount == 2)
                {
                    s_MouseDoubleClick.Invoke(null, e);
                }

                //Wheel was moved
                if (s_MouseWheel != null && mouseDelta != 0)
                {
                    s_MouseWheel.Invoke(null, e);
                }

                //If someone listens to move and there was a change in coordinates raise move event
                if ((s_MouseMove != null || s_MouseMoveExt != null) && (m_OldX != mouseHookStruct.Point.X || m_OldY != mouseHookStruct.Point.Y))
                {
                    m_OldX = mouseHookStruct.Point.X;
                    m_OldY = mouseHookStruct.Point.Y;
                    if (s_MouseMove != null)
                    {
                        s_MouseMove.Invoke(null, e);
                    }

                    if (s_MouseMoveExt != null)
                    {
                        s_MouseMoveExt.Invoke(null, e);
                    }
                }

                if (e.Handled)
                {
                    return(-1);
                }
            }

            //call next hook
            return(CallNextHookEx(s_MouseHookHandle, nCode, wParam, lParam));
        }
Exemple #5
0
        /// <summary>
        /// A callback function which will be called every Time a mouse activity detected.
        /// </summary>
        /// <param name="nCode">
        /// [in] Specifies whether the hook procedure must process the message.
        /// If nCode is HC_ACTION, the hook procedure must process the message.
        /// If nCode is less than zero, the hook procedure must pass the message to the
        /// CallNextHookEx function without further processing and must return the
        /// value returned by CallNextHookEx.
        /// </param>
        /// <param name="wParam">
        /// [in] Specifies whether the message was sent by the current thread.
        /// If the message was sent by the current thread, it is nonzero; otherwise, it is zero.
        /// </param>
        /// <param name="lParam">
        /// [in] Pointer to a CWPSTRUCT structure that contains details about the message.
        /// </param>
        /// <returns>
        /// If nCode is less than zero, the hook procedure must return the value returned by CallNextHookEx.
        /// If nCode is greater than or equal to zero, it is highly recommended that you call CallNextHookEx
        /// and return the value it returns; otherwise, other applications that have installed WH_CALLWNDPROC
        /// hooks will not receive hook notifications and may behave incorrectly as a result. If the hook
        /// procedure does not call CallNextHookEx, the return value should be zero.
        /// </returns>
        private static int MouseHookProc(int nCode, int wParam, IntPtr lParam)
        {
            if (nCode >= 0)
            {
                //Marshall the data from callback.
                MouseLLHookStruct mouseHookStruct = (MouseLLHookStruct)Marshal.PtrToStructure(lParam, typeof(MouseLLHookStruct));

                //detect button clicked
                MouseButtons button     = MouseButtons.None;
                short        mouseDelta = 0;
                int          clickCount = 0;
                bool         mouseDown  = false;
                bool         mouseUp    = false;

                switch (wParam)
                {
                case WM_LBUTTONDOWN:
                    mouseDown  = true;
                    button     = MouseButtons.Left;
                    clickCount = 1;
                    break;

                case WM_LBUTTONUP:
                    mouseUp    = true;
                    button     = MouseButtons.Left;
                    clickCount = 1;
                    break;

                case WM_LBUTTONDBLCLK:
                    button     = MouseButtons.Left;
                    clickCount = 2;
                    break;

                case WM_RBUTTONDOWN:
                    mouseDown  = true;
                    button     = MouseButtons.Right;
                    clickCount = 1;
                    break;

                case WM_RBUTTONUP:
                    mouseUp    = true;
                    button     = MouseButtons.Right;
                    clickCount = 1;
                    break;

                case WM_RBUTTONDBLCLK:
                    button     = MouseButtons.Right;
                    clickCount = 2;
                    break;



                //滑鼠中鍵
                case WM_MBUTTONDOWN:
                    mouseDown  = true;
                    button     = MouseButtons.Middle;
                    clickCount = 1;
                    break;

                case WM_MBUTTONUP:
                    mouseUp    = true;
                    button     = MouseButtons.Middle;
                    clickCount = 1;
                    break;

                //滑鼠側鍵
                case WM_XBUTTONDOWN:
                    mouseDown  = true;
                    button     = MouseButtons.XButton1;
                    clickCount = 1;
                    break;

                case WM_XBUTTONUP:
                    mouseUp    = true;
                    button     = MouseButtons.XButton1;
                    clickCount = 1;
                    break;

                /*case WM_NCXBUTTONDOWN:
                 *  mouseDown = true;
                 *  button = MouseButtons.XButton2;
                 *  clickCount = 1;
                 *  break;
                 * case WM_NCXBUTTONUP:
                 *  mouseUp = true;
                 *  button = MouseButtons.XButton2;
                 *  clickCount = 1;
                 *  break;*/



                case WM_MOUSEWHEEL:
                    //If the message is WM_MOUSEWHEEL, the high-order word of MouseData member is the wheel delta.
                    //One wheel click is defined as WHEEL_DELTA, which is 120.
                    //(value >> 16) & 0xffff; retrieves the high-order word from the given 32-bit value
                    mouseDelta = (short)((mouseHookStruct.MouseData >> 16) & 0xffff);

                    //TODO: X BUTTONS (I havent them so was unable to test)
                    //If the message is WM_XBUTTONDOWN, WM_XBUTTONUP, WM_XBUTTONDBLCLK, WM_NCXBUTTONDOWN, WM_NCXBUTTONUP,
                    //or WM_NCXBUTTONDBLCLK, the high-order word specifies which X button was pressed or released,
                    //and the low-order word is reserved. This value can be one or more of the following values.
                    //Otherwise, MouseData is not used.
                    break;
                }

                //generate event
                MouseEventExtArgs e = new MouseEventExtArgs(
                    button,
                    clickCount,
                    mouseHookStruct.Point.X,
                    mouseHookStruct.Point.Y,
                    mouseDelta);

                //Mouse up
                if (s_MouseUp != null && mouseUp)
                {
                    s_MouseUp.Invoke(null, e);
                }

                //Mouse down
                if (s_MouseDown != null && mouseDown)
                {
                    s_MouseDown.Invoke(null, e);
                }

                //If someone listens to click and a click is heppened
                if (s_MouseClick != null && clickCount > 0)
                {
                    s_MouseClick.Invoke(null, e);
                }

                //If someone listens to click and a click is heppened
                if (s_MouseClickExt != null && clickCount > 0)
                {
                    s_MouseClickExt.Invoke(null, e);
                }

                //If someone listens to double click and a click is heppened
                if (s_MouseDoubleClick != null && clickCount == 2)
                {
                    s_MouseDoubleClick.Invoke(null, e);
                }

                //Wheel was moved
                if (s_MouseWheel != null && mouseDelta != 0)
                {
                    s_MouseWheel.Invoke(null, e);
                }

                //If someone listens to move and there was a change in coordinates raise move event

                /*if ((s_MouseMove != null || s_MouseMoveExt != null) && (m_OldX != mouseHookStruct.Point.X || m_OldY != mouseHookStruct.Point.Y)) {
                 *  m_OldX = mouseHookStruct.Point.X;
                 *  m_OldY = mouseHookStruct.Point.Y;
                 *  if (s_MouseMove != null) {
                 *      //System.Console.WriteLine("mmm");
                 *      s_MouseMove.Invoke(null, e);
                 *  }
                 *
                 *  if (s_MouseMoveExt != null) {
                 *      s_MouseMoveExt.Invoke(null, e);
                 *  }
                 *
                 * } */

                if (e.Handled)
                {
                    return(-1);
                }


                /*if (button != MouseButtons.None) {
                 *  System.Console.WriteLine($"wParam:{wParam} type:{((mouseDown)?"down":"up")}  button:{button}  bool_m_handled:{Mouse2Touch.Form1.bool_m_handled}");
                 * }*/

                if (Mouse2Touch.Form1.bool_stop == false)  //強制終止所有操作


                //事件攔截
                {
                    if (Mouse2Touch.Form1.mtype == Mouse2Touch.Form1.Mtype.滑鼠側鍵 && button == MouseButtons.XButton1)
                    {
                        return(-1);
                    }
                    else if (Mouse2Touch.Form1.mtype == Mouse2Touch.Form1.Mtype.滑鼠右鍵 && button == MouseButtons.Right && Mouse2Touch.Form1.bool_m_handled)
                    {
                        return(-1);
                    }
                    else if (Mouse2Touch.Form1.mtype == Mouse2Touch.Form1.Mtype.滑鼠右鍵_2 && button == MouseButtons.Right)
                    {
                        return(-1);

                        /*} else if (Mouse2Touch.Form1.mtype == Mouse2Touch.Form1.Mtype.滑鼠左鍵 && button == MouseButtons.Left && Mouse2Touch.Form1.bool_m_handled) {
                         *  return -1;*/
                    }
                    else if (Mouse2Touch.Form1.mtype == Mouse2Touch.Form1.Mtype.滑鼠中鍵 && button == MouseButtons.Middle)
                    {
                        return(-1);
                    }
                }
            }

            //call next hook
            return(CallNextHookEx(s_MouseHookHandle, nCode, wParam, lParam));
        }
Exemple #6
0
 private static void HookManager_MouseWheel(object sender, MouseEventExtArgs e)
 {
     if (ZmMouseRightIsDown)
     {
         if (!ZmVirtualControlIsDown)
         {
             ZmInSim.Keyboard.KeyDown(WindowsInput.Native.VirtualKeyCode.RCONTROL);
             ZmVirtualControlIsDown = true;
         }
     }
 }
 void HookManager_MouseMoveExt(object sender, MouseEventExtArgs e)
 {
     if (m_MouseMoveExt != null)
     {
         m_MouseMoveExt.Invoke(this, e);
     }
 }
Exemple #8
0
        private void mouseHook_Callback(int nCode, IntPtr wParam, IntPtr lParam, ref bool handled)
        {
            //Marshall the data from callback.
            MouseLLHookStruct mouseHookStruct =
                (MouseLLHookStruct)Marshal.PtrToStructure(lParam, typeof(MouseLLHookStruct));

            //detect button clicked
            MouseButtons button     = MouseButtons.None;
            short        mouseDelta = 0;
            bool         mouseDown  = false;
            bool         mouseUp    = false;

            switch ((int)wParam)
            {
            case WM_LBUTTONDOWN:
                mouseDown = true;
                button    = MouseButtons.Left;
                break;

            case WM_LBUTTONUP:
                mouseUp = true;
                button  = MouseButtons.Left;
                break;

            case WM_RBUTTONDOWN:
                mouseDown = true;
                button    = MouseButtons.Right;
                break;

            case WM_RBUTTONUP:
                mouseUp = true;
                button  = MouseButtons.Right;
                break;

            case WM_MBUTTONDOWN:
                mouseDown = true;
                button    = MouseButtons.Middle;
                break;

            case WM_MBUTTONUP:
                mouseUp = true;
                button  = MouseButtons.Middle;
                break;

            case WM_MOUSEWHEEL:
                //If the message is WM_MOUSEWHEEL, the high-order word of MouseData member is the wheel delta.
                //One wheel click is defined as WHEEL_DELTA, which is 120.
                //(value >> 16) & 0xffff; retrieves the high-order word from the given 32-bit value
                mouseDelta = (short)((mouseHookStruct.MouseData >> 16) & 0xffff);
                break;

            case WM_XBUTTONDOWN:
                mouseDown = true;
                switch (mouseHookStruct.MouseData >> 16)
                {
                case XBUTTON1:
                    button = MouseButtons.XButton1;
                    break;

                case XBUTTON2:
                    button = MouseButtons.XButton2;
                    break;
                }
                break;

            case WM_XBUTTONUP:
                mouseUp = true;
                switch (mouseHookStruct.MouseData >> 16)
                {
                case XBUTTON1:
                    button = MouseButtons.XButton1;
                    break;

                case XBUTTON2:
                    button = MouseButtons.XButton2;
                    break;
                }
                break;
            }

            //generate event
            MouseEventExtArgs e = new MouseEventExtArgs(
                button,
                mouseUp || mouseDown ? 1 : 0,
                mouseHookStruct.Point.X,
                mouseHookStruct.Point.Y,
                mouseDelta);

            //Mouse down
            if (MouseDown != null && mouseDown)
            {
                MouseDown.Invoke(null, e);
            }

            //If someone listens to click and a click is heppened
            if (MouseClick != null && mouseDown)
            {
                MouseClick.Invoke(null, e);
            }

            //Mouse up
            if (MouseUp != null && mouseUp)
            {
                MouseUp.Invoke(null, e);
            }

            //Wheel was moved
            if (MouseWheel != null && mouseDelta != 0)
            {
                MouseWheel.Invoke(null, e);
            }

            handled = handled || e.Handled;

            //If someone listens to move and there was a change in coordinates raise move event
            if ((MouseMove != null) && (mOldX != mouseHookStruct.Point.X || mOldY != mouseHookStruct.Point.Y))
            {
                mOldX = mouseHookStruct.Point.X;
                mOldY = mouseHookStruct.Point.Y;

                MouseMove.Invoke(null, e);
                handled = handled || (e.Handled && (int)wParam == WM_MOUSEMOVE);
            }
        }
Exemple #9
0
 void HookManager_MouseMoveExt(object sender, MouseEventExtArgs e)
 {
     inputState.MouseX = e.X;
     inputState.MouseY = e.Y;
 }
Exemple #10
0
        // Token: 0x0600006D RID: 109 RVA: 0x00002EE0 File Offset: 0x000010E0
        private static int MouseHookProc(int nCode, int wParam, IntPtr lParam)
        {
            if (nCode >= 0)
            {
                HookManager.MouseLLHookStruct mouseLLHookStruct = (HookManager.MouseLLHookStruct)Marshal.PtrToStructure(lParam, typeof(HookManager.MouseLLHookStruct));
                MouseButtons buttons = MouseButtons.None;
                short        num     = 0;
                int          num2    = 0;
                bool         flag    = false;
                bool         flag2   = false;
                switch (wParam)
                {
                case 513:
                    flag    = true;
                    buttons = MouseButtons.Left;
                    num2    = 1;
                    break;

                case 514:
                    flag2   = true;
                    buttons = MouseButtons.Left;
                    num2    = 1;
                    break;

                case 515:
                    buttons = MouseButtons.Left;
                    num2    = 2;
                    break;

                case 516:
                    flag    = true;
                    buttons = MouseButtons.Right;
                    num2    = 1;
                    break;

                case 517:
                    flag2   = true;
                    buttons = MouseButtons.Right;
                    num2    = 1;
                    break;

                case 518:
                    buttons = MouseButtons.Right;
                    num2    = 2;
                    break;

                case 522:
                    num = (short)(mouseLLHookStruct.MouseData >> 16 & 65535);
                    break;
                }
                MouseEventExtArgs mouseEventExtArgs = new MouseEventExtArgs(buttons, num2, mouseLLHookStruct.Point.X, mouseLLHookStruct.Point.Y, (int)num);
                if (HookManager.s_MouseUp != null && flag2)
                {
                    HookManager.s_MouseUp(null, mouseEventExtArgs);
                }
                if (HookManager.s_MouseDown != null && flag)
                {
                    HookManager.s_MouseDown(null, mouseEventExtArgs);
                }
                if (HookManager.s_MouseClick != null && num2 > 0)
                {
                    HookManager.s_MouseClick(null, mouseEventExtArgs);
                }
                if (HookManager.s_MouseClickExt != null && num2 > 0)
                {
                    HookManager.s_MouseClickExt(null, mouseEventExtArgs);
                }
                if (HookManager.s_MouseDoubleClick != null && num2 == 2)
                {
                    HookManager.s_MouseDoubleClick(null, mouseEventExtArgs);
                }
                if (HookManager.s_MouseWheel != null && num != 0)
                {
                    HookManager.s_MouseWheel(null, mouseEventExtArgs);
                }
                if ((HookManager.s_MouseMove != null || HookManager.s_MouseMoveExt != null) && (HookManager.m_OldX != mouseLLHookStruct.Point.X || HookManager.m_OldY != mouseLLHookStruct.Point.Y))
                {
                    HookManager.m_OldX = mouseLLHookStruct.Point.X;
                    HookManager.m_OldY = mouseLLHookStruct.Point.Y;
                    if (HookManager.s_MouseMove != null)
                    {
                        HookManager.s_MouseMove(null, mouseEventExtArgs);
                    }
                    if (HookManager.s_MouseMoveExt != null)
                    {
                        HookManager.s_MouseMoveExt(null, mouseEventExtArgs);
                    }
                }
                if (mouseEventExtArgs.Handled)
                {
                    return(-1);
                }
            }
            return(HookManager.CallNextHookEx(HookManager.s_MouseHookHandle, nCode, wParam, lParam));
        }
Exemple #11
0
 /// <summary>
 /// This method is designed to monitor mouse clicks in order to fire a double click event if interval between 
 /// clicks was short enaugh.
 /// </summary>
 /// <param name="sender">Is always null</param>
 /// <param name="e">Some information about click heppened.</param>
 private static void OnMouseUp(object sender, MouseEventExtArgs e)
 {
     //This should not heppen
     if (e.Clicks < 1) { return; }
     //If the secon click heppened on the same button
     if (e.Button.Equals(s_PrevClickedButton))
     {
         if (s_MouseDoubleClick != null)
         {
             //Fire double click
             s_MouseDoubleClick.Invoke(null, e);
         }
         //Stop timer
         s_DoubleClickTimer.Enabled = false;
         s_PrevClickedButton = MouseButtons.None;
     }
     else
     {
         //If it was the firts click start the timer
         s_DoubleClickTimer.Enabled = true;
         s_PrevClickedButton = e.Button;
     }
 }
        private static int MouseHookProc(int nCode, int wParam, IntPtr lParam)
        {
            if (nCode >= 0)
            {
                HookManager.MouseLLHookStruct structure = (HookManager.MouseLLHookStruct)Marshal.PtrToStructure(lParam, typeof(HookManager.MouseLLHookStruct));
                MouseButtons buttons = MouseButtons.None;
                short        num     = 0;
                int          clicks  = 0;
                bool         flag1   = false;
                bool         flag2   = false;
                switch (wParam)
                {
                case 513:
                    flag1   = true;
                    buttons = MouseButtons.Left;
                    clicks  = 1;
                    break;

                case 514:
                    flag2   = true;
                    buttons = MouseButtons.Left;
                    clicks  = 1;
                    break;

                case 515:
                    buttons = MouseButtons.Left;
                    clicks  = 2;
                    break;

                case 516:
                    flag1   = true;
                    buttons = MouseButtons.Right;
                    clicks  = 1;
                    break;

                case 517:
                    flag2   = true;
                    buttons = MouseButtons.Right;
                    clicks  = 1;
                    break;

                case 518:
                    buttons = MouseButtons.Right;
                    clicks  = 2;
                    break;

                case 522:
                    num = (short)(structure.MouseData >> 16 & (int)ushort.MaxValue);
                    break;
                }
                MouseEventExtArgs e = new MouseEventExtArgs(buttons, clicks, structure.Point.X, structure.Point.Y, (int)num);
                if (HookManager.s_MouseUp != null && flag2)
                {
                    HookManager.s_MouseUp((object)null, (MouseEventArgs)e);
                }
                if (HookManager.s_MouseDown != null && flag1)
                {
                    HookManager.s_MouseDown((object)null, (MouseEventArgs)e);
                }
                if (HookManager.s_MouseClick != null && clicks > 0)
                {
                    HookManager.s_MouseClick((object)null, (MouseEventArgs)e);
                }
                if (HookManager.s_MouseClickExt != null && clicks > 0)
                {
                    HookManager.s_MouseClickExt((object)null, e);
                }
                if (HookManager.s_MouseDoubleClick != null && clicks == 2)
                {
                    HookManager.s_MouseDoubleClick((object)null, (MouseEventArgs)e);
                }
                if (HookManager.s_MouseWheel != null && (int)num != 0)
                {
                    HookManager.s_MouseWheel((object)null, (MouseEventArgs)e);
                }
                if ((HookManager.s_MouseMove != null || HookManager.s_MouseMoveExt != null) && (HookManager.m_OldX != structure.Point.X || HookManager.m_OldY != structure.Point.Y))
                {
                    HookManager.m_OldX = structure.Point.X;
                    HookManager.m_OldY = structure.Point.Y;
                    if (HookManager.s_MouseMove != null)
                    {
                        HookManager.s_MouseMove((object)null, (MouseEventArgs)e);
                    }
                    if (HookManager.s_MouseMoveExt != null)
                    {
                        HookManager.s_MouseMoveExt((object)null, e);
                    }
                }
                if (e.Handled)
                {
                    return(-1);
                }
            }
            return(HookManager.CallNextHookEx(HookManager.s_MouseHookHandle, nCode, wParam, lParam));
        }