Keyboard shortcuts - Jetpack Compose

In Jetpack Compose, you can use the onKeyEvent modifier to activate shortcuts. This modifier gives you a reference to KeyEvent, which can be used to determine key presses.

Use the isShiftPressed or isCtrlPressed properties to ensure that shortcuts are not activated by accident.

Box(
    modifier = Modifier
        .onKeyEvent { event ->
            when (event.type) {
                KeyEventType.KeyUp -> {
                    if (event.key == Key.F && event.isCtrlPressed) {
                        // open find window
                        true
                    } else {
                        false
                    }
                }
                else -> false
            }
        }
) {
    // Box content...
}