Browse Source

Update Key Events Tutorial

As per this discussion on slack: https://kotlinlang.slack.com/archives/C01D6HTPATV/p1701186380386439
pull/3988/head
Sebastian 1 year ago committed by GitHub
parent
commit
0572f2a964
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 6
      tutorials/Keyboard/README.md

6
tutorials/Keyboard/README.md

@ -166,3 +166,9 @@ fun App() {
```
<img alt="window_keyboard" src="window_keyboard.gif" height="280" />
## TextFields
TextFields in Compose for Desktop consume special events of type `java.awt.event.KeyEvent.KEY_TYPED`. If you want to avoid consuming Events that have already been consumed by a TextField, you have to check for this special eventType, as TextFields will not consume `KeyEventType.KeyDown` or `KeyEventType.KeyUp` events on Desktop.
You can do this using a condition like `keyEvent.isTypedEvent && keyEvent.awtEventOrNull?.keyChar == 'a'` where `isTypedEvent` uses the `actual val KeyEvent.isTypedEvent: Boolean` in `TextFieldKeyInput.desktop.kt`.

Loading…
Cancel
Save