press_key
Simulate keyboard key presses to automate Windows system interactions. Send individual keys or combinations with modifiers like control, shift, and alt for automated input tasks.
Instructions
按下键盘按键
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| key | Yes | 按键名称(如 enter, tab, escape) | |
| modifiers | No | 修饰键(如 control, shift, alt) |
Input Schema (JSON Schema)
{
"properties": {
"key": {
"description": "按键名称(如 enter, tab, escape)",
"type": "string"
},
"modifiers": {
"description": "修饰键(如 control, shift, alt)",
"items": {
"type": "string"
},
"type": "array"
}
},
"required": [
"key"
],
"type": "object"
}
Implementation Reference
- src/tools/mouse-keyboard.js:166-177 (handler)The pressKey method implements the core logic of the 'press_key' tool. It uses robotjs.keyTap to press the specified key, supporting optional modifiers like control, shift, etc., and returns success/failure with 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 in getToolDefinitions(), providing the name, description, and inputSchema for validation of 'press_key' tool parameters.{ 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)In the executeTool switch statement, the case for 'press_key' that dispatches to the pressKey handler.case 'press_key': return this.pressKey(args.key, args.modifiers);
- src/server.js:46-46 (registration)Instantiates the MouseKeyboardTools class in the main server, which provides the 'press_key' tool among others, enabling its registration via getToolDefinitions().mouseKeyboard: new MouseKeyboardTools(),
- src/tools/mouse-keyboard.js:93-96 (registration)The canHandle method lists 'press_key' as one of the tools this module can handle, used by the server to route calls correctly.canHandle(toolName) { const tools = ['move_mouse', 'mouse_click', 'type_text', 'press_key', 'get_mouse_position', 'get_screen_size']; return tools.includes(toolName);