Vadim Kapustin
06/01/2021, 12:22 PMIgor Demin
06/01/2021, 12:59 PMimport androidx.compose.desktop.Window
import androidx.compose.material.TextField
import androidx.compose.ui.ExperimentalComposeUiApi
import androidx.compose.ui.Modifier
import androidx.compose.ui.input.key.Key
import androidx.compose.ui.input.key.KeyEventType
import androidx.compose.ui.input.key.key
import androidx.compose.ui.input.key.onPreviewKeyEvent
import androidx.compose.ui.input.key.type
@OptIn(ExperimentalComposeUiApi::class)
fun main() = Window {
TextField("", {}, modifier = Modifier.onPreviewKeyEvent {
if (it.key == Key.Enter && it.type == KeyEventType.KeyDown) {
println("Enter")
true
} else {
false
}
})
}
P.S. probably with singleLine == true
we should propagate Enter key to the parent nodes, so onKeyEvent
would work too 🤔Vadim Kapustin
06/01/2021, 1:02 PMAlexey Glushkov
08/07/2021, 8:45 PMe: ...kt This API is experimental and is likely to change in the future.
Igor Demin
08/11/2021, 12:21 PMdeprecated solutiononly
Window
is deprecated here (we can use singleWindowApplication
instead), the rest of the code stays the same.
This API is experimental and is likely to change in the future.Just add
@OptIn(ExperimentalComposeUiApi::class)
to your functionAlexey Glushkov
08/11/2021, 12:21 PMThomas
12/27/2021, 8:47 PM