get_active_window
Retrieve the currently active window on a Windows system to monitor or control application focus for automation workflows.
Instructions
获取当前激活的窗口
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- src/tools/window.js:159-187 (handler)The main handler function `getActiveWindow()` that executes a PowerShell script using Windows API calls (GetForegroundWindow and GetWindowText) to retrieve and return the title of the currently active (foreground) window.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)Tool definition including name, description, and input schema (empty object, no parameters required).{ name: 'get_active_window', description: '获取当前激活的窗口', inputSchema: { type: 'object', properties: {}, }, },
- src/tools/window.js:87-88 (registration)Switch case in `executeTool` method that registers and dispatches calls to the `get_active_window` tool by invoking the handler method.case 'get_active_window': return await this.getActiveWindow();
- src/server.js:47-52 (registration)Instantiation of WindowTools class in the main tools registry object, enabling discovery and execution of its tools including get_active_window.window: new WindowTools(), screen: new ScreenTools(), clipboard: new ClipboardTools(), powershell: new PowerShellTools(), browser: new BrowserTools(), };
- src/tools/window.js:78-80 (helper)The `canHandle` method's tools list explicitly includes 'get_active_window' for tool name validation.const tools = ['list_windows', 'get_active_window', 'activate_window', 'close_window', 'minimize_window', 'maximize_window']; return tools.includes(toolName);