网淘吧来吧,欢迎您!

返回首页 微信
微信
手机版
手机版

Windows Control技能使用说明

2026-03-27 新闻来源:网淘吧 围观:25
电脑广告
手机广告

Windows 控制技能

适用于 Windows 的完整桌面自动化。像真人用户一样控制鼠标、键盘和屏幕。

快速开始

所有脚本位于skills/windows-control/scripts/

屏幕截图

py screenshot.py > output.b64

返回整个屏幕的 base64 PNG 图像。

点击

py click.py 500 300              # Left click at (500, 300)
py click.py 500 300 right        # Right click
py click.py 500 300 left 2       # Double click

输入文本

py type_text.py "Hello World"

在当前光标位置输入文本(按键间隔 10 毫秒)。

按键

py key_press.py "enter"
py key_press.py "ctrl+s"
py key_press.py "alt+tab"
py key_press.py "ctrl+shift+esc"

移动鼠标

py mouse_move.py 500 300

将鼠标移动到指定坐标(平滑动画,耗时 0.2 秒)。

滚动

py scroll.py up 5      # Scroll up 5 notches
py scroll.py down 10   # Scroll down 10 notches

窗口管理(新增!)

py focus_window.py "Chrome"           # Bring window to front
py minimize_window.py "Notepad"       # Minimize window
py maximize_window.py "VS Code"       # Maximize window
py close_window.py "Calculator"       # Close window
py get_active_window.py               # Get title of active window

高级操作(新增!)

# Click by text (No coordinates needed!)
py click_text.py "Save"               # Click "Save" button anywhere
py click_text.py "Submit" "Chrome"    # Click "Submit" in Chrome only

# Drag and Drop
py drag.py 100 100 500 300            # Drag from (100,100) to (500,300)

# Robust Automation (Wait/Find)
py wait_for_text.py "Ready" "App" 30  # Wait up to 30s for text
py wait_for_window.py "Notepad" 10    # Wait for window to appear
py find_text.py "Login" "Chrome"      # Get coordinates of text
py list_windows.py                    # List all open windows

读取窗口文本

py read_window.py "Notepad"           # Read all text from Notepad
py read_window.py "Visual Studio"     # Read text from VS Code
py read_window.py "Chrome"            # Read text from browser

使用 Windows UI 自动化提取实际文本(非 OCR)。比屏幕截图快得多且更准确!

读取 UI 元素(新增!)

py read_ui_elements.py "Chrome"               # All interactive elements
py read_ui_elements.py "Chrome" --buttons-only  # Just buttons
py read_ui_elements.py "Chrome" --links-only    # Just links
py read_ui_elements.py "Chrome" --json          # JSON output

返回按钮、链接、选项卡、复选框、下拉菜单及其点击坐标。

读取网页内容(新增!)

py read_webpage.py                     # Read active browser
py read_webpage.py "Chrome"            # Target Chrome specifically
py read_webpage.py "Chrome" --buttons  # Include buttons
py read_webpage.py "Chrome" --links    # Include links with coords
py read_webpage.py "Chrome" --full     # All elements (inputs, images)
py read_webpage.py "Chrome" --json     # JSON output

增强浏览器内容提取功能,支持标题、文本、按钮和链接的提取。

处理对话框(新功能!)

# List all open dialogs
py handle_dialog.py list

# Read current dialog content
py handle_dialog.py read
py handle_dialog.py read --json

# Click button in dialog
py handle_dialog.py click "OK"
py handle_dialog.py click "Save"
py handle_dialog.py click "Yes"

# Type into dialog text field
py handle_dialog.py type "myfile.txt"
py handle_dialog.py type "C:\path\to\file" --field 0

# Dismiss dialog (auto-finds OK/Close/Cancel)
py handle_dialog.py dismiss

# Wait for dialog to appear
py handle_dialog.py wait --timeout 10
py handle_dialog.py wait "Save As" --timeout 5

处理保存/打开对话框、消息框、警告框、确认框等。

按名称点击元素(新功能!)

py click_element.py "Save"                    # Click "Save" anywhere
py click_element.py "OK" --window "Notepad"   # In specific window
py click_element.py "Submit" --type Button    # Only buttons
py click_element.py "File" --type MenuItem    # Menu items
py click_element.py --list                    # List clickable elements
py click_element.py --list --window "Chrome"  # List in specific window

无需坐标,即可通过名称点击按钮、链接和菜单项。

读取屏幕区域(OCR - 可选功能)

py read_region.py 100 100 500 300     # Read text from coordinates

注:需要安装Tesseract OCR。建议使用read_window.py以获得更好的效果。

工作流程模式

  1. 读取窗口- 从特定窗口提取文本(快速、准确)
  2. 读取UI元素- 获取按钮、链接及其坐标
  3. 截图(如需要)- 查看视觉布局
  4. 操作- 通过名称或坐标点击元素
  5. 处理对话框- 与弹出窗口/保存对话框交互
  6. 读取窗口- 验证变更

屏幕坐标

  • 原点 (0, 0) 位于左上角
  • 你的屏幕:2560x1440(通过截图确认)
  • 使用截图分析得出的坐标

示例

打开记事本并输入

# Press Windows key
py key_press.py "win"

# Type "notepad"
py type_text.py "notepad"

# Press Enter
py key_press.py "enter"

# Wait a moment, then type
py type_text.py "Hello from AI!"

# Save
py key_press.py "ctrl+s"

在 VS Code 中点击

# Read current VS Code content
py read_window.py "Visual Studio Code"

# Click at specific location (e.g., file explorer)
py click.py 50 100

# Type filename
py type_text.py "test.js"

# Press Enter
py key_press.py "enter"

# Verify new file opened
py read_window.py "Visual Studio Code"

监控记事本的变化

# Read current content
py read_window.py "Notepad"

# User types something...

# Read updated content (no screenshot needed!)
py read_window.py "Notepad"

文本读取方法

方法一:Windows UI 自动化(最佳)

  • 使用read_window.py用于任何窗口
  • 使用read_ui_elements.py用于带坐标的按钮/链接
  • 使用read_webpage.py用于带结构的浏览器内容
  • 获取实际的文本数据(非基于图像)

方法二:按名称点击(新增)

  • 使用click_element.py通过名称点击按钮/链接
  • 无需坐标 - 自动查找元素
  • 适用于所有窗口或可指定目标窗口

方法三:对话框处理(新增)

  • 使用handle_dialog.py处理弹窗、保存对话框、警告框
  • 读取对话框内容、点击按钮、输入文本
  • 使用常见按钮自动关闭(确定、取消等)

方法四:截图 + 视觉识别(备用方案)

  • 截取完整屏幕
  • AI视觉读取文本
  • 速度较慢但适用于任何内容

方法五:OCR识别(可选)

  • 使用read_region.py配合Tesseract
  • 需要额外安装
  • 适用于含文本的图像/PDF文件

安全功能

  • pyautogui.FAILSAFE = True(移动鼠标至左上角可中止程序)
  • 动作之间的短暂延迟
  • 平滑的鼠标移动(非瞬时跳跃)

要求

  • Python 3.11+
  • pyautogui(已安装 ✅)
  • pillow(已安装 ✅)

提示

  • 始终先截图以查看当前状态
  • 坐标为绝对坐标(非相对于窗口)
  • 点击后稍作等待,以便UI更新
  • 使用ctrl+z尽可能使用友好操作

状态:✅ 准备就绪(v2.0 - 对话框和UI元素)创建于:2026-02-01更新于:2026-02-02

天猫隐藏优惠券

网淘吧

免责申明
部分文章来自各大搜索引擎,如有侵权,请与我联系删除。
打赏
文章底部电脑广告
手机广告位-内容正文底部

相关文章

您是本站第292481名访客 今日有288篇新文章/评论