take_screenshot_region
Capture a specific rectangular area of your Windows screen by defining coordinates and dimensions, then save the screenshot to a specified path.
Instructions
截取屏幕区域
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| x | Yes | X 坐标 | |
| y | Yes | Y 坐标 | |
| width | Yes | 宽度 | |
| height | Yes | 高度 | |
| path | No | 保存路径(可选) |
Implementation Reference
- src/tools/screen.js:97-129 (handler)The core handler function that executes the region screenshot using PowerShell to capture a specific screen area and save it as PNG.async takeScreenshotRegion(x, y, width, height, savePath) { try { const timestamp = new Date().toISOString().replace(/[:.]/g, '-'); const fileName = `screenshot-region-${timestamp}.png`; const defaultPath = path.join(process.env.USERPROFILE, 'Desktop', fileName); const finalPath = savePath || defaultPath; const script = ` Add-Type -AssemblyName System.Windows.Forms,System.Drawing $bitmap = New-Object System.Drawing.Bitmap ${width}, ${height} $graphics = [System.Drawing.Graphics]::FromImage($bitmap) $graphics.CopyFromScreen(${x}, ${y}, 0, 0, [System.Drawing.Size]::new(${width}, ${height})) $bitmap.Save("${finalPath}", [System.Drawing.Imaging.ImageFormat]::Png) $bitmap.Dispose() $graphics.Dispose() `; await execAsync(`powershell -Command "${script.replace(/"/g, '\\"')}"`, { shell: 'powershell.exe' }); await fs.access(finalPath); return { success: true, path: finalPath, region: { x, y, width, height }, message: '区域截图已保存' }; } catch (error) { return { success: false, error: error.message }; } }
- src/tools/screen.js:25-39 (schema)Tool schema definition including name, description, input schema with properties x, y, width, height (required), and optional path.{ name: 'take_screenshot_region', description: '截取屏幕区域', inputSchema: { type: 'object', properties: { x: { type: 'number', description: 'X 坐标' }, y: { type: 'number', description: 'Y 坐标' }, width: { type: 'number', description: '宽度' }, height: { type: 'number', description: '高度' }, path: { type: 'string', description: '保存路径(可选)' }, }, required: ['x', 'y', 'width', 'height'], }, },
- src/tools/screen.js:52-53 (registration)Registration of the tool handler in the executeTool switch statement, mapping tool name to the takeScreenshotRegion method.case 'take_screenshot_region': return await this.takeScreenshotRegion(args.x, args.y, args.width, args.height, args.path);
- src/server.js:97-102 (registration)Tool dispatching logic in handleToolCall that routes tool calls to the appropriate module (ScreenTools) based on canHandle.for (const [category, toolModule] of Object.entries(this.tools)) { if (toolModule.canHandle(name)) { result = await toolModule.executeTool(name, args); break; } }
- src/server.js:48-48 (registration)Instantiation and registration of ScreenTools instance in the server's tools object.screen: new ScreenTools(),