https://kotlinlang.org logo
#compose-android
Title
# compose-android
u

יעקב

02/25/2024, 2:55 PM
How can I get virtual keyboard keycodes events from TextField in Jetpack? I tried the following, but it works only in english keyboard, on other language
keyMap.getEvents(...)
returns
null
The goal is to send keyboard keycodes to remote device
Copy code
@Composable
fun Screen() {
    TextField(value = "", onValueChange = {e ->
        val keyMap = KeyCharacterMap.load(KeyCharacterMap.VIRTUAL_KEYBOARD)
        println("keymap: $keyMap change: $e")
        val chars = e.toCharArray()

        for (char in chars) {
            val events = keyMap.getEvents(charArrayOf(char))
            if (!events.isNullOrEmpty()) {
                val event = events.first()
                println("keydown: $event")
            }

        }

    })
}
z

Zach Klippenstein (he/him) [MOD]

02/26/2024, 6:15 PM
How would you want this to work for keyboards that use text composition?