focus_window
Bring a specific game window to the foreground by title or handle for focused interaction during game hacking and reverse engineering tasks.
Instructions
Bring a window to the foreground.
Args:
target: Window title (string) or HWND handle (integer)
Returns:
Success status.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| target | Yes |
Implementation Reference
- The handler function implementing the 'focus_window' MCP tool. It locates the target window by title or handle and brings it to the foreground using Windows API (win32gui.SetForegroundWindow). Requires pywin32 for Windows support.@mcp.tool() def focus_window(target: Union[str, int]) -> Dict[str, Any]: """ Bring a window to the foreground. Args: target: Window title (string) or HWND handle (integer) Returns: Success status. """ if not SCREENSHOT_AVAILABLE: return {"error": "Window control not available. Install: pip install pywin32"} try: hwnd = None if isinstance(target, int): hwnd = target else: def find_window(h, _): nonlocal hwnd if win32gui.IsWindowVisible(h): title = win32gui.GetWindowText(h) if title and target.lower() in title.lower(): hwnd = h return False return True win32gui.EnumWindows(find_window, None) if not hwnd: return {"error": f"Window not found: {target}"} win32gui.SetForegroundWindow(hwnd) return { "success": True, "window": win32gui.GetWindowText(hwnd), "hwnd": hwnd } except Exception as e: return {"error": f"Failed to focus window: {str(e)}"}