public void OnMouseDown(object sender, MouseButtonEventArgs e) { if (MouseDownEvent != null) { MouseDownEvent.Invoke(sender, e); } }
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) { MouseButtons button = MouseButtons.None; int clickCount = 0; switch ((Int32)wParam) { case WM_LBUTTONDOWN: button = MouseButtons.Left; clickCount = 1; MouseDownEvent?.Invoke(this, new MouseEventArgs(button, clickCount, point.X, point.Y, 0)); break; case WM_RBUTTONDOWN: button = MouseButtons.Right; clickCount = 1; MouseDownEvent?.Invoke(this, new MouseEventArgs(button, clickCount, point.X, point.Y, 0)); break; case WM_MBUTTONDOWN: button = MouseButtons.Middle; clickCount = 1; MouseDownEvent?.Invoke(this, new MouseEventArgs(button, clickCount, point.X, point.Y, 0)); break; case WM_LBUTTONUP: button = MouseButtons.Left; clickCount = 1; MouseUpEvent?.Invoke(this, new MouseEventArgs(button, clickCount, point.X, point.Y, 0)); break; case WM_RBUTTONUP: button = MouseButtons.Right; clickCount = 1; MouseUpEvent?.Invoke(this, new MouseEventArgs(button, clickCount, point.X, point.Y, 0)); break; case WM_MBUTTONUP: 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(this, e); } this.Point = new Point(MyMouseHookStruct.pt.x, MyMouseHookStruct.pt.y); return(Win32Api.CallNextHookEx(hHook, nCode, wParam, lParam)); } }
private void MouseDownHandler(object sender, MouseEventArgs e) { e.Handled = true; Point mousePosition = e.GetPosition(_mapV); Location polygonPointLocation = _mapV.ViewportPointToLocation(mousePosition); MouseDownEvent?.Invoke(polygonPointLocation); }
private int MouseHookProc(int nCode, IntPtr wParam, IntPtr lParam) { var myMouseHookStruct = (Win32Api.MouseHookStruct)Marshal.PtrToStructure(lParam, typeof(Win32Api.MouseHookStruct)); if (nCode < 0) { return(Win32Api.CallNextHookEx(_hHook, nCode, wParam, lParam)); } MouseButtons button; int clickCount; switch ((int)wParam) { case WmLbuttondown: button = MouseButtons.Left; clickCount = 1; MouseDownEvent?.Invoke(this, new MouseEventArgs(button, clickCount, _point.X, _point.Y, 0)); break; case WmRbuttondown: button = MouseButtons.Right; clickCount = 1; MouseDownEvent?.Invoke(this, new MouseEventArgs(button, clickCount, _point.X, _point.Y, 0)); break; case WmMbuttondown: button = MouseButtons.Middle; clickCount = 1; MouseDownEvent?.Invoke(this, new MouseEventArgs(button, clickCount, _point.X, _point.Y, 0)); break; case WmLbuttonup: button = MouseButtons.Left; clickCount = 1; MouseUpEvent?.Invoke(this, new MouseEventArgs(button, clickCount, _point.X, _point.Y, 0)); break; case WmRbuttonup: button = MouseButtons.Right; clickCount = 1; MouseUpEvent?.Invoke(this, new MouseEventArgs(button, clickCount, _point.X, _point.Y, 0)); break; case WmMbuttonup: button = MouseButtons.Middle; clickCount = 1; MouseUpEvent?.Invoke(this, new MouseEventArgs(button, clickCount, _point.X, _point.Y, 0)); break; } if (myMouseHookStruct != null) { Point = new Point(myMouseHookStruct.pt.x, myMouseHookStruct.pt.y); } return(Win32Api.CallNextHookEx(_hHook, nCode, wParam, lParam)); }
public void MouseDown(Point position, MouseButton button) { m_LastClickPosition = position; int x = (int)position.X - X - ParentX; int y = (int)position.Y - Y - ParentY; OnMouseDown(x, y, button); MouseDownEvent?.Invoke(this, x, y, button); }
public void MouseDown(Vector2Int position, MouseButton button) { _lastClickPosition = position; var x = (int)position.x - X - ParentX; var y = (int)position.y - Y - ParentY; OnMouseDown(x, y, button); MouseDownEvent?.Invoke(this, x, y, button); }
//地图控件鼠标左键双击事件 private void axMapControl_eventLButtonDbClick(object sender, _DHOSOFTMapControlEvents_eventLButtonDbClickEvent e) { if (Utils.bPublishEvent == false) { return; } MapLngLat lnglat = new MapLngLat(e.dLong, e.dLat); MFMouseEventArgs args = new MFMouseEventArgs(lnglat, MouseButtons.Left, e.x, e.y); if (MouseDbClickEvent != null) { MouseDownEvent.Invoke(this, args); } }
// 鼠标按下事件 private void mapControl_MouseDown(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 (MouseDownEvent != null) { MouseDownEvent.Invoke(this, args); } }
private void HandleNewMouseDown() { Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); isDown = true; _clickTimeout = DateTime.Now.AddMilliseconds(500); RaycastHit[] hits = Physics.RaycastAll(ray, 5f); foreach (RaycastHit hit in hits) { if (ClickObjectNames.Contains(hit.transform.gameObject.name)) { _selectedObjects.Add(hit.transform.gameObject); OnMouseDown?.Invoke(this, hit.transform.gameObject.name, hit.transform.gameObject); _mouseDownPosition = hit.point; } } }
protected override IntPtr CustomHookProc(IntPtr wParam, IntPtr lParam) { MSLLHOOKSTRUCT ms = (MSLLHOOKSTRUCT)Marshal.PtrToStructure(lParam, typeof(MSLLHOOKSTRUCT)); bool injected = (ms.flags & (uint)LLMHF.INJECTED) != 0; switch ((WM)wParam) { case WM.LBUTTONDOWN: if (MouseDownEvent?.Invoke(this, (uint)VK.LBUTTON, ms.pt.x, ms.pt.y, 0, injected) == true) { return((IntPtr)(-1)); } break; case WM.LBUTTONUP: if (MouseUpEvent?.Invoke(this, (uint)VK.LBUTTON, ms.pt.x, ms.pt.y, 0, injected) == true) { return((IntPtr)(-1)); } break; case WM.MOUSEMOVE: if (MouseMoveEvent?.Invoke(this, 0, ms.pt.x, ms.pt.y, 0, injected) == true) { return((IntPtr)(-1)); } break; case WM.MOUSEWHEEL: if (MouseWheelEvent?.Invoke(this, 0, ms.pt.x, ms.pt.y, HighWord(ms.mouseData), injected) == true) { return((IntPtr)(-1)); } break; case WM.MOUSEHWHEEL: if (MouseHWheelEvent?.Invoke(this, 0, ms.pt.x, ms.pt.y, HighWord(ms.mouseData), injected) == true) { return((IntPtr)(-1)); } break; case WM.RBUTTONDOWN: if (MouseDownEvent?.Invoke(this, (uint)VK.RBUTTON, ms.pt.x, ms.pt.y, 0, injected) == true) { return((IntPtr)(-1)); } break; case WM.RBUTTONUP: if (MouseUpEvent?.Invoke(this, (uint)VK.RBUTTON, ms.pt.x, ms.pt.y, 0, injected) == true) { return((IntPtr)(-1)); } break; case WM.MBUTTONDOWN: if (MouseDownEvent?.Invoke(this, (uint)VK.MBUTTON, ms.pt.x, ms.pt.y, 0, injected) == true) { return((IntPtr)(-1)); } break; case WM.MBUTTONUP: if (MouseUpEvent?.Invoke(this, (uint)VK.MBUTTON, ms.pt.x, ms.pt.y, 0, injected) == true) { return((IntPtr)(-1)); } break; case WM.XBUTTONDOWN: if (HighWord(ms.mouseData) == (int)MOUSEDATA.XBUTTON1) { if (MouseDownEvent?.Invoke(this, (uint)VK.XBUTTON1, ms.pt.x, ms.pt.y, 0, injected) == true) { return((IntPtr)(-1)); } } else if (HighWord(ms.mouseData) == (int)MOUSEDATA.XBUTTON2) { if (MouseDownEvent?.Invoke(this, (uint)VK.XBUTTON2, ms.pt.x, ms.pt.y, 0, injected) == true) { return((IntPtr)(-1)); } } break; case WM.XBUTTONUP: if (HighWord(ms.mouseData) == (int)MOUSEDATA.XBUTTON1) { if (MouseUpEvent?.Invoke(this, (uint)VK.XBUTTON1, ms.pt.x, ms.pt.y, 0, injected) == true) { return((IntPtr)(-1)); } } else if (HighWord(ms.mouseData) == (int)MOUSEDATA.XBUTTON2) { if (MouseUpEvent?.Invoke(this, (uint)VK.XBUTTON2, ms.pt.x, ms.pt.y, 0, injected) == true) { return((IntPtr)(-1)); } } break; } return(IntPtr.Zero); }
private void OnMouseDown() { MouseDownEvent.Invoke(); }
public override bool Poll() { bool returnStatus = false; MouseStateEventData[] eventDataArray; lock (_mouseEventData) { eventDataArray = _mouseEventData.ToArray(); _mouseEventData.Clear(); } if (eventDataArray.Length == 0) { return(returnStatus); } MouseButtons[] currentState = _getButtonState(eventDataArray); Point currentPoint = eventDataArray[0].Data.Position; MouseButtons[] pressedButtons = GetNewItems(_mouseStateArray, currentState); MouseButtons[] releasedButtons = GetMissingItems(_mouseStateArray, currentState); //Subtract current values so positive values result in a positive delta. Point relativePoint = currentPoint - _mouseStatePoint; int wheelDelta = eventDataArray[0].Data.WheelDelta; _mouseStateWheel = _mouseStateWheel + wheelDelta; MouseEventData eventData = new MouseEventData(pressedButtons, releasedButtons, currentState, currentPoint, relativePoint, _mouseStateWheel, wheelDelta); //System.Diagnostics.Trace.WriteLine(eventData.ToString()); if (pressedButtons.Length != 0 || releasedButtons.Length != 0 || relativePoint != Point.Empty || wheelDelta != 0) { MouseEvent?.Invoke(new MouseEventArgs(eventData)); returnStatus = true; } if (pressedButtons.Length != 0) { MouseDownEvent?.Invoke(new MouseEventArgs(eventData)); } if (releasedButtons.Length != 0) { MouseUpEvent?.Invoke(new MouseEventArgs(eventData)); } if (relativePoint != Point.Empty) { MouseMoveEvent?.Invoke(new MouseEventArgs(eventData)); } if (wheelDelta != 0) { MouseWheelEvent?.Invoke(new MouseEventArgs(eventData)); } _mouseStateArray = currentState; return(returnStatus); }
private void OnMouseDown(Keys key) => MouseDownEvent?.Invoke(this, key, DateTime.Now);
private int MouseHookProc(int nCode, IntPtr wParam, IntPtr lParam) { MouseHookStruct mouseHookStruct = (MouseHookStruct)Marshal.PtrToStructure(lParam, typeof(MouseHookStruct)); bool flag = nCode < 0; int result; if (flag) { result = HookFunction.CallNextHookEx(hHook, nCode, wParam, lParam); } else { switch ((int)wParam) { case 513: { MouseButtons button = MouseButtons.Left; int clicks = 1; MouseDownEvent?.Invoke(this, new MouseEventArgs(button, clicks, point.X, point.Y, 0)); break; } case 514: { MouseButtons button = MouseButtons.Left; int clicks = 1; MouseUpEvent?.Invoke(this, new MouseEventArgs(button, clicks, point.X, point.Y, 0)); break; } case 516: { MouseButtons button = MouseButtons.Right; int clicks = 1; MouseDownEvent?.Invoke(this, new MouseEventArgs(button, clicks, point.X, point.Y, 0)); break; } case 517: { MouseButtons button = MouseButtons.Right; int clicks = 1; MouseUpEvent?.Invoke(this, new MouseEventArgs(button, clicks, point.X, point.Y, 0)); break; } case 519: { MouseButtons button = MouseButtons.Middle; int clicks = 1; MouseDownEvent?.Invoke(this, new MouseEventArgs(button, clicks, point.X, point.Y, 0)); break; } case 520: { MouseButtons button = MouseButtons.Middle; int clicks = 1; MouseUpEvent?.Invoke(this, new MouseEventArgs(button, clicks, point.X, point.Y, 0)); break; } } this.Point = new Point(mouseHookStruct.pt.x, mouseHookStruct.pt.y); result = HookFunction.CallNextHookEx(hHook, nCode, wParam, lParam); } return(result); }
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)); }
protected virtual void OnMouseDownEvent(EditorEventArgs e) { MouseDownEvent?.Invoke(this, e); }