---
title: "performMouseInput"
description: "Executes the mouse gesture specified in the given [block]. The gesture doesn't need to be
complete and can be resumed in a later invocation of one of the `perform.*Input` methods. The
event time is initialized to the current time of the [MainTestClock].

Be aware that if you split a gesture over multiple invocations of `perform.*Input`, everything
that happens in between will run as if the gesture is still ongoing (imagine a mouse button still
being pressed).

All events that are injected from the [block] are batched together and sent after [block] is
complete. This method blocks while the events are injected. If an error occurs during execution
of [block] or injection of the events, all (subsequent) events are dropped and the error is
thrown here.

Due to the batching of events, all events in a block are sent together and no recomposition will
take place in between events. Additionally all events will be generated before any of the events
take effect. This means that the screen coordinates of all events are resolved before any of the
events can cause the position of the node being injected into to change. This has certain
advantages, for example, in the cases of nested scrolling or dragging an element around, it
prevents the injection of events into a moving target since all events are enqueued before any of
them has taken effect.

Example of performing a mouse click:


Example of scrolling the mouse wheel while the mouse button is pressed:"
type: "function"
---

<div class='type'>Function</div>


<a id='references'></a>
<div class='sourceset sourceset-common'>Common</div>


```kotlin
fun SemanticsNodeInteraction.performMouseInput(
    block: MouseInjectionScope.() -> Unit
): SemanticsNodeInteraction
```


Executes the mouse gesture specified in the given `block`. The gesture doesn't need to be
complete and can be resumed in a later invocation of one of the `perform.*Input` methods. The
event time is initialized to the current time of the `MainTestClock`.

Be aware that if you split a gesture over multiple invocations of `perform.*Input`, everything
that happens in between will run as if the gesture is still ongoing (imagine a mouse button still
being pressed).

All events that are injected from the `block` are batched together and sent after `block` is
complete. This method blocks while the events are injected. If an error occurs during execution
of `block` or injection of the events, all (subsequent) events are dropped and the error is
thrown here.

Due to the batching of events, all events in a block are sent together and no recomposition will
take place in between events. Additionally all events will be generated before any of the events
take effect. This means that the screen coordinates of all events are resolved before any of the
events can cause the position of the node being injected into to change. This has certain
advantages, for example, in the cases of nested scrolling or dragging an element around, it
prevents the injection of events into a moving target since all events are enqueued before any of
them has taken effect.

Example of performing a mouse click:


Example of scrolling the mouse wheel while the mouse button is pressed:

#### Parameters

| | |
| --- | --- |
| block | A lambda with `MouseInjectionScope` as receiver that describes the gesture by sending all mouse events. |


#### Returns

| | |
| --- | --- |
|  | The `SemanticsNodeInteraction` that is the receiver of this method |




## Code Examples
### mouseInputClick
```kotlin
fun mouseInputClick() {
    composeTestRule.onNodeWithTag("myComponent").performMouseInput {
        // Click in the middle of the node
        click(center)
    }
}
```
### mouseInputScrollWhileDown
```kotlin
fun mouseInputScrollWhileDown() {
    composeTestRule
        .onNodeWithTag("verticalScrollable")
        // Scroll downwards while keeping a button pressed:
        .performMouseInput {
            // Presses the primary mouse button
            press()
            // Scroll the scroll wheel by 6 units
            repeat(6) {
                advanceEventTime()
                scroll(1f)
            }
            // And release the mouse button
            advanceEventTime()
            release()
        }
}
```

