All Downloads are FREE. Search and download functionalities are using the official Maven repository.

jvmMain.Utils.kt Maven / Gradle / Ivy

Go to download

Unstyled, fully accesible Compose Multiplatform components that you can customize to your heart's desire.

There is a newer version: 1.19.1
Show newest version
@file:JvmName("CommonUtilsKt")

package com.composables.core

import androidx.compose.runtime.Composable
import androidx.compose.runtime.DisposableEffect
import androidx.compose.ui.input.key.Key
import java.awt.KeyEventDispatcher
import java.awt.KeyboardFocusManager
import java.awt.event.KeyEvent

@Composable
internal actual fun KeyDownHandler(onEvent: (KeyDownEvent) -> Boolean) {
    DisposableEffect(Unit) {
        val dispatcher = KeyEventDispatcher { keyEvent ->
            if (keyEvent.id == KeyEvent.KEY_PRESSED) {
                val keyDownEvent = KeyDownEvent(Key(keyEvent.keyCode))
                onEvent(keyDownEvent)
            } else {
                false
            }
        }
        val keyboardFocusManager = KeyboardFocusManager.getCurrentKeyboardFocusManager()
        keyboardFocusManager.addKeyEventDispatcher(dispatcher)
        onDispose {
            keyboardFocusManager.removeKeyEventDispatcher(dispatcher)
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy