Esempio n. 1
0
        public void SetRotateButtons(bool bLeft, bool bMiddle, bool bRight, bool bRotateWithoutButtonDown)
        {
            m_nActiveButtonMask = (bLeft ? MouseKeys.LeftButton : 0) |
                                  (bMiddle ? MouseKeys.MiddleButton : 0) |
                                  (bRight ? MouseKeys.RightButton : 0);

            m_bRotateWithoutButtonDown = bRotateWithoutButtonDown;
        }
Esempio n. 2
0
        public void UnregisterMouseListener(MouseKeys key)
        {
            if (Disposed)
            {
                throw new ObjectDisposedException("Attempted to access InputHandler after object is disposed!");
            }

            MouseListeners.Remove(key);
        }
Esempio n. 3
0
 public static void PressButton(MouseKeys mKey, int Delay = 0)
 {
     ButtonDown(mKey);
     if (Delay > 0)
     {
         System.Threading.Thread.Sleep(Delay);
     }
     ButtonUp(mKey);
 }
Esempio n. 4
0
        /// <summary>
        /// Sends a mouse press signal (down and up).
        /// </summary>
        /// <param name="mKey">The key to press.</param>
        /// <param name="delay">The delay to set between the events.</param>
        public static void PressButton(MouseKeys mKey, int delay = 0)
        {
            ButtonDown(mKey);

            if (delay > 0)
            {
                Thread.Sleep(delay);
            }

            ButtonUp(mKey);
        }
Esempio n. 5
0
 public bool IsKeyDown(MouseKeys mousekey)
 {
     switch (mousekey)
     {
         case MouseKeys.Left:
             return Mouse.GetState().LeftButton == ButtonState.Pressed;
         case MouseKeys.Right:
             return Mouse.GetState().RightButton == ButtonState.Pressed;
         default:
             return false;
     }
 }
Esempio n. 6
0
        private void PictureBox1_MouseDown(object sender, MouseEventArgs e)
        {
            //var a = g;
            //leftPressed = true;
            //mouseFlags = 0;
            if (e.Button.HasFlag(MouseButtons.Left))
            {
                mouseFlags |= MouseKeys.Left;
            }

            if (e.Button.HasFlag(MouseButtons.Middle))
            {
                mouseFlags |= MouseKeys.Middle;
            }

            if (e.Button.HasFlag(MouseButtons.Right))
            {
                mouseFlags |= MouseKeys.Right;
            }

            if (e.Delta > 0)
            {
                mouseFlags |= MouseKeys.ScrollUp;
            }

            if (e.Delta < 0)
            {
                mouseFlags |= MouseKeys.ScrollDown;
            }

            if (!hasTurn)
            {
                if (e.Button.HasFlag(MouseButtons.Left))
                {
                    Send("turn");
                }
            }
            else
            {
                Console.WriteLine("You pressed the " + mouseFlags + " mouse button!");
                Send("mouse", (int)(e.X * scalex), (int)(e.Y * scaley), (int)mouseFlags);
                if (!mouseFlags.HasFlag(MouseKeys.ScrollUp) && !mouseFlags.HasFlag(MouseKeys.ScrollDown))
                {
                    return;
                }

                mouseFlags &= ~MouseKeys.ScrollDown;
                mouseFlags &= ~MouseKeys.ScrollUp;
                Send("mouse", (int)(e.X * scalex), (int)(e.Y * scaley), (int)mouseFlags);
            }
        }
Esempio n. 7
0
        public void RegisterMouseListener(MouseKeys key)
        {
            if (Disposed)
            {
                throw new ObjectDisposedException("Attempted to access InputHandler after object is disposed!");
            }

            if (MouseListeners.Contains(key))
            {
                return;
            }

            MouseListeners.Add(key);
        }
Esempio n. 8
0
 public bool mouseStillUp(MouseKeys mouseKey)
 {
     if (mouseKey == MouseKeys.LEFT_BUTTON)
     {
         return(!(newMouseState.LeftButton == ButtonState.Pressed) && !(oldMouseState.LeftButton == ButtonState.Pressed));
     }
     else if (mouseKey == MouseKeys.MIDDLE_BUTTON)
     {
         return(!(newMouseState.MiddleButton == ButtonState.Pressed) && !(oldMouseState.MiddleButton == ButtonState.Pressed));
     }
     else
     {
         return(!(newMouseState.RightButton == ButtonState.Pressed) && !(oldMouseState.RightButton == ButtonState.Pressed));
     }
 }
Esempio n. 9
0
        /// <summary>
        /// Send a mouse button down signal.
        /// </summary>
        /// <param name="mKey">The mouse key to send as mouse button down.</param>
        /// <remarks></remarks>
        public static void ButtonDown(MouseKeys mKey)
        {
            switch (mKey)
            {
            case MouseKeys.Left:
                SendButton(MouseButtons.LeftDown);
                return;

            case MouseKeys.Right:
                SendButton(MouseButtons.RightDown);
                return;

            case MouseKeys.Middle:
                SendButton(MouseButtons.MiddleDown);
                return;
            }
        }
Esempio n. 10
0
        /// <summary>
        /// Send a mouse button up signal.
        /// </summary>
        /// <param name="mKey">The mouse key to send as mouse button up.</param>
        /// <remarks></remarks>
        public static void ButtonUp(MouseKeys mKey)
        {
            switch (mKey)
            {
            case MouseKeys.Left:
                SendButton(MouseButtons.LeftUp);
                return;

            case MouseKeys.Right:
                SendButton(MouseButtons.RightUp);
                return;

            case MouseKeys.Middle:
                SendButton(MouseButtons.MiddleUp);
                return;
            }
        }
Esempio n. 11
0
            /// <summary>
            /// Move Mouse And Click Left
            /// </summary>
            /// <param name="x"></param>
            /// <param name="y"></param>
            /// <param name="mk"></param>
            ///
            public static void MoveCursorAndDo(int x, int y, MouseKeys mk = MouseKeys.LEFT)
            {
                INPUT mouseInput = new INPUT();

                mouseInput.type              = SendInputEventType.InputMouse;
                mouseInput.mkhi.mi.dx        = x * 65536 / GetSystemMetrics(SystemMetric.SM_CXSCREEN);
                mouseInput.mkhi.mi.dy        = y * 65536 / GetSystemMetrics(SystemMetric.SM_CYSCREEN);
                mouseInput.mkhi.mi.mouseData = 0;
                mouseInput.mkhi.mi.dwFlags   = MouseEventFlags.MOUSEEVENTF_MOVE | MouseEventFlags.MOUSEEVENTF_ABSOLUTE;
                SendInput(1, ref mouseInput, Marshal.SizeOf(new INPUT()));
                if (mk == MouseKeys.NOTCLICK)
                {
                    return;
                }
                if (mk == MouseKeys.RIGHT)
                {
                    mouseInput.mkhi.mi.dwFlags = MouseEventFlags.MOUSEEVENTF_RIGHTDOWN;
                }
                else if (mk == MouseKeys.LEFT)
                {
                    mouseInput.mkhi.mi.dwFlags = MouseEventFlags.MOUSEEVENTF_LEFTDOWN;
                }
                else if (mk == MouseKeys.WHEELUP)
                {
                    mouse_event(2048, 0, 0, 120, (UIntPtr)0);
                    return;
                }
                SendInput(1, ref mouseInput, Marshal.SizeOf(new INPUT()));
                if (mk == MouseKeys.RIGHT)
                {
                    mouseInput.mkhi.mi.dwFlags = MouseEventFlags.MOUSEEVENTF_RIGHTUP;
                }
                else if (mk == MouseKeys.LEFT)
                {
                    mouseInput.mkhi.mi.dwFlags = MouseEventFlags.MOUSEEVENTF_LEFTUP;
                }
                else if (mk == MouseKeys.WHEELDOWN)
                {
                    mouse_event(2048, 0, 0, -120, (UIntPtr)0);
                    return;
                }
                SendInput(1, ref mouseInput, Marshal.SizeOf(new INPUT()));
            }
Esempio n. 12
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="x"></param>
        /// <param name="y"></param>
        /// <param name="waitTime"></param>
        public void DoClickPoint(double waitTime = 0.1, double x = 0, double y = 0, MouseKeys mk = MouseKeys.LEFT)
        {
            var ptClick = new System.Windows.Point();

            if (x == 0 && y == 0)
            {
                try
                {
                    ptClick = AutomationElement.GetClickablePoint();
                }
                catch
                {
                    try
                    {
                        ptClick = new Point((AutomationElement.Current.BoundingRectangle.Left + 2), (AutomationElement.Current.BoundingRectangle.Top + 2));
                    }
                    catch (Exception ex)
                    {
                        throw new Exception("Failed to GetClickablePoint. " + ex);
                    }
                }
            }
            else
            {
                try
                {
                    ptClick = new Point((AutomationElement.Current.BoundingRectangle.Left), (AutomationElement.Current.BoundingRectangle.Top));
                }
                catch (Exception ex)
                {
                    throw new Exception("Failed to GetBoundingRectangle. " + ex);
                }
            }
            try
            {
                MoveCursorAndDo((int)ptClick.X + (int)x, (int)ptClick.Y + (int)y, mk);
            }
            catch (Exception ex)
            {
                throw new Exception("Click point error. " + ex);
            }
            Thread.Sleep((int)(waitTime * 1000));
        }
Esempio n. 13
0
            public ButtonState this[MouseKeys index]
            {
                get
                {
                    switch (index)
                    {
                    case MouseKeys.LEFT:    return(LEFT);

                    case MouseKeys.MIDDLE:  return(MIDDLE);

                    case MouseKeys.RIGHT:   return(RIGHT);

                    case MouseKeys.BTN_4:   return(MOUSE_4);

                    case MouseKeys.BTN_5:   return(MOUSE_5);

                    default:                return(LEFT);
                    }
                }
            }
Esempio n. 14
0
        /// <summary>
        /// Send a mouse button up signal.
        /// </summary>
        /// <param name="mKey">The mouse key to send as mouse button up.</param>
        public static void ButtonUp(MouseKeys mKey)
        {
            switch (mKey)
            {
            case MouseKeys.Left:
                SendButton(MouseButtons.LeftUp);
                break;

            case MouseKeys.Right:
                SendButton(MouseButtons.RightUp);
                break;

            case MouseKeys.Middle:
                SendButton(MouseButtons.MiddleUp);
                break;

            default:
                break;
            }
        }
        private static KeyDisjunction ParseConjunction(string disjunction)
        {
            KeyDisjunction keyDisjunction = new KeyDisjunction();

            foreach (string conjunction in disjunction.Split('|'))
            {
                KeyConjunction keyConjunction = new KeyConjunction();
                foreach (string term in conjunction.Split('+'))
                {
                    string key    = term.Trim();
                    bool   isUp   = false;
                    bool   isEdge = false;
                    if (key.Contains("^"))
                    {
                        isUp = true;
                        key  = key.Replace("^", "");
                    }
                    if (key.Contains("~"))
                    {
                        isEdge = true;
                        key    = key.Replace("~", "");
                    }
                    SignalState state = new SignalState(isUp, isEdge);
                    if (Keys.TryParse(key, true, out Keys keyboardKey))
                    {
                        keyConjunction[keyboardKey] = state;
                    }
                    else if (MouseKeys.TryParse(key, true, out MouseKeys mouseKey))
                    {
                        keyConjunction[mouseKey] = state;
                    }
                    else
                    {
                        Console.Error.WriteLine(String.Format("ERROR! - Unable to parse key: {0}", key));
                    }
                }
                keyDisjunction.Add(keyConjunction);
            }
            return(keyDisjunction);
        }
Esempio n. 16
0
        private void PictureBox1_MouseUp(object sender, MouseEventArgs e)
        {
            //mouseFlags = 0;
            if (e.Button.HasFlag(MouseButtons.Left))
            {
                mouseFlags &= ~MouseKeys.Left;
            }

            if (e.Button.HasFlag(MouseButtons.Middle))
            {
                mouseFlags &= ~MouseKeys.Middle;
            }

            if (e.Button.HasFlag(MouseButtons.Right))
            {
                mouseFlags &= ~MouseKeys.Right;
            }
            //if (e.Delta != 0)
            //{
            //    Console.WriteLine(e.Delta);
            //}
            //if (e.Delta > 0)
            //{
            //    mouseFlags &= ~MouseKeys.ScrollUp;
            //}
            //if (e.Delta < 0)
            //{
            //    mouseFlags |= MouseKeys.ScrollDown;
            //}

            if (hasTurn)
            {
                //Console.WriteLine(mouseFlags);
                Send("mouse", (int)(e.X * scalex), (int)(e.Y * scaley), (int)mouseFlags);
            }

            //mouseFlags = 0;
        }
Esempio n. 17
0
        public static void ButtonDown(MouseKeys mKey)
        {
            switch (mKey)
            {
            case MouseKeys.Left:
            {
                SendButton(MouseButtons.LeftDown);
                break;
            }

            case MouseKeys.Right:
            {
                SendButton(MouseButtons.RightDown);
                break;
            }

            case MouseKeys.Middle:
            {
                SendButton(MouseButtons.MiddleDown);
                break;
            }
            }
        }
Esempio n. 18
0
 public static IntPtr WParam(Int16 wheelDelta, MouseKeys mouseKeys)
 {
     return(IntPtr.Zero + (wheelDelta << 16) + (Int16)mouseKeys);
 }
 public MouseCommand(MouseKeys btn, InputState state, Point pos)
 {
     Button   = btn;
     State    = state;
     Position = pos;
 }
Esempio n. 20
0
 /// <summary>
 /// Returns whether the mouse key was pressed down.
 /// </summary>
 /// <param name="key">The mouse key to check.</param>
 /// <returns>Whether the mouse key was pressed down.</returns>
 public bool IsMouseKeyDown(MouseKeys key)
 {
     return(MousePressed[(int)key]);
 }
Esempio n. 21
0
 public static bool MouseKeyHasBeenReleased(MouseKeys key)
 {
     return(_actualFrameMouseState[key] == ButtonState.Released && _lastFrameMouseState[key] == ButtonState.Pressed);
 }
Esempio n. 22
0
 /// <summary>
 /// Returns whether the mouse key was let go.
 /// </summary>
 /// <param name="key">The mouse key to check.</param>
 /// <returns>Whether the mouse key was let go.</returns>
 public bool IsMouseKeyUp(MouseKeys key)
 {
     return(MouseUp[(int)key]);
 }
Esempio n. 23
0
 public static bool MouseKeyIsUp(MouseKeys key)
 {
     return(_actualFrameMouseState[key] == ButtonState.Released);
 }
Esempio n. 24
0
        private void checkForInput()
        {
            Keys moveRight     = SettingsManager.getInstance.getKeyboardKeys().ElementAt(0);
            Keys moveLeft      = SettingsManager.getInstance.getKeyboardKeys().ElementAt(1);
            Keys moveDown      = SettingsManager.getInstance.getKeyboardKeys().ElementAt(2);
            Keys moveUp        = SettingsManager.getInstance.getKeyboardKeys().ElementAt(3);
            Keys moveRight2    = SettingsManager.getInstance.getKeyboardKeys().ElementAt(4);
            Keys moveLeft2     = SettingsManager.getInstance.getKeyboardKeys().ElementAt(5);
            Keys moveDown2     = SettingsManager.getInstance.getKeyboardKeys().ElementAt(6);
            Keys moveUp2       = SettingsManager.getInstance.getKeyboardKeys().ElementAt(7);
            Keys quit          = SettingsManager.getInstance.getKeyboardKeys().ElementAt(8);
            Keys showInventory = SettingsManager.getInstance.getKeyboardKeys().ElementAt(9);
            Keys showQuests    = SettingsManager.getInstance.getKeyboardKeys().ElementAt(10);

            MouseKeys action = SettingsManager.getInstance.getMouseKeys().ElementAt(0);

            if (Input.getInstance.keyDown(quit))
            {
                SceneManager.getInstance.setGameState(GameState.IN_INGAMEMENU);
                SceneManager.getInstance.getMenuManager().findIndex("InGameMenu");
            }

            bool [] movement = { false, false, false, false, false };
            bool    doAction = false;

            if (Input.getInstance.keyDown(moveLeft) || Input.getInstance.keyStillDown(moveLeft) ||
                Input.getInstance.keyDown(moveLeft2) || Input.getInstance.keyStillDown(moveLeft2))
            {
                movement[0] = true;
            }
            if (Input.getInstance.keyDown(moveRight) || Input.getInstance.keyStillDown(moveRight) ||
                Input.getInstance.keyDown(moveRight2) || Input.getInstance.keyStillDown(moveRight2))
            {
                movement[1] = true;
            }
            if (Input.getInstance.keyDown(moveUp) || Input.getInstance.keyStillDown(moveUp) ||
                Input.getInstance.keyDown(moveUp2) || Input.getInstance.keyStillDown(moveUp2))
            {
                movement[2] = true;
            }
            if (Input.getInstance.keyDown(moveDown) || Input.getInstance.keyStillDown(moveDown) ||
                Input.getInstance.keyDown(moveDown2) || Input.getInstance.keyStillDown(moveDown2))
            {
                movement[3] = true;
            }

            if (Input.getInstance.keyStillDown(moveLeft) || Input.getInstance.keyStillDown(moveRight) ||
                Input.getInstance.keyStillDown(moveUp) || Input.getInstance.keyStillDown(moveDown) ||
                Input.getInstance.keyStillDown(moveLeft2) || Input.getInstance.keyStillDown(moveRight2) ||
                Input.getInstance.keyStillDown(moveUp2) || Input.getInstance.keyStillDown(moveDown2))
            {
                if (AudioManager.getInstance.isStopped(new Sound("Walk grass")))
                {
                    AudioManager.getInstance.playSound(new Sound("Walk grass"), AudioManager.WALK_GRASS);
                }

                // movement[4] = true;
            }

            if (!Input.getInstance.keyStillDown(moveLeft) && !Input.getInstance.keyStillDown(moveRight) &&
                !Input.getInstance.keyStillDown(moveUp) && !Input.getInstance.keyStillDown(moveDown) &&
                !Input.getInstance.keyStillDown(moveLeft2) && !Input.getInstance.keyStillDown(moveRight2) &&
                !Input.getInstance.keyStillDown(moveUp2) && !Input.getInstance.keyStillDown(moveDown2))
            {
                AudioManager.getInstance.stopSound(new Sound("Walk grass"));
            }

            if (Input.getInstance.keyDown(showInventory))
            {
                SceneManager.getInstance.getPlayer1().setOpenInventory(!SceneManager.getInstance.getPlayer1().getOpenInventory());
            }

            if (Input.getInstance.keyDown(showQuests))
            {
                SceneManager.getInstance.getPlayer1().setOpenQuests(!SceneManager.getInstance.getPlayer1().getOpenQuests());
            }

            if (Input.getInstance.mouseDown(action))
            {
                doAction = true;
            }

            // DEBUG
            if (Input.getInstance.keyDown(Keys.D1))
            {
                --fps;
                //Console.WriteLine("New FPS: " + fps);
                TargetElapsedTime = TimeSpan.FromSeconds(1.0f / fps);
            }

            if (Input.getInstance.keyDown(Keys.D2))
            {
                ++fps;
                //Console.WriteLine("New FPS: " + fps);
                TargetElapsedTime = TimeSpan.FromSeconds(1.0f / fps);
            }

            // DEBUG
            if (Input.getInstance.keyDown(Keys.D3))
            {
                debugDrawCollision = !debugDrawCollision;
            }

            SceneManager.getInstance.getPlayer1().setMovement(movement);
            SceneManager.getInstance.getPlayer1().setDoAction(doAction);
            SceneManager.getInstance.getPlayer1().setOpenInventory(SceneManager.getInstance.getPlayer1().getOpenInventory());
            SceneManager.getInstance.getPlayer1().setOpenQuests(SceneManager.getInstance.getPlayer1().getOpenQuests());
        }
Esempio n. 25
0
 /// <summary>
 /// Returns whether the mouse key is being held down.
 /// </summary>
 /// <param name="key">The mouse key to check.</param>
 /// <returns>Whether the mouse key is being held down.</returns>
 public bool IsMouseKeyHeld(MouseKeys key)
 {
     return(MouseHeld[(int)key]);
 }
Esempio n. 26
0
 public SdkFirstPersonCamera()
 {
     m_nActiveButtonMask = MouseKeys.LeftButton | MouseKeys.RightButton | MouseKeys.Shift;
 }
Esempio n. 27
0
 /// <summary>
 /// Send a mouse button up signal.
 /// </summary>
 /// <param name="mKey">The mouse key to send as mouse button up.</param>
 /// <remarks></remarks>
 public static void ButtonUp(MouseKeys mKey)
 {
     switch (mKey)
     {
         case MouseKeys.Left:
             SendButton(MouseButtons.LeftUp);
             return;
         case MouseKeys.Right:
             SendButton(MouseButtons.RightUp);
             return;
         case MouseKeys.Middle:
             SendButton(MouseButtons.MiddleUp);
             return;
     }
 }
Esempio n. 28
0
 /// <summary>
 /// Send a mouse button down signal.
 /// </summary>
 /// <param name="mKey">The mouse key to send as mouse button down.</param>
 /// <remarks></remarks>
 public static void ButtonDown(MouseKeys mKey)
 {
     switch (mKey)
     {
         case MouseKeys.Left:
             SendButton(MouseButtons.LeftDown);
             return;
         case MouseKeys.Right:
             SendButton(MouseButtons.RightDown);
             return;
         case MouseKeys.Middle:
             SendButton(MouseButtons.MiddleDown);
             return;
     }
 }
Esempio n. 29
0
 public override void MouseDown(MouseKeys key)
 {
     OnClick?.Invoke();
 }
Esempio n. 30
0
 public static bool MouseKeyIsHeld(MouseKeys key)
 {
     return(_actualFrameMouseState[key] == ButtonState.Pressed);
 }
Esempio n. 31
0
 /// <summary>
 /// Sends a mouse press signal (down and up).
 /// </summary>
 /// <param name="mKey">The key to press.</param>
 /// <param name="Delay">The delay to set between the events.</param>
 /// <remarks></remarks>
 public static void PressButton(MouseKeys mKey, int Delay /*= 0*/)
 {
     ButtonDown(mKey);
     if (Delay > 0) System.Threading.Thread.Sleep(Delay);
     ButtonUp(mKey);
 }
Esempio n. 32
0
 public bool mouseUp(MouseKeys mouseKey)
 {
     if (mouseKey == MouseKeys.LEFT_BUTTON)
     {
         return !(newMouseState.LeftButton == ButtonState.Pressed) && (oldMouseState.LeftButton == ButtonState.Pressed);
     }
     else if (mouseKey == MouseKeys.MIDDLE_BUTTON)
     {
         return !(newMouseState.MiddleButton == ButtonState.Pressed) && (oldMouseState.MiddleButton == ButtonState.Pressed);
     }
     else
     {
         return !(newMouseState.RightButton == ButtonState.Pressed) && (oldMouseState.RightButton == ButtonState.Pressed);
     }
 }
Esempio n. 33
0
        public virtual void HandleMessages(IntPtr hWnd, WindowMessageType msg, IntPtr wParam, IntPtr lParam)
        {
            // Current mouse position
            int iMouseX = (short)((ulong)lParam & 0xffffU);
            int iMouseY = (short)((ulong)lParam >> 16);

            switch (msg)
            {
            case WindowMessageType.ActivateApplication:
            {
                m_isActive = wParam.ToInt32() == 1;
                break;
            }

            case WindowMessageType.KeyDown:
            {
                // Map this key to a D3DUtil_CameraKeys enum and update the
                // state of m_aKeys[] by adding the KEY_WAS_DOWN_MASK|KEY_IS_DOWN_MASK mask
                // only if the key is not down
                SdkCameraKey mappedKey = MapKey((VirtualKey)wParam);

                if (mappedKey != SdkCameraKey.Unknown)
                {
                    if (!IsKeyDown(m_aKeys[(int)mappedKey]))
                    {
                        m_aKeys[(int)mappedKey] = SdkCameraKeyStates.WasDownMask | SdkCameraKeyStates.IsDownMask;
                        m_cKeysDown++;
                    }
                }

                break;
            }

            case WindowMessageType.KeyUp:
            {
                // Map this key to a D3DUtil_CameraKeys enum and update the
                // state of m_aKeys[] by removing the KEY_IS_DOWN_MASK mask.
                SdkCameraKey mappedKey = MapKey((VirtualKey)wParam);

                if (mappedKey != SdkCameraKey.Unknown)
                {
                    m_aKeys[(int)mappedKey] &= ~SdkCameraKeyStates.IsDownMask;
                    m_cKeysDown--;
                }

                break;
            }

            case WindowMessageType.RightButtonDown:
            case WindowMessageType.MiddleButtonDown:
            case WindowMessageType.LeftButtonDown:
            case WindowMessageType.RightButtonDoubleClick:
            case WindowMessageType.MiddleButtonDoubleClick:
            case WindowMessageType.LeftButtonDoubleClick:
            {
                // Compute the drag rectangle in screen coord.
                XMInt2 ptCursor = new XMInt2(iMouseX, iMouseY);

                // Update member var state
                if ((msg == WindowMessageType.LeftButtonDown || msg == WindowMessageType.LeftButtonDoubleClick) && NativeMethods.PtInRect(ref m_rcDrag, ptCursor))
                {
                    m_bMouseLButtonDown   = true;
                    m_nCurrentButtonMask |= MouseKeys.LeftButton;
                }

                if ((msg == WindowMessageType.MiddleButtonDown || msg == WindowMessageType.MiddleButtonDoubleClick) && NativeMethods.PtInRect(ref m_rcDrag, ptCursor))
                {
                    m_bMouseMButtonDown   = true;
                    m_nCurrentButtonMask |= MouseKeys.MiddleButton;
                }

                if ((msg == WindowMessageType.RightButtonDown || msg == WindowMessageType.RightButtonDoubleClick) && NativeMethods.PtInRect(ref m_rcDrag, ptCursor))
                {
                    m_bMouseRButtonDown   = true;
                    m_nCurrentButtonMask |= MouseKeys.RightButton;
                }

                // Capture the mouse, so if the mouse button is
                // released outside the window, we'll get the WM_LBUTTONUP message
                NativeMethods.SetCapture(hWnd);
                NativeMethods.GetCursorPos(out m_ptLastMousePosition);
                break;
            }

            case WindowMessageType.RightButtonUp:
            case WindowMessageType.MiddleButtonUp:
            case WindowMessageType.LeftButtonUp:
            {
                // Update member var state
                if (msg == WindowMessageType.LeftButtonUp)
                {
                    m_bMouseLButtonDown   = false;
                    m_nCurrentButtonMask &= ~MouseKeys.LeftButton;
                }

                if (msg == WindowMessageType.MiddleButtonUp)
                {
                    m_bMouseMButtonDown   = false;
                    m_nCurrentButtonMask &= ~MouseKeys.MiddleButton;
                }

                if (msg == WindowMessageType.RightButtonUp)
                {
                    m_bMouseRButtonDown   = false;
                    m_nCurrentButtonMask &= ~MouseKeys.RightButton;
                }

                // Release the capture if no mouse buttons down
                if (!m_bMouseLButtonDown &&
                    !m_bMouseRButtonDown &&
                    !m_bMouseMButtonDown)
                {
                    NativeMethods.ReleaseCapture();
                }

                break;
            }

            case WindowMessageType.CaptureChanged:
            {
                if (lParam != hWnd)
                {
                    if ((m_nCurrentButtonMask & MouseKeys.LeftButton) != 0 ||
                        (m_nCurrentButtonMask & MouseKeys.MiddleButton) != 0 ||
                        (m_nCurrentButtonMask & MouseKeys.RightButton) != 0)
                    {
                        m_bMouseLButtonDown   = false;
                        m_bMouseMButtonDown   = false;
                        m_bMouseRButtonDown   = false;
                        m_nCurrentButtonMask &= ~MouseKeys.LeftButton;
                        m_nCurrentButtonMask &= ~MouseKeys.MiddleButton;
                        m_nCurrentButtonMask &= ~MouseKeys.RightButton;
                        NativeMethods.ReleaseCapture();
                    }
                }

                break;
            }

            case WindowMessageType.MouseWheel:
            {
                // Update member var state
                m_nMouseWheelDelta += (short)((uint)wParam >> 16);
                break;
            }
            }
        }