private static IntPtr HookCallback( int nCode, IntPtr wParam, IntPtr lParam) { if (nCode >= 0 && MouseMessages.WM_RBUTTONDOWN == (MouseMessages)wParam) { MouseAction?.Invoke(null, new EventArgs()); } return(CallNextHookEx(_hookID, nCode, wParam, lParam)); }
private static IntPtr HookMouseCallBack( int nCode, IntPtr wParam, IntPtr lParam) { if (nCode >= 0) { MSLLHOOKSTRUCT hookStruct = Marshal.PtrToStructure <MSLLHOOKSTRUCT>(lParam); MouseAction?.Invoke((EventMessage)wParam, hookStruct); } return(CallNextHookEx(_hookID, nCode, wParam, lParam)); }
private static IntPtr HookCallback( int nCode, IntPtr wParam, IntPtr lParam) { if (nCode >= 0 && MouseMessages.WM_LBUTTONDOWN == (MouseMessages)wParam) { Thread th = new Thread(() => { MSLLHOOKSTRUCT hookStruct = (MSLLHOOKSTRUCT)Marshal.PtrToStructure(lParam, typeof(MSLLHOOKSTRUCT)); MouseAction.Invoke(null, new EventArgs()); }); th.Start(); th.Join(); } return(CallNextHookEx(_hookID, nCode, wParam, lParam)); }
private void OnMouseAction(object sender, MouseHookEventArgs e) { MouseAction?.Invoke(this, e); if (e.Handled) { return; } if ((e.Action == Enums.MouseAction.LeftButtonPressed && GestureActionButton == MouseButtons.LeftMouseButton) || (e.Action == Enums.MouseAction.RightButtonPressed && GestureActionButton == MouseButtons.RightMouseButton)) { // If left button is pressed, start work IsGestureMaking = true; } else if ((e.Action == Enums.MouseAction.LeftButtonReleased && GestureActionButton == MouseButtons.LeftMouseButton) || e.Action == Enums.MouseAction.RightButtonReleased && GestureActionButton == MouseButtons.RightMouseButton) { // If left button is released, stop work IsGestureMaking = false; if (_mousePointsList.Count > 2) { // Get gesture that was doing var gesture = DetectGesture(); if (!string.Equals(gesture.Name, "-1", StringComparison.Ordinal) && gesture.CheckPoinstArray != null) { var eventArgs = new MouseGestureEventArgs(gesture.Name, gesture.CheckPoinstArray, DateTime.Now.Ticks); AddEventToHistory(eventArgs); e.Handled = true; Logger.Instance.Information($"Mouse gesture detected by {nameof(MouseAndKeyboardHookService)}."); MouseGestureDetected?.Invoke(this, eventArgs); } } _mousePointsList.Clear(); } else if (e.Action == Enums.MouseAction.MouseMove) { // If the mouse is moved, add point to coords list if (IsGestureMaking) { _mousePointsList.Add(e.Coords); } } }
private IntPtr LLMouseProc(int nCode, IntPtr wParam, IntPtr lParam) { MouseActionEventArgs eventArgs = new MouseActionEventArgs { IsCancelled = false }; if (nCode >= 0) { eventArgs.Action = (MouseAction)wParam.ToInt32(); eventArgs.Data = Marshal.PtrToStructure <MouseEventData>(lParam); try { MouseAction?.Invoke(this, eventArgs); } catch { } } return(eventArgs.IsCancelled ? (IntPtr)1 : CallNextHookEx(m_hhook, nCode, wParam, lParam)); }
// Update is called once per frame public void OnUpdate() { if (EventSystem.current.IsPointerOverGameObject()) { return; } //리스너 패턴 if (Input.anyKey && KeyAction != null) { KeyAction.Invoke(); } if (MouseAction != null) { if (Input.GetMouseButton(0)) { if (!_pressed) { MouseAction.Invoke(Define.MouseEvent.PointerDown); _pressedTime = Time.time; } MouseAction.Invoke(Define.MouseEvent.Press); _pressed = true; } else { if (_pressed) { if (Time.time < _pressedTime + 0.2f) { MouseAction.Invoke(Define.MouseEvent.Click); } MouseAction.Invoke(Define.MouseEvent.PointerUp); } _pressed = false; _pressedTime = 0f; } } }
private int HookCallBack(int nCode, int wParam, int lParam) { //Marshall the data from the callback. MouseHookStruct CurrentMouseHookStruct = (MouseHookStruct)Marshal.PtrToStructure((IntPtr)lParam, typeof(MouseHookStruct)); MouseMessages CurrentMouseMessage = (MouseMessages)wParam; if (nCode < 0) { return(CallNextHookEx(hHook, nCode, wParam, lParam)); } else { //Create a string variable that shows the current mouse coordinates. String strCaption = "x = " + CurrentMouseHookStruct.pt.x.ToString("d") + " y = " + CurrentMouseHookStruct.pt.y.ToString("d"); MouseAction?.Invoke(CurrentMouseMessage, CurrentMouseHookStruct.pt.x, CurrentMouseHookStruct.pt.y); return(CallNextHookEx(hHook, nCode, wParam, lParam)); } }
private IntPtr MouseHookProc(int code, IntPtr wParam, IntPtr lParam) { // If code is smaller than 0, this is error if (code < 0) { return(NativeMethods.CallNextHookEx(_mouseHookHandle, code, wParam, lParam)); } var mouseAction = (MouseSignal)wParam; var mouseData = (MouseHookStruct)Marshal.PtrToStructure(lParam, typeof(MouseHookStruct)); var mouseWheelData = (int)mouseData.mouseData >> 16; var wheelAction = MouseWheelAction.Unknown; if (mouseAction == MouseSignal.MouseWheel) { if (mouseWheelData > 0) { wheelAction = MouseWheelAction.WheelUp; } else { wheelAction = MouseWheelAction.WheelDown; } } //Get mouse coords from point MouseCoords = mouseData.pt; //Calculate mouse coords delta var delta = new Point { X = mouseData.pt.X - _lastMouseCoords.X, Y = mouseData.pt.Y - _lastMouseCoords.Y }; //Update last mouse coords _lastMouseCoords = mouseData.pt; //Init MouseAction enum var action = new MouseAction(); //Set action from mouseAction (wParam) if (mouseAction == MouseSignal.LButtonDown) { action = Enums.MouseAction.LeftButtonPressed; LeftMouseButtonState = KeyState.Pressed; } else if (mouseAction == MouseSignal.LButtonUp) { action = Enums.MouseAction.LeftButtonReleased; LeftMouseButtonState = KeyState.Released; } else if (mouseAction == MouseSignal.RButtonDown) { action = Enums.MouseAction.RightButtonPressed; RightMouseButtonState = KeyState.Pressed; } else if (mouseAction == MouseSignal.RButtonUp) { action = Enums.MouseAction.RightButtonReleased; RightMouseButtonState = KeyState.Released; } else if (mouseAction == MouseSignal.MouseMove) { action = Enums.MouseAction.MouseMove; } else if (mouseAction == MouseSignal.MouseWheel) { action = Enums.MouseAction.MouseWheel; } //If this action is allowed, go next if (IsActionAllowed(mouseAction)) { var eventArgs = new MouseHookEventArgs(mouseData.pt, delta, action, wheelAction, DateTime.Now.Ticks); AddEventToHistory(eventArgs); MouseAction?.Invoke(this, eventArgs); if (eventArgs.Handled) { return((IntPtr)1); } } return(NativeMethods.CallNextHookEx(_mouseHookHandle, code, wParam, lParam)); }
private static IntPtr HookCallback( int nCode, IntPtr wParam, IntPtr lParam) { if (nCode >= 0) { //MSLLHOOKSTRUCT hookStruct = (MSLLHOOKSTRUCT)Marshal.PtrToStructure(lParam, typeof(MSLLHOOKSTRUCT)); bool shouldInvoke = false; MouseKey key = MouseKey.LEFT_UP; if (((MouseMessages)wParam) == (MouseMessages.WM_LBUTTONDOWN)) { shouldInvoke = true; key = MouseKey.LEFT_DOWN; } if (((MouseMessages)wParam) == (MouseMessages.WM_LBUTTONUP)) { shouldInvoke = true; key = MouseKey.LEFT_UP; } if (((MouseMessages)wParam) == MouseMessages.WM_LBUTTONDBLCLK) { shouldInvoke = true; key = MouseKey.LEFT_DBCLICK; } if (((MouseMessages)wParam) == (MouseMessages.WM_MBUTTONDOWN)) { shouldInvoke = true; key = MouseKey.MIDDLE_DOWN; } if (((MouseMessages)wParam) == (MouseMessages.WM_MBUTTONUP)) { shouldInvoke = true; key = MouseKey.MIDDLE_UP; } //if (((MouseMessages)wParam) == (MouseMessages.WM_MOUSEWHEEL)) { // shouldInvoke = true; // key = MouseKey.WHEEL; //} if (((MouseMessages)wParam) == (MouseMessages.WM_RBUTTONDOWN)) { shouldInvoke = true; key = MouseKey.RIGHT_DOWN; } if (((MouseMessages)wParam) == (MouseMessages.WM_RBUTTONUP)) { shouldInvoke = true; key = MouseKey.RIGHT_UP; } if (((MouseMessages)wParam) == (MouseMessages.WM_RBUTTONDBLCLK)) { shouldInvoke = true; key = MouseKey.RIGHT_DBCLICK; } if (shouldInvoke) { MouseAction?.Invoke(new MouseHookEventArgs() { Message = wParam, Key = key }); } } return(CallNextHookEx(_hookID, nCode, wParam, lParam)); }