Skip to content

Commit

Permalink
Release 4.18.0.
Browse files Browse the repository at this point in the history
  • Loading branch information
sw3103 committed Apr 24, 2024
1 parent 7ff536f commit a8affff
Show file tree
Hide file tree
Showing 6 changed files with 184 additions and 82 deletions.
96 changes: 65 additions & 31 deletions 4x/Move Mouse/Actions/MoveMouseCursorAction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -112,6 +144,7 @@ public int Delay
public MoveMouseCursorAction()
{
_distance = 10;
_upperDistance = 20;
_direction = CursorDirection.Square;
Speed = CursorSpeed.Normal;
InterruptsIdleTime = true;
Expand All @@ -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
Expand All @@ -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;
}
}
Expand Down
48 changes: 42 additions & 6 deletions 4x/Move Mouse/Actions/ScrollMouseAction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,17 @@ namespace ellabi.Actions
public class ScrollMouseAction : ActionBase
{
private uint _distance;
private uint _upperDistance;
private bool _random;
private WheelDirection _direction;

public enum WheelDirection
{
Up,
Down,
Left,
Right
Right,
Random
}

public IEnumerable<WheelDirection> WheelDirectionValues => Enum.GetValues(typeof(WheelDirection)).Cast<WheelDirection>();
Expand All @@ -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;
Expand All @@ -46,6 +79,7 @@ public WheelDirection Direction
public ScrollMouseAction()
{
_distance = 100;
_upperDistance = 200;
_direction = WheelDirection.Down;
InterruptsIdleTime = true;
}
Expand All @@ -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;
}
}
Expand Down
3 changes: 2 additions & 1 deletion 4x/Move Mouse/Actions/SleepAction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ public bool Random
get => _random;
set
{
_random = value; OnPropertyChanged();
_random = value;
OnPropertyChanged();
}
}

Expand Down
4 changes: 2 additions & 2 deletions 4x/Move Mouse/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
21 changes: 0 additions & 21 deletions 4x/Move Mouse/Views/MouseWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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}");
Expand Down
Loading

0 comments on commit a8affff

Please sign in to comment.