{% setvar book_path %}/reference/androidx/_book.yaml{% endsetvar %} {% include "_shared/_reference-head-tags.html" %}

MouseInjectionScopeKt

public final class MouseInjectionScopeKt


Summary

Public methods

static final void
@ExperimentalTestApi
animateAlong(
    @NonNull MouseInjectionScope receiver,
    @NonNull Function1<@NonNull Long, @NonNull Offset> curve,
    long durationMillis
)

Move the mouse along the given curve, sending a stream of move events to get an animated path of durationMillis milliseconds.

static final void
@ExperimentalTestApi
animateBy(
    @NonNull MouseInjectionScope receiver,
    @NonNull Offset delta,
    long durationMillis
)

Move the mouse from the current position by the given delta, sending a stream of move events to get an animated path of durationMillis milliseconds.

static final void
@ExperimentalTestApi
animateTo(
    @NonNull MouseInjectionScope receiver,
    @NonNull Offset position,
    long durationMillis
)

Move the mouse from the current position to the given position, sending a stream of move events to get an animated path of durationMillis milliseconds.

static final void

Click on position, or on the current mouse position if position is unspecified.

static final void

Double-click on position, or on the current mouse position if position is unspecified.

static final void
@ExperimentalTestApi
dragAndDrop(
    @NonNull MouseInjectionScope receiver,
    @NonNull Offset start,
    @NonNull Offset end,
    long durationMillis
)

Drag and drop something from start to end in durationMillis milliseconds.

static final void

Long-click on position, or on the current mouse position if position is unspecified.

static final void

Secondary-click on position, or on the current mouse position if position is unspecified.

static final void
@ExperimentalTestApi
smoothScroll(
    @NonNull MouseInjectionScope receiver,
    float scrollAmount,
    long durationMillis,
    @NonNull ScrollWheel scrollWheel
)

Rotate the mouse's scrollWheel by the given scrollAmount.

static final void

Triple-click on position, or on the current mouse position if position is unspecified.

Public methods

animateAlong

@ExperimentalTestApi
public static final void animateAlong(
    @NonNull MouseInjectionScope receiver,
    @NonNull Function1<@NonNull Long, @NonNull Offset> curve,
    long durationMillis
)

Move the mouse along the given curve, sending a stream of move events to get an animated path of durationMillis milliseconds. The mouse will initially be moved to the start of the path, curve(0), if it is not already there. The positions defined by the curve are in the node's local coordinate system, where (0, 0) is the top left corner of the node.

Parameters
@NonNull Function1<@NonNull Long, @NonNull Offset> curve

The function that defines the position of the mouse over time for this gesture, in the node's local coordinate system.

long durationMillis

The duration of the gesture. By default 300 milliseconds.

animateBy

@ExperimentalTestApi
public static final void animateBy(
    @NonNull MouseInjectionScope receiver,
    @NonNull Offset delta,
    long durationMillis
)

Move the mouse from the current position by the given delta, sending a stream of move events to get an animated path of durationMillis milliseconds.

Parameters
@NonNull Offset delta

The position where to move the mouse to, relative to the current position of the mouse. For example, `delta = Offset(100.px, -100.px) will move the mouse 100 pixels to the right and 100 pixels upwards.

long durationMillis

The duration of the gesture. By default 300 milliseconds.

animateTo

@ExperimentalTestApi
public static final void animateTo(
    @NonNull MouseInjectionScope receiver,
    @NonNull Offset position,
    long durationMillis
)

Move the mouse from the current position to the given position, sending a stream of move events to get an animated path of durationMillis milliseconds. Move the mouse to the desired start position if you want to start from a different position. The position is in the node's local coordinate system, where (0, 0) is the top left corner of the node.

Parameters
@NonNull Offset position

The position where to move the mouse to, in the node's local coordinate system

long durationMillis

The duration of the gesture. By default 300 milliseconds.

click

@ExperimentalTestApi
public static final void click(@NonNull MouseInjectionScope receiver, @NonNull Offset position)

Click on position, or on the current mouse position if position is unspecified. The position is in the node's local coordinate system, where (0, 0) is the top left corner of the node.

Parameters
@NonNull Offset position

The position where to click, in the node's local coordinate system. If omitted, the center of the node will be used. If unspecified, clicks on the current mouse position.

doubleClick

@ExperimentalTestApi
public static final void doubleClick(
    @NonNull MouseInjectionScope receiver,
    @NonNull Offset position
)

Double-click on position, or on the current mouse position if position is unspecified. The position is in the node's local coordinate system, where (0, 0) is the top left corner of the node.

Parameters
@NonNull Offset position

The position where to click, in the node's local coordinate system. If omitted, the center of the node will be used. If unspecified, clicks on the current mouse position.

dragAndDrop

@ExperimentalTestApi
public static final void dragAndDrop(
    @NonNull MouseInjectionScope receiver,
    @NonNull Offset start,
    @NonNull Offset end,
    long durationMillis
)

Drag and drop something from start to end in durationMillis milliseconds. This gesture uses the primary mouse button to drag with, and does not reset any mouse buttons prior to starting the gesture. The mouse position is updated to the start position before starting the gesture. The positions defined by the start and end are in the node's local coordinate system, where (0, 0) is the top left corner of the node.

Parameters
@NonNull Offset start

The position where to press the primary mouse button and initiate the drag, in the node's local coordinate system.

@NonNull Offset end

The position where to release the primary mouse button and end the drag, in the node's local coordinate system.

long durationMillis

The duration of the gesture. By default 300 milliseconds.

longClick

@ExperimentalTestApi
public static final void longClick(@NonNull MouseInjectionScope receiver, @NonNull Offset position)

Long-click on position, or on the current mouse position if position is unspecified. The position is in the node's local coordinate system, where (0, 0) is the top left corner of the node.

Parameters
@NonNull Offset position

The position where to click, in the node's local coordinate system. If omitted, the center of the node will be used. If unspecified, clicks on the current mouse position.

rightClick

@ExperimentalTestApi
public static final void rightClick(@NonNull MouseInjectionScope receiver, @NonNull Offset position)

Secondary-click on position, or on the current mouse position if position is unspecified. While the secondary mouse button is not necessarily the right mouse button (e.g. on left-handed mice), this method is still called rightClick for it's widespread use. The position is in the node's local coordinate system, where (0, 0) is the top left corner of the node.

Parameters
@NonNull Offset position

The position where to click, in the node's local coordinate system. If omitted, the center of the node will be used. If unspecified, clicks on the current mouse position.

smoothScroll

@ExperimentalTestApi
public static final void smoothScroll(
    @NonNull MouseInjectionScope receiver,
    float scrollAmount,
    long durationMillis,
    @NonNull ScrollWheel scrollWheel
)

Rotate the mouse's scrollWheel by the given scrollAmount. The total scroll delta is linearly smoothed out over a stream of scroll events with roughly the InjectionScope.eventPeriodMillis between each scroll event. Negative scrollAmount values correspond to rotating the scroll wheel leftward or downward, positive values correspond to rotating the scroll wheel rightward or upward.

Parameters
float scrollAmount

The total delta to scroll the scrollWheel by

long durationMillis

The duration of the gesture. By default 300 milliseconds.

@NonNull ScrollWheel scrollWheel

Which scroll wheel will be rotated. By default ScrollWheel.Vertical.

tripleClick

@ExperimentalTestApi
public static final void tripleClick(
    @NonNull MouseInjectionScope receiver,
    @NonNull Offset position
)

Triple-click on position, or on the current mouse position if position is unspecified. The position is in the node's local coordinate system, where (0, 0) is the top left corner of the node.

Parameters
@NonNull Offset position

The position where to click, in the node's local coordinate system. If omitted, the center of the node will be used. If unspecified, clicks on the current mouse position.