---
title: "pressKey"
description: "Holds down the given [key] for the given [pressDurationMillis] by sending a key down event,
advancing the event time and sending a key up event.

If the given key is already down, an [IllegalStateException] will be thrown."
type: "function"
---

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


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


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


Holds down the given `key` for the given `pressDurationMillis` by sending a key down event,
advancing the event time and sending a key up event.

If the given key is already down, an `IllegalStateException` will be thrown.

#### Parameters

| | |
| --- | --- |
| key | The key to be pressed down. |
| pressDurationMillis | Duration of press in milliseconds. |




