# androidx.compose.ui.input.key

Common/AllAndroid/JVM

## Interfaces

|---|---|---|
| `https://developer.android.com/reference/kotlin/androidx/compose/ui/input/key/KeyInputModifierNode` | Implement this interface to create a `https://developer.android.com/reference/kotlin/androidx/compose/ui/Modifier.Node` that can intercept hardware Key events. | Cmn |
| `https://developer.android.com/reference/kotlin/androidx/compose/ui/input/key/SoftKeyboardInterceptionModifierNode` | Implement this interface to create a `https://developer.android.com/reference/kotlin/androidx/compose/ui/Modifier.Node` that can intercept hardware Key events before they are sent to the software keyboard. | Cmn |

## Classes

|---|---|---|
| `https://developer.android.com/reference/kotlin/androidx/compose/ui/input/key/Key` | Represents keys on a keyboard. | Cmn android |
| `https://developer.android.com/reference/kotlin/androidx/compose/ui/input/key/KeyEvent` | When a user presses a key on a hardware keyboard, a `https://developer.android.com/reference/kotlin/androidx/compose/ui/input/key/KeyEvent` is sent to the item that is currently focused. | Cmn |
| `https://developer.android.com/reference/kotlin/androidx/compose/ui/input/key/KeyEventType` | The type of Key Event. | Cmn |
| `https://developer.android.com/reference/kotlin/androidx/compose/ui/input/key/NativeKeyEvent` | The native platform-specific keyboard key event. | Cmn android |

## Modifiers

|---|---|---|
| `https://developer.android.com/reference/kotlin/androidx/compose/ui/input/key/onInterceptKeyBeforeSoftKeyboard.modifier` | Adding this `https://developer.android.com/reference/kotlin/androidx/compose/ui/Modifier` to the `https://developer.android.com/reference/kotlin/androidx/compose/ui/Modifier` parameter of a component will allow it to intercept hardware key events before they are sent to the software keyboard. | Cmn |
| `https://developer.android.com/reference/kotlin/androidx/compose/ui/input/key/onKeyEvent.modifier` | Adding this `https://developer.android.com/reference/kotlin/androidx/compose/ui/Modifier` to the `https://developer.android.com/reference/kotlin/androidx/compose/ui/Modifier` parameter of a component will allow it to intercept hardware key events when it (or one of its children) is focused. | Cmn |
| `https://developer.android.com/reference/kotlin/androidx/compose/ui/input/key/onPreInterceptKeyBeforeSoftKeyboard.modifier` | Adding this `https://developer.android.com/reference/kotlin/androidx/compose/ui/Modifier` to the `https://developer.android.com/reference/kotlin/androidx/compose/ui/Modifier` parameter of a component will allow it to intercept hardware key events before they are sent to the software keyboard. | Cmn |
| `https://developer.android.com/reference/kotlin/androidx/compose/ui/input/key/onPreviewKeyEvent.modifier` | Adding this `https://developer.android.com/reference/kotlin/androidx/compose/ui/Modifier` to the `https://developer.android.com/reference/kotlin/androidx/compose/ui/Modifier` parameter of a component will allow it to intercept hardware key events when it (or one of its children) is focused. | Cmn |

## Type aliases

|---|---|---|
| `https://developer.android.com/reference/kotlin/androidx/compose/ui/input/key/NativeKeyEvent` | The native Android `https://developer.android.com/reference/kotlin/androidx/compose/ui/input/key/NativeKeyEvent`. | android |

## Top-level functions summary

|---|---|---|
| `https://developer.android.com/reference/kotlin/androidx/compose/ui/input/key/Key` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/input/key/package-summary#Key(kotlin.Int)(nativeKeyCode: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)` | android |

## Extension properties summary

|---|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/input/key/KeyEvent.https://developer.android.com/reference/kotlin/androidx/compose/ui/input/key/package-summary#(androidx.compose.ui.input.key.KeyEvent).isAltPressed()` Indicates whether the Alt key is pressed. | Cmn android |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/input/key/KeyEvent.https://developer.android.com/reference/kotlin/androidx/compose/ui/input/key/package-summary#(androidx.compose.ui.input.key.KeyEvent).isCtrlPressed()` Indicates whether the Ctrl key is pressed. | Cmn android |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/input/key/KeyEvent.https://developer.android.com/reference/kotlin/androidx/compose/ui/input/key/package-summary#(androidx.compose.ui.input.key.KeyEvent).isMetaPressed()` Indicates whether the Meta key is pressed. | Cmn android |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/input/key/KeyEvent.https://developer.android.com/reference/kotlin/androidx/compose/ui/input/key/package-summary#(androidx.compose.ui.input.key.KeyEvent).isShiftPressed()` Indicates whether the Shift key is pressed. | Cmn android |
| `https://developer.android.com/reference/kotlin/androidx/compose/ui/input/key/Key` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/input/key/KeyEvent.https://developer.android.com/reference/kotlin/androidx/compose/ui/input/key/package-summary#(androidx.compose.ui.input.key.KeyEvent).key()` The key that was pressed. | Cmn android |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/input/key/Key.https://developer.android.com/reference/kotlin/androidx/compose/ui/input/key/package-summary#(androidx.compose.ui.input.key.Key).nativeKeyCode()` The native keycode corresponding to this `https://developer.android.com/reference/kotlin/androidx/compose/ui/input/key/Key`. | android |
| `https://developer.android.com/reference/kotlin/androidx/compose/ui/input/key/KeyEventType` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/input/key/KeyEvent.https://developer.android.com/reference/kotlin/androidx/compose/ui/input/key/package-summary#(androidx.compose.ui.input.key.KeyEvent).type()` The `https://developer.android.com/reference/kotlin/androidx/compose/ui/input/key/KeyEventType` of key event. | Cmn android |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/input/key/KeyEvent.https://developer.android.com/reference/kotlin/androidx/compose/ui/input/key/package-summary#(androidx.compose.ui.input.key.KeyEvent).utf16CodePoint()` The UTF16 value corresponding to the key event that was pressed. | Cmn android |

## Top-level functions

### Key

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

```
fun Key(nativeKeyCode: Int): Key
```

## Extension properties

### KeyEvent.isAltPressed

Cmn android Artifact: [androidx.compose.ui:ui](https://developer.android.com/jetpack/androidx/releases/compose-ui) [View Source](https://cs.android.com/search?q=file:androidx/compose/ui/input/key/KeyEvent.+symbol:isAltPressed)

```
val KeyEvent.isAltPressed: Boolean
```

Indicates whether the Alt key is pressed.

```kotlin
import androidx.compose.foundation.focusable
import androidx.compose.foundation.layout.Box
import androidx.compose.ui.Modifier
import androidx.compose.ui.input.key.Key
import androidx.compose.ui.input.key.isAltPressed
import androidx.compose.ui.input.key.key
import androidx.compose.ui.input.key.onKeyEvent

Box(
    Modifier.onKeyEvent {
            if (it.isAltPressed && it.key == Key.A) {
                println("Alt + A is pressed")
                true
            } else {
                false
            }
        }
        .focusable()
)
```

### KeyEvent.isCtrlPressed

Cmn android Artifact: [androidx.compose.ui:ui](https://developer.android.com/jetpack/androidx/releases/compose-ui) [View Source](https://cs.android.com/search?q=file:androidx/compose/ui/input/key/KeyEvent.+symbol:isCtrlPressed)

```
val KeyEvent.isCtrlPressed: Boolean
```

Indicates whether the Ctrl key is pressed.

```kotlin
import androidx.compose.foundation.focusable
import androidx.compose.foundation.layout.Box
import androidx.compose.ui.Modifier
import androidx.compose.ui.input.key.Key
import androidx.compose.ui.input.key.isCtrlPressed
import androidx.compose.ui.input.key.key
import androidx.compose.ui.input.key.onKeyEvent

Box(
    Modifier.onKeyEvent {
            if (it.isCtrlPressed && it.key == Key.A) {
                println("Ctrl + A is pressed")
                true
            } else {
                false
            }
        }
        .focusable()
)
```

### KeyEvent.isMetaPressed

Cmn android Artifact: [androidx.compose.ui:ui](https://developer.android.com/jetpack/androidx/releases/compose-ui) [View Source](https://cs.android.com/search?q=file:androidx/compose/ui/input/key/KeyEvent.+symbol:isMetaPressed)

```
val KeyEvent.isMetaPressed: Boolean
```

Indicates whether the Meta key is pressed.

```kotlin
import androidx.compose.foundation.focusable
import androidx.compose.foundation.layout.Box
import androidx.compose.ui.Modifier
import androidx.compose.ui.input.key.Key
import androidx.compose.ui.input.key.isMetaPressed
import androidx.compose.ui.input.key.key
import androidx.compose.ui.input.key.onKeyEvent

Box(
    Modifier.onKeyEvent {
            if (it.isMetaPressed && it.key == Key.A) {
                println("Meta + A is pressed")
                true
            } else {
                false
            }
        }
        .focusable()
)
```

### KeyEvent.isShiftPressed

Cmn android Artifact: [androidx.compose.ui:ui](https://developer.android.com/jetpack/androidx/releases/compose-ui) [View Source](https://cs.android.com/search?q=file:androidx/compose/ui/input/key/KeyEvent.+symbol:isShiftPressed)

```
val KeyEvent.isShiftPressed: Boolean
```

Indicates whether the Shift key is pressed.

```kotlin
import androidx.compose.foundation.focusable
import androidx.compose.foundation.layout.Box
import androidx.compose.ui.Modifier
import androidx.compose.ui.input.key.Key
import androidx.compose.ui.input.key.isShiftPressed
import androidx.compose.ui.input.key.key
import androidx.compose.ui.input.key.onKeyEvent

Box(
    Modifier.onKeyEvent {
            if (it.isShiftPressed && it.key == Key.A) {
                println("Shift + A is pressed")
                true
            } else {
                false
            }
        }
        .focusable()
)
```

### KeyEvent.key

Cmn android Artifact: [androidx.compose.ui:ui](https://developer.android.com/jetpack/androidx/releases/compose-ui) [View Source](https://cs.android.com/search?q=file:androidx/compose/ui/input/key/KeyEvent.+symbol:key)

```
val KeyEvent.key: Key
```

The key that was pressed.

```kotlin
import androidx.compose.foundation.focusable
import androidx.compose.foundation.layout.Box
import androidx.compose.ui.Modifier
import androidx.compose.ui.input.key.Key
import androidx.compose.ui.input.key.isAltPressed
import androidx.compose.ui.input.key.key
import androidx.compose.ui.input.key.onKeyEvent

Box(
    Modifier.onKeyEvent {
            if (it.isAltPressed && it.key == Key.A) {
                println("Alt + A is pressed")
                true
            } else {
                false
            }
        }
        .focusable()
)
```

### Key.nativeKeyCode

android Artifact: [androidx.compose.ui:ui](https://developer.android.com/jetpack/androidx/releases/compose-ui) [View Source](https://cs.android.com/search?q=file:androidx/compose/ui/input/key/Key.android.kt+symbol:nativeKeyCode)

```
val Key.nativeKeyCode: Int
```

The native keycode corresponding to this `https://developer.android.com/reference/kotlin/androidx/compose/ui/input/key/Key`.

### KeyEvent.type

Cmn android Artifact: [androidx.compose.ui:ui](https://developer.android.com/jetpack/androidx/releases/compose-ui) [View Source](https://cs.android.com/search?q=file:androidx/compose/ui/input/key/KeyEvent.+symbol:type)

```
val KeyEvent.type: KeyEventType
```

The `https://developer.android.com/reference/kotlin/androidx/compose/ui/input/key/KeyEventType` of key event.

```kotlin
import androidx.compose.foundation.focusable
import androidx.compose.foundation.layout.Box
import androidx.compose.ui.Modifier
import androidx.compose.ui.input.key.Key
import androidx.compose.ui.input.key.KeyEventType.Companion.KeyDown
import androidx.compose.ui.input.key.KeyEventType.Companion.KeyUp
import androidx.compose.ui.input.key.KeyEventType.Companion.Unknown
import androidx.compose.ui.input.key.key
import androidx.compose.ui.input.key.onKeyEvent
import androidx.compose.ui.input.key.type

Box(
    Modifier.onKeyEvent {
            when (it.type) {
                KeyUp -> println("KeyUp Pressed")
                KeyDown -> println("KeyUp Pressed")
                Unknown -> println("Unknown key type")
                else -> println("New KeyType (for future use)")
            }
            false
        }
        .focusable()
)
```

### KeyEvent.utf16CodePoint

Cmn android Artifact: [androidx.compose.ui:ui](https://developer.android.com/jetpack/androidx/releases/compose-ui) [View Source](https://cs.android.com/search?q=file:androidx/compose/ui/input/key/KeyEvent.+symbol:utf16CodePoint)

```
val KeyEvent.utf16CodePoint: Int
```

The UTF16 value corresponding to the key event that was pressed. The unicode character takes into account any meta keys that are pressed (eg. Pressing shift results in capital alphabets). The UTF16 value uses the U+n notation\[http://www.unicode.org/reports/tr27/#notation\] of the Unicode Standard.

An `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` is used instead of a `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-char/index.html` so that we can support supplementary characters. The Unicode Standard allows for characters whose representation requires more than 16 bits. The range of legal code points is U+0000 to U+10FFFF, known as Unicode scalar value.

The set of characters from U+0000 to U+FFFF is sometimes referred to as the Basic Multilingual Plane (BMP). Characters whose code points are greater than U+FFFF are called supplementary characters. In this representation, supplementary characters are represented as a pair of char values, the first from the high-surrogates range, (\\uD800-\\uDBFF), the second from the low-surrogates range (\\uDC00-\\uDFFF).