Skip to content

API 参考 ​

Wingman 提供了丰富的 API 来支持游戏自动化开发。

目录 ​

核心 API ​

核心 API 提供屏幕操作、输入模拟、窗口管理等基础功能。

模块列表 ​

模块功能文档
screen屏幕截图、颜色检测、图像识别screen
input鼠标点击、键盘输入、文本输入input
window窗口查找、激活、位置获取window
process进程查找和管理process
vision图像识别和匹配vision
ocrOCR 文字识别ocr
smarttrigger智能触发器系统smart-trigger
human人性化模拟human
perf性能监控perf
system系统信息获取system
uiaUI Automation 控件交互uia
bt行为树引擎behavior-tree
security安全模块security
crypto加密函数crypto
verification验证码识别、TOTPverification
gameprofile游戏配置档案gameprofile
util工具函数util
mlONNX 模型加载与输入/输出元数据查询(可选依赖)ml
file文件 IO(读写、移动复制、目录操作)file
filewatcher文件系统监听filewatcher
clipboard剪贴板读写clipboard
hotkey全局热键监听hotkey
systemwatch系统事件源(进程/窗口变化)systemwatch

快速示例 ​

Lua ​

lua
local wingman = require("wingman")

-- 截图(返回是否成功,图像存于内部缓冲区)
local ok = wingman.screen.capture()
if not ok then
    print("截屏失败")
end

-- 查找颜色(返回 {point, found},region 可选)
local result = wingman.screen.findColor(0xFF0000, {x=0, y=0, width=1920, height=1080}, 10)
if result.found then
    wingman.input.click(result.point.x, result.point.y)
end

-- 查找图像(返回 {point, found},threshold 可选,默认 0.9)
local match = wingman.screen.findImage("target.png", {x=0, y=0, width=1920, height=1080}, 0.8)
if match.found then
    wingman.input.move(match.point.x, match.point.y, 500)
    wingman.input.click(match.point.x, match.point.y)
end

Python ​

python
from wingman import screen, input

# 截图(返回是否成功,图像存于内部缓冲区)
ok = screen.capture()
if not ok:
    print("截屏失败")

# 查找颜色(返回 {point, found},region 可选)
result = screen.findColor(0xFF0000, {"x": 0, "y": 0, "width": 1920, "height": 1080}, 10)
if result["found"]:
    input.click(result["point"]["x"], result["point"]["y"])

# 查找图像(返回 {point, found},threshold 可选,默认 0.9)
match = screen.findImage("target.png", {"x": 0, "y": 0, "width": 1920, "height": 1080}, 0.8)
if match["found"]:
    input.move(match["point"]["x"], match["point"]["y"], 500)
    input.click(match["point"]["x"], match["point"]["y"])

数据持久化 API ​

数据持久化 API 提供键值存储和数据库支持。

模块列表 ​

模块功能文档
kv键值存储kv
dbSQLite 数据库db

快速示例 ​

Lua ​

lua
local wingman = require("wingman")

-- 键值存储
wingman.kv.set("username", "player1")
local name = wingman.kv.get("username")

-- 数据库操作
local conn = wingman.db.open("game_data")
wingman.db.execute(conn, "CREATE TABLE players (id INTEGER PRIMARY KEY, name TEXT)")
wingman.db.execute(conn, "INSERT INTO players (name) VALUES (?)", {"player1"})
local rows = wingman.db.query(conn, "SELECT * FROM players")

Python ​

python
from wingman import kv, db

# 键值存储
kv.set("username", "player1")
name = kv.get("username")

# 数据库操作
conn = db.open("game_data")
db.execute(conn, "CREATE TABLE players (id INTEGER PRIMARY KEY, name TEXT)")
db.execute(conn, "INSERT INTO players (name) VALUES (?)", ["player1"])
rows = db.query(conn, "SELECT * FROM players")

序列化 API ​

序列化 API 提供多种数据格式支持。

模块列表 ​

模块功能文档
jsonJSON 编码/解码json
iniINI 配置文件解析ini

快速示例 ​

Lua ​

lua
local wingman = require("wingman")

-- JSON
local data = {name = "player1", level = 10}
local json_string = wingman.json.encode(data)
local decoded = wingman.json.decode(json_string)

-- INI
local config = wingman.ini.decode(ini_content)
local config_string = wingman.ini.encode(config)

Python ​

python
from wingman import json, ini

# JSON
data = {"name": "player1", "level": 10}
json_string = json.encode(data)
decoded = json.decode(json_string)

# INI
config = ini.decode(ini_content)
config_string = ini.encode(config)

脚本 API ​

脚本 API 提供脚本执行和管理功能。

模块列表 ​

模块功能文档
event事件系统event
task任务管理task
notify通知系统notify
fsm有限状态机fsm
httpHTTP 请求http
config配置管理config
transportTCP/UDP 网络通信transport
script脚本管理控制面(列举、启动/停止/重载)script
timer定时器(一次性/周期回调)timer
macro宏录制与回放macro
orchestration编排控制orchestration
inbox消息收件箱inbox
team组队编排team
node节点管理node

调试 API ​

调试 API 提供脚本调试功能。

模块列表 ​

模块功能文档
debuggerEmmyLua 调试器debugger

快速示例 ​

Lua ​

lua
local wingman = require("wingman")

-- 启动调试器
wingman.debugger.start()

-- 在当前位置设置断点
wingman.debugger.breakHere()

按功能查找 API ​

屏幕和图像 ​

  • [截图: screen.capture(), screen.captureRegion()]
  • [颜色检测: screen.findColor(), screen.findColors()]
  • [图像识别: screen.findImage()]
  • [OCR: ocr.recognize()]

输入和控制 ​

  • [鼠标: input.click(), input.move(), input.scroll()]
  • 键盘: input.keyDown(), input.keyUp(), input.key()
  • [文本: input.type()]
  • [人性化: human.mouse_move(), human.mouse_click(), human.keyboard_type()]

窗口和进程 ​

  • [窗口: window.find(), window.activate(), window.getBounds()]
  • [进程: process.find(), process.exists()]

数据和配置 ​

  • [存储: kv.set(), kv.get(), db.open()]
  • [配置: json.encode(), json.decode(), ini.encode(), ini.decode()]

自动化 ​

  • [触发器: smarttrigger.create(), smarttrigger.start()]
  • [录制: macro.start(), macro.stop(), macro.playback()]
  • [事件: event.on(), event.emit()]
  • [任务: task.submit(), task.status()]

网络 ​

  • [HTTP: http.get(), http.post()]

调试 ​

  • [调试器: debugger.start(), debugger.breakpoint(), debugger.breakHere()]

API 命名约定 ​

Lua ​

  • 统一引入: local wingman = require("wingman"),模块作为子表访问: wingman.screen
  • 方法以模块实际注册名为准(如 wingman.screen.capture()、wingman.uia.find_button())
  • 脚本层当前没有注册常量

Python ​

  • 模块使用小写: from wingman import screen
  • 方法以模块实际注册名为准(camelCase 注册名会同时提供 snake_case 别名;原生 snake_case 注册名仅此一种形式)

[命名约定:Python 绑层对 camelCase 注册名自动提供 snake_case 别名(如 util 模块的 getTime 可写作 get_time);原生 snake_case 注册名(如 uia 模块的 find_by_name)仅此一种形式,没有 camelCase 形式。推荐脚本先查各模块文档确认注册名。]

类型转换 ​

Lua 到 ScriptValue ​

Lua 类型ScriptValue 类型
nilNull
booleanBoolean
numberInteger/Float
stringString
tableObject/Array
functionFunction

Python 到 ScriptValue ​

Python 类型ScriptValue 类型
NoneNull
boolBoolean
intInteger
floatFloat
strString
dictObject
listArray
functionFunction

错误处理 ​

Lua ​

lua
local ok, result = pcall(function()
    return wingman.screen.capture()
end)

if not ok then
    print("Error:", result)
else
    -- result 为布尔值,表示是否截屏成功
end

Python ​

python
try:
    ok = screen.capture()
except Exception as e:
    print(f"Error: {e}")

相关文档 ​


返回: 文档首页