Key and shortcut tools
Press keys and keyboard shortcuts.
Press keys and keyboard shortcuts.
| Tool | Description | Platforms |
|---|---|---|
press_key | Press and release one key. | macOS, Linux, Windows |
hotkey | Press a key combination: e.g. | macOS, Linux, Windows |
Served by cua-driver mcp; see MCP tools for every tool.
press_key#Effect: destructive. Platforms: macOS, Linux, Windows.
Press and release one key. delivery_mode as in click/type_text.
background (default): posts to the pid without raising the window; with element_token it focuses that element first.foreground: fronts the exact window (needs window_id), sends a real HID key transition (Chromium content, inline editors, menu equivalents), then restores the prior app.Confirmed only when a native AX value/selection read-back changes; otherwise effect:"unverifiable" (not a delivery failure). Keys: return, tab, escape, up/down/left/right, space, delete, home, end, pageup, pagedown, f1-f12, any letter or digit.
macOS parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
delivery_mode | "background" | "foreground" | Default "background": no fronting or focus steal. "foreground": briefly front the window, act, restore the prior app; last resort when background did not land. | |
key | string | required | Key name. |
modifiers | string[] | cmd, shift, option/alt, ctrl, fn. | |
pid | integer | Target process ID. | |
scope | "window" | "desktop" | "window" | "desktop" with no pid/window_id sends to the frontmost app. |
session | string | For multi-call work, prefer a short public session label and repeat it on every call that accepts it. | |
window_id | integer | Target window; required for foreground. Does not raise by itself. | |
x | number | Screenshot-pixel X: pixel-click to focus, then send the key. With y, no element_token. | |
y | number | Screenshot-pixel Y (see x). |
Parameters on every platform
| Parameter | Type | Default | Description |
|---|---|---|---|
element_token | string | Element handle <snapshot_id>:<row> from get_window_state: row [11] of a read whose snapshot_id is s0000002a is "s0000002a:11" (also in structuredContent.elements[].element_token). Returns an explicit stale error naming the current snapshots once a newer read supersedes it. | |
target | object | Preferred per-call target: an exact window (kind="window", pid, window_id) or the primary desktop (kind="desktop", display_id="primary"). | |
target.display_id | string | Display id. Required when kind is desktop; use "primary". | |
target.kind | "window" | "desktop" | window requires pid and window_id; desktop requires display_id. | |
target.pid | integer | Process id. Required when kind is window. Minimum: 0. | |
target.window_id | integer | Window id from list_windows. Required when kind is window. Minimum: 0. |
Example arguments
{"key":"<key>"}hotkey#Effect: destructive. Platforms: macOS, Linux, Windows.
Press a key combination: e.g. ["cmd", "c"] for Copy, ["cmd", "shift", "4"] for screenshot selection. Follows the same delivery_mode ladder as click/type_text: it does NOT raise the window by default:
• background (default): post the combo to the target pid WITHOUT fronting or raising it; uses the macOS 14+ auth-message envelope so Chromium/Electron accept it as trusted live input. With an AX target, focus that exact element first. No top-level focus steal. window_id here only targets the combo; it does not raise. Background key events never reach a native app's menus, so when the combo is a menu item's key equivalent (cmd+s, cmd+w, ...) and the app is not in front, that menu item runs through accessibility instead (a disabled Save is saved through the app's scripting interface and verified on disk); a menu item macOS keeps disabled in the background is refused with background_unavailable, and no keys are sent.
• foreground: briefly front the window (NSMenu path, < 1 ms via SLPSSetFrontProcessWithOptions) so native menu key-equivalents (Cmd+Z, Cmd+W) dispatch, then restore the prior frontmost; the explicit escalation for menu-bar shortcuts on non-Chromium apps that ignore a background combo. With an AX target or x,y, the focused field receives the chord through the foreground HID queue (needed by native Chromium fields such as the omnibox). Requires window_id.
A combo is never driver-verifiable (no read-back) → effect:"unverifiable"; confirm via screenshot. NOTE: a keyboard combo does NOT focus a text field; to type into a backgrounded Electron input, establish real renderer focus with a PIXEL click first, then type_text. If an app only accepts paste, call clipboard_write, then clipboard_read and verify its types (and text when applicable) before selecting or replacing editor content; only then send Cmd+V.
Recognized modifiers: cmd/command, shift, option/alt, ctrl/control, fn. Non-modifier keys use the same vocabulary as press_key. Order: modifiers first, one non-modifier last.
macOS parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
delivery_mode | "background" | "foreground" | Best-effort-background ladder rung (default "background"). "background": inject without fronting or raising the target; no focus steal. "foreground": briefly front the target, act, then restore the prior frontmost; the explicit last resort when a background attempt didn't land. Re-call with "foreground" only for the action that needs it. | |
keys | string[] | required | Modifier(s) and one non-modifier key, e.g. ["cmd", "c"]. Items: 2 to any. |
pid | integer | Target process ID. Required with x, y; optional with element_token (the token carries the pid). | |
scope | "window" | "desktop" | "window" | Use desktop with no pid/window_id to send the chord to the frontmost application. |
window_id | integer | Target window. Required for delivery_mode:"foreground" (the NSMenu activation needs a window). Does NOT itself raise the window: raising is gated on delivery_mode. | |
x | number | Screenshot-pixel X: the element px action form: pixel-click there to focus, then send the combo (so e.g. Cmd+V pastes into that field). Pass with y. Use for Chromium/Electron surfaces the background combo can't reach. | |
y | number | Screenshot-pixel Y (see x). |
Parameters on every platform
| Parameter | Type | Default | Description |
|---|---|---|---|
element_token | string | Element handle <snapshot_id>:<row> from get_window_state: row [11] of a read whose snapshot_id is s0000002a is "s0000002a:11" (also in structuredContent.elements[].element_token). Returns an explicit stale error naming the current snapshots once a newer read supersedes it. | |
session | string | For multi-call work, prefer a short public session label and repeat it on every call that accepts it. Omit it to use the authenticated transport's implicit lifecycle session. | |
target | object | Preferred per-call target: an exact window (kind="window", pid, window_id) or the primary desktop (kind="desktop", display_id="primary"). | |
target.display_id | string | Display id. Required when kind is desktop; use "primary". | |
target.kind | "window" | "desktop" | window requires pid and window_id; desktop requires display_id. | |
target.pid | integer | Process id. Required when kind is window. Minimum: 0. | |
target.window_id | integer | Window id from list_windows. Required when kind is window. Minimum: 0. |
Example arguments
{"keys":["<key>","<key>"]}