key_press
Press keyboard combinations (e.g., ctrl+c, alt+Tab) using xdotool keysym notation for desktop automation.
Instructions
Press a keyboard combination using xdotool's keysym notation. Examples: 'ctrl+c', 'alt+Tab', 'super', 'Return', 'Escape', 'Page_Down'.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| combo | Yes |
Implementation Reference
- server.js:289-297 (handler)The key_press handler function. Uses xdotool to press a keyboard combination (e.g. 'ctrl+c', 'alt+Tab'). Validates that args.combo is a non-empty string, then spawns 'xdotool key -- <combo>'. Returns the combo on success or an error result on failure.
// ─── Tool: key_press ────────────────────────────────────────────────────── async function keyPress(args) { const missing = requireBin('xdotool'); if (missing) return errorResult(missing); if (typeof args.combo !== 'string' || !args.combo) return errorResult('combo is required (e.g. "ctrl+c")'); const r = await run(BIN.xdotool, ['key', '--', args.combo]); if (r.code !== 0) return errorResult(`key_press failed: ${r.stderr || r.stdout}`); return textResult({ combo: args.combo }); } - server.js:502-510 (schema)Input schema for the 'key_press' tool. Defines a single required string property 'combo' (e.g. 'ctrl+c', 'Return', 'Escape'). Also includes the description and annotations.
{ name: 'key_press', description: "Press a keyboard combination using xdotool's keysym notation. Examples: 'ctrl+c', 'alt+Tab', 'super', 'Return', 'Escape', 'Page_Down'.", annotations: { title: 'Press keys', destructiveHint: true }, inputSchema: { type: 'object', properties: { combo: { type: 'string' } }, required: ['combo'], }, - server.js:564-564 (registration)Registration of the key_press tool in the HANDLERS map, mapping the tool name 'key_press' to the keyPress function.
key_press: keyPress, - server.js:64-83 (helper)The run() helper function used by keyPress to spawn xdotool. It spawns a child process, collects stdout/stderr, and returns the exit code and output.
function run(cmd, args, opts = {}) { return new Promise((resolve) => { const child = spawn(cmd, args, { stdio: ['pipe', 'pipe', 'pipe'], ...opts }); let out = Buffer.alloc(0); let err = Buffer.alloc(0); child.stdout.on('data', (d) => { out = Buffer.concat([out, d]); }); child.stderr.on('data', (d) => { err = Buffer.concat([err, d]); }); if (opts.stdin !== undefined) { child.stdin.end(opts.stdin); } else { child.stdin.end(); } child.on('error', (e) => resolve({ code: -1, stdout: '', stderr: e.message })); child.on('close', (code) => resolve({ code, stdout: out.toString('utf8'), stderr: err.toString('utf8'), })); }); } - server.js:56-62 (helper)The requireBin() helper used by keyPress to check if 'xdotool' is installed before attempting to run it.
// ─── Helpers ────────────────────────────────────────────────────────────── function requireBin(name) { if (!BIN[name]) { return `Required system tool "${name}" is not installed. Install with: sudo apt install ${name === 'gnomeShot' ? 'gnome-screenshot' : name === 'xclip' ? 'xclip' : name === 'xdotool' ? 'xdotool' : 'wmctrl'}`; } return null; }