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​

def press(button: str) -> None

Press 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 raises with what to do instead, rather than sending an edge swipe — a different event an app can tell apart. Any press can move the screen, so the refs from the last map are discarded.

back​

def back(gesture: bool=False) -> dict

Go back, and say where it went.

Returns foreground (the app in front afterwards), left (the app back closed, absent when it stayed in front), title (an iOS navigation bar's, afterwards) and confirmed. With gesture=True 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​

device.press("back")

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​

device.press("home")

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​

device.press("dpad-down")

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 = device.back(gesture=True)
print(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