介绍
# Windows UI Automation
以编程方式控制 Windows 桌面环境。
## 核心功能
- **鼠标**:移动、点击(左键/右键/双击)、拖拽。 - **键盘**:发送文本、按下特殊键(Enter、Tab、Alt 等)。 - **窗口**:查找、聚焦、最小化/最大化以及截取窗口屏幕。
## 使用指南
### 鼠标控制
使用提供的 PowerShell 脚本 `mouse_control.ps1.txt`:
```powershell # Move to X, Y powershell -File skills/windows-ui-automation/mouse_control.ps1.txt -Action move -X 500 -Y 500
# Click at current position powershell -File skills/windows-ui-automation/mouse_control.ps1.txt -Action click
# Right click powershell -File skills/windows-ui-automation/mouse_control.ps1.txt -Action rightclick ```
### 键盘控制
使用 `keyboard_control.ps1.txt`:
```powershell # Type text powershell -File skills/windows-ui-automation/keyboard_control.ps1.txt -Text "Hello World"
# Press Enter powershell -File skills/windows-ui-automation/keyboard_control.ps1.txt -Key "{ENTER}" ```
### 窗口管理
要通过标题聚焦窗口: ```powershell $wshell = New-Object -ComObject WScript.Shell; $wshell.AppActivate("Notepad") ```
## 最佳实践
1. **安全性**:移动鼠标时始终保持缓慢,或在操作之间包含延迟。 2. **验证**:在复杂的 UI 操作之前和之后截取屏幕,以验证状态。 3. **坐标**:请记住,坐标 (0,0) 位于主显示器的左上角。