Nucleus
Input

Mouse buttonsNew

Handle the back and forward side buttons of a mouse as Compose pointer buttons.

View as Markdown

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

Was this page helpful?
Edit on GitHub

Last updated on

On this page