Mouse

Methods to interact with the mouse.


EMouseDistribution

EMouseDistribution = (
  MOUSE_DISTRIBUTION_DEFAULT, // Use Mouse.Distribution
  MOUSE_DISTRIBUTION_RANDOM,  // Completely random point
  MOUSE_DISTRIBUTION_GAUSS,   // Weighted towards the center
  MOUSE_DISTRIBUTION_SKEWED,  // Weighted torwards current mouse position
  MOUSE_DISTRIBUTION_ROWP     // Weighted torwards current mouse position but more "rounded" compared to EMouseDistribution.MOUSE_DISTRIBUTION_SKEWED
);
The available distributions used to generate a point in a box.

TMouse

TMouse = record(TSRLBaseRecord)
  Speed: Double;                     // Overall mouse speed (Default: 12)
  Gravity, Wind: Double;             // Gravity & Wind for generating mouse path (Default: 9 & 5)
  Distribution: EMouseDistribution;  // Default distribution to use (Default: EMouseDistribution.MOUSE_DISTRIBUTION_ROWP)
  MissChance: Double;                // Percentage chance to "Miss" the mouse (Default: 10)
  IdleInterval: Double;              // Distance to travel before calling Mouse.Idle() (Default: 0)
  IdleProgress: Double;
  IdleGoal: Double;
  OnMoving: TMouseMovingEvent;       // Callback while mouse is being moved
  OnTeleport: TMouseTeleportEvent;   // Callback when mouse is teleported
end;

Mouse.Setup()

procedure TMouse.Setup;

Initializes mouse variables.

Note

This is automatically called on the Mouse variable.


Mouse.Teleport

procedure TMouse.Teleport(X, Y: Int32);
procedure TMouse.Teleport(P: TPoint); overload;

Teleport the mouse to the desired X,Y coordinates or the specified TPoint P.

Example:

Mouse.Teleport(50, 50);

Mouse.Position

function TMouse.Position: TPoint;

Returns the mouse current position.

Example:

var P: TPoint;

P := Mouse.Position();

WriteLn('X: ', P.X);
WriteLn('Y: ', P.Y);

Mouse.Hold

procedure TMouse.Hold(Button: Int32);

Holds the desired mouse button down. The button will continue to be held down until Mouse.Release is called.

Available buttons:

  • MOUSE_LEFT

  • MOUSE_RIGHT

  • MOUSE_SCROLL

  • MOUSE_EXTRA_1

  • MOUSE_EXTRA_2

Example:

Mouse.Hold(MOUSE_LEFT); // The mouse is now holding down left click.

Mouse.Release

procedure TMouse.Release(Button: Int32);

Releases the desired mouse button which has been previously held.

Available buttons:

  • MOUSE_LEFT

  • MOUSE_RIGHT

  • MOUSE_SCROLL

  • MOUSE_EXTRA_1

  • MOUSE_EXTRA_2

Example:

Mouse.Release(MOUSE_LEFT); // The mouse is no holding left click.

Mouse.WindMouse

procedure TMouse.Release(Button: Int32);

The internal algorithm used by Mouse.Move to move the mouse in a human’ish way.

Credit: BenLand100 (https://github.com/BenLand100/SMART/blob/master/src/EventNazi.java#L201)


Mouse.Idle()

procedure TMouse.Idle();

When IdleInterval is reached this is called. Override to change behavior.

  • An IdleInterval of 1.0 equals to the distance between the top left and bottom right of the client.

  • Assuming the client dimensions are 500,500 the distance between (0,0) and (500,500) is ~700. With an IdleInterval of 2.0 this would automatically be called every time the mouse has travelled ~1400 pixels.


Mouse.Move()

procedure TMouse.Move(Destination: TPoint);
procedure TMouse.Move(X, Y: Int32); overload;
procedure TMouse.Move(Center: TPoint; Radius: Int32; ForcedMove: Boolean = False); overload;
procedure TMouse.Move(Box: TBox; ForcedMove: Boolean = False; Distribution: EMouseDistribution = EMouseDistribution.MOUSE_DISTRIBUTION_DEFAULT); overload;
procedure TMouse.Move(Circle: TCircle; ForcedMove: Boolean = False); overload;
procedure TMouse.Move(Rect: TRectangle; ForcedMove: Boolean = False); overload;

Moves the mouse to the desired destination. This method has several overloads available that are self explanatory.

Example:

var P: TPoint;
begin
  P.X := 50;
  P.Y := 50;
  Mouse.Move(P); // The mouse is now at 50,50
end;

Mouse.Click()

procedure TMouse.Click(Button: Int32);
procedure TMouse.Click(X, Y: Int32; Button: Int32); overload;
procedure TMouse.Click(P: TPoint; Button: Int32); overload;
procedure TMouse.Click(Center: TPoint; Radius: Int32; Button: Int32; ForcedMove: Boolean = False); overload;
procedure TMouse.Click(Box: TBox; Button: Int32; ForcedMove: Boolean = False; Distribution: EMouseDistribution = EMouseDistribution.MOUSE_DISTRIBUTION_DEFAULT); overload;
procedure TMouse.Click(Circle: TCircle; Button: Int32; ForcedMove: Boolean = False); overload;
procedure TMouse.Click(Rect: TRectangle; Button: Int32; ForcedMove: Boolean = False); overload;

Clicks the mouse with the desired button. This method has several overloads available that are all self explanatory. By using the original method you will simply click the mouse at the current mouse position.

Available buttons:

  • MOUSE_LEFT

  • MOUSE_RIGHT

  • MOUSE_SCROLL

  • MOUSE_EXTRA_1

  • MOUSE_EXTRA_2

Example:

Mouse.Click([50,50], MOUSE_LEFT); // Left click the current mouse position

Mouse.Miss()

function TMouse.Miss(P: TPoint): TPoint;

“Misses” the destination point P. Will stop somewhere along the path or overshoot. Returns the position the mouse was moved to.

This could automatically be called depending on Mouse.MissChance.


Mouse.DragTo()

procedure TMouse.DragTo(X, Y: Int32; button: Int32 = MOUSE_LEFT);
procedure TMouse.DragTo(P: TPoint; button: Int32 = MOUSE_LEFT); overload;

Holds the desired button and moves the mouse to the specified X and Y coordinates or the specified TPoint p. button by default is MOUSE_LEFT.

Example:

var P: TPoint;
begin
  P.X := 50;
  P.Y := 50;
  Mouse.DragTo(P); // Moves the mouse to 50,50 while holding MOUSE_LEFT
end;

Mouse.Scroll()

procedure TMouse.Scroll(amount: Int32; down: Boolean);
procedure TMouse.Scroll(p: TPoint; amount: Int32; down: Boolean);
procedure TMouse.Scroll(b: TBox; amount: Int32; down: Boolean);

Scrolls the mouse X amount of times. If a TPoint P or a TBox b is passed in, the mouse will be moved there to scroll. Otherwise, the current mouse position is used.

Example:

var P: TPoint;
begin
  P.X := 50;
  P.Y := 50;
  Mouse.Scroll(P, 5, True);  // Scroll 5 times down at 50,50
  Mouse.Scroll(P, 5, False); // Scroll 5 times up at 50,50
end;

var Mouse

Global mouse variable.