Input
Mouse buttonsNew
Handle the back and forward side buttons of a mouse as Compose pointer buttons.
The side buttons of a mouse reach Compose as PointerButton.Back and PointerButton.Forward, on
macOS, Windows and Linux. Use them for history navigation, as a browser or a file manager does:
Modifier.pointerInput(Unit) {
awaitPointerEventScope {
while (true) {
val event = awaitPointerEvent()
if (event.type != PointerEventType.Press) continue
when (event.button) {
PointerButton.Back -> navigator.back()
PointerButton.Forward -> navigator.forward()
else -> Unit
}
}
}
}Native popup windows and the Windows NativeView overlay do not receive the side buttons.
What's next
- Trackpad gestures: scrolling, pinch and rotation.
- Pointer icons: cursors beyond the four Compose defines.
Was this page helpful?
Edit on GitHub
Last updated on