Exemplo n.º 1
0
        private ExtraMouseActions ExtractAction(IntPtr wParam, Win32.MouseLLHookStruct hookStruct)
        {
            ExtraMouseActions action = ExtraMouseActions.None;

            switch (wParam.ToInt32())
            {
            case Win32.WM_MOUSEMOVE:
            case Win32.WM_NCMOUSEMOVE:
                action = ExtraMouseActions.Move;
                break;

            case Win32.WM_LBUTTONDOWN:
            case Win32.WM_RBUTTONDOWN:
            case Win32.WM_MBUTTONDOWN:
            case Win32.WM_XBUTTONDOWN:
            case Win32.WM_NCLBUTTONDOWN:
            case Win32.WM_NCRBUTTONDOWN:
            case Win32.WM_NCMBUTTONDOWN:
            case Win32.WM_NCXBUTTONDOWN:
                action = ExtraMouseActions.Down;
                break;

            // button up messages
            case Win32.WM_LBUTTONUP:
            case Win32.WM_RBUTTONUP:
            case Win32.WM_MBUTTONUP:
            case Win32.WM_XBUTTONUP:
            case Win32.WM_NCLBUTTONUP:
            case Win32.WM_NCRBUTTONUP:
            case Win32.WM_NCMBUTTONUP:
            case Win32.WM_NCXBUTTONUP:
                action = ExtraMouseActions.Up;
                break;

            // double click messages
            case Win32.WM_LBUTTONDBLCLK:
            case Win32.WM_RBUTTONDBLCLK:
            case Win32.WM_MBUTTONDBLCLK:
            case Win32.WM_XBUTTONDBLCLK:
            case Win32.WM_NCLBUTTONDBLCLK:
            case Win32.WM_NCRBUTTONDBLCLK:
            case Win32.WM_NCMBUTTONDBLCLK:
            case Win32.WM_NCXBUTTONDBLCLK:
                action = ExtraMouseActions.DoubleClick;
                break;

            case Win32.WM_MOUSEWHEEL:
                short mouseDelta = (short)((hookStruct.mouseData >> 16) & 0xffff);
                if (mouseDelta == 120)
                {
                    action = ExtraMouseActions.WheelDown;
                }
                else if (mouseDelta == -120)
                {
                    action = ExtraMouseActions.WheelUp;
                }
                break;
            }
            return(action);
        }
Exemplo n.º 2
0
 public ExtraMouse(IntPtr wParam, IntPtr lParam)
 {
     Win32.MouseLLHookStruct hookStruct = (Win32.MouseLLHookStruct)Marshal.PtrToStructure(lParam, typeof(Win32.MouseLLHookStruct));
     m_button = ExtractButton(wParam, hookStruct);
     m_action = ExtractAction(wParam, hookStruct);
     m_point  = new Point(hookStruct.pt.x, hookStruct.pt.y);
     m_clicks = m_action == ExtraMouseActions.DoubleClick ? 2 : 1;
 }
Exemplo n.º 3
0
        public static void SimulateMouseAction(ExtraMouseBtns button, ExtraMouseActions action, IntPtr lParam)
        {
            Win32.MouseLLHookStruct hookStruct = (Win32.MouseLLHookStruct)Marshal.PtrToStructure(lParam, typeof(Win32.MouseLLHookStruct));
            int dwData  = GetDwData(button, action);
            int dwFlags = GetMouseEventValue(button, action);

            if (action == ExtraMouseActions.DoubleClick)
            {
                //Win32.SetCursorPos(hookStruct.pt.x, hookStruct.pt.y);
                Win32.mouse_event(dwFlags, hookStruct.pt.x, hookStruct.pt.y, dwData, IntPtr.Zero);
                System.Threading.Thread.Sleep(10);
                Win32.mouse_event(dwFlags, hookStruct.pt.x, hookStruct.pt.y, dwData, IntPtr.Zero);
            }
            else
            {
                //Win32.SetCursorPos(hookStruct.pt.x, hookStruct.pt.y);
                Win32.mouse_event(dwFlags, hookStruct.pt.x, hookStruct.pt.y, dwData, IntPtr.Zero);
            }
        }
Exemplo n.º 4
0
        protected int MouseProc(int code, IntPtr wParam, IntPtr lParam)
        {
            // by convention a code < 0 means skip

            if (code < 0)
            {
                return(CallNextHookEx(m_hhook, code, wParam, lParam));
            }
            // Yield to the next hook in the chain
            //LParam = lParam;
            Debug.Write(code.ToString() + " " + wParam.ToString() + " " + lParam.ToString());
            Win32.MouseLLHookStruct mouse = (Win32.MouseLLHookStruct)Marshal.PtrToStructure(lParam, typeof(Win32.MouseLLHookStruct));
            point = new Point(mouse.pt.x, mouse.pt.y);


            if (wParam.ToInt32() == Win32.WM_LBUTTONUP)
            {
                OnLeftMouseUp();
                this.Uninstall();
            }

            //informacia o mysi sa posiela do dalsich programov (systemu) na spracovanie
            return(CallNextHookEx(m_hhook, code, wParam, lParam));
        }
Exemplo n.º 5
0
        /// <summary>
        /// The callback passed to SetWindowsHookEx
        /// </summary>
        /// <param name="code">The action code passed from the hook chain</param>
        /// <param name="wParam">The mouse message being received</param>
        /// <param name="lParam">Message paramters</param>
        /// <returns>return code to hook chain</returns>
        protected int MouseProc(int code, IntPtr wParam, IntPtr lParam)
        {
            // by convention a code < 0 means skip

            if (code < 0)
            {
                return(CallNextHookEx(m_hhook, code, wParam, lParam));
            }
            // Yield to the next hook in the chain

            // used in m_cEnableModdifier_Tick
            m_LParam = lParam;

            if (m_iSimulateCount == 0 && !m_bShouldUninstall && !m_bCrossMode)
            {
                bool handled = HandleEvent(code, wParam, lParam);
                if (handled)
                {
                    return(1);
                }
            }

            if (m_bCrossMode)
            {
                Win32.MouseLLHookStruct mouse = (Win32.MouseLLHookStruct)Marshal.PtrToStructure(lParam, typeof(Win32.MouseLLHookStruct));
                m_pCrossPosition = new Point(mouse.pt.x, mouse.pt.y);
                if (wParam.ToInt32() == Win32.WM_LBUTTONUP)
                {
                    OnCrossLeftMouseUp();
                    //StopCrossMode();
                }
            }

            // if uninstall is called and mouse button is still pressed, then wait until it is released
            if (m_bShouldUninstall)
            {
                if (m_mouseHoldDownBtn != null)
                {
                    if (CheckAndRelease(m_mouseHoldDownBtn, wParam))
                    {
                        if (m_mouseMode == MouseMode.WheelBtn)
                        {
                            //necessary to release some pushed buttons...
                            Debug.WriteLineIf(DEBUG, "Raise OnMouseTabWheel");
                            OnWheelBtnAction(m_mouseHoldDownBtn.ToMouseEvent(), ExtraMouseActions.None);
                        }
                        m_mouseHoldDownBtn = null;
                        TryUninstall();
                        return(1);
                    }
                }
                if (m_mouseExecuteBtn != null)
                {
                    if (CheckAndRelease(m_mouseExecuteBtn, wParam))
                    {
                        m_mouseExecuteBtn = null;
                        TryUninstall();
                        return(1);
                    }
                }
            }

            // pass information about mouse activity to other programs in a the system for further processing
            return(CallNextHookEx(m_hhook, code, wParam, lParam));
        }
Exemplo n.º 6
0
        private ExtraMouseBtns ExtractButton(IntPtr wParam, Win32.MouseLLHookStruct hookStruct)
        {
            ExtraMouseBtns button = ExtraMouseBtns.None;

            switch (wParam.ToInt32())
            {
            //left button messages
            case Win32.WM_LBUTTONDBLCLK:
            case Win32.WM_NCLBUTTONDBLCLK:
            case Win32.WM_LBUTTONDOWN:
            case Win32.WM_LBUTTONUP:
            case Win32.WM_NCLBUTTONDOWN:
            case Win32.WM_NCLBUTTONUP:
                button = ExtraMouseBtns.Left;
                break;

            //right button messages
            case Win32.WM_RBUTTONDBLCLK:
            case Win32.WM_NCRBUTTONDBLCLK:
            case Win32.WM_RBUTTONDOWN:
            case Win32.WM_RBUTTONUP:
            case Win32.WM_NCRBUTTONDOWN:
            case Win32.WM_NCRBUTTONUP:
                button = ExtraMouseBtns.Right;
                break;

            //middle button messages
            case Win32.WM_MBUTTONDBLCLK:
            case Win32.WM_NCMBUTTONDBLCLK:
            case Win32.WM_MBUTTONDOWN:
            case Win32.WM_MBUTTONUP:
            case Win32.WM_NCMBUTTONDOWN:
            case Win32.WM_NCMBUTTONUP:
                button = ExtraMouseBtns.Middle;
                break;

            //x button messages
            case Win32.WM_XBUTTONDBLCLK:
            case Win32.WM_NCXBUTTONDBLCLK:
            case Win32.WM_XBUTTONDOWN:
            case Win32.WM_XBUTTONUP:
            case Win32.WM_NCXBUTTONDOWN:
            case Win32.WM_NCXBUTTONUP:
                short xstate = (short)((hookStruct.mouseData >> 16) & 0xffff);
                if (xstate == Win32.XBUTTON1)
                {
                    button = ExtraMouseBtns.XButton1;
                }
                else if (xstate == Win32.XBUTTON2)
                {
                    button = ExtraMouseBtns.XButton2;
                }
                else
                {
                    button = ExtraMouseBtns.None;
                }
                break;

            case Win32.WM_MOUSEWHEEL:
                button = ExtraMouseBtns.Wheel;
                break;
            }
            return(button);
        }