Mouse

Methods to interact with the mouse.

To see a click heatmap at the end of your botting session add the following compiler directive before you include WaspLib:

{$DEFINE WL_DEBUG_MOUSE}

EMouseDistribution

EMouseDistribution = enum(DEFAULT, RANDOM, GAUSS, SKEWED, ROWP);

The available distributions used to generate a point in a shape.

  • EMouseDistribution.DEFAULT: Uses whatever is set for TMouse.Distribution, which is EMouseDistribution.GAUSS by default.

  • EMouseDistribution.RANDOM: Completely random point

  • EMouseDistribution.GAUSS: Weighted towards the center of the shape

  • EMouseDistribution.SKEWED: Weighted torwards current mouse position

  • EMouseDistribution.ROWP: Weighted torwards current mouse position but more “rounded” compared to SKEWED

You can view what the distributions look like by running the Tool: Distribution Viewer:

_images/distribution_viewer.gif

TMouse

Main record used to interact with the Mouse.


Mouse.Setup

procedure TMouse.Setup();

Initializes TMouse internal values.

Note

This is automatically called on the Mouse variable.


Mouse variables and properties

The following are some of the variables and properties that TMouse has available to control it’s behaviour.


Mouse.Distribution

TMouse.Distribution: EMouseDistribution;

Variable used to set the type of click EMouseDistribution distrubution you want the Mouse to use.

The default value is EMouseDistribution.GAUSS.

Read EMouseDistribution for more information about it.


Mouse.MissChance

TMouse.MissChance: Double;

Variable used to control the miss chance of the Mouse.


Mouse.CanIdle

TMouse.CanIdle: Boolean;

Variable used to control the whether the Mouse can randomly idle while traveling. The default is True.


Mouse.UseTeleport

TMouse.UseTeleport: Boolean;

Variable used to control the whether the Mouse will teleport instead of traveling to it’s destinations. The default is False.

Setting this to True will make all the above variables and the below properties irrelevant as they will not be used.

It will also make all of the Mouse.Move methods use Mouse.Teleport instead.


Mouse.Wind

property TMouse.Wind: Double;
property TMouse.Wind(value: Double);

Get/Set TMouse wind value.

To understand what this does it might be worth reading BenLand’s blog about it as he is the original creator of the wind mouse algorithm.

You can imagine Wind as the tendency the Mouse will have to spiral. The default value is 5. Especially if it’s increased. The value you set should be balanced with Mouse.Gravity and Mouse.Speed.

Keep in mind that adjusting this without understanding what you are doing can cause the mouse to do some very weird movements, even spin forever or until TMouse.Timeout is reached.


Mouse.Speed

property TMouse.Speed: Double;
property TMouse.Speed(value: Double);

Get/Set TMouse speed value.

To understand what this does it might be worth reading BenLand’s blog about it as he is the original creator of the wind mouse algorithm.

This should be self explanatory, basically speeds up the mouse. The default value is 12.

Keep in mind that adjusting this without understanding what you are doing can cause the mouse to do some very weird movements, even spin forever or until TMouse.Timeout is reached. Especially if it’s increased. The value you set should be balanced with Mouse.Wind and Mouse.Gravity and this basically amplifies their effects.

Also, despite what value you add here, there’s 2 hard limits to how fast the mouse can travel:

  • The first is your computer speed, there’s a limit to how fast your computer can calculate the path and/or the next pixel to move and also how fast it can actually move the mouse from one pixel to another.

  • The second one is that the mouse always travels pixel by pixel. When you are this already at your computer speed limit, increasing speed won’t do anything the only way to make it faster would be to make it jump pixels.


Mouse.Timeout

property TMouse.Timeout: Integer;
property TMouse.Timeout(value: Integer);

Get/Set TMouse timeout value.

This is basically a failsafe that stops the mouse from moving if it’s taking too long to reach it’s destination.


Mouse.Gravity

property TMouse.Gravity: Double;
property TMouse.Gravity(value: Double);

Get/Set TMouse gravity value.

To understand what this does it might be worth reading BenLand’s blog about it as he is the original creator of the wind mouse algorithm.

You can imagine this as a force that pulls the mouse towards it’s destination. The default value is 9.

Keep in mind that adjusting this without understanding what you are doing can cause the mouse to do some very weird movements, even spin forever or until TMouse.Timeout is reached. Especially if it’s decreased. The value you set should be balanced with Mouse.Wind and Mouse.Speed.


Mouse.PressMin

property TMouse.PressMin: Integer;
property TMouse.PressMin(value: Integer);

Get/Set TMouse PressMin value.

Basically the minimum time the TMouse buttons will be held when clicking.

When clicking the mouse buttons the mouse button will be held a random time between TMouse.PressMin and TMouse.PressMax.


Mouse.PressMax

property TMouse.PressMax: Integer;
property TMouse.PressMax(value: Integer);

Get/Set TMouse PressMax value.

Basically the maximum time the TMouse buttons will be held when clicking.

When clicking the mouse buttons the mouse button will be held a random time between TMouse.PressMin and TMouse.PressMax.


Mouse.Teleport

procedure TMouse.Teleport(coordinate: TPoint);

Teleport the mouse to the desired coordinate.

Example:

Mouse.Teleport(50, 50);

Mouse.Position

property TMouse.Position: TPoint;
property TMouse.Position(value: TPoint);

Used to return or set the mouse current position as a TPoint.

Example:

WriteLn(Mouse.Position);
Mouse.Position := [100, 100];
WriteLn(Mouse.Position);

Mouse.Hold

procedure TMouse.Hold(button: EMouseButton);

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

Example:

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

Mouse.Release

procedure TMouse.Release(button: EMouseButton);

Releases the desired mouse button which has been previously held.

Example:

Mouse.Release(EMouseButton.LEFT);

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.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.Move

procedure TMouse.Move(destination: TPoint);
procedure TMouse.Move(circle: TCircle; forcedMove: Boolean = False; distribution: EMouseDistribution = EMouseDistribution.DEFAULT); overload;
procedure TMouse.Move(b: TBox; forcedMove: Boolean = False; distribution: EMouseDistribution = EMouseDistribution.DEFAULT); overload;
procedure TMouse.Move(quad: TQuad; forcedMove: Boolean = False; distribution: EMouseDistribution = EMouseDistribution.DEFAULT); overload;

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

Example:

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

Mouse.Click

procedure TMouse.Click(button: EMouseButton);
procedure TMouse.Click(destination: TPoint; button: EMouseButton); overload;
procedure TMouse.Click(circle: TCircle; button: EMouseButton; forcedMove: Boolean = False; distribution: EMouseDistribution = EMouseDistribution.DEFAULT); overload;
procedure TMouse.Click(b: TBox; button: EMouseButton; forcedMove: Boolean = False; distribution: EMouseDistribution = EMouseDistribution.DEFAULT); overload;
procedure TMouse.Click(quad: TQuad; button: EMouseButton; forcedMove: Boolean = False; distribution: EMouseDistribution = EMouseDistribution.DEFAULT); overload;

Moves and clicks the mouse on the desired destination with the desired button. This method has several overloads available that are self explanatory.

Example:

var p: TPoint;
begin
  p := TPoint.Create(50, 50);
  Mouse.Click(p, EMouseButton.LEFT); // Moves and clicks the mouse left button at 50,50
end;

Mouse.Drag

procedure TMouse.Drag(destination: TPoint; button: EMouseButton);
procedure TMouse.Drag(circle: TCircle; button: EMouseButton); overload;
procedure TMouse.Drag(box: TBox; button: EMouseButton); overload;
procedure TMouse.Drag(quad: TQuad; button: EMouseButton); overload;

Press and hold button while the mouse is moved to the specified destination.


Mouse.Scroll

procedure TMouse.Scroll(amount: Integer; down: Boolean);
procedure TMouse.Scroll(pt: TPoint; amount: Integer; down: Boolean);
procedure TMouse.Scroll(box: TBox; amount: Integer; 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;

Mouse variable

Global TMouse variable.


ASyncMouse variable

Global TASyncMouse variable.