Example #1
0
        public void MouseClick(Vector2Int position, MouseButton button)
        {
            var x           = position.x - X - ParentX;
            var y           = position.y - Y - ParentY;
            var totalMS     = (float)Service.Get <UltimaGame>().TotalMS;
            var doubleClick = false;

            if (_maxTimeForDoubleClick != 0f)
            {
                if (totalMS <= _maxTimeForDoubleClick)
                {
                    _maxTimeForDoubleClick = 0f;
                    doubleClick            = true;
                }
            }
            else
            {
                _maxTimeForDoubleClick = totalMS + UltimaGameSettings.UserInterface.Mouse.DoubleClickMS;
            }
            if (button == MouseButton.Right && !IsUncloseableWithRMB)
            {
                CloseWithRightMouseButton();
                return;
            }
            if (doubleClick)
            {
                OnMouseDoubleClick(x, y, button);
                MouseDoubleClickEvent?.Invoke(this, x, y, button);
            }
            else
            {
                OnMouseClick(x, y, button);
                MouseClickEvent?.Invoke(this, x, y, button);
            }
        }
Example #2
0
        // 鼠标点击地图控件事件
        private void mapControl_MouseClick(object sender, MouseEventArgs e)
        {
            if (MapFrame.GMap.Common.Utils.bPublishEvent == false)
            {
                return;
            }

            var p = FromLocalToLngLat(e.X, e.Y);
            MFMouseEventArgs args = new MFMouseEventArgs(p, e.Button, e.X, e.Y);

            if (MouseClickEvent != null)
            {
                MouseClickEvent.Invoke(this, args);
            }
        }
Example #3
0
        /// <summary>
        /// 鼠标钩子回调函数
        /// </summary>
        /// <param name="nCode"></param>
        /// <param name="wParam"></param>
        /// <param name="lParam"></param>
        /// <returns></returns>
        private int MouseHookProc(int nCode, IntPtr wParam, IntPtr lParam)
        {
            try
            {
                if (nCode < 0)
                {
                    return(WinUserApi.CallNextHookEx(hHook, nCode, wParam, lParam));
                }
                else
                {
                    WinUserApi.POINT point = new WinUserApi.POINT();
                    WinUserApi.GetCursorPos(out point);


                    {
                        switch ((uint)wParam)
                        {
                        case WinUserApi.WM_LBUTTONDOWN:
                            MouseEventArgs LMouseClickEventArgs = new MouseEventArgs(MouseButtons.Left, 1, point.x, point.y, 0);
                            MouseClickEvent?.Invoke(this, LMouseClickEventArgs);
                            break;

                        case WinUserApi.WM_RBUTTONDOWN:
                            MouseEventArgs RMouseClickEventArgs = new MouseEventArgs(MouseButtons.Right, 1, point.x, point.y, 0);
                            MouseClickEvent?.Invoke(this, RMouseClickEventArgs);
                            break;

                        case WinUserApi.WM_RBUTTONDBLCLK:
                            MouseEventArgs RBDBLMouseClickEventArgs = new MouseEventArgs(MouseButtons.Right, 2, point.x, point.y, 0);
                            MouseClickEvent?.Invoke(this, RBDBLMouseClickEventArgs);
                            break;

                        case WinUserApi.WM_MOUSEMOVE:
                            MouseEventArgs MouseMoveEventArgs = new MouseEventArgs(MouseButtons.None, 0, point.x, point.y, 0);
                            MouseMoveEvent?.Invoke(this, MouseMoveEventArgs);
                            break;
                        }
                    }
                    return(WinUserApi.CallNextHookEx(hHook, nCode, wParam, lParam));
                }
            }
            catch { }

            return(0);
        }
Example #4
0
        public void MouseClick(Point position, MouseButton button)
        {
            int   x       = position.X - X - ParentX;
            int   y       = position.Y - Y - ParentY;
            float totalMS = (float)Service.Get <UltimaGame>().TotalMS;

            bool doubleClick = false;

            if (m_MaxTimeForDoubleClick != 0f)
            {
                if (totalMS <= m_MaxTimeForDoubleClick)
                {
                    m_MaxTimeForDoubleClick = 0f;
                    doubleClick             = true;
                }
            }
            else
            {
                m_MaxTimeForDoubleClick = totalMS + Settings.UserInterface.Mouse.DoubleClickMS;
            }

            if (button == MouseButton.Right && !IsUncloseableWithRMB)
            {
                CloseWithRightMouseButton();
                return;
            }

            if (doubleClick)
            {
                OnMouseDoubleClick(x, y, button);
                MouseDoubleClickEvent?.Invoke(this, x, y, button);
            }
            else
            {
                OnMouseClick(x, y, button);
                MouseClickEvent?.Invoke(this, x, y, button);
            }
        }
Example #5
0
        private static IntPtr MouseProc(int nCode, IntPtr wParam, IntPtr lParam)
        {
            if (nCode >= 0)
            {
                _mouseParam = (Win32Api.MOUSEHOOKSTRUCT)Marshal.PtrToStructure(lParam, typeof(Win32Api.MOUSEHOOKSTRUCT));
                var mouseMessage = (Win32Api.MouseMessages)wParam;

                if (UseGlobal)
                {
                    if (mouseMessage == Win32Api.MouseMessages.WM_LBUTTONDOWN || mouseMessage == Win32Api.MouseMessages.WM_LBUTTONUP)
                    {
                        MouseClickEvent?.Invoke(_mouseParam.pt, mouseMessage);

                        if (mouseMessage == Win32Api.MouseMessages.WM_LBUTTONDOWN && IsHookingArea())
                        {
                            return((IntPtr)1);
                        }
                    }
                }
            }

            return(Win32Api.CallNextHookEx(_mouseId, nCode, wParam, lParam));
        }
 void OnMouseDown()
 {
     MouseClickEvent?.Invoke(this.cell);
 }
Example #7
0
        private int MouseHookProc(int nCode, IntPtr wParam, IntPtr lParam)
        {
            Win32Api.MouseHookStruct MyMouseHookStruct = (Win32Api.MouseHookStruct)Marshal.PtrToStructure(lParam, typeof(Win32Api.MouseHookStruct));
            if (nCode < 0)
            {
                return(Win32Api.CallNextHookEx(hHook, nCode, wParam, lParam));
            }
            else
            {
                if (MouseClickEvent != null)
                {
                    bool?        isUp       = null;
                    MouseButtons button     = MouseButtons.None;
                    int          clickCount = 0;
                    switch ((Int32)wParam)
                    {
                    case WM_LBUTTONDOWN:
                        isUp       = false;
                        button     = MouseButtons.Left;
                        clickCount = 1;
                        MouseDownEvent?.Invoke(this, new MouseEventArgs(button, clickCount, point.X, point.Y, 0));
                        break;

                    case WM_RBUTTONDOWN:
                        isUp       = false;
                        button     = MouseButtons.Right;
                        clickCount = 1;
                        MouseDownEvent?.Invoke(this, new MouseEventArgs(button, clickCount, point.X, point.Y, 0));
                        break;

                    case WM_MBUTTONDOWN:
                        isUp       = false;
                        button     = MouseButtons.Middle;
                        clickCount = 1;
                        MouseDownEvent?.Invoke(this, new MouseEventArgs(button, clickCount, point.X, point.Y, 0));
                        break;

                    case WM_LBUTTONUP:
                        isUp       = true;
                        button     = MouseButtons.Left;
                        clickCount = 1;
                        MouseUpEvent?.Invoke(this, new MouseEventArgs(button, clickCount, point.X, point.Y, 0));
                        break;

                    case WM_RBUTTONUP:
                        isUp       = true;
                        button     = MouseButtons.Right;
                        clickCount = 1;
                        MouseUpEvent?.Invoke(this, new MouseEventArgs(button, clickCount, point.X, point.Y, 0));
                        break;

                    case WM_MBUTTONUP:
                        isUp       = true;
                        button     = MouseButtons.Middle;
                        clickCount = 1;
                        MouseUpEvent?.Invoke(this, new MouseEventArgs(button, clickCount, point.X, point.Y, 0));
                        break;
                    }

                    var e = new MouseEventArgs(button, clickCount, point.X, point.Y, 0);
                    MouseClickEvent?.Invoke(this, e, isUp);
                }
                this.Point = new Point(MyMouseHookStruct.pt.x, MyMouseHookStruct.pt.y);
                return(Win32Api.CallNextHookEx(hHook, nCode, wParam, lParam));
            }
        }
Example #8
0
 private void InputHandlerComponent_OnMouseClickedEventHandler(object sender, EventArgs e)
 {
     MouseClickEvent?.Invoke(this, EventArgs.Empty);
 }
Example #9
0
        private int MouseHookProc(int nCode, int wParam, IntPtr lParam)
        {
            if (nCode >= 0)
            {
                var   mouseHookStruct = (MouseHookStruct)Marshal.PtrToStructure(lParam, typeof(MouseHookStruct));
                var   button          = MouseButtons.None;
                short mouseDelta      = 0;
                var   clickCount      = 0;
                var   mouseDown       = false;
                var   mouseUp         = false;
                switch ((WindowsMessage)wParam)
                {
                case WindowsMessage.WM_LBUTTONDOWN:
                    mouseDown  = true;
                    button     = MouseButtons.Left;
                    clickCount = 1;
                    break;

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

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

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

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

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

                case WindowsMessage.WM_MOUSEWHEEL:
                    mouseDelta = (short)((mouseHookStruct.MouseData >> 16) & 0xffff);
                    break;
                }
                var e = new MouseEventExtArgs(
                    button,
                    clickCount,
                    mouseHookStruct.Point.X,
                    mouseHookStruct.Point.Y,
                    mouseDelta);
                if (MouseEvent != null)
                {
                    MouseEvent.Invoke(null, e);
                }
                if (MouseUpEvent != null && mouseUp)
                {
                    MouseUpEvent.Invoke(null, e);
                }
                if (MouseDownEvent != null && mouseDown)
                {
                    MouseDownEvent.Invoke(null, e);
                }
                if (MouseClickEvent != null && clickCount > 0)
                {
                    MouseClickEvent.Invoke(null, e);
                }
                if (MouseDoubleClickEvent != null && clickCount == 2)//这里不会触发
                {
                    MouseDoubleClickEvent.Invoke(null, e);
                }
                if (MouseWheelEvent != null && mouseDelta != 0)
                {
                    MouseWheelEvent.Invoke(null, e);
                }
                if (MouseMoveEvent != null && (oldX != mouseHookStruct.Point.X || oldY != mouseHookStruct.Point.Y))
                {
                    oldX = mouseHookStruct.Point.X;
                    oldY = mouseHookStruct.Point.Y;
                    if (MouseMoveEvent != null)
                    {
                        MouseMoveEvent.Invoke(null, e);
                    }
                }
                if (e.Handled)
                {
                    return(-1);
                }
            }
            return(NativeMethods.CallNextHookEx(idHook, nCode, wParam, lParam));
        }