onPreviewKeyEvent

fun Modifier.onPreviewKeyEvent(onPreviewKeyEvent: (event: KeyEvent) -> Boolean): Modifier

Adding this modifier to the modifier parameter of a component will allow it to intercept key events.

Parameters

onPreviewKeyEvent

This callback is invoked when the user interacts with the keyboard. It gives ancestors of a focused component the chance to intercept a KeyEvent. Return true to stop propagation of this event. If you return false, the key event will be sent to this onPreviewKeyEvent's child. If none of the children consume the event, it will be sent back up to the root KeyModifier using the onKeyEvent callback.