Skip to main content

Press · Back

This tool on every surface: CLI · MCP · Python · JavaScript · Go · Java · .NET

Press a hardware button. These call app_press.

Press​

func (d *Device) Press(ctx context.Context, button string) error

Press sends a hardware button: "back", "home", "recents", "volume-up" or "volume-down"; a remote's D-pad, "dpad-up", "dpad-down", "dpad-left", "dpad-right" and "select"; or a media key, "play-pause", "stop", "next", "previous", "rewind" or "fast-forward". A D-pad press reports where focus went.

On Android back is primary navigation. iOS has no back button by design and returns an error saying what to do instead, rather than sending an edge swipe — a different event that an app can tell apart. Any press can move the screen, so the refs from the last Map are discarded.

Back​

func (d *Device) Back(ctx context.Context, gesture bool) (BackResult, error)

Back goes back and says where it went: whether it left the app, and on iOS what the navigation bar says. With gesture it is a swipe in from the left edge rather than the key — the only back iOS has, and refused on an Android device that navigates with buttons.

Examples​

Press Back​

if err := dev.Press(ctx, "back"); err != nil {
return err
}

The same call from the command line, mobium press back, printed on an Android 15 emulator:

pressed back
BeforeAfter
Before: mobium press back on an Android 15 emulatorAfter: mobium press back on an Android 15 emulator

mobium press back on an Android 15 emulator

Go to the home screen​

if err := dev.Press(ctx, "home"); err != nil {
return err
}

The same call from the command line, mobium press home, printed on an Android 15 emulator:

pressed home — com.google.android.apps.nexuslauncher is in the foreground

mobium press home on an Android 15 emulator

mobium press home on an Android 15 emulator

Move focus with a TV remote's D-pad​

if err := dev.Press(ctx, "dpad-down"); err != nil {
return err
}

The same call from the command line, mobium press dpad-down, printed on an Android 15 emulator:

pressed dpad-down — focus moved to homepage_container

Go back with a swipe in from the edge​

went, err := dev.Back(ctx, true)
if err != nil {
return err
}
fmt.Println(went.Foreground, went.Confirmed)

The same call from the command line, mobium press back --gesture, printed on an Android 15 emulator:

swiped back from the left edge, halfway down — com.android.settings is still in the foreground; app_map shows which screen