Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Key Events Tutorial #3988

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions tutorials/Keyboard/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Heya! From your addition, it's not quite clear why users should care about this. From our private convo, you said this is relevant if you have keyboard shortcuts that shouldn't trigger while you're currently in a text field. Would you be able to provide a short code snippet that demonstrates that use case? That would also make it easier for my colleagues to see if what you're doing is idiomatic, and whether we can move forward with adding it to the tutorial. :)


In desktop code you can check this using `keyEvent.isTypedEvent` where `isTypedEvent` uses the `actual val KeyEvent.isTypedEvent: Boolean` in `TextFieldKeyInput.desktop.kt`.