Пример #1
0
        private void m_tMouseInactivityTimer_Tick(object state)
        {
            switch (m_mouseMode)
            {
            case MouseMode.Toggle:
                // OnMouseStoped is still being processed
                if (m_bToolTipVisible)
                {
                    return;
                }
                // mouse cursor was moved therefore do nothing
                if (m_pCurrentPosition != m_pPreviousPosition)
                {
                    m_pPreviousPosition  = m_pCurrentPosition;
                    m_iInactivityCounter = 0;
                    m_bToolTipWasVisible = false;
                    return;
                }
                // if tool tip was already displayed do not show it again
                if (m_pCurrentPosition == m_pPreviousPosition && m_bToolTipWasVisible)
                {
                    return;
                }

                // increment the inactivity counter
                m_iInactivityCounter += m_iInactivityTickInterval;

                int delta = m_iInactivityTickInterval / 2;
                // if counter is near to tool tip interval
                if (m_iToolTipInterval - delta < m_iInactivityCounter && m_iInactivityCounter <= m_iToolTipInterval + delta)
                {
                    m_bToolTipVisible = true;

                    Debug.WriteLineIf(DEBUG, "ToolTip_Tick Raise MouseStoped => Show Tool tip ");

                    // raise event that mouse has been stoped
                    OnMouseStoped(new EventArgs());
                    // do not stop the inactivity timer, as the mouse might be moved and stoped again

                    m_bToolTipVisible    = false;
                    m_bToolTipWasVisible = true;
                    // reset counter
                    m_iInactivityCounter = 0;
                }
                break;

            case MouseMode.DoubleBtn:
                Debug.WriteLineIf(DEBUG, "ToolTip_Tick Raise MouseStoped => Show Tool tip ");
                // stop mouse inactivity timer because it should be shown only once
                StopMouseInactivityTimer();
                // raise event to show tool tip about double button gesture
                OnDoubleBtnAction(m_mouseHoldDownBtn.ToMouseEvent(), m_mouseExecuteBtn.ToMouseEvent(), true);
                break;
            }
        }
Пример #2
0
        private void RaiseMouseEvent(ExtraMouse mouse)
        {
            if (mouse.Action != ExtraMouseActions.Move)
            {
                Debug.WriteLineIf(DEBUG, string.Format("RaiseMouseEvent button: {0}, action {1}", mouse.Button, mouse.Action));
            }
            MouseEventArgs args = mouse.ToMouseEvent();

            if (mouse.Button == ExtraMouseBtns.Wheel)
            {
                OnMouseWheel(args);
            }
            else
            {
                switch (mouse.Action)
                {
                case ExtraMouseActions.Down:
                    OnMouseDown(args);
                    break;

                case ExtraMouseActions.Click:
                    OnMouseClick(args);
                    break;

                case ExtraMouseActions.Up:
                    OnMouseUp(args);
                    break;

                case ExtraMouseActions.DoubleClick:
                    OnMouseDoubleClick(args);
                    break;

                case ExtraMouseActions.Move:
                    OnMouseMove(args);
                    break;
                }
            }
        }
Пример #3
0
        private bool HandleEvent(int code, IntPtr wParam, IntPtr lParam)
        {
            //Debug.WriteLineIf(DEBUG, string.Format("Code: {0} wParam: {1} lParam: {2}", code, wParam, lParam));
            ExtraMouse mouseEvent = new ExtraMouse(wParam, lParam);

            switch (mouseEvent.Action)
            {
            case ExtraMouseActions.Down:
                Debug.WriteLineIf(DEBUG, string.Format("{0} button _DOWN_ X: {1} Y: {2}", mouseEvent.Button, mouseEvent.Position.X, mouseEvent.Position.Y));
                if (m_mouseMode == MouseMode.Toggle || m_mouseMode == MouseMode.WheelBtn)
                {
                    return(false);
                }
                if (m_bUsingClassicCurveOnly && mouseEvent.Button != m_btnToggle)
                {
                    break;                                                                   //raise event
                }
                if (m_mouseHoldDownBtn == null)
                {
                    m_mouseHoldDownBtn = mouseEvent;
                    m_cEnableHoldDownBtn.Start();
                    return(true);
                }
                else
                {
                    if (!m_bUsingDoublebtn)
                    {
                        return(false);
                    }
                    //m_wndUnderCursor = GetWndUnderCursor.FromPoint(mouseEvent.Position);
                    m_mouseMode = MouseMode.DoubleBtn;

                    // second button has not been pushed yet
                    if (m_mouseExecuteBtn == null)
                    {
                        m_cEnableHoldDownBtn.Stop();
                        m_mouseExecuteBtn = mouseEvent;
                        Debug.WriteLineIf(DEBUG, "Start Timer OnDoubleBtnAction Notify Only");
                        RestartMouseInactivityTimer();
                        //OnDoubleBtnAction(m_mouseTrigger.ToMouseEvent(), m_mouseModifier.ToMouseEvent(), true);
                        return(true);
                    }
                    // second button was already released, use it again
                    else if (m_mouseExecuteBtn.Action == ExtraMouseActions.Up)
                    {
                        m_mouseExecuteBtn = mouseEvent;
                        Debug.WriteLineIf(DEBUG, "Start Timer OnDoubleBtnAction Notify Only");
                        RestartMouseInactivityTimer();
                        //OnDoubleBtnAction(m_mouseTrigger.ToMouseEvent(), m_mouseModifier.ToMouseEvent(), true);
                        return(true);
                    }
                }
                break;

            case ExtraMouseActions.Up:
                Debug.WriteLineIf(DEBUG, string.Format("{0} button ^UP^ X: {1} Y: {2}", mouseEvent.Button, mouseEvent.Position.X, mouseEvent.Position.Y));

                if (m_mouseMode == MouseMode.Toggle && m_mouseHoldDownBtn.Button == mouseEvent.Button)
                {
                    m_mouseHoldDownBtn = null;
                    m_mouseMode        = MouseMode.None;
                    StopMouseInactivityTimer();
                    //SimulateHiddenAction(ExtraMouseActions.Up, mouseEvent.Position);
                    RaiseMouseEvent(mouseEvent);
                    return(true);
                }
                else if (m_mouseMode == MouseMode.WheelBtn && m_mouseHoldDownBtn.Button == mouseEvent.Button)
                {
                    Debug.WriteLineIf(DEBUG, "Raise OnWheelBtnAction - Hold-down button released");
                    OnWheelBtnAction(m_mouseHoldDownBtn.ToMouseEvent(), ExtraMouseActions.None);
                    m_mouseHoldDownBtn = null;
                    m_mouseMode        = MouseMode.None;
                    return(true);
                }

                //raise event...
                if (m_mouseHoldDownBtn == null)
                {
                    RaiseMouseEvent(mouseEvent);
                    if (isEventCancelled())
                    {
                        return(true);
                    }
                    else
                    {
                        return(false);
                    }
                }

                if (m_mouseHoldDownBtn.Button == mouseEvent.Button)
                {
                    StopMouseInactivityTimer();
                    m_cEnableHoldDownBtn.Stop();

                    if (m_mouseExecuteBtn == null)
                    {
                        // mouse click action is raised
                        lock (this)
                        {
                            //RaiseMouseEvent(m_mouseTrigger); //action down
                            //SimulateMouseAction(m_mouseTrigger);
                            //RaiseMouseEvent(mouseEvent); //action up
                            //SimulateMouseAction(mouseEvent.Button, ExtraMouseActions.Click);

                            RaiseMouseEvent(new ExtraMouse(m_mouseHoldDownBtn.Button, ExtraMouseActions.Click, m_mouseHoldDownBtn.Position));
                            if (!isEventCancelled())
                            {
                                SimulateMouseAction(mouseEvent.Button, ExtraMouseActions.Down);
                                System.Threading.Thread.Sleep(10);
                                SimulateMouseAction(mouseEvent.Button, ExtraMouseActions.Up);
                            }
                        }
                        m_mouseHoldDownBtn = null;
                        m_mouseMode        = MouseMode.None;
                        return(true);
                    }
                    else if (m_mouseExecuteBtn.Action == ExtraMouseActions.Down)
                    {
                        Debug.WriteLineIf(DEBUG, "Trigger ^UP^ & Modifier _DOWN_ => Swap MODIFIER & TRIGGER");
                        m_mouseHoldDownBtn = m_mouseExecuteBtn;
                        m_mouseExecuteBtn  = mouseEvent;
                        //m_mouseMode = MouseMode.DoubleBtn;
                        return(true);
                    }
                    else
                    {
                        m_mouseExecuteBtn  = null;
                        m_mouseHoldDownBtn = null;
                        m_mouseMode        = MouseMode.None;
                        return(true);
                    }
                }
                else if (m_mouseExecuteBtn != null)
                {
                    if (m_mouseExecuteBtn.Button == mouseEvent.Button)
                    {
                        StopMouseInactivityTimer();

                        m_mouseExecuteBtn = mouseEvent;
                        if (m_mouseHoldDownBtn != null)
                        {
                            //m_wndUnderCursor = GetWndUnderCursor.FromPoint(mouseEvent.Position);

                            Debug.WriteLineIf(DEBUG, "Raise OnDoubleBtnAction");
                            OnDoubleBtnAction(m_mouseHoldDownBtn.ToMouseEvent(), m_mouseExecuteBtn.ToMouseEvent(), false);
                            //m_mouseModifier = null;
                            return(true);
                        }
                    }
                }
                break;

            case ExtraMouseActions.WheelDown:
            case ExtraMouseActions.WheelUp:
                if (!m_bUsingWheelBtn)
                {
                    return(false);
                }

                if (m_mouseHoldDownBtn != null && m_mouseMode == MouseMode.None)
                {
                    m_mouseMode = MouseMode.WheelBtn;
                    m_cEnableHoldDownBtn.Stop();
                    //m_wndUnderCursor = GetWndUnderCursor.FromPoint(m_mouseTrigger.Position);
                    Debug.WriteLineIf(DEBUG, "Raise OnWheelBtnAction");
                    OnWheelBtnAction(m_mouseHoldDownBtn.ToMouseEvent(), mouseEvent.Action);
                    return(true);
                }
                else if (m_mouseMode == MouseMode.WheelBtn)
                {
                    Debug.WriteLineIf(DEBUG, "Raise OnWheelBtnAction");
                    OnWheelBtnAction(m_mouseHoldDownBtn.ToMouseEvent(), mouseEvent.Action);
                    return(true);
                }
                break;

            case ExtraMouseActions.Move:
                if (m_mouseHoldDownBtn != null && m_mouseMode == MouseMode.None)
                {
                    if (IsDistanceLessThan(m_mouseHoldDownBtn.Position, mouseEvent.Position, m_sensibleZone))
                    {
                        return(false);
                    }

                    if (m_mouseHoldDownBtn.Button == m_btnToggle && m_bUsingClassicCurve)
                    {
                        m_mouseMode = MouseMode.Toggle;
                        m_cEnableHoldDownBtn.Stop();
                        Debug.WriteLineIf(DEBUG, "Mouse start moving & ToggleBtn _DOWN_ => RaiseMouseHookEvent()");
                        OnMouseDownGesture(m_mouseHoldDownBtn.ToMouseEvent());
                        StartMouseInactivityTimer();
                        //m_wndUnderCursor = GetWndUnderCursor.FromPoint(m_mouseTrigger.Position);
                        //SimulateHiddenAction(ExtraMouseActions.Down, m_mouseTrigger.Position);
                        //return true;
                    }
                    else
                    {
                        m_mouseMode = MouseMode.None;
                        m_cEnableHoldDownBtn.Stop();
                        ExtraMouse mouseTemp = new ExtraMouse(m_mouseHoldDownBtn);     //backup mouse trigger so it can be changed during this process
                        RaiseMouseEvent(mouseTemp);
                        if (!isEventCancelled())
                        {
                            SimulateMouseAction(mouseTemp);
                        }
                        m_mouseHoldDownBtn = null;
                    }
                }
                else if (m_mouseMode == MouseMode.Toggle)
                {
                    m_pCurrentPosition = mouseEvent.Position;
                }
                break;
            }

            if (code == Win32.HC_ACTION)
            {
                RaiseMouseEvent(mouseEvent);
            }

            return(false);
        }
Пример #4
0
        private bool HandleEvent(int code, IntPtr wParam, IntPtr lParam)
        {
            //Debug.WriteLineIf(DEBUG, string.Format("Code: {0} wParam: {1} lParam: {2}", code, wParam, lParam));
            ExtraMouse mouseEvent = new ExtraMouse(wParam, lParam);
            switch (mouseEvent.Action)
            {
                case ExtraMouseActions.Down:
                    Debug.WriteLineIf(DEBUG, string.Format("{0} button _DOWN_ X: {1} Y: {2}", mouseEvent.Button, mouseEvent.Position.X, mouseEvent.Position.Y));
                    if (m_mouseMode == MouseMode.Toggle || m_mouseMode == MouseMode.WheelBtn) return false;
                    if (m_bUsingClassicCurveOnly && mouseEvent.Button != m_btnToggle) break; //raise event

                    if (m_mouseHoldDownBtn == null)
                    {
                        m_mouseHoldDownBtn = mouseEvent;
                        m_cEnableHoldDownBtn.Start();
                        return true;
                    }
                    else
                    {
                        if (!m_bUsingDoublebtn) return false;
                        //m_wndUnderCursor = GetWndUnderCursor.FromPoint(mouseEvent.Position);
                        m_mouseMode = MouseMode.DoubleBtn;
                        
                        // second button has not been pushed yet
                        if (m_mouseExecuteBtn == null)
                        {
                            m_cEnableHoldDownBtn.Stop();
                            m_mouseExecuteBtn = mouseEvent;
                            Debug.WriteLineIf(DEBUG, "Start Timer OnDoubleBtnAction Notify Only");
                            RestartMouseInactivityTimer();                    
                            //OnDoubleBtnAction(m_mouseTrigger.ToMouseEvent(), m_mouseModifier.ToMouseEvent(), true);
                            return true;
                        }
                        // second button was already released, use it again
                        else if (m_mouseExecuteBtn.Action == ExtraMouseActions.Up)
                        {
                            m_mouseExecuteBtn = mouseEvent;
                            Debug.WriteLineIf(DEBUG, "Start Timer OnDoubleBtnAction Notify Only");
                            RestartMouseInactivityTimer();
                            //OnDoubleBtnAction(m_mouseTrigger.ToMouseEvent(), m_mouseModifier.ToMouseEvent(), true);
                            return true;
                        }
                    }
                    break;
                case ExtraMouseActions.Up:
                    Debug.WriteLineIf(DEBUG, string.Format("{0} button ^UP^ X: {1} Y: {2}", mouseEvent.Button, mouseEvent.Position.X, mouseEvent.Position.Y));
                    
                    if (m_mouseMode == MouseMode.Toggle && m_mouseHoldDownBtn.Button == mouseEvent.Button)
                    {
                        m_mouseHoldDownBtn = null;
                        m_mouseMode = MouseMode.None;
                        StopMouseInactivityTimer();
                        //SimulateHiddenAction(ExtraMouseActions.Up, mouseEvent.Position);
                        RaiseMouseEvent(mouseEvent);
                        return true;
                    }
                    else if (m_mouseMode == MouseMode.WheelBtn && m_mouseHoldDownBtn.Button == mouseEvent.Button)
                    {
                        Debug.WriteLineIf(DEBUG, "Raise OnWheelBtnAction - Hold-down button released");
                        OnWheelBtnAction(m_mouseHoldDownBtn.ToMouseEvent(), ExtraMouseActions.None);
                        m_mouseHoldDownBtn = null;
                        m_mouseMode = MouseMode.None;                        
                        return true;
                    }

                    //raise event...
                    if (m_mouseHoldDownBtn == null)
                    {
                        RaiseMouseEvent(mouseEvent);
                        if (isEventCancelled())
                            return true;
                        else        
                            return false;
                    }

                    if (m_mouseHoldDownBtn.Button == mouseEvent.Button)
                    {
                        StopMouseInactivityTimer();
                        m_cEnableHoldDownBtn.Stop();
                        
                        if (m_mouseExecuteBtn == null)
                        {
                            // mouse click action is raised
                            lock (this)
                            {
                                //RaiseMouseEvent(m_mouseTrigger); //action down
                                //SimulateMouseAction(m_mouseTrigger);
                                //RaiseMouseEvent(mouseEvent); //action up
                                //SimulateMouseAction(mouseEvent.Button, ExtraMouseActions.Click);

                                RaiseMouseEvent(new ExtraMouse(m_mouseHoldDownBtn.Button, ExtraMouseActions.Click, m_mouseHoldDownBtn.Position));
                                if (!isEventCancelled())
                                {
                                    SimulateMouseAction(mouseEvent.Button, ExtraMouseActions.Down);
                                    System.Threading.Thread.Sleep(10);
                                    SimulateMouseAction(mouseEvent.Button, ExtraMouseActions.Up);
                                }
                            }
                            m_mouseHoldDownBtn = null;
                            m_mouseMode = MouseMode.None;
                            return true;
                        }
                        else if (m_mouseExecuteBtn.Action == ExtraMouseActions.Down)
                        {
                            Debug.WriteLineIf(DEBUG, "Trigger ^UP^ & Modifier _DOWN_ => Swap MODIFIER & TRIGGER");
                            m_mouseHoldDownBtn = m_mouseExecuteBtn;
                            m_mouseExecuteBtn = mouseEvent;
                            //m_mouseMode = MouseMode.DoubleBtn;
                            return true;
                        }
                        else
                        {
                            m_mouseExecuteBtn = null;
                            m_mouseHoldDownBtn = null;
                            m_mouseMode = MouseMode.None;
                            return true;
                        }
                    }
                    else if (m_mouseExecuteBtn != null)
                    {
                        if (m_mouseExecuteBtn.Button == mouseEvent.Button)
                        {
                            StopMouseInactivityTimer();

                            m_mouseExecuteBtn = mouseEvent;
                            if (m_mouseHoldDownBtn != null)
                            {                                
                                //m_wndUnderCursor = GetWndUnderCursor.FromPoint(mouseEvent.Position);

                                Debug.WriteLineIf(DEBUG, "Raise OnDoubleBtnAction");
                                OnDoubleBtnAction(m_mouseHoldDownBtn.ToMouseEvent(), m_mouseExecuteBtn.ToMouseEvent(), false);
                                //m_mouseModifier = null;
                                return true;
                            }
                        }
                    }
                    break;
                case ExtraMouseActions.WheelDown:
                case ExtraMouseActions.WheelUp:
                    if (!m_bUsingWheelBtn) return false;

                    if (m_mouseHoldDownBtn != null && m_mouseMode == MouseMode.None)
                    {
                        m_mouseMode = MouseMode.WheelBtn;
                        m_cEnableHoldDownBtn.Stop();
                        //m_wndUnderCursor = GetWndUnderCursor.FromPoint(m_mouseTrigger.Position);
                        Debug.WriteLineIf(DEBUG, "Raise OnWheelBtnAction");
                        OnWheelBtnAction(m_mouseHoldDownBtn.ToMouseEvent(), mouseEvent.Action);
                        return true;
                    }
                    else if (m_mouseMode == MouseMode.WheelBtn)
                    {
                        Debug.WriteLineIf(DEBUG, "Raise OnWheelBtnAction");
                        OnWheelBtnAction(m_mouseHoldDownBtn.ToMouseEvent(), mouseEvent.Action);
                        return true;
                    }
                    break;
                case ExtraMouseActions.Move:
                    if (m_mouseHoldDownBtn != null && m_mouseMode == MouseMode.None)
                    {
                        if (IsDistanceLessThan(m_mouseHoldDownBtn.Position, mouseEvent.Position, m_sensibleZone))
                            return false;

                        if (m_mouseHoldDownBtn.Button == m_btnToggle && m_bUsingClassicCurve)
                        {
                            m_mouseMode = MouseMode.Toggle;
                            m_cEnableHoldDownBtn.Stop();
                            Debug.WriteLineIf(DEBUG, "Mouse start moving & ToggleBtn _DOWN_ => RaiseMouseHookEvent()");
                            OnMouseDownGesture(m_mouseHoldDownBtn.ToMouseEvent());
                            StartMouseInactivityTimer();
                            //m_wndUnderCursor = GetWndUnderCursor.FromPoint(m_mouseTrigger.Position);
                            //SimulateHiddenAction(ExtraMouseActions.Down, m_mouseTrigger.Position);
                            //return true;
                        }
                        else
                        {
                            m_mouseMode = MouseMode.None;
                            m_cEnableHoldDownBtn.Stop();
                            ExtraMouse mouseTemp = new ExtraMouse(m_mouseHoldDownBtn); //backup mouse trigger so it can be changed during this process
                            RaiseMouseEvent(mouseTemp);
                            if (!isEventCancelled())                                
                                SimulateMouseAction(mouseTemp);                            
                            m_mouseHoldDownBtn = null;
                        }
                    }
                    else if (m_mouseMode == MouseMode.Toggle)
                    {
                        m_pCurrentPosition = mouseEvent.Position;                      
                    }
                    break;
            }

            if (code == Win32.HC_ACTION)
                RaiseMouseEvent(mouseEvent);

            return false;

        }
Пример #5
0
 private void RaiseMouseEvent(ExtraMouse mouse)
 {
     if (mouse.Action != ExtraMouseActions.Move)
         Debug.WriteLineIf(DEBUG, string.Format("RaiseMouseEvent button: {0}, action {1}", mouse.Button, mouse.Action));
     MouseEventArgs args = mouse.ToMouseEvent();
     if (mouse.Button == ExtraMouseBtns.Wheel)
     {
         OnMouseWheel(args);
     }
     else
     {
         switch (mouse.Action)
         {
             case ExtraMouseActions.Down:
                 OnMouseDown(args);
                 break;
             case ExtraMouseActions.Click:
                 OnMouseClick(args);
                 break;
             case ExtraMouseActions.Up:
                 OnMouseUp(args);
                 break;                    
             case ExtraMouseActions.DoubleClick:
                 OnMouseDoubleClick(args);
                 break;
             case ExtraMouseActions.Move:
                 OnMouseMove(args);
                 break;
         }
     }
 }