karagoz key
Presses one key.
- Android emulator Done
- Android device Done
- iOS simulator Done
- iOS device Done
karagoz key <key> [--device <id>]Before you start
Section titled “Before you start”- On Android, for the key to reach apps: the screen unlocked. On a lock screen
keytypes into the PIN field, and a wrong PIN counts as a failed unlock attempt. With the screen off, keys still arrive; both cases exit0. - On an iOS simulator: Xcode 27 or newer, opened once.
- On an iPhone: paired with the Mac, Developer Mode on, connected by USB cable, Settings > Developer > Enable UI Automation on, and Karagöz’s runner installed with
install-runner.
Options
Section titled “Options”<key> is an Android KeyEvent name or code:
- A name, case-insensitive, with or without
KEYCODE_:HOME,back,KEYCODE_ENTER,VOLUME_UP. - A number from 1 to 340 is a key code:
key 3isHOME. To press the digit 7, useKEYCODE_7, becausekey 7is code 7, which isKEYCODE_0.
Examples
Section titled “Examples”Press Home
Section titled “Press Home”karagoz key HOME{"device":"emulator-5554","key":"KEYCODE_HOME","code":3}exit 0Output
Section titled “Output”{ "device": "emulator-5554", "key": "KEYCODE_HOME", "code": 3}devicestring- Serial, or the simulator's or iPhone's UDID.
keystring- The resolved name.
codenumber- The number of the resolved key.
Errors
Section titled “Errors”INVALID_ARGS: unknown key 'FOO'; use a KeyEvent name such as HOME, BACK or ENTER, or a code from 1 to 340. Checked before any device call.
A key can also get INPUT_BLOCKED, the device selection errors and the adb errors.
- A device knows the key codes of its Android version only (12: up to 288, 13: 304, 14: 316, 15: 318, 16: 337); a higher code is sent as
KEYCODE_UNKNOWN, still with exit0. - Some keys act on the whole device: code 312 opens Recents, 318 saves a screenshot.
- Exit
0means Android accepted the key, not that the app reacted to it.
On an iOS simulator
Section titled “On an iOS simulator”The same names and codes, and the same output. Only these have an iOS key:
| Name | On the simulator |
|---|---|
HOME |
The Home button |
POWER |
The side button: locks the screen |
VOLUME_UP, VOLUME_DOWN |
The volume buttons |
A-Z, 0-9, ENTER, DEL (backspace), FORWARD_DEL, TAB, SPACE, ESCAPE, DPAD_UP, DPAD_DOWN, DPAD_LEFT, DPAD_RIGHT, MOVE_HOME, MOVE_END, PAGE_UP, PAGE_DOWN, F1-F24, COMMA, PERIOD, MINUS, EQUALS, LEFT_BRACKET, RIGHT_BRACKET, BACKSLASH, SEMICOLON, APOSTROPHE, SLASH, GRAVE, SHIFT_*, CTRL_*, ALT_*, META_*, CAPS_LOCK |
The hardware keyboard key |
Any other name fails before anything is sent:
{ "error": { "code": "INVALID_ARGS", "message": "'BACK' has no iOS simulator key; iOS takes HOME, POWER, VOLUME_UP, VOLUME_DOWN and keyboard keys (letters, digits, ENTER, DEL, TAB, ESCAPE, DPAD_*, F1-F24); tap the app's back button or swipe from the left edge" }}- Each key is pressed alone, with no modifier held.
- Keyboard keys act only where iOS uses them: in a focused field, or with Full Keyboard Access.
- A letter goes through iOS’s typing, so auto-capitalization applies:
key Ain an empty field typedA. - The first of
ui-tree,tap,swipe,textorkeyon a simulator compiles a small helper, which takes a few seconds. - Errors:
NOT_SUPPORTED,DEVICE_NOT_READYandHELPER_FAILED, as fortap.
On an iPhone
Section titled “On an iPhone”The same names, codes and output, through Karagöz’s runner. Fewer keys have an iPhone counterpart:
| Name | On an iPhone |
|---|---|
HOME |
Brings the Home screen to the front; when it is already in front nothing changes (the page, an open folder). |
POWER |
The side button: locks the screen. Unlocking is yours, and the next runner start asks for the passcode on the phone. |
VOLUME_UP, VOLUME_DOWN |
The volume buttons |
A-Z (typed lowercase), 0-9, SPACE, ENTER (Return), TAB, DEL (backspace), ESCAPE, MINUS, EQUALS, LEFT_BRACKET, RIGHT_BRACKET, BACKSLASH, SEMICOLON, APOSTROPHE, GRAVE, COMMA, PERIOD, SLASH |
The character, typed as text types it |
A key that types no character (DPAD_*, F1-F24, PAGE_UP, MOVE_HOME, FORWARD_DEL, modifiers) fails before anything is sent:
{ "error": { "code": "INVALID_ARGS", "message": "'DPAD_UP' has no iPhone key; an iPhone takes HOME, POWER, VOLUME_UP, VOLUME_DOWN and keys that type a character (letters, digits, SPACE, ENTER, TAB, DEL, ESCAPE, punctuation)" }}A volume key takes about 0.4 s, POWER about 0.9 s. Errors: those of tap on an iPhone.
MCP equivalent
Section titled “MCP equivalent”Arguments: key (required), device. The names are the CLI's option and positional names.
Related commands
Section titled “Related commands”- karagoz tap
- On a simulator and on an iPhone, key fails with the errors tap gets.
- karagoz text
- On an iPhone, a key that types a character types it as text does.