# KeyInjectionScope

Artifact: [androidx.compose.ui:ui-test](https://developer.android.com/jetpack/androidx/releases/compose-ui) [View Source](https://cs.android.com/search?q=file:androidx/compose/ui/test/KeyInjectionScope.kt+class:androidx.compose.ui.test.KeyInjectionScope) Added in [1.2.0](https://developer.android.com/jetpack/androidx/releases/compose-ui#1.2.0) Common/AllAndroid/JVM
- Cmn

  ```
  interface KeyInjectionScope : InjectionScope
  ```

*** ** * ** ***

The receiver scope of the key input injection lambda from `https://developer.android.com/reference/kotlin/androidx/compose/ui/test/package-summary#(androidx.compose.ui.test.SemanticsNodeInteraction).performKeyInput(kotlin.Function1)`.

All sequences and patterns of key input can be expressed using the two fundamental methods of this API - `https://developer.android.com/reference/kotlin/androidx/compose/ui/test/KeyInjectionScope#keyDown(androidx.compose.ui.input.key.Key)` and `https://developer.android.com/reference/kotlin/androidx/compose/ui/test/KeyInjectionScope#keyUp(androidx.compose.ui.input.key.Key)`. All other injection functions are provided as abstractions built on top of these two methods in order to improve test code readability/maintainability and decrease development time.

The entire event injection state is shared between all `perform.*Input` methods, meaning you can continue an unfinished key input sequence in a subsequent invocation of `https://developer.android.com/reference/kotlin/androidx/compose/ui/test/package-summary#(androidx.compose.ui.test.SemanticsNodeInteraction).performKeyInput(kotlin.Function1)` or `https://developer.android.com/reference/kotlin/androidx/compose/ui/test/package-summary#(androidx.compose.ui.test.SemanticsNodeInteraction).performMultiModalInput(kotlin.Function1)`.

All events sent by these methods are batched together and sent as a whole after `https://developer.android.com/reference/kotlin/androidx/compose/ui/test/package-summary#(androidx.compose.ui.test.SemanticsNodeInteraction).performKeyInput(kotlin.Function1)` has executed its code block.

When a key is held down - i.e. the virtual clock is forwarded whilst the key is pressed down, repeat key down events will be sent. In a fashion consistent with Android's implementation, the first repeat key event will be sent after a key has been held down for 500ms. Subsequent repeat events will be sent at 50ms intervals, until the key is released or another key is pressed down.

The sending of repeat key events is handled as an implicit side-effect of `https://developer.android.com/reference/kotlin/androidx/compose/ui/test/InjectionScope#advanceEventTime(kotlin.Long)`, which is called within the injection scope. As such, no repeat key events will be sent if `https://developer.android.com/reference/kotlin/androidx/compose/ui/test/MainTestClock#advanceTimeBy(kotlin.Long,kotlin.Boolean)` is used to advance the time.

```kotlin
import androidx.compose.foundation.clickable
import androidx.compose.foundation.text.BasicText
import androidx.compose.ui.Modifier
import androidx.compose.ui.focus.FocusRequester
import androidx.compose.ui.focus.focusRequester
import androidx.compose.ui.input.InputMode.Companion.Keyboard
import androidx.compose.ui.input.InputModeManager
import androidx.compose.ui.input.key.Key
import androidx.compose.ui.platform.LocalInputModeManager
import androidx.compose.ui.platform.testTag
import androidx.compose.ui.test.onNodeWithTag
import androidx.compose.ui.test.performKeyInput

var counter = 0
val focusRequester = FocusRequester()
lateinit var inputModeManager: InputModeManager
composeTestRule.setContent {
    inputModeManager = LocalInputModeManager.current
    BasicText(
        "ClickableText",
        modifier =
            Modifier.testTag("myClickable").focusRequester(focusRequester).clickable {
                counter++
            },
    )
}
composeTestRule.runOnIdle {
    inputModeManager.requestInputMode(Keyboard)
    focusRequester.requestFocus()
}

composeTestRule.onNodeWithTag("myClickable").performKeyInput { keyDown(Key.Enter) }

composeTestRule.runOnIdle { assert(counter == 0) }

composeTestRule.onNodeWithTag("myClickable").performKeyInput { keyUp(Key.Enter) }

composeTestRule.runOnIdle { assert(counter == 1) }
```

| See also |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/compose/ui/test/InjectionScope` |   |

## Summary

| ### Public functions |
|---|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/test/KeyInjectionScope#isKeyDown(androidx.compose.ui.input.key.Key)(key: https://developer.android.com/reference/kotlin/androidx/compose/ui/input/key/Key)` Checks if the given `https://developer.android.com/reference/kotlin/androidx/compose/ui/test/KeyInjectionScope#isKeyDown(androidx.compose.ui.input.key.Key)` is down. | Cmn |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/test/KeyInjectionScope#keyDown(androidx.compose.ui.input.key.Key)(key: https://developer.android.com/reference/kotlin/androidx/compose/ui/input/key/Key)` Sends a key down event for the given `https://developer.android.com/reference/kotlin/androidx/compose/ui/test/KeyInjectionScope#keyDown(androidx.compose.ui.input.key.Key)`. | Cmn |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/test/KeyInjectionScope#keyUp(androidx.compose.ui.input.key.Key)(key: https://developer.android.com/reference/kotlin/androidx/compose/ui/input/key/Key)` Sends a key up event for the given `https://developer.android.com/reference/kotlin/androidx/compose/ui/test/KeyInjectionScope#keyUp(androidx.compose.ui.input.key.Key)`. | Cmn |

| ### Public properties |
|---|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/test/KeyInjectionScope#isCapsLockOn()` Indicates whether caps lock is on or not. | Cmn |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/test/KeyInjectionScope#isNumLockOn()` Indicates whether num lock is on or not. | Cmn |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/test/KeyInjectionScope#isScrollLockOn()` Indicates whether scroll lock is on or not. | Cmn |

| ### Extension functions |
|---|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/test/KeyInjectionScope.https://developer.android.com/reference/kotlin/androidx/compose/ui/test/KeyInjectionScope#(androidx.compose.ui.test.KeyInjectionScope).pressKey(androidx.compose.ui.input.key.Key,kotlin.Long)(key: https://developer.android.com/reference/kotlin/androidx/compose/ui/input/key/Key, pressDurationMillis: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html)` Holds down the given `https://developer.android.com/reference/kotlin/androidx/compose/ui/test/package-summary#(androidx.compose.ui.test.KeyInjectionScope).pressKey(androidx.compose.ui.input.key.Key,kotlin.Long)` for the given `https://developer.android.com/reference/kotlin/androidx/compose/ui/test/package-summary#(androidx.compose.ui.test.KeyInjectionScope).pressKey(androidx.compose.ui.input.key.Key,kotlin.Long)` by sending a key down event, advancing the event time and sending a key up event. | Cmn |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/test/KeyInjectionScope.https://developer.android.com/reference/kotlin/androidx/compose/ui/test/KeyInjectionScope#(androidx.compose.ui.test.KeyInjectionScope).withKeyDown(androidx.compose.ui.input.key.Key,kotlin.Function1)(key: https://developer.android.com/reference/kotlin/androidx/compose/ui/input/key/Key, block: https://developer.android.com/reference/kotlin/androidx/compose/ui/test/KeyInjectionScope.() -> https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html)` Executes the keyboard sequence specified in the given `https://developer.android.com/reference/kotlin/androidx/compose/ui/test/package-summary#(androidx.compose.ui.test.KeyInjectionScope).withKeyDown(androidx.compose.ui.input.key.Key,kotlin.Function1)`, whilst holding down the given `https://developer.android.com/reference/kotlin/androidx/compose/ui/test/package-summary#(androidx.compose.ui.test.KeyInjectionScope).withKeyDown(androidx.compose.ui.input.key.Key,kotlin.Function1)`. | Cmn |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/test/KeyInjectionScope.https://developer.android.com/reference/kotlin/androidx/compose/ui/test/KeyInjectionScope#(androidx.compose.ui.test.KeyInjectionScope).withKeyToggled(androidx.compose.ui.input.key.Key,kotlin.Function1)(key: https://developer.android.com/reference/kotlin/androidx/compose/ui/input/key/Key, block: https://developer.android.com/reference/kotlin/androidx/compose/ui/test/KeyInjectionScope.() -> https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html)` Executes the keyboard sequence specified in the given `https://developer.android.com/reference/kotlin/androidx/compose/ui/test/package-summary#(androidx.compose.ui.test.KeyInjectionScope).withKeyToggled(androidx.compose.ui.input.key.Key,kotlin.Function1)`, in between presses to the given `https://developer.android.com/reference/kotlin/androidx/compose/ui/test/package-summary#(androidx.compose.ui.test.KeyInjectionScope).withKeyToggled(androidx.compose.ui.input.key.Key,kotlin.Function1)`. | Cmn |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/test/KeyInjectionScope.https://developer.android.com/reference/kotlin/androidx/compose/ui/test/KeyInjectionScope#(androidx.compose.ui.test.KeyInjectionScope).withKeysDown(kotlin.collections.List,kotlin.Function1)(keys: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html<https://developer.android.com/reference/kotlin/androidx/compose/ui/input/key/Key>, block: https://developer.android.com/reference/kotlin/androidx/compose/ui/test/KeyInjectionScope.() -> https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html)` Executes the keyboard sequence specified in the given `https://developer.android.com/reference/kotlin/androidx/compose/ui/test/package-summary#(androidx.compose.ui.test.KeyInjectionScope).withKeysDown(kotlin.collections.List,kotlin.Function1)`, whilst holding down the each of the given `https://developer.android.com/reference/kotlin/androidx/compose/ui/test/package-summary#(androidx.compose.ui.test.KeyInjectionScope).withKeysDown(kotlin.collections.List,kotlin.Function1)`. | Cmn |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/test/KeyInjectionScope.https://developer.android.com/reference/kotlin/androidx/compose/ui/test/KeyInjectionScope#(androidx.compose.ui.test.KeyInjectionScope).withKeysToggled(kotlin.collections.List,kotlin.Function1)(keys: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html<https://developer.android.com/reference/kotlin/androidx/compose/ui/input/key/Key>, block: https://developer.android.com/reference/kotlin/androidx/compose/ui/test/KeyInjectionScope.() -> https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html)` Executes the keyboard sequence specified in the given `https://developer.android.com/reference/kotlin/androidx/compose/ui/test/package-summary#(androidx.compose.ui.test.KeyInjectionScope).withKeysToggled(kotlin.collections.List,kotlin.Function1)`, in between presses to the given `https://developer.android.com/reference/kotlin/androidx/compose/ui/test/package-summary#(androidx.compose.ui.test.KeyInjectionScope).withKeysToggled(kotlin.collections.List,kotlin.Function1)`. | Cmn |

| ### Extension properties |
|---|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/test/KeyInjectionScope.https://developer.android.com/reference/kotlin/androidx/compose/ui/test/KeyInjectionScope#(androidx.compose.ui.test.KeyInjectionScope).isAltDown()` Verifies whether either of the alt keys are down. | Cmn |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/test/KeyInjectionScope.https://developer.android.com/reference/kotlin/androidx/compose/ui/test/KeyInjectionScope#(androidx.compose.ui.test.KeyInjectionScope).isCtrlDown()` Verifies whether either of the control keys are down. | Cmn |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/test/KeyInjectionScope.https://developer.android.com/reference/kotlin/androidx/compose/ui/test/KeyInjectionScope#(androidx.compose.ui.test.KeyInjectionScope).isFnDown()` Verifies whether the function key is down. | Cmn |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/test/KeyInjectionScope.https://developer.android.com/reference/kotlin/androidx/compose/ui/test/KeyInjectionScope#(androidx.compose.ui.test.KeyInjectionScope).isMetaDown()` Verifies whether either of the meta keys are down. | Cmn |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/test/KeyInjectionScope.https://developer.android.com/reference/kotlin/androidx/compose/ui/test/KeyInjectionScope#(androidx.compose.ui.test.KeyInjectionScope).isShiftDown()` Verifies whether either of the shift keys are down. | Cmn |

| ### Inherited functions |
|---|
| From [androidx.compose.ui.unit.Density](https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/Density) |---|---|---| | `open https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/Dp.https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/Density#(androidx.compose.ui.unit.Dp).roundToPx()()` Convert `https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/Dp` to `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` by rounding | Cmn | | `open https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/TextUnit.https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/Density#(androidx.compose.ui.unit.TextUnit).roundToPx()()` Convert Sp to `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` by rounding | Cmn | | `open https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/Dp` | `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html.https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/Density#(kotlin.Int).toDp()()` Convert an `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` pixel value to `https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/Dp`. | Cmn | | `open https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/Dp` | `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html.https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/Density#(kotlin.Float).toDp()()` Convert a `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html` pixel value to a Dp | Cmn | | `open https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/DpSize` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/geometry/Size.https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/Density#(androidx.compose.ui.geometry.Size).toDpSize()()` Convert a `https://developer.android.com/reference/kotlin/androidx/compose/ui/geometry/Size` to a `https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/DpSize`. | Cmn | | `open https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/Dp.https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/Density#(androidx.compose.ui.unit.Dp).toPx()()` Convert `https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/Dp` to pixels. | Cmn | | `open https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/TextUnit.https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/Density#(androidx.compose.ui.unit.TextUnit).toPx()()` Convert Sp to pixels. | Cmn | | `open https://developer.android.com/reference/kotlin/androidx/compose/ui/geometry/Rect` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/DpRect.https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/Density#(androidx.compose.ui.unit.DpRect).toRect()()` Convert a `https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/DpRect` to a `https://developer.android.com/reference/kotlin/androidx/compose/ui/geometry/Rect`. | Cmn | | `open https://developer.android.com/reference/kotlin/androidx/compose/ui/geometry/Size` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/DpSize.https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/Density#(androidx.compose.ui.unit.DpSize).toSize()()` Convert a `https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/DpSize` to a `https://developer.android.com/reference/kotlin/androidx/compose/ui/geometry/Size`. | Cmn | | `open https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/TextUnit` | `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html.https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/Density#(kotlin.Int).toSp()()` Convert an `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` pixel value to Sp. | Cmn | | `open https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/TextUnit` | `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html.https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/Density#(kotlin.Float).toSp()()` Convert a `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html` pixel value to a Sp | Cmn | |
| From [androidx.compose.ui.unit.FontScaling](https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/FontScaling) |---|---|---| | `https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/Dp` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/TextUnit.https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/FontScaling#(androidx.compose.ui.unit.TextUnit).toDp()()` Convert Sp to `https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/Dp`. | Cmn | | `https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/TextUnit` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/Dp.https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/FontScaling#(androidx.compose.ui.unit.Dp).toSp()()` Convert `https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/Dp` to Sp. | Cmn | |
| From [androidx.compose.ui.test.InjectionScope](https://developer.android.com/reference/kotlin/androidx/compose/ui/test/InjectionScope) |---|---|---| | `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/test/InjectionScope#advanceEventTime(kotlin.Long)(durationMillis: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html)` Adds the given `https://developer.android.com/reference/kotlin/androidx/compose/ui/test/InjectionScope#advanceEventTime(kotlin.Long)` to the current event time, delaying the next event by that time. | Cmn | | `open https://developer.android.com/reference/kotlin/androidx/compose/ui/geometry/Offset` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/test/InjectionScope#percentOffset(kotlin.Float,kotlin.Float)(x: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html, y: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html)` Creates an `https://developer.android.com/reference/kotlin/androidx/compose/ui/geometry/Offset` relative to the size of the node we're interacting with. | Cmn | |

| ### Inherited properties |
|---|
| From [androidx.compose.ui.unit.Density](https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/Density) |---|---|---| | `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/Density#density()` The logical density of the display. | Cmn | |
| From [androidx.compose.ui.unit.FontScaling](https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/FontScaling) |---|---|---| | `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/FontScaling#fontScale()` Current user preference for the scaling factor for fonts. | Cmn | |
| From [androidx.compose.ui.test.InjectionScope](https://developer.android.com/reference/kotlin/androidx/compose/ui/test/InjectionScope) |---|---|---| | `open https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/test/InjectionScope#bottom()` The y-coordinate for the bottom of the node we're interacting with in px, in the node's local coordinate system, where (0, 0) is the top left corner of the node. | Cmn | | `open https://developer.android.com/reference/kotlin/androidx/compose/ui/geometry/Offset` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/test/InjectionScope#bottomCenter()` The center of the bottom edge of the node we're interacting with, in the node's local coordinate system, where (0, 0) is the top left corner of the node. | Cmn | | `open https://developer.android.com/reference/kotlin/androidx/compose/ui/geometry/Offset` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/test/InjectionScope#bottomLeft()` The bottom left corner of the node we're interacting with, in the node's local coordinate system, where (0, 0) is the top left corner of the node. | Cmn | | `open https://developer.android.com/reference/kotlin/androidx/compose/ui/geometry/Offset` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/test/InjectionScope#bottomRight()` The bottom right corner of the node we're interacting with, in the node's local coordinate system, where (0, 0) is the top left corner of the node. | Cmn | | `open https://developer.android.com/reference/kotlin/androidx/compose/ui/geometry/Offset` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/test/InjectionScope#center()` The center of the node we're interacting with, in the node's local coordinate system, where (0, 0) is the top left corner of the node. | Cmn | | `open https://developer.android.com/reference/kotlin/androidx/compose/ui/geometry/Offset` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/test/InjectionScope#centerLeft()` The center of the left edge of the node we're interacting with, in the node's local coordinate system, where (0, 0) is the top left corner of the node. | Cmn | | `open https://developer.android.com/reference/kotlin/androidx/compose/ui/geometry/Offset` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/test/InjectionScope#centerRight()` The center of the right edge of the node we're interacting with, in the node's local coordinate system, where (0, 0) is the top left corner of the node. | Cmn | | `open https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/test/InjectionScope#centerX()` The x-coordinate for the center of the node we're interacting with in px, in the node's local coordinate system, where (0, 0) is the top left corner of the node. | Cmn | | `open https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/test/InjectionScope#centerY()` The y-coordinate for the center of the node we're interacting with in px, in the node's local coordinate system, where (0, 0) is the top left corner of the node. | Cmn | | `open https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/test/InjectionScope#eventPeriodMillis()` The default time between two successive events. | Cmn | | `open https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/test/InjectionScope#height()` The height of the node in px. | Cmn | | `open https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/test/InjectionScope#left()` The x-coordinate for the left edge of the node we're interacting with in px, in the node's local coordinate system, where (0, 0) is the top left corner of the node. | Cmn | | `open https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/test/InjectionScope#right()` The x-coordinate for the right edge of the node we're interacting with in px, in the node's local coordinate system, where (0, 0) is the top left corner of the node. | Cmn | | `open https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/test/InjectionScope#top()` The y-coordinate for the top of the node we're interacting with in px, in the node's local coordinate system, where (0, 0) is the top left corner of the node. | Cmn | | `open https://developer.android.com/reference/kotlin/androidx/compose/ui/geometry/Offset` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/test/InjectionScope#topCenter()` The center of the top edge of the node we're interacting with, in the node's local coordinate system, where (0, 0) is the top left corner of the node. | Cmn | | `open https://developer.android.com/reference/kotlin/androidx/compose/ui/geometry/Offset` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/test/InjectionScope#topLeft()` The top left corner of the node we're interacting with, in the node's local coordinate system, where (0, 0) is the top left corner of the node. | Cmn | | `open https://developer.android.com/reference/kotlin/androidx/compose/ui/geometry/Offset` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/test/InjectionScope#topRight()` The top right corner of the node we're interacting with, in the node's local coordinate system, where (0, 0) is the top left corner of the node. | Cmn | | `https://developer.android.com/reference/kotlin/androidx/compose/ui/platform/ViewConfiguration` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/test/InjectionScope#viewConfiguration()` The `https://developer.android.com/reference/kotlin/androidx/compose/ui/platform/ViewConfiguration` in use by the `https://developer.android.com/reference/kotlin/androidx/compose/ui/semantics/SemanticsNode` from the `https://developer.android.com/reference/kotlin/androidx/compose/ui/test/SemanticsNodeInteraction` on which the input injection method is called. | Cmn | | `https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/IntSize` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/test/InjectionScope#visibleSize()` The size of the visible part of the node we're interacting with in px, i.e. its clipped bounds. | Cmn | | `open https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/test/InjectionScope#width()` The width of the node in px. | Cmn | |

## Public functions

### isKeyDown

Cmn Added in [1.10.0](https://developer.android.com/jetpack/androidx/releases/compose-ui#1.10.0)

```
fun isKeyDown(key: Key): Boolean
```

Checks if the given `https://developer.android.com/reference/kotlin/androidx/compose/ui/test/KeyInjectionScope#isKeyDown(androidx.compose.ui.input.key.Key)` is down.

| Parameters |
|---|---|
| `key: https://developer.android.com/reference/kotlin/androidx/compose/ui/input/key/Key` | The key to be checked. |

| Returns |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | true if the given `https://developer.android.com/reference/kotlin/androidx/compose/ui/test/KeyInjectionScope#isKeyDown(androidx.compose.ui.input.key.Key)` is pressed down, false otherwise. |

### keyDown

Cmn Added in [1.10.0](https://developer.android.com/jetpack/androidx/releases/compose-ui#1.10.0)

```
fun keyDown(key: Key): Unit
```

Sends a key down event for the given `https://developer.android.com/reference/kotlin/androidx/compose/ui/test/KeyInjectionScope#keyDown(androidx.compose.ui.input.key.Key)`.

If the given key is already down, an `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-illegal-state-exception/index.html` will be thrown.

| Parameters |
|---|---|
| `key: https://developer.android.com/reference/kotlin/androidx/compose/ui/input/key/Key` | The key to be pressed down. |

### keyUp

Cmn Added in [1.10.0](https://developer.android.com/jetpack/androidx/releases/compose-ui#1.10.0)

```
fun keyUp(key: Key): Unit
```

Sends a key up event for the given `https://developer.android.com/reference/kotlin/androidx/compose/ui/test/KeyInjectionScope#keyUp(androidx.compose.ui.input.key.Key)`.

If the given key is already up, an `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-illegal-state-exception/index.html` will be thrown.

| Parameters |
|---|---|
| `key: https://developer.android.com/reference/kotlin/androidx/compose/ui/input/key/Key` | The key to be released. |

## Public properties

### isCapsLockOn

Cmn Added in [1.2.0](https://developer.android.com/jetpack/androidx/releases/compose-ui#1.2.0)

```
val isCapsLockOn: Boolean
```

Indicates whether caps lock is on or not.

Note that this reflects the state of the injected input only, it does not correspond to the state of an actual keyboard attached to the device on which a test is run

### isNumLockOn

Cmn Added in [1.2.0](https://developer.android.com/jetpack/androidx/releases/compose-ui#1.2.0)

```
val isNumLockOn: Boolean
```

Indicates whether num lock is on or not.

Note that this reflects the state of the injected input only, it does not correspond to the state of an actual keyboard attached to the device on which a test is run

### isScrollLockOn

Cmn Added in [1.2.0](https://developer.android.com/jetpack/androidx/releases/compose-ui#1.2.0)

```
val isScrollLockOn: Boolean
```

Indicates whether scroll lock is on or not.

Note that this reflects the state of the injected input only, it does not correspond to the state of an actual keyboard attached to the device on which a test is run

## Extension functions

### KeyInjectionScope.pressKey

Cmn Artifact: [androidx.compose.ui:ui-test](https://developer.android.com/jetpack/androidx/releases/compose-ui) [View Source](https://cs.android.com/search?q=file:androidx/compose/ui/test/KeyInjectionScope.kt+function:pressKey)

```
fun KeyInjectionScope.pressKey(
    key: Key,
    pressDurationMillis: Long = DefaultKeyPressDurationMillis
): Unit
```

Holds down the given `https://developer.android.com/reference/kotlin/androidx/compose/ui/test/package-summary#(androidx.compose.ui.test.KeyInjectionScope).pressKey(androidx.compose.ui.input.key.Key,kotlin.Long)` for the given `https://developer.android.com/reference/kotlin/androidx/compose/ui/test/package-summary#(androidx.compose.ui.test.KeyInjectionScope).pressKey(androidx.compose.ui.input.key.Key,kotlin.Long)` by sending a key down event, advancing the event time and sending a key up event.

If the given key is already down, an `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-illegal-state-exception/index.html` will be thrown.

| Parameters |
|---|---|
| `key: https://developer.android.com/reference/kotlin/androidx/compose/ui/input/key/Key` | The key to be pressed down. |
| `pressDurationMillis: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html = DefaultKeyPressDurationMillis` | Duration of press in milliseconds. |

### KeyInjectionScope.withKeyDown

Cmn Artifact: [androidx.compose.ui:ui-test](https://developer.android.com/jetpack/androidx/releases/compose-ui) [View Source](https://cs.android.com/search?q=file:androidx/compose/ui/test/KeyInjectionScope.kt+function:withKeyDown)

```
fun KeyInjectionScope.withKeyDown(key: Key, block: KeyInjectionScope.() -> Unit): Unit
```

Executes the keyboard sequence specified in the given `https://developer.android.com/reference/kotlin/androidx/compose/ui/test/package-summary#(androidx.compose.ui.test.KeyInjectionScope).withKeyDown(androidx.compose.ui.input.key.Key,kotlin.Function1)`, whilst holding down the given `https://developer.android.com/reference/kotlin/androidx/compose/ui/test/package-summary#(androidx.compose.ui.test.KeyInjectionScope).withKeyDown(androidx.compose.ui.input.key.Key,kotlin.Function1)`. This key must not be used within the `https://developer.android.com/reference/kotlin/androidx/compose/ui/test/package-summary#(androidx.compose.ui.test.KeyInjectionScope).withKeyDown(androidx.compose.ui.input.key.Key,kotlin.Function1)`.

If the given `https://developer.android.com/reference/kotlin/androidx/compose/ui/test/package-summary#(androidx.compose.ui.test.KeyInjectionScope).withKeyDown(androidx.compose.ui.input.key.Key,kotlin.Function1)` is already down, an `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-illegal-state-exception/index.html` will be thrown.

| Parameters |
|---|---|
| `key: https://developer.android.com/reference/kotlin/androidx/compose/ui/input/key/Key` | The key to be held down during injection of the `https://developer.android.com/reference/kotlin/androidx/compose/ui/test/package-summary#(androidx.compose.ui.test.KeyInjectionScope).withKeyDown(androidx.compose.ui.input.key.Key,kotlin.Function1)`. |
| `block: https://developer.android.com/reference/kotlin/androidx/compose/ui/test/KeyInjectionScope.() -> https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | Sequence of KeyInjectionScope methods to be injected with the given key down. |

### KeyInjectionScope.withKeyToggled

Cmn Artifact: [androidx.compose.ui:ui-test](https://developer.android.com/jetpack/androidx/releases/compose-ui) [View Source](https://cs.android.com/search?q=file:androidx/compose/ui/test/KeyInjectionScope.kt+function:withKeyToggled)

```
fun KeyInjectionScope.withKeyToggled(key: Key, block: KeyInjectionScope.() -> Unit): Unit
```

Executes the keyboard sequence specified in the given `https://developer.android.com/reference/kotlin/androidx/compose/ui/test/package-summary#(androidx.compose.ui.test.KeyInjectionScope).withKeyToggled(androidx.compose.ui.input.key.Key,kotlin.Function1)`, in between presses to the given `https://developer.android.com/reference/kotlin/androidx/compose/ui/test/package-summary#(androidx.compose.ui.test.KeyInjectionScope).withKeyToggled(androidx.compose.ui.input.key.Key,kotlin.Function1)`. This key can also be used within the `https://developer.android.com/reference/kotlin/androidx/compose/ui/test/package-summary#(androidx.compose.ui.test.KeyInjectionScope).withKeyToggled(androidx.compose.ui.input.key.Key,kotlin.Function1)`, as long as it is not down at the end of the block.

If the given `https://developer.android.com/reference/kotlin/androidx/compose/ui/test/package-summary#(androidx.compose.ui.test.KeyInjectionScope).withKeyToggled(androidx.compose.ui.input.key.Key,kotlin.Function1)` is already down, an `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-illegal-state-exception/index.html` will be thrown.

| Parameters |
|---|---|
| `key: https://developer.android.com/reference/kotlin/androidx/compose/ui/input/key/Key` | The key to be toggled around the injection of the `https://developer.android.com/reference/kotlin/androidx/compose/ui/test/package-summary#(androidx.compose.ui.test.KeyInjectionScope).withKeyToggled(androidx.compose.ui.input.key.Key,kotlin.Function1)`. |
| `block: https://developer.android.com/reference/kotlin/androidx/compose/ui/test/KeyInjectionScope.() -> https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | Sequence of KeyInjectionScope methods to be injected with the given key down. |

### KeyInjectionScope.withKeysDown

Cmn Artifact: [androidx.compose.ui:ui-test](https://developer.android.com/jetpack/androidx/releases/compose-ui) [View Source](https://cs.android.com/search?q=file:androidx/compose/ui/test/KeyInjectionScope.kt+function:withKeysDown)

```
fun KeyInjectionScope.withKeysDown(keys: List<Key>, block: KeyInjectionScope.() -> Unit): Unit
```

Executes the keyboard sequence specified in the given `https://developer.android.com/reference/kotlin/androidx/compose/ui/test/package-summary#(androidx.compose.ui.test.KeyInjectionScope).withKeysDown(kotlin.collections.List,kotlin.Function1)`, whilst holding down the each of the given `https://developer.android.com/reference/kotlin/androidx/compose/ui/test/package-summary#(androidx.compose.ui.test.KeyInjectionScope).withKeysDown(kotlin.collections.List,kotlin.Function1)`. Each of the `https://developer.android.com/reference/kotlin/androidx/compose/ui/test/package-summary#(androidx.compose.ui.test.KeyInjectionScope).withKeysDown(kotlin.collections.List,kotlin.Function1)` will be pressed down and released simultaneously. These keys must not be used within the `https://developer.android.com/reference/kotlin/androidx/compose/ui/test/package-summary#(androidx.compose.ui.test.KeyInjectionScope).withKeysDown(kotlin.collections.List,kotlin.Function1)`.

If any of the given `https://developer.android.com/reference/kotlin/androidx/compose/ui/test/package-summary#(androidx.compose.ui.test.KeyInjectionScope).withKeysDown(kotlin.collections.List,kotlin.Function1)` are already down, an `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-illegal-state-exception/index.html` will be thrown.

| Parameters |
|---|---|
| `keys: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html<https://developer.android.com/reference/kotlin/androidx/compose/ui/input/key/Key>` | List of keys to be held down during injection of the `https://developer.android.com/reference/kotlin/androidx/compose/ui/test/package-summary#(androidx.compose.ui.test.KeyInjectionScope).withKeysDown(kotlin.collections.List,kotlin.Function1)`. |
| `block: https://developer.android.com/reference/kotlin/androidx/compose/ui/test/KeyInjectionScope.() -> https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | Sequence of KeyInjectionScope methods to be injected with the given keys down. |

### KeyInjectionScope.withKeysToggled

Cmn Artifact: [androidx.compose.ui:ui-test](https://developer.android.com/jetpack/androidx/releases/compose-ui) [View Source](https://cs.android.com/search?q=file:androidx/compose/ui/test/KeyInjectionScope.kt+function:withKeysToggled)

```
fun KeyInjectionScope.withKeysToggled(keys: List<Key>, block: KeyInjectionScope.() -> Unit): Unit
```

Executes the keyboard sequence specified in the given `https://developer.android.com/reference/kotlin/androidx/compose/ui/test/package-summary#(androidx.compose.ui.test.KeyInjectionScope).withKeysToggled(kotlin.collections.List,kotlin.Function1)`, in between presses to the given `https://developer.android.com/reference/kotlin/androidx/compose/ui/test/package-summary#(androidx.compose.ui.test.KeyInjectionScope).withKeysToggled(kotlin.collections.List,kotlin.Function1)`. Each of the `https://developer.android.com/reference/kotlin/androidx/compose/ui/test/package-summary#(androidx.compose.ui.test.KeyInjectionScope).withKeysToggled(kotlin.collections.List,kotlin.Function1)` will be toggled simultaneously.These keys can also be used within the `https://developer.android.com/reference/kotlin/androidx/compose/ui/test/package-summary#(androidx.compose.ui.test.KeyInjectionScope).withKeysToggled(kotlin.collections.List,kotlin.Function1)`, as long as they are not down at the end of the block.

If any of the given `https://developer.android.com/reference/kotlin/androidx/compose/ui/test/package-summary#(androidx.compose.ui.test.KeyInjectionScope).withKeysToggled(kotlin.collections.List,kotlin.Function1)` are already down, an `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-illegal-state-exception/index.html` will be thrown.

| Parameters |
|---|---|
| `keys: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html<https://developer.android.com/reference/kotlin/androidx/compose/ui/input/key/Key>` | The keys to be toggled around the injection of the `https://developer.android.com/reference/kotlin/androidx/compose/ui/test/package-summary#(androidx.compose.ui.test.KeyInjectionScope).withKeysToggled(kotlin.collections.List,kotlin.Function1)`. |
| `block: https://developer.android.com/reference/kotlin/androidx/compose/ui/test/KeyInjectionScope.() -> https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | Sequence of KeyInjectionScope methods to be injected with the given keys down. |

## Extension properties

### KeyInjectionScope.isAltDown

Cmn Artifact: [androidx.compose.ui:ui-test](https://developer.android.com/jetpack/androidx/releases/compose-ui) [View Source](https://cs.android.com/search?q=file:androidx/compose/ui/test/KeyInjectionScope.kt+symbol:isAltDown) Added in [1.2.0](https://developer.android.com/jetpack/androidx/releases/compose-ui#1.2.0)

```
val KeyInjectionScope.isAltDown: Boolean
```

Verifies whether either of the alt keys are down.

| Returns |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | true if an alt key is currently down, false otherwise. |

### KeyInjectionScope.isCtrlDown

Cmn Artifact: [androidx.compose.ui:ui-test](https://developer.android.com/jetpack/androidx/releases/compose-ui) [View Source](https://cs.android.com/search?q=file:androidx/compose/ui/test/KeyInjectionScope.kt+symbol:isCtrlDown) Added in [1.2.0](https://developer.android.com/jetpack/androidx/releases/compose-ui#1.2.0)

```
val KeyInjectionScope.isCtrlDown: Boolean
```

Verifies whether either of the control keys are down.

| Returns |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | true if a control key is currently down, false otherwise. |

### KeyInjectionScope.isFnDown

Cmn Artifact: [androidx.compose.ui:ui-test](https://developer.android.com/jetpack/androidx/releases/compose-ui) [View Source](https://cs.android.com/search?q=file:androidx/compose/ui/test/KeyInjectionScope.kt+symbol:isFnDown) Added in [1.2.0](https://developer.android.com/jetpack/androidx/releases/compose-ui#1.2.0)

```
val KeyInjectionScope.isFnDown: Boolean
```

Verifies whether the function key is down.

| Returns |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | true if the function key is currently down, false otherwise. |

### KeyInjectionScope.isMetaDown

Cmn Artifact: [androidx.compose.ui:ui-test](https://developer.android.com/jetpack/androidx/releases/compose-ui) [View Source](https://cs.android.com/search?q=file:androidx/compose/ui/test/KeyInjectionScope.kt+symbol:isMetaDown) Added in [1.2.0](https://developer.android.com/jetpack/androidx/releases/compose-ui#1.2.0)

```
val KeyInjectionScope.isMetaDown: Boolean
```

Verifies whether either of the meta keys are down.

| Returns |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | true if a meta key is currently down, false otherwise. |

### KeyInjectionScope.isShiftDown

Cmn Artifact: [androidx.compose.ui:ui-test](https://developer.android.com/jetpack/androidx/releases/compose-ui) [View Source](https://cs.android.com/search?q=file:androidx/compose/ui/test/KeyInjectionScope.kt+symbol:isShiftDown) Added in [1.2.0](https://developer.android.com/jetpack/androidx/releases/compose-ui#1.2.0)

```
val KeyInjectionScope.isShiftDown: Boolean
```

Verifies whether either of the shift keys are down.

| Returns |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | true if a shift key is currently down, false otherwise. |