Why keyboard action will invoke twice but i only trigger once?
See original GitHub issueWhen i test keyboard simple example, i find a problem that the action will invoke twice but i only trigger once.
My code is simple and from: https://github.com/JetBrains/compose-jb/blob/master/tutorials/Keyboard/README.md
fun main() = Window {
MaterialTheme {
var text by remember { mutableStateOf("") }
Column(Modifier.fillMaxSize(), Arrangement.spacedBy(5.dp)) {
TextField(
value = text,
onValueChange = { text = it },
modifier = Modifier.onPreviewKeyEvent {
when {
(it.isCtrlPressed && it.key == Key.Minus) -> {
println("on enter")
true
}
else -> false
}
}
)
}
}
}
here is the recording, you can see the “on enter” print twice when i trigger once
Issue Analytics
- State:
- Created 2 years ago
- Comments:7 (4 by maintainers)
Top Results From Across the Web
button trigger behaviour: "release only" triggers twice!?
The event will be triggered 2 times. First after the button crosses the presspoint with context.started = true and context.performed = false.
Read more >Hotkey trigger tapped twice issue - Questions & Suggestions
I set Keyboard maestro to launch an app by tapping twice a letter. It's work but I can't use this letter to type...
Read more >Why is onKey() called twice? - android - Stack Overflow
OnKey is fired twice: the first time for key down, and the second time for key up, so you have to filter: YOUR_VIEW.setOnKeyListener(new...
Read more >Oops! 10 Keyboard Shortcuts Users Keep Hitting by Mistake
Accidentally pressed something on your keyboard and now you can't type properly? Here are fixes for common keyboard shortcut issues.
Read more >How to correctly use preventDefault(), stopPropagation(), or ...
Here we have taken the click event and prevented its default behaviour using event.preventDefault() , then invoked the fileUpload() function. We ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@akurasov I have added a PR for updating the keyboard tutorial here: https://github.com/JetBrains/compose-jb/pull/1877
thank your for giving solution, really works ! But i wonder why not add the condition “it.type == KeyEventType.KeyDown” to sample?