How can I make it so pressing the enter key produc...
# compose
z
How can I make it so pressing the enter key produces the same behavior as pressing the IME action on the on-screen keyboard?
m
Copy code
OutlinedTextField(
                modifier = Modifier.onKeyEvent { event ->
                    if (event.key == Key.Enter) {
                        println("foo")
                    }
                    true
                },
A word of caution that this is an experimental function and you either have to opt-in or pass along
ExperimentalComposeUiApi
I suppose if you want to avoid the opt-in, you can do this as well in there:
Copy code
if (event.nativeKeyEvent.keyCode == KeyEvent.KEYCODE_ENTER) {
z
You also might want to check that the key event is either up or down, but not both, so you don’t invoke the callback twice for a single press