public int GetMouse(int index, ref RawMouse mouse) { if (index >= 0 && index < _rmInput.Mice.Count) { mouse = (RawMouse)_rmInput.Mice[index]; return(0); } return(-1); }
private void DetatchMouse() { if (attachedMouse != null) { attachedMouse = null; System.Windows.Forms.Cursor.Clip = new System.Drawing.Rectangle(); mouseDisabler.Unlock(); Monitor.Log("Detached mouse", StardewModdingAPI.LogLevel.Trace); } }
// Reading global raw input private void VirtualCursorUpdate(ref Message m) { int RidInput = 0x10000003; int headerSize = Marshal.SizeOf(typeof(RawInputHeader)); int size = Marshal.SizeOf(typeof(RawInput)); RawInput input; GetRawInputData(m.LParam, RidInput, out input, ref size, headerSize); RawMouse mouse = input.Mouse; if (!config.disableAutoDetection) { if (mouse.LastX > config.tolerance || mouse.LastY > config.tolerance) { checkBox_tabletMode.Checked = true; tabletMode = true; } else { checkBox_tabletMode.Checked = false; tabletMode = false; } } if (isDrawing) { if (tabletMode) { Point offset = new Point(0, 0); if (config.tabletOffsetOverride) { offset = config.tabletOffset; } int tabletX = mouse.LastX * virtualWidth / 65536; int tabletY = mouse.LastY * virtualHeight / 65536; Point p = new Point(tabletX + offset.X + virtualLeft, tabletY + offset.Y + virtualTop); position = p; overlay.cursorPos = p; overlay.Invalidate(); } else { Point p = new Point(position.X + mouse.LastX, position.Y + mouse.LastY); //if (p.X < virtualLeft) p.X = virtualLeft; //if (p.X > virtualWidth) p.X = virtualWidth; //if (p.Y < virtualTop) p.Y = virtualTop; //if (p.Y > virtualHeight) p.Y = virtualHeight; position = p; overlay.cursorPos = p; overlay.Invalidate(); } } }
private void DetachMouse() { if (attachedMouse != null) { attachedMouse = null; System.Windows.Forms.Cursor.Clip = new System.Drawing.Rectangle(); inputDisabler?.Unlock(); lockMouse = false; Monitor.Log("Detached mouse"); } }
internal static Vector2 ToScreenCoords(RawMouse hardware) { const int range = 65536; Rectangle screenRect = (hardware.Flags & RawMouseFlags.VirtualDesktop) > 0 ? VirtualScreenRect : new Rectangle( GameBase.InitialDesktopLocation.X, GameBase.InitialDesktopLocation.Y, GameBase.InitialDesktopResolution.Width, GameBase.InitialDesktopResolution.Height); return(new Vector2( (float)hardware.LastX / range * screenRect.Width + screenRect.X, (float)hardware.LastY / range * screenRect.Height + screenRect.Y)); }
private void HandleRawInput(RawInput input) { if (input.header.dwType != RawInputType.Mouse) { Console.WriteLine("Other input type"); return; } RawMouse mouse = input.data.mouse; //Console.WriteLine("Raw mouse: {0},{1} -> {2}", mouse.lLastX, mouse.lLastY, mouse.usFlags.ToString()); //Console.WriteLine("button flags: {0}", mouse.usButtonFlags); //Console.WriteLine("button data: {0}", (short)mouse.usButtonData); }
public void AttachMouseButtonClicked() { foreach (RawMouse mouse in mice) { if (attachedMouse != mouse && mouse.Buttons[0]) { attachedMouse = mouse; totalAttachedDelta = new Vector2(0, 0); Monitor.Log($"Set attached mouse to {mouse.Handle.ToString()}", StardewModdingAPI.LogLevel.Trace); mouseDisabler.Lock(); break; } } }
private static void ScrollVirtualDesktop(RawMouse mouse) { if (!mouse.Buttons.HasFlag(RawMouseButtonFlags.MouseWheel)) { return; } if (mouse.ButtonData > 0) { GoToLeftDesktop(); } else if (mouse.ButtonData < 0) { GoToRightDesktop(); } }
private PointF MousePosition(RawMouse data) { if ((data.Flags & RawMouseFlags.MoveAbsolute) > 0) { const int range = 65536; Rectangle resolution = Screen.PrimaryScreen.Bounds; PointF pos = new PointF( ((float)(data.LastX - range / 2) + range / 2) / range * resolution.Width, ((float)(data.LastY - range / 2) + range / 2) / range * resolution.Height); return(window.PointToClient(Point.Round(pos))); } // We cheat here and use absolute mouse position from opentk. Raw input is possible by always starting // at the absolute mouse position on button down, but there is a slight drift detaching our current position // from the windows cursor. Not desired! return(window.Mouse == null ? new PointF(0, 0) : new PointF(window.Mouse.X, window.Mouse.Y)); }
private void MouseHandler(RawInput data) { RawMouse m = data.Mouse; float speed = (float)ConfigManager.sMouseSpeed; AbsoluteMovement = (m.Flags & RawMouseFlags.MoveAbsolute) > 0; if (AbsoluteMovement) { if (ConfigManager.sAbsoluteToOsuWindow) { const int range = 65536; position.X = ((float)((m.LastX - range / 2) * speed) + range / 2) / range * GameBase.WindowManager.Width; position.Y = ((float)((m.LastY - range / 2) * speed) + range / 2) / range * GameBase.WindowManager.Height; } else { // Absolute coordinates need to be shifted to the osu window's position and scaled to the desktop resolution. position = ToScreenCoords(m) - new Vector2(GameBase.ClientBounds.X, GameBase.ClientBounds.Y); position.X = (position.X - GameBase.WindowManager.Width / 2) * speed + GameBase.WindowManager.Width / 2; position.Y = (position.Y - GameBase.WindowManager.Height / 2) * speed + GameBase.WindowManager.Height / 2; } } else { position.X += m.LastX * speed; position.Y += m.LastY * speed; } if (InputManager.ShallClampMouseToWindow) { position.X = OsuMathHelper.Clamp(position.X, 0, GameBase.WindowManager.Width - 1); position.Y = OsuMathHelper.Clamp(position.Y, 0, GameBase.WindowManager.Height - 1); } intermediatePositionsNextFrame.Add(position); ++amountMessages; latency += GameBase.stopWatch.ElapsedMilliseconds - lastProcessTime; }
protected override void WndProc(ref System.Windows.Forms.Message m) { switch (m.Msg) { case WM_INPUT: RawInput.UpdateRawMouse(m.LParam); for (int i = 0; i <= Cursors.Count - 1; i++) { System.Windows.Interop.WindowInteropHelper helper = new System.Windows.Interop.WindowInteropHelper((DeviceVisual)Cursors[i]); RawMouse rm = (RawMouse)RawInput.Mice[i]; SetWindowPos(helper.Handle, IntPtr.Zero, rm.X, rm.Y, 0, 0, (uint)17693); if (_MyInputEvent != null) { _MyInputEvent(helper.Handle.ToInt32(), rm.X, rm.Y, rm.Buttons); } } System.Windows.Forms.Cursor.Position = new System.Drawing.Point(System.Windows.Forms.Screen.PrimaryScreen.Bounds.Width, System.Windows.Forms.Screen.PrimaryScreen.Bounds.Height / 2); return; } base.WndProc(ref m); }
public void Update() { if (keepCheckingForMouseAttach) { foreach (RawMouse mouse in mice) { if (attachedMouse != mouse && mouse.Buttons[0]) { attachedMouse = mouse; keepCheckingForMouseAttach = false; totalAttachedDelta = new Vector2(0, 0); Monitor.Log($"Set attached mouse to {mouse.Handle.ToString()}"); if (lockMouse) { inputDisabler = inputDisabler ?? new InputDisabler(); inputDisabler.Lock(); } break; } } } if (lockMouse && HasAttachedMouse() && inputDisabler != null && !InputDisabler.IsAutoHotKeyNull) { Mouse.SetPosition(0, 0); System.Windows.Forms.Cursor.Position = new System.Drawing.Point(0, 0); System.Windows.Forms.Cursor.Clip = new System.Drawing.Rectangle(new System.Drawing.Point(0, 0), new System.Drawing.Size(1, 1)); } if (HasAttachedMouse()) { totalAttachedDelta.X = Math.Max(0, Math.Min(totalAttachedDelta.X + attachedMouse.XDelta, Terraria.Main.instance.GraphicsDevice.PresentationParameters.Bounds.Width - 1)); totalAttachedDelta.Y = Math.Max(0, Math.Min(totalAttachedDelta.Y + attachedMouse.YDelta, Terraria.Main.instance.GraphicsDevice.PresentationParameters.Bounds.Height - 1)); totalMouseZ += attachedMouse.ZDelta * 5000; } }
public RawInputMouseData(RawInputHeader header, RawMouse mouse) : base(header) =>
public bool ProcessMouseEvent(IntPtr raw_buffer) { bool processed = false; RawInput rin; if (Functions.GetRawInputData(raw_buffer, out rin) > 0) { RawMouse raw = rin.Data.Mouse; ContextHandle handle = new ContextHandle(rin.Header.Device); MouseState mouse; if (!rawids.ContainsKey(handle)) { RefreshDevices(); } if (mice.Count == 0) { return(false); } // Note:For some reason, my Microsoft Digital 3000 keyboard reports 0 // as rin.Header.Device for the "zoom-in/zoom-out" buttons. // That's problematic, because no device has a "0" id. // As a workaround, we'll add those buttons to the first device (if any). int mouse_handle = rawids.ContainsKey(handle) ? rawids[handle] : 0; mouse = mice[mouse_handle]; // Set and release capture of the mouse to fix http://www.opentk.com/node/2133, Patch by Artfunkel if ((raw.ButtonFlags & RawInputMouseState.LEFT_BUTTON_DOWN) != 0) { mouse.EnableBit((int)MouseButton.Left); Functions.SetCapture(Window); } if ((raw.ButtonFlags & RawInputMouseState.LEFT_BUTTON_UP) != 0) { mouse.DisableBit((int)MouseButton.Left); Functions.ReleaseCapture(); } if ((raw.ButtonFlags & RawInputMouseState.RIGHT_BUTTON_DOWN) != 0) { mouse.EnableBit((int)MouseButton.Right); Functions.SetCapture(Window); } if ((raw.ButtonFlags & RawInputMouseState.RIGHT_BUTTON_UP) != 0) { mouse.DisableBit((int)MouseButton.Right); Functions.ReleaseCapture(); } if ((raw.ButtonFlags & RawInputMouseState.MIDDLE_BUTTON_DOWN) != 0) { mouse.EnableBit((int)MouseButton.Middle); Functions.SetCapture(Window); } if ((raw.ButtonFlags & RawInputMouseState.MIDDLE_BUTTON_UP) != 0) { mouse.DisableBit((int)MouseButton.Middle); Functions.ReleaseCapture(); } if ((raw.ButtonFlags & RawInputMouseState.BUTTON_4_DOWN) != 0) { mouse.EnableBit((int)MouseButton.Button1); Functions.SetCapture(Window); } if ((raw.ButtonFlags & RawInputMouseState.BUTTON_4_UP) != 0) { mouse.DisableBit((int)MouseButton.Button1); Functions.ReleaseCapture(); } if ((raw.ButtonFlags & RawInputMouseState.BUTTON_5_DOWN) != 0) { mouse.EnableBit((int)MouseButton.Button2); Functions.SetCapture(Window); } if ((raw.ButtonFlags & RawInputMouseState.BUTTON_5_UP) != 0) { mouse.DisableBit((int)MouseButton.Button2); Functions.ReleaseCapture(); } if ((raw.ButtonFlags & RawInputMouseState.WHEEL) != 0) { mouse.SetScrollRelative(0, (short)raw.ButtonData / 120.0f); } if ((raw.ButtonFlags & RawInputMouseState.HWHEEL) != 0) { mouse.SetScrollRelative((short)raw.ButtonData / 120.0f, 0); } mouse.Flags = (MouseStateFlags)raw.Flags; if ((raw.Flags & RawMouseFlags.MOUSE_MOVE_ABSOLUTE) != 0) { mouse.X = raw.LastX; mouse.Y = raw.LastY; } else { // Seems like MOUSE_MOVE_RELATIVE is the default, unless otherwise noted. mouse.X += raw.LastX; mouse.Y += raw.LastY; } lock (UpdateLock) { mice[mouse_handle] = mouse; processed = true; } } return(processed); }
public MouseInfo(RawMouse mouse) { this.X = mouse.X; this.Y = mouse.Y; }