We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
There should be a simple way to handle key presses on window/screen/dialog level.
Desktop currently have and additional API for that:
Window(onPreviewKeyEvent = )
There are issues with it:
Modifier.onPreviewKeyEvent
Alternatively, we can use this approach, but it is cumbersome:
import androidx.compose.foundation.focusable import androidx.compose.foundation.layout.Box import androidx.compose.runtime.Composable import androidx.compose.runtime.LaunchedEffect import androidx.compose.runtime.remember import androidx.compose.ui.ExperimentalComposeUiApi import androidx.compose.ui.Modifier import androidx.compose.ui.focus.FocusRequester import androidx.compose.ui.focus.focusProperties import androidx.compose.ui.focus.focusRequester import androidx.compose.ui.input.key.key import androidx.compose.ui.input.key.onPreviewKeyEvent @OptIn(ExperimentalComposeUiApi::class) @Composable fun App() { val focusRequester = remember { FocusRequester() } Box( Modifier .focusRequester(focusRequester) .focusProperties{ exit = { focusRequester } } // make LocalFocusManager.current.clear() to focus this node instead of the root window node .focusable() .onPreviewKeyEvent { println(it.key) true } ) LaunchedEffect(Unit) { focusRequester.requestFocus() } }
The text was updated successfully, but these errors were encountered:
No branches or pull requests
There should be a simple way to handle key presses on window/screen/dialog level.
Desktop currently have and additional API for that:
There are issues with it:
Modifier.onPreviewKeyEvent
)Alternatively, we can use this approach, but it is cumbersome:
The text was updated successfully, but these errors were encountered: