public void Stop() { // TODO : if (!Hook.Enabled) return; if (Config == null) { return; } Hook.MouseMove -= _handler; if (Config.AdjustPointer) { ZoneChanged -= AdjustPointer; } if (Config.AdjustSpeed) { ZoneChanged -= AdjustSpeed; } if (Config.HomeCinema) { ZoneChanged -= HomeCinema; } Hook.UnHook(); if (Config == null) { return; } if (Config.AdjustSpeed) { LbmMouse.MouseSpeed = _initMouseSpeed; using (var key = ScreenConfig.OpenRootRegKey(true)) { key.DeleteValue("InitialMouseSpeed"); } } if (Config.AdjustPointer) { using (var key = ScreenConfig.OpenRootRegKey()) { using (RegistryKey savekey = key.OpenSubKey("InitialCursor")) { if (savekey != null) { LbmMouse.RestoreCursor(savekey); } } key.DeleteSubKey("InitialCursor"); } } Process.GetCurrentProcess().PriorityClass = ProcessPriorityClass.Normal; }
public void Start() { Stop(); LoadConfig(); if (Config == null || !Config.Enabled) { return; } using (RegistryKey key = ScreenConfig.OpenRootRegKey(true)) { string ms = key.GetValue("InitialMouseSpeed", string.Empty).ToString(); if (string.IsNullOrEmpty(ms)) { _initMouseSpeed = LbmMouse.MouseSpeed; key.SetValue("InitialMouseSpeed", _initMouseSpeed.ToString(CultureInfo.InvariantCulture), RegistryValueKind.String); } else { double.TryParse(ms, out _initMouseSpeed); } using (RegistryKey savekey = key.CreateSubKey("InitialCursor")) { if (savekey?.ValueCount == 0) { LbmMouse.SaveCursor(savekey); } } } Process.GetCurrentProcess().PriorityClass = ProcessPriorityClass.RealTime; _handler = OnMouseMoveExtFirst; Hook.MouseMoveExt += _handler; if (Config.AdjustPointer) { ZoneChanged += AdjustPointer; } if (Config.AdjustSpeed) { ZoneChanged += AdjustSpeed; } if (Config.HomeCinema) { ZoneChanged += HomeCinema; } Hook.Enabled = true; }
private void AdjustPointer(object sender, ZoneChangeEventArgs args) { if (args.NewZone.Dpi - args.OldZone.Dpi < 1) { return; } if (args.NewZone.Dpi > 110) { LbmMouse.SetCursorAero(args.NewZone.Dpi > 138 ? 3 : 2); } else { LbmMouse.SetCursorAero(1); } }
public void Start() { if (Hook.Enabled) { return; } if (Config == null) { LoadConfig(); } if (Config == null || !Config.Enabled) { return; } SystemEvents.DisplaySettingsChanged += OnDisplaySettingsChanged; using (RegistryKey key = ScreenConfig.OpenRootRegKey(true)) { string ms = key.GetValue("InitialMouseSpeed", string.Empty).ToString(); if (string.IsNullOrEmpty(ms)) { _initMouseSpeed = LbmMouse.MouseSpeed; key.SetValue("InitialMouseSpeed", _initMouseSpeed.ToString(CultureInfo.InvariantCulture), RegistryValueKind.String); } else { double.TryParse(ms, out _initMouseSpeed); } using (RegistryKey savekey = key.CreateSubKey("InitialCursor")) { if (savekey?.ValueCount == 0) { LbmMouse.SaveCursor(savekey); } } } Process.GetCurrentProcess().PriorityClass = ProcessPriorityClass.RealTime; Hook.MouseMoveExt += OnMouseMoveExt; Hook.Enabled = true; // LittleBigMouseDaemon.Callback?.OnStateChange(); }
public void Stop() { SystemEvents.DisplaySettingsChanged -= OnDisplaySettingsChanged; if (!Hook.Enabled) { return; } Hook.MouseMoveExt -= OnMouseMoveExt; Hook.Enabled = false; // LittleBigMouseDaemon.Callback?.OnStateChange(); if (Config == null) { return; } if (Config.AdjustSpeed) { LbmMouse.MouseSpeed = _initMouseSpeed; using (var key = ScreenConfig.OpenRootRegKey(true)) { key.DeleteValue("InitialMouseSpeed"); } } if (Config.AdjustPointer) { using (var key = ScreenConfig.OpenRootRegKey()) { using (RegistryKey savekey = key.OpenSubKey("InitialCursor")) { if (savekey != null) { LbmMouse.RestoreCursor(savekey); } } key.DeleteSubKey("InitialCursor"); } } Process.GetCurrentProcess().PriorityClass = ProcessPriorityClass.Normal; }
private void MouseMoveStraight(object sender, HookMouseEventArg e) { //TODO : if (e.Clicked) return; var pIn = e.Point; if (_oldZone.ContainsPx(pIn)) { _oldPoint = pIn; e.Handled = false; return; } //Point oldpInMm = _oldZone.Px2Mm(_oldPoint); Point pInMm = _oldZone.Px2Mm(pIn); Zone zoneOut = null; var minDx = 0.0; var minDy = 0.0; if (pIn.Y > _oldZone.Px.Bottom) { foreach (var zone in _zones.All /*.Where(z => z.Mm.Top > _oldZone.Mm.Bottom)*/) { if (zone.Mm.Left > pInMm.X || zone.Mm.Right < pInMm.X) { continue; } var dy = zone.Mm.Top - _oldZone.Mm.Bottom; if (dy < 0) { continue; } if (dy > minDy && minDy > 0) { continue; } // = pInMm + new Vector(0, dy); minDy = dy; zoneOut = zone; } } else if (pIn.Y < _oldZone.Px.Top) { foreach (var zone in _zones.All /*.Where(z => !ReferenceEquals(z, _oldZone))*/) { if (zone.Mm.Left > pInMm.X || zone.Mm.Right < pInMm.X) { continue; } var dy = zone.Mm.Bottom - _oldZone.Mm.Top; if (dy > 0) { continue; } if (dy < minDy && minDy < 0) { continue; } minDy = dy; zoneOut = zone; } } if (pIn.X > _oldZone.Px.Right) { foreach (var zone in _zones.All) { if (zone.Mm.Top > pInMm.Y || zone.Mm.Bottom < pInMm.Y) { continue; } var dx = zone.Mm.Left - _oldZone.Mm.Right; if (dx < 0) { continue; } if (dx > minDx && minDx > 0) { continue; } minDx = dx; zoneOut = zone; } } else if (pIn.X < _oldZone.Px.Left) { foreach (var zone in _zones.All) { if (zone.Mm.Top > pInMm.Y || zone.Mm.Bottom < pInMm.Y) { continue; } var dx = zone.Mm.Right - _oldZone.Mm.Left; if (dx < minDx && minDx < 0) { continue; } if (dx > 0) { continue; } minDx = dx; zoneOut = zone; } } if (zoneOut == null) { LbmMouse.CursorPos = _oldZone.InsidePx(pIn); e.Handled = true; return; } var pOut = zoneOut.Mm2Px(new Point(pInMm.X + minDx, pInMm.Y + minDy)); pOut = zoneOut.InsidePx(pOut); _oldZone = zoneOut.Main; _oldPoint = pOut; //IntPtr hwnd = OpenInputDesktop(0, false, DESKTOP_SWITCHDESKTOP); //SetThreadDesktop(hwnd); //var movement = new INPUT { Type = (UInt32)0 }; //movement.Data.Mouse.Flags = (UInt32)(MouseFlag.Move | MouseFlag.Absolute | MouseFlag.VirtualDesk); //movement.Data.Mouse.X = (int)pOut.X; //movement.Data.Mouse.Y = (int)pOut.Y; //INPUT[] inputs = {movement}; //SendInput((UInt32)inputs.Length, inputs, Marshal.SizeOf(typeof(INPUT))); LbmMouse.CursorPos = pOut; var p = LbmMouse.CursorPos; if (Math.Abs(pOut.X - p.X) >= 1 || Math.Abs(pOut.Y - p.Y) >= 1) { IntPtr hOldDesktop = GetThreadDesktop(GetCurrentThreadId()); IntPtr hwnd = OpenInputDesktop(0, true, (uint)DESKTOP_ACCESS.GENERIC_ALL); Thread t = new Thread(() => { SwitchDesktop(hwnd); var b = SetThreadDesktop(hwnd); var b2 = LbmMouse.MouseEvent( NativeMethods.MOUSEEVENTF.ABSOLUTE | NativeMethods.MOUSEEVENTF.MOVE | NativeMethods.MOUSEEVENTF.VIRTUALDESK , pOut.X, pOut.Y); if (b2 == 0) { var s = NativeMethods.GetLastError(); } //LbmMouse.CursorPos = pOut; var b3 = NativeMethods.SetCursorPos((int)pOut.X, (int)pOut.Y); if (b3 == false) { var s = NativeMethods.GetLastError(); } // IList<string> list = new List<string>(); // GCHandle gch = GCHandle.Alloc(list); // EnumWindowStationsDelegate childProc = new EnumWindowStationsDelegate(EnumWindowStationsCallback); // EnumWindowStations(childProc, GCHandle.ToIntPtr(gch)); //} }); t.Start(); t.Join(); SwitchDesktop(hOldDesktop); //var w = new Window //{ // WindowStyle = WindowStyle.None, // Visibility = Visibility.Collapsed, // Width = 0, // Height = 0 //}; //w.Show(); ////const int DESKTOP_SWITCHDESKTOP = 256; ////IntPtr hwnd = OpenInputDesktop(0, false, 0x00020000); ////var b = SetThreadDesktop(hwnd); //LbmMouse.CursorPos = pOut; //w.Close(); } ZoneChanged?.Invoke(this, new ZoneChangeEventArgs(_oldZone, zoneOut)); e.Handled = true; }
private void OnMouseMoveExt(object sender, MouseEventExtArgs e) { // If first time called just save that point if (_oldPoint == null) { _oldPoint = new Point(e.X, e.Y); return; } if (e.Clicked) { return; } Screen oldScreen = Config.ScreenFromPixel(_oldPoint.Value); Point pIn = new Point(e.X, e.Y); // No move if (pIn.Equals(_oldPoint)) { return; } //Debug.Print(pIn.X + " , " + pIn.Y + " -> " + pIn.TargetScreen?.Monitor.Adapter.DeviceName); // no screen change if (oldScreen == null || Equals(Config.ScreenFromPixel(pIn), oldScreen)) { _oldPoint = pIn; return; } Point oldpInMm = oldScreen.InMm.GetPoint(oldScreen.InPixel, _oldPoint.Value); Point pInMm = oldScreen.InMm.GetPoint(oldScreen.InPixel, pIn); Screen screenOut = null; //Config.ScreenFromMmPosition(pInMm);// pIn.Mm.TargetScreen; Debug.Print(oldScreen?.Monitor.Adapter.DeviceName + "P:" + _oldPoint + " --> P:" + pIn + " " + screenOut?.Monitor.Adapter.DeviceName); Point pOut = pIn; // // Allow Corner Jump // if (screenOut == null) { double dist = double.PositiveInfinity;// (100.0); Segment seg = new Segment(oldpInMm, pInMm); // Calculate side to enter screen when corner crossing not allowed. Side side = seg.IntersectSide(oldScreen.InMm.Bounds); if (Config.AllowCornerCrossing) { foreach (var screen in Config.AllBut(oldScreen)) { foreach (Point p in seg.Line.Intersect(screen.InMm.Bounds)) { var travel = new Segment(oldpInMm, p); if (!travel.Rect.Contains(pInMm)) { continue; } if (travel.Size > dist) { continue; } dist = travel.Size; pOut = screen.InPixel.GetPoint(screen.InMm, p); // (new PhysicalPoint(Config, screen, p.X, p.Y)).Pixel.Inside; pOut = screen.InPixel.Inside(pOut); screenOut = screen; } } } else { foreach (var screen in Config.AllBut(oldScreen)) { Vector offset = new Vector(0, 0); switch (side) { case Side.None: break; case Side.Bottom: offset.Y = seg.Rect.Height + screen.InMm.Y - (oldScreen.InMm.Y + oldScreen.InMm.Height); if (offset.Y < 0) { offset.Y = 0; } break; case Side.Top: offset.Y = -seg.Rect.Height + (screen.InMm.Y + screen.InMm.Height) - oldScreen.InMm.Y; if (offset.Y > 0) { offset.Y = 0; } break; case Side.Right: offset.X = seg.Rect.Width + screen.InMm.X - (oldScreen.InMm.X + oldScreen.InMm.Width); if (offset.X < 0) { offset.X = 0; } break; case Side.Left: offset.X = -seg.Rect.Width + (screen.InMm.X + screen.InMm.Width) - oldScreen.InMm.X; if (offset.X > 0) { offset.X = 0; } break; default: throw new ArgumentOutOfRangeException(); } Debug.Print(screen.Monitor.Adapter.DeviceName + " = " + offset.Length); if (offset.Length > 0 && offset.Length < dist) { Point shiftedPoint = pInMm + offset; if (Equals(Config.ScreenFromMmPosition(shiftedPoint), screen)) { dist = offset.Length; pOut = screen.InPixel.GetPoint(screen.InMm, shiftedPoint); pOut = screen.InPixel.Inside(pOut); screenOut = screen; } else { } } } } } // if new position is not within another screen if (screenOut == null) { Debug.Print("Out"); LbmMouse.CursorPos = _oldPoint.Value;//TODO : .Inside.Point; e.Handled = true; return; } // Actual mouving mouse to new location LbmMouse.CursorPos = pOut;//.Mm.ToScreen(screenOut).Pixel.Inside.Point; Debug.Print(">" + pOut.X + "," + pOut.Y); Debug.Print(">" + LbmMouse.CursorPos.X + "," + LbmMouse.CursorPos.Y); // Adjust pointer size to dpi ratio : should not be usefull if windows screen ratio is used if (Config.AdjustPointer) { if (screenOut.RealDpiAvg > 110) { LbmMouse.SetCursorAero(screenOut.RealDpiAvg > 138 ? 3 : 2); } else { LbmMouse.SetCursorAero(1); } } // Adjust pointer speed to dpi ratio : should not be usefull if windows screen ratio is used if (Config.AdjustSpeed) { LbmMouse.MouseSpeed = Math.Round((5.0 / 96.0) * screenOut.RealDpiAvg, 0); } if (Config.HomeCinema) { oldScreen.Monitor.Vcp().Power = false; } screenOut.Monitor.Vcp().Power = true; _oldPoint = pOut; e.Handled = true; }