---
title: "withKeysToggled"
description: "Executes the keyboard sequence specified in the given [block], in between presses to the given
[keys]. Each of the [keys] will be toggled simultaneously.These keys can also be used within the
[block], as long as they are not down at the end of the block.

If any of the given [keys] are 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.withKeysToggled(keys: List<Key>, block: KeyInjectionScope.() -> Unit)
```


Executes the keyboard sequence specified in the given `block`, in between presses to the given
`keys`. Each of the `keys` will be toggled simultaneously.These keys can also be used within the
`block`, as long as they are not down at the end of the block.

If any of the given `keys` are already down, an `IllegalStateException` will be thrown.

#### Parameters

| | |
| --- | --- |
| keys | The keys to be toggled around the injection of the `block`. |
| block | Sequence of KeyInjectionScope methods to be injected with the given keys down. |




