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 KeyType (for future use)")
            }
            false
        }
        .focusable()
)

Summary

Public companion properties

KeyEventType

Type of KeyEvent sent when the user presses down their finger on a key on the keyboard.

Cmn
KeyEventType

Type of KeyEvent sent when the user lifts their finger off a key on the keyboard.

Cmn
KeyEventType

Unknown key event.

Cmn

Public functions

open String
Cmn

Public companion properties

KeyDown

val KeyDownKeyEventType

Type of KeyEvent sent when the user presses down their finger on a key on the keyboard.

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()
)

KeyUp

val KeyUpKeyEventType

Type of KeyEvent sent when the user lifts their finger off a key on the keyboard.

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()
)

Unknown

val UnknownKeyEventType

Unknown 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 KeyType (for future use)")
            }
            false
        }
        .focusable()
)

Public functions

toString

open fun toString(): String