Class: Mouse

PD. Mouse


new Mouse()

A static controller class for managing a simulated mouse.

This class uses a DOM element that looks like a mouse cursor to enhance scripts and assist live demonstrations.

Author:
  • drajmarsh

Methods


button( [button] [, duration]) <static>

Add queued action to highlight a mouse button.

Parameters:
Name Type Argument Description
button string | number <optional>

The mouse button to drag, defaults to LEFT.

duration number <optional>

The duration to wait after showing in milliseconds, defaults to 0 (no wait).

Returns:

Returns this mouse instance to support method chaining.

Type
PD.Mouse

buttonAsync( [button] [, duration]) <async, static>

Highlight a mouse button.

Parameters:
Name Type Argument Description
button string | number <optional>

The mouse button to drag, defaults to LEFT.

duration number <optional>

The duration to wait after showing in milliseconds, defaults to 0 (no wait).


callback(callback, args) <static>

Add queued action to invoke a callback function.

Parameters:
Name Type Argument Description
callback function

The function to call in the sequence.

args any <repeatable>

The arguments associated with the call.

Returns:

Returns this mouse instance to support method chaining.

Type
PD.Mouse

click( [button] [, duration]) <static>

Add queued action to click and releases the simulated mouse arrow in the model.

Parameters:
Name Type Argument Description
button string | number <optional>

The mouse button to click, defaults to LEFT.

duration number <optional>

The duration of the click in milliseconds, default to cursor default duration.

Returns:

Returns this mouse instance to support method chaining.

Type
PD.Mouse

clickAndRelease( [button] [, duration]) <static>

Add queued action to click the simulated mouse arrow and sends click event to target.

Parameters:
Name Type Argument Description
button string | number <optional>

The mouse button to click, defaults to LEFT.

duration number <optional>

The duration of the click in milliseconds, default to cursor default duration.

Returns:

Returns this mouse instance to support method chaining.

Type
PD.Mouse

clickAndReleaseAsync( [button] [, duration]) <static>

Click the simulated mouse arrow and sends click event to model canvas.

Parameters:
Name Type Argument Description
button string | number <optional>

The mouse button to click, defaults to LEFT.

duration number <optional>

The duration of the click in milliseconds, default to cursor default duration.

Returns:

Returns this mouse instance to support method chaining.

Type
PD.Mouse

clickAsync( [button] [, duration]) <async, static>

Click the simulated mouse arrow in the model.

Parameters:
Name Type Argument Description
button string | number <optional>

The mouse button to click, defaults to LEFT.

duration number <optional>

The duration of the click in milliseconds, default to cursor default duration.


clickOn(id [, duration]) <static>

Add queued action to move the simulated mouse arrow to the given HTML element id and click it.

Parameters:
Name Type Argument Description
id string

The element id of a HTMLElement within the DOM.

duration number <optional>

The duration of the move in milliseconds, default to cursor default duration.

Returns:

Returns this mouse instance to support method chaining.

Type
PD.Mouse

clickOnAsync(id [, duration]) <async, static>

Move the simulated mouse arrow to the given HTML element id and click it.

Parameters:
Name Type Argument Description
id string

The element id of a HTMLElement in the DOM.

duration number <optional>

The duration of the move in milliseconds, default to 600ms.


drag(x, y [, button] [, duration]) <static>

Add queued action to drag the simulated mouse arrow to the given page coordinates.

Parameters:
Name Type Argument Description
x number

The X-axis page position to drag the mouse to.

y number

The Y-axis page position to move the mouse to.

button string | number <optional>

The mouse button to drag, defaults to LEFT.

duration number <optional>

The duration of the drag in milliseconds, default to cursor default duration.

Returns:

Returns this mouse instance to support method chaining.

Type
PD.Mouse

dragAsync(x, y [, button] [, duration]) <async, static>

Drags the simulated mouse arrow to the given page coordinates.

Parameters:
Name Type Argument Description
x number

The X-axis position to drag the mouse to.

y number

The Y-axis position to move the mouse to.

button string | number <optional>

The mouse button to drag, defaults to LEFT.

duration number <optional>

The duration of the move in milliseconds, default to cursor default.


dragToPoint(point [, button] [, duration]) <static>

Add queued action to drag the simulated mouse arrow to the given 3D point in the model.

Parameters:
Name Type Argument Description
point THREE.Vector3

A 3D point in the form {x,y,z}.

button string | number <optional>

The mouse button to drag, defaults to LEFT.

duration number <optional>

The duration of the drag in milliseconds, default to cursor default duration.

Returns:

Returns this mouse instance to support method chaining.

Type
PD.Mouse

dragToPointAsync(point [, button] [, duration]) <async, static>

Add queued action to drag the simulated mouse arrow to the given 3D point in the model.

Parameters:
Name Type Argument Description
point THREE.Vector3

A 3D point in the form {x,y,z}.

button string | number <optional>

The mouse button to drag, defaults to LEFT.

duration number <optional>

The duration of the drag in milliseconds, default to cursor default duration.


dragToXYZ(x, y, z [, button] [, duration]) <static>

Add queued action to drag the simulated mouse arrow to the given 3D model coordinates.

Parameters:
Name Type Argument Description
x number

The X-axis model position to drag the mouse to.

y number

The Y-axis model position to move the mouse to.

z number

The Z-axis model position to move the mouse to.

button string | number <optional>

The mouse button to drag, defaults to LEFT.

duration number <optional>

The duration of the drag in milliseconds, default to cursor default duration.

Returns:

Returns this mouse instance to support method chaining.

Type
PD.Mouse

dragToXYZAsync(x, y, z [, button] [, duration]) <async, static>

Drags the simulated mouse arrow to the given position in the main model canvas.

Parameters:
Name Type Argument Description
x number | THREE.Vector3

The X-axis position or a 3D model position to move the mouse to.

y number | string

The Y-axis position to move the mouse to or, if x is a vector, the button to drag.

z number

The z-axis position to move the mouse to or, if x is a vector, the duration in milliseconds.

button number | string <optional>

The duration of the move in milliseconds, default to 600ms.

duration number <optional>

The duration of the move in milliseconds, default to 600ms.

Returns:

Returns the page coordinates of the destination mouse position.

Type
THREE.Vector3

getElementAtPos( [x] [, y]) <static>

Tries to find the DOM element directly underneath the given page coordinates.

If no coordinates are given the current fake mouse position is used.

Parameters:
Name Type Argument Description
x number <optional>

The X-axis page coordinate, defaults to the fake mouse left position.

y number <optional>

The Y-axis page coordinate, defaults to the fake mouse top position.

Returns:

Returns the 2D page coordinates.

Type
HTMLElement | null

getPos() <static>

Retrieves the position of the mouse in 2D page coordinates.

Returns:

Returns the 2D page coordinates.

Type
THREE.Vector2

getPosAtPoint(point) <static>

Compute the 2D page coordinates of a point in the 3D model.

Parameters:
Name Type Description
point THREE.Vector3

A point within the 3D model.

Returns:

Returns the 2D page coordinates.

Type
THREE.Vector2

getPosAtXYZ(x, y, z) <static>

Compute the 2D page coordinates of the 3D model position.

Parameters:
Name Type Description
x number

The X-axis model position.

y number

The Y-axis model position.

z number

The Z-axis model position.

Returns:

Returns the 2D page coordinates.

Type
THREE.Vector2

go() <async, static>

Processes any queued simulated mouse action events.


hide( [duration]) <static>

Add queued action to hide the simulated mouse arrow.

Parameters:
Name Type Argument Description
duration number <optional>

The duration to wait before hiding in milliseconds, defaults to 0 (no wait).

Returns:

Returns this mouse instance to support method chaining.

Type
PD.Mouse

hideAsync( [duration]) <async, static>

Hide the simulated mouse arrow.

Parameters:
Name Type Argument Description
duration number <optional>

The duration to wait before hiding in milliseconds, defaults to 0 (no wait).


mouse( [state] [, duration]) <static>

Add queued action to show or hide the mouse indicator adjacent to the cursor.

Parameters:
Name Type Argument Description
state boolean <optional>

Whether to show or hide, defaults to true.

duration number <optional>

The duration to wait after showing in milliseconds, defaults to 0 (no wait).

Returns:

Returns this mouse instance to support method chaining.

Type
PD.Mouse

mouseAsync( [state] [, duration]) <async, static>

Show or hide the mouse indicator adjacent to the cursor.

Parameters:
Name Type Argument Description
state boolean <optional>

Whether to show or hide, defaults to true.

duration number <optional>

The duration to wait after showing in milliseconds, defaults to 0 (no wait).


move(x, y [, duration]) <static>

Add queued action to move the simulated mouse arrow to the given page coordinates.

Parameters:
Name Type Argument Description
x number

The X-axis page position to drag the mouse to.

y number

The Y-axis page position to move the mouse to.

duration number <optional>

The duration of the move in milliseconds, default to cursor default duration.

Returns:

Returns this mouse instance to support method chaining.

Type
PD.Mouse

moveAsync(x, y [, duration]) <async, static>

Add queued action to move the simulated mouse arrow to the given page coordinates.

Parameters:
Name Type Argument Description
x number

The X-axis page position to drag the mouse to.

y number

The Y-axis page position to move the mouse to.

duration number <optional>

The duration of the move in milliseconds, default to cursor default duration.


moveToCursor( [duration]) <static>

Add queued action to move the simulated mouse arrow to the current 3D model cursor position.

This action is most ofter used immediately after dragging the 3D model cursor in order to ensure that a snap value did not move it beyond the range of the simulated mouse arrow.

Parameters:
Name Type Argument Description
duration number <optional>

The duration of the drag in milliseconds, default to 250ms.

Returns:

Returns this mouse instance to support method chaining.

Type
PD.Mouse

moveToCursorAsync( [duration]) <async, static>

Add queued action to move the simulated mouse arrow to the current 3D model cursor position.

This action is most ofter used immediately after dragging the 3D model cursor in order to ensure that a snap value did not move it beyond the range of the simulated mouse arrow.

Parameters:
Name Type Argument Description
duration number <optional>

The duration of the drag in milliseconds, default to 250ms.


moveToPoint(point [, duration]) <static>

Add queued action to move the simulated mouse arrow to the given 3D point in the model.

Parameters:
Name Type Argument Description
point THREE.Vector3

A 3D point in the form {x,y,z}.

duration number <optional>

The duration of the drag in milliseconds, default to cursor default duration.

Returns:

Returns this mouse instance to support method chaining.

Type
PD.Mouse

moveToPointAsync(point [, duration]) <async, static>

Move the simulated mouse arrow to the given 3D point in the model.

Parameters:
Name Type Argument Description
point THREE.Vector3

A 3D point in the form {x,y,z}.

duration number <optional>

The duration of the drag in milliseconds, default to cursor default duration.


moveToXYZ(x, y, z [, duration]) <static>

Add queued action to move the simulated mouse arrow to the given 3D model coordinates.

Parameters:
Name Type Argument Description
x number

The X-axis model position to drag the mouse to.

y number

The Y-axis model position to move the mouse to.

z number

The Z-axis model position to move the mouse to.

duration number <optional>

The duration of the move in milliseconds, default to cursor default duration.

Returns:

Returns this mouse instance to support method chaining.

Type
PD.Mouse

moveToXYZAsync(x, y, z [, duration]) <async, static>

Moves the simulated mouse arrow to the given position in the main model canvas.

Parameters:
Name Type Argument Description
x number | THREE.Vector3

The X-axis position or a 3D model position to move the mouse to.

y number

The Y-axis position to move the mouse to or, if x is a vector, the duration in milliseconds.

z number

The Z-axis position to move the mouse to.

duration number <optional>

The duration of the move in milliseconds, default to 600ms.

Returns:

Returns the page coordinates of the destination mouse position.

Type
THREE.Vector3

setSimulatedArrow(cursor) <static>

Set the simulated mouse arrow controller to use.

Parameters:
Name Type Description
cursor object

The simulated mouse arrow controller with an action() method.


show( [duration]) <static>

Add queued action to display the simulated mouse arrow.

Parameters:
Name Type Argument Description
duration number <optional>

The duration to wait after showing in milliseconds, defaults to 0 (no wait).

Returns:

Returns this mouse instance to support method chaining.

Type
PD.Mouse

showAsync( [duration]) <async, static>

Displays the simulated mouse arrow.

Parameters:
Name Type Argument Description
duration number <optional>

The duration to wait after showing in milliseconds, defaults to 0 (no wait).


text(message [, duration]) <static>

Add queued action to display the given message beneath the simulated mouse arrow.

Parameters:
Name Type Argument Description
message string

The message tp display beneath the cursor.

duration number <optional>

The duration to wait after showing in milliseconds, defaults to 0 (no wait).

Returns:

Returns this mouse instance to support method chaining.

Type
PD.Mouse

textAsync(message [, duration]) <async, static>

Add queued action to display the given message beneath the simulated mouse arrow.

Parameters:
Name Type Argument Description
message string

The message tp display beneath the cursor.

duration number <optional>

The duration to wait after showing in milliseconds, defaults to 0 (no wait).


wait( [duration]) <static>

Add queued action to wait for the given duration.

Parameters:
Name Type Argument Description
duration number <optional>

The duration to wait after showing in milliseconds, defaults to 0 (no wait).

Returns:

Returns this mouse instance to support method chaining.

Type
PD.Mouse

waitAsync( [duration]) <async, static>

Wait for the given duration.

Parameters:
Name Type Argument Description
duration number <optional>

The duration to wait after showing in milliseconds, defaults to 0 (no wait).