get_active_window
Retrieve the currently active window on Windows systems to monitor user activity, track application focus, or automate window-based workflows.
Instructions
获取当前激活的窗口
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Input Schema (JSON Schema)
{
"properties": {},
"type": "object"
}
Implementation Reference
- src/tools/window.js:159-187 (handler)The handler function that retrieves the title of the currently active (foreground) window using Windows API via PowerShell.async getActiveWindow() { try { const script = ` Add-Type @" using System; using System.Runtime.InteropServices; using System.Text; public class Win32 { [DllImport("user32.dll")] public static extern IntPtr GetForegroundWindow(); [DllImport("user32.dll")] public static extern int GetWindowText(IntPtr hWnd, StringBuilder lpString, int nMaxCount); } "@ $hWnd = [Win32]::GetForegroundWindow() $title = New-Object System.Text.StringBuilder 256 [Win32]::GetWindowText($hWnd, $title, 256) $title.ToString() `; const { stdout } = await execAsync(`powershell -Command "${script.replace(/"/g, '\\"')}"`, { shell: 'powershell.exe' }); return { success: true, window: stdout.trim() }; } catch (error) { return { success: false, error: error.message }; } }
- src/tools/window.js:22-29 (schema)The tool schema definition, specifying name, description, and empty input schema (no parameters required).{ name: 'get_active_window', description: '获取当前激活的窗口', inputSchema: { type: 'object', properties: {}, }, },
- src/tools/window.js:83-100 (registration)The dispatcher method that handles tool execution, routing 'get_active_window' to the getActiveWindow handler.async executeTool(name, args) { switch (name) { case 'list_windows': return await this.listWindows(args.filter); case 'get_active_window': return await this.getActiveWindow(); case 'activate_window': return await this.activateWindow(args.title); case 'close_window': return await this.closeWindow(args.title); case 'minimize_window': return await this.minimizeWindow(args.title); case 'maximize_window': return await this.maximizeWindow(args.title); default: throw new Error(`未知工具: ${name}`); } }
- src/tools/window.js:77-80 (registration)The canHandle method listing supported tools, including 'get_active_window'.canHandle(toolName) { const tools = ['list_windows', 'get_active_window', 'activate_window', 'close_window', 'minimize_window', 'maximize_window']; return tools.includes(toolName);