Anyone know why my key listener activates 3 times ...
# compose-desktop
d
Anyone know why my key listener activates 3 times and also has a 0 key code for one of them? Code:
Copy code
application {
    Window(
        onCloseRequest = ::exitApplication,
        title = "App",
        onKeyEvent = {
            println("keyTyped: ${it.key.nativeKeyCode}:${it.key.nativeKeyCode.toChar()}")
            false
        }
    ) {
        // Window stuff
    }
}
Logs:
Copy code
keyTyped: 65:A
keyTyped: 0: 
keyTyped: 65:A
Using
keyCode
instead would just give this output (pressing a):
Copy code
keyTyped: 279709745152: 
keyTyped: 536870912: 
keyTyped: 279709745152:
k
Look at
Copy code
${it.nativeKeyEvent}
It'll give you one
PRESSED
, one
TYPED
and one
RELEASED
- which is what AWT produces for key events
Copy code
val nativeKeyEvent = it.nativeKeyEvent as java.awt.event.KeyEvent
This will give you the AWT event. Then you can look at its
id
and compare it to
KeyEvent.KEY_TYPED
etc
d
thank you so much!! 😄
it worked :))
k
👍