예제 #1
0
        /// <summary>
        ///     Creates <see cref="MouseEventExtArgs" /> from relevant mouse data.
        /// </summary>
        /// <param name="wParam">First Windows Message parameter.</param>
        /// <param name="mouseInfo">A MouseStruct containing information from which to construct MouseEventExtArgs.</param>
        /// <returns>A new MouseEventExtArgs object.</returns>
        private static MouseEventExtArgs FromRawDataUniversal(IntPtr wParam, MouseStruct mouseInfo)
        {
            MouseButtons button     = MouseButtons.None;
            short        mouseDelta = 0;
            int          clickCount = 0;

            bool isMouseKeyDown = false;
            bool isMouseKeyUp   = false;


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

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

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

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

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

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

            case Messages.WM_MBUTTONDOWN:
                isMouseKeyDown = true;
                button         = MouseButtons.Middle;
                clickCount     = 1;
                break;

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

            case Messages.WM_MBUTTONDBLCLK:
                isMouseKeyDown = true;
                button         = MouseButtons.Middle;
                clickCount     = 2;
                break;

            case Messages.WM_MOUSEWHEEL:
                mouseDelta = mouseInfo.MouseData;
                break;

            case Messages.WM_XBUTTONDOWN:
                button = mouseInfo.MouseData == 1
                        ? MouseButtons.XButton1
                        : MouseButtons.XButton2;
                isMouseKeyDown = true;
                clickCount     = 1;
                break;

            case Messages.WM_XBUTTONUP:
                button = mouseInfo.MouseData == 1
                        ? MouseButtons.XButton1
                        : MouseButtons.XButton2;
                isMouseKeyUp = true;
                clickCount   = 1;
                break;

            case Messages.WM_XBUTTONDBLCLK:
                isMouseKeyDown = true;
                button         = mouseInfo.MouseData == 1
                        ? MouseButtons.XButton1
                        : MouseButtons.XButton2;
                clickCount = 2;
                break;

            case Messages.WM_MOUSEHWHEEL:
                mouseDelta = mouseInfo.MouseData;
                break;
            }

            var e = new MouseEventExtArgs(
                button,
                clickCount,
                mouseInfo.Point,
                mouseDelta,
                mouseInfo.Timestamp,
                isMouseKeyDown,
                isMouseKeyUp);

            return(e);
        }
예제 #2
0
        /// <summary>
        ///     Creates <see cref="MouseEventExtArgs" /> from relevant mouse data.
        /// </summary>
        /// <param name="wParam">First Windows Message parameter.</param>
        /// <param name="mouseInfo">A MouseStruct containing information from which to construct MouseEventExtArgs.</param>
        /// <returns>A new MouseEventExtArgs object.</returns>
        private static MouseEventExtArgs FromRawDataUniversal(IntPtr wParam, MouseStruct mouseInfo)
        {
            MouseButtons button = MouseButtons.None;
            short mouseDelta = 0;
            int clickCount = 0;

            bool isMouseKeyDown = false;
            bool isMouseKeyUp = false;

            switch ((long) wParam)
            {
                case Messages.WM_LBUTTONDOWN:
                    isMouseKeyDown = true;
                    button = MouseButtons.Left;
                    clickCount = 1;
                    break;
                case Messages.WM_LBUTTONUP:
                    isMouseKeyUp = true;
                    button = MouseButtons.Left;
                    clickCount = 1;
                    break;
                case Messages.WM_LBUTTONDBLCLK:
                    isMouseKeyDown = true;
                    button = MouseButtons.Left;
                    clickCount = 2;
                    break;
                case Messages.WM_RBUTTONDOWN:
                    isMouseKeyDown = true;
                    button = MouseButtons.Right;
                    clickCount = 1;
                    break;
                case Messages.WM_RBUTTONUP:
                    isMouseKeyUp = true;
                    button = MouseButtons.Right;
                    clickCount = 1;
                    break;
                case Messages.WM_RBUTTONDBLCLK:
                    isMouseKeyDown = true;
                    button = MouseButtons.Right;
                    clickCount = 2;
                    break;
                case Messages.WM_MBUTTONDOWN:
                    isMouseKeyDown = true;
                    button = MouseButtons.Middle;
                    clickCount = 1;
                    break;
                case Messages.WM_MBUTTONUP:
                    isMouseKeyUp = true;
                    button = MouseButtons.Middle;
                    clickCount = 1;
                    break;
                case Messages.WM_MBUTTONDBLCLK:
                    isMouseKeyDown = true;
                    button = MouseButtons.Middle;
                    clickCount = 2;
                    break;
                case Messages.WM_MOUSEWHEEL:
                    mouseDelta = mouseInfo.MouseData;
                    break;
                case Messages.WM_XBUTTONDOWN:
                    button = mouseInfo.MouseData == 1
                        ? MouseButtons.XButton1
                        : MouseButtons.XButton2;
                    isMouseKeyDown = true;
                    clickCount = 1;
                    break;

                case Messages.WM_XBUTTONUP:
                    button = mouseInfo.MouseData == 1
                        ? MouseButtons.XButton1
                        : MouseButtons.XButton2;
                    isMouseKeyUp = true;
                    clickCount = 1;
                    break;

                case Messages.WM_XBUTTONDBLCLK:
                    isMouseKeyDown = true;
                    button = mouseInfo.MouseData == 1
                        ? MouseButtons.XButton1
                        : MouseButtons.XButton2;
                    clickCount = 2;
                    break;

                case Messages.WM_MOUSEHWHEEL:
                    mouseDelta = mouseInfo.MouseData;
                    break;
            }

            var e = new MouseEventExtArgs(
                button,
                clickCount,
                mouseInfo.Point,
                mouseDelta,
                mouseInfo.Timestamp,
                isMouseKeyDown,
                isMouseKeyUp);

            return e;
        }