{% setvar book_path %}/reference/androidx/_book.yaml{% endsetvar %} {% include "_shared/_reference-head-tags.html" %}

KeyEventType

value public final class KeyEventType


The type of Key Event.

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 KeyTpe (For Future Use)")
            }
            false
        }
        .focusable()
)

Summary

Nested types

public static class KeyEventType.Companion

Public methods

@NonNull String

Public methods

toString

public @NonNull String toString()