press_key
Simulate keyboard key presses on Windows systems. Specify keys like enter, tab, or escape, optionally with modifiers such as control or shift, to automate typing tasks.
Instructions
按下键盘按键
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| key | Yes | 按键名称(如 enter, tab, escape) | |
| modifiers | No | 修饰键(如 control, shift, alt) |
Implementation Reference
- src/tools/mouse-keyboard.js:166-177 (handler)The pressKey method that executes the core logic of the 'press_key' tool using robotjs.keyTap(key, modifiers). Returns success status and details.pressKey(key, modifiers = []) { try { if (modifiers.length > 0) { this.robot.keyTap(key, modifiers); } else { this.robot.keyTap(key); } return { success: true, key, modifiers, message: '按键已按下' }; } catch (error) { return { success: false, error: error.message }; } }
- src/tools/mouse-keyboard.js:62-73 (schema)The tool definition object in getToolDefinitions() that registers the 'press_key' tool name and its input schema (key required, modifiers optional).{ name: 'press_key', description: '按下键盘按键', inputSchema: { type: 'object', properties: { key: { type: 'string', description: '按键名称(如 enter, tab, escape)' }, modifiers: { type: 'array', items: { type: 'string' }, description: '修饰键(如 control, shift, alt)' }, }, required: ['key'], }, },
- src/tools/mouse-keyboard.js:114-115 (registration)Dispatch logic in executeTool switch statement that handles 'press_key' by calling the pressKey handler with parsed arguments.case 'press_key': return this.pressKey(args.key, args.modifiers);
- src/tools/mouse-keyboard.js:94-95 (registration)Inclusion of 'press_key' in the canHandle tool list, enabling routing in the main server handleToolCall.const tools = ['move_mouse', 'mouse_click', 'type_text', 'press_key', 'get_mouse_position', 'get_screen_size'];
- src/server.js:46-46 (registration)Instantiation of MouseKeyboardTools class in the main server, which provides the press_key tool via getToolDefinitions and executeTool.mouseKeyboard: new MouseKeyboardTools(),