From a8affff800c580ce2df0b789c9d1ff150ed49d45 Mon Sep 17 00:00:00 2001 From: Steve Williams Date: Wed, 24 Apr 2024 22:45:32 +0100 Subject: [PATCH] Release 4.18.0. --- .../Actions/MoveMouseCursorAction.cs | 96 +++++++++++++------ 4x/Move Mouse/Actions/ScrollMouseAction.cs | 48 ++++++++-- 4x/Move Mouse/Actions/SleepAction.cs | 3 +- 4x/Move Mouse/Properties/AssemblyInfo.cs | 4 +- 4x/Move Mouse/Views/MouseWindow.xaml.cs | 21 ---- 4x/Move Mouse/Views/SettingsWindow.xaml | 94 ++++++++++++++---- 6 files changed, 184 insertions(+), 82 deletions(-) diff --git a/4x/Move Mouse/Actions/MoveMouseCursorAction.cs b/4x/Move Mouse/Actions/MoveMouseCursorAction.cs index 4725328..5b6c056 100644 --- a/4x/Move Mouse/Actions/MoveMouseCursorAction.cs +++ b/4x/Move Mouse/Actions/MoveMouseCursorAction.cs @@ -9,6 +9,8 @@ namespace ellabi.Actions public class MoveMouseCursorAction : ActionBase { private int _distance; + private int _upperDistance; + private bool _random; private CursorDirection _direction; private CursorSpeed _speed; private int _delay; @@ -49,11 +51,41 @@ public int Distance get => _distance; set { + if (value > UpperDistance) + { + UpperDistance = value; + } + _distance = value; OnPropertyChanged(); } } + public int UpperDistance + { + get => _upperDistance; + set + { + if (value < Distance) + { + Distance = value; + } + + _upperDistance = value < 1 ? 1 : value; + OnPropertyChanged(); + } + } + + public bool Random + { + get => _random; + set + { + _random = value; + OnPropertyChanged(); + } + } + public CursorDirection Direction { get => _direction; @@ -112,6 +144,7 @@ public int Delay public MoveMouseCursorAction() { _distance = 10; + _upperDistance = 20; _direction = CursorDirection.Square; Speed = CursorSpeed.Normal; InterruptsIdleTime = true; @@ -128,64 +161,65 @@ public override void Execute() { IntervalExecutionCount++; StaticCode.Logger?.Here().Information(ToString()); + int distance = Random ? new Random().Next(Convert.ToInt32(Distance), Convert.ToInt32(UpperDistance)) : Distance; switch (Direction) { case CursorDirection.Square: - MouseCursorWrapper.MoveEast(Distance, _delay); - MouseCursorWrapper.MoveSouth(Distance, _delay); - MouseCursorWrapper.MoveWest(Distance, _delay); - MouseCursorWrapper.MoveNorth(Distance, _delay); + MouseCursorWrapper.MoveEast(distance, _delay); + MouseCursorWrapper.MoveSouth(distance, _delay); + MouseCursorWrapper.MoveWest(distance, _delay); + MouseCursorWrapper.MoveNorth(distance, _delay); break; case CursorDirection.North: - MouseCursorWrapper.MoveNorth(Distance, _delay); + MouseCursorWrapper.MoveNorth(distance, _delay); break; case CursorDirection.East: - MouseCursorWrapper.MoveEast(Distance, _delay); + MouseCursorWrapper.MoveEast(distance, _delay); break; case CursorDirection.South: - MouseCursorWrapper.MoveSouth(Distance, _delay); + MouseCursorWrapper.MoveSouth(distance, _delay); break; case CursorDirection.West: - MouseCursorWrapper.MoveWest(Distance, _delay); + MouseCursorWrapper.MoveWest(distance, _delay); break; case CursorDirection.NorthEast: - MouseCursorWrapper.MoveNorthEast(Distance, _delay); + MouseCursorWrapper.MoveNorthEast(distance, _delay); break; case CursorDirection.SouthEast: - MouseCursorWrapper.MoveSouthEast(Distance, _delay); + MouseCursorWrapper.MoveSouthEast(distance, _delay); break; case CursorDirection.SouthWest: - MouseCursorWrapper.MoveSouthWest(Distance, _delay); + MouseCursorWrapper.MoveSouthWest(distance, _delay); break; case CursorDirection.NorthWest: - MouseCursorWrapper.MoveNorthWest(Distance, _delay); + MouseCursorWrapper.MoveNorthWest(distance, _delay); break; case CursorDirection.UpAndDown: - MouseCursorWrapper.MoveNorth(Distance, _delay); - MouseCursorWrapper.MoveSouth(Distance, _delay); + MouseCursorWrapper.MoveNorth(distance, _delay); + MouseCursorWrapper.MoveSouth(distance, _delay); break; case CursorDirection.DownAndUp: - MouseCursorWrapper.MoveSouth(Distance, _delay); - MouseCursorWrapper.MoveNorth(Distance, _delay); + MouseCursorWrapper.MoveSouth(distance, _delay); + MouseCursorWrapper.MoveNorth(distance, _delay); break; case CursorDirection.LeftAndRight: - MouseCursorWrapper.MoveWest(Distance, _delay); - MouseCursorWrapper.MoveEast(Distance, _delay); + MouseCursorWrapper.MoveWest(distance, _delay); + MouseCursorWrapper.MoveEast(distance, _delay); break; case CursorDirection.RightAndLeft: - MouseCursorWrapper.MoveEast(Distance, _delay); - MouseCursorWrapper.MoveWest(Distance, _delay); + MouseCursorWrapper.MoveEast(distance, _delay); + MouseCursorWrapper.MoveWest(distance, _delay); break; case CursorDirection.Random: - int distanceRemaining = Distance; + int distanceRemaining = distance; int lastDirection = 0; while (distanceRemaining > 0) { const int maxDistance = 150; - int distance = new Random(distanceRemaining).Next(1, (distanceRemaining < maxDistance) ? distanceRemaining : maxDistance); - distanceRemaining = distanceRemaining - distance; + int randomDistance = new Random(distanceRemaining).Next(1, (distanceRemaining < maxDistance) ? distanceRemaining : maxDistance); + distanceRemaining = distanceRemaining - randomDistance; int direction; do @@ -198,28 +232,28 @@ public override void Execute() switch (direction) { case 1: - MouseCursorWrapper.MoveNorth(distance, _delay); + MouseCursorWrapper.MoveNorth(randomDistance, _delay); break; case 2: - MouseCursorWrapper.MoveEast(distance, _delay); + MouseCursorWrapper.MoveEast(randomDistance, _delay); break; case 3: - MouseCursorWrapper.MoveSouth(distance, _delay); + MouseCursorWrapper.MoveSouth(randomDistance, _delay); break; case 4: - MouseCursorWrapper.MoveWest(distance, _delay); + MouseCursorWrapper.MoveWest(randomDistance, _delay); break; case 5: - MouseCursorWrapper.MoveNorthEast(distance, _delay); + MouseCursorWrapper.MoveNorthEast(randomDistance, _delay); break; case 6: - MouseCursorWrapper.MoveSouthEast(distance, _delay); + MouseCursorWrapper.MoveSouthEast(randomDistance, _delay); break; case 7: - MouseCursorWrapper.MoveSouthWest(distance, _delay); + MouseCursorWrapper.MoveSouthWest(randomDistance, _delay); break; case 8: - MouseCursorWrapper.MoveNorthWest(distance, _delay); + MouseCursorWrapper.MoveNorthWest(randomDistance, _delay); break; } } diff --git a/4x/Move Mouse/Actions/ScrollMouseAction.cs b/4x/Move Mouse/Actions/ScrollMouseAction.cs index 499a466..2751a9b 100644 --- a/4x/Move Mouse/Actions/ScrollMouseAction.cs +++ b/4x/Move Mouse/Actions/ScrollMouseAction.cs @@ -9,6 +9,8 @@ namespace ellabi.Actions public class ScrollMouseAction : ActionBase { private uint _distance; + private uint _upperDistance; + private bool _random; private WheelDirection _direction; public enum WheelDirection @@ -16,7 +18,8 @@ public enum WheelDirection Up, Down, Left, - Right + Right, + Random } public IEnumerable WheelDirectionValues => Enum.GetValues(typeof(WheelDirection)).Cast(); @@ -28,11 +31,41 @@ public uint Distance get => _distance; set { + if (value > UpperDistance) + { + UpperDistance = value; + } + _distance = value; OnPropertyChanged(); } } + public uint UpperDistance + { + get => _upperDistance; + set + { + if (value < Distance) + { + Distance = value; + } + + _upperDistance = value < 1 ? 1 : value; + OnPropertyChanged(); + } + } + + public bool Random + { + get => _random; + set + { + _random = value; + OnPropertyChanged(); + } + } + public WheelDirection Direction { get => _direction; @@ -46,6 +79,7 @@ public WheelDirection Direction public ScrollMouseAction() { _distance = 100; + _upperDistance = 200; _direction = WheelDirection.Down; InterruptsIdleTime = true; } @@ -60,27 +94,29 @@ public override void Execute() try { StaticCode.Logger?.Here().Information(ToString()); + var direction = (Direction == WheelDirection.Random) ? WheelDirectionValues.OrderBy(wd => Guid.NewGuid()).FirstOrDefault() : Direction; + uint distance = Random ? (uint)(new Random().Next(Convert.ToInt32(Distance), Convert.ToInt32(UpperDistance))) : Distance; - switch (_direction) + switch (direction) { case WheelDirection.Up: { - NativeMethods.mouse_event((int)NativeMethods.MouseEventFlags.WHEEL, 0, 0, Distance, 0); + NativeMethods.mouse_event((int)NativeMethods.MouseEventFlags.WHEEL, 0, 0, distance, 0); break; } case WheelDirection.Down: { - NativeMethods.mouse_event((int)NativeMethods.MouseEventFlags.WHEEL, 0, 0, (uint)(Distance * -1), 0); + NativeMethods.mouse_event((int)NativeMethods.MouseEventFlags.WHEEL, 0, 0, (uint)(distance * -1), 0); break; } case WheelDirection.Left: { - NativeMethods.mouse_event((int)NativeMethods.MouseEventFlags.HWHEEL, 0, 0, Distance, 0); + NativeMethods.mouse_event((int)NativeMethods.MouseEventFlags.HWHEEL, 0, 0, distance, 0); break; } case WheelDirection.Right: { - NativeMethods.mouse_event((int)NativeMethods.MouseEventFlags.HWHEEL, 0, 0, (uint)(Distance * -1), 0); + NativeMethods.mouse_event((int)NativeMethods.MouseEventFlags.HWHEEL, 0, 0, (uint)(distance * -1), 0); break; } } diff --git a/4x/Move Mouse/Actions/SleepAction.cs b/4x/Move Mouse/Actions/SleepAction.cs index 84a0ac6..d943143 100644 --- a/4x/Move Mouse/Actions/SleepAction.cs +++ b/4x/Move Mouse/Actions/SleepAction.cs @@ -46,7 +46,8 @@ public bool Random get => _random; set { - _random = value; OnPropertyChanged(); + _random = value; + OnPropertyChanged(); } } diff --git a/4x/Move Mouse/Properties/AssemblyInfo.cs b/4x/Move Mouse/Properties/AssemblyInfo.cs index 07edea9..efe1c01 100644 --- a/4x/Move Mouse/Properties/AssemblyInfo.cs +++ b/4x/Move Mouse/Properties/AssemblyInfo.cs @@ -51,5 +51,5 @@ // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("4.17.0.0")] -[assembly: AssemblyFileVersion("4.17.0.0")] +[assembly: AssemblyVersion("4.18.0.0")] +[assembly: AssemblyFileVersion("4.18.0.0")] diff --git a/4x/Move Mouse/Views/MouseWindow.xaml.cs b/4x/Move Mouse/Views/MouseWindow.xaml.cs index cb41e53..70d5b3e 100644 --- a/4x/Move Mouse/Views/MouseWindow.xaml.cs +++ b/4x/Move Mouse/Views/MouseWindow.xaml.cs @@ -165,27 +165,6 @@ private void _vm_MouseStateChanged(object sender, MouseWindowViewModel.MouseStat try { - try - { - Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Normal, new Action(delegate - { - if (TaskbarItemInfo != null) - { - TaskbarItemInfo.ProgressState = - state.Equals(MouseWindowViewModel.MouseState.Running) ? TaskbarItemProgressState.Normal : - state.Equals(MouseWindowViewModel.MouseState.Executing) ? TaskbarItemProgressState.Error : - state.Equals(MouseWindowViewModel.MouseState.Paused) ? TaskbarItemProgressState.Paused : - state.Equals(MouseWindowViewModel.MouseState.Sleeping) ? TaskbarItemProgressState.Paused : - state.Equals(MouseWindowViewModel.MouseState.OnBattery) ? TaskbarItemProgressState.Paused : - TaskbarItemProgressState.None; - } - })); - } - catch (Exception ex) - { - StaticCode.Logger?.Here().Error(ex.Message); - } - //Debug.WriteLine($"state = {state}"); var duration = _vm.ExecutionTime.Subtract(DateTime.Now); //Debug.WriteLine($"duration = {duration}"); diff --git a/4x/Move Mouse/Views/SettingsWindow.xaml b/4x/Move Mouse/Views/SettingsWindow.xaml index ee7bd7b..79549d8 100644 --- a/4x/Move Mouse/Views/SettingsWindow.xaml +++ b/4x/Move Mouse/Views/SettingsWindow.xaml @@ -544,27 +544,79 @@ - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +