Keyboard & Text Input
Type text, press HID key codes, run key sequences and send modifier shortcuts, on simulators and physical devices.
AXe sends keyboard input as HID key codes for the US keyboard layout. That is deterministic, and it means type can only send characters on a US keyboard.
Type text
type takes exactly one source: the text as an argument, --stdin or --file.
axe type 'Hello, world!' --udid "$UDID"
printf 'line one\nline two' | axe type --stdin --udid "$UDID"
axe type --file message.txt --udid "$UDID"Focus the field first, for example with tap --id EmailField. type does not clear existing text. A character outside the US layout, such as é or £, fails with invalidArguments before anything is typed.
On a physical device, and in agent and selected modes, one type command sends at most 256 UTF-8 bytes.
To enter accented or non-Latin text in a simulator, put it on the clipboard with axe clipboard copy --stdin, then paste it in the app. See Command Reference.
Single keys
axe key 40 --udid "$UDID" # Return
axe key 42 --duration 1.0 --udid "$UDID" # hold Backspace for one secondThe key code is 0 to 255. --duration holds the key for up to 10 seconds.
Key sequences
axe key-sequence --keycodes 11,8,15,15,18 --udid "$UDID" # h e l l o
axe key-sequence --keycodes 42,42 --delay 0.2 --udid "$UDID" # two Backspaces--keycodes is a comma-separated list of up to 100 codes. --delay between keys defaults to 0.1 seconds (0 to 5).
Shortcuts
key-combo holds the modifiers in order, presses one key, then releases the modifiers in reverse order.
axe key-combo --modifiers 227 --key 4 --udid "$UDID" # Cmd+A
axe key-combo --modifiers 227 --key 6 --udid "$UDID" # Cmd+C
axe key-combo --modifiers 227 --key 25 --udid "$UDID" # Cmd+V
axe key-combo --modifiers 227,225 --key 29 --udid "$UDID" # Cmd+Shift+ZA combo holds 1 to 8 modifiers.
In agent mode
Agents type into a field by ref. --focus taps the field, waits for focus and types in one call:
axe type 'London' --agent --focus --snapshot-id "$SNAPSHOT_ID" --ref e7 --udid "$UDID"
axe key 42 --agent --snapshot-id "$SNAPSHOT_ID" --ref e7 --udid "$UDID"AXe checks before every key that the same field still has focus. See Agent Mode.
Common key codes
| Key | Code | Key | Code |
|---|---|---|---|
| a | 4 | Left Control | 224 |
| c | 6 | Left Shift | 225 |
| v | 25 | Left Option | 226 |
| z | 29 | Left Command | 227 |
| Return | 40 | Right Control | 228 |
| Escape | 41 | Right Shift | 229 |
| Backspace | 42 | Right Option | 230 |
| Tab | 43 | Right Command | 231 |
| Space | 44 | F1 | 58 |
| Right arrow | 79 | F12 | 69 |
| Left arrow | 80 | Down arrow | 81 |
| Up arrow | 82 |