keyboard
Press keys or key combinations in a browser to automate typing, navigation, and form interactions during web automation tasks.
Instructions
Press a key or key combination
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| key | Yes | Key to press (e.g., "Enter", "Tab", "a") | |
| modifiers | No | Modifier keys to hold | |
| tabId | No | Tab ID to operate on (uses active tab if not specified) |
Implementation Reference
- src/tools/input.ts:19-55 (handler)Handler implementation for the 'keyboard' tool: registers the tool and provides the execution logic using Puppeteer's keyboard API to press modifiers and the key.server.tool( 'keyboard', 'Press a key or key combination', keyboardSchema.shape, async ({ key, modifiers, tabId }) => { const pageResult = await getPageForOperation(tabId); if (!pageResult.success) { return handleResult(pageResult); } const page = pageResult.data; const mods = (modifiers ?? []) as KeyModifier[]; try { // Press modifier keys for (const mod of mods) { await page.keyboard.down(mod); } // Press the main key await page.keyboard.press(key as KeyInput); // Release modifier keys for (const mod of mods.reverse()) { await page.keyboard.up(mod); } return handleResult(ok({ pressed: true, key, modifiers: mods, })); } catch (error) { return handleResult(err(normalizeError(error))); } } );
- src/schemas.ts:88-92 (schema)Zod schema defining the input parameters for the 'keyboard' tool: key, optional modifiers, and optional tabId.export const keyboardSchema = z.object({ key: z.string().min(1).describe('Key to press (e.g., "Enter", "Tab", "a")'), modifiers: z.array(z.enum(['Alt', 'Control', 'Meta', 'Shift'])).optional().default([]).describe('Modifier keys to hold'), tabId: tabIdSchema, });
- src/server.ts:29-29 (registration)Calls registerInputTools which includes the registration of the 'keyboard' tool.registerInputTools(server);
- src/types.ts:145-147 (helper)Type definition for keyboard modifier keys used in the keyboard tool.* Keyboard modifier keys */ export type KeyModifier = 'Alt' | 'Control' | 'Meta' | 'Shift';