Agent
点击通过系统自动化服务送达,可用节点选择器、界面树、多指手势和 W3C Actions。需要用电脑通过 USB 运行「ketec 激活器」一次性激活(见下载页)。
文档
先看快速开始,再浏览脚本模块和 HTTP 接口;每节末尾都链接到完整参考。
$ curl http://<iphone-ip>:9800/api/status # app and iOS version, device model, run mode, recording state $ curl "http://<iphone-ip>:9800/api/control/click?x=540&y=1200" # tapped at 540, 1200 $ curl -o screen.jpg http://<iphone-ip>:9800/api/screenshot # full-resolution JPEG saved
从安装到第一次自动点击,只需五步。
在 iOS 15 及以上的 iPhone 上通过 TestFlight 安装,打开一次 ketec,让本地服务启动。
在「设置」里选 Agent 或 HID,「状态」页会显示通道是否就绪。
新建 scripts/main.js、scripts/main.lua 或 scripts/main.py,下面三段示例做的是同一件事。
在「软件」页安装软件包,或把一段 JavaScript 发到 HTTP 接口。
注册停止回调,它会收到 success、error 或 stopped,结束前可以保存状态。
// scripts/main.js
setStopCallback((status) => logi("finished: " + status));
logi("Hello from ketec on iOS " + device.getOSVersion());
system.startApp("com.apple.Preferences");
sleep(1500);
// Find "General" with on-device OCR and tap it
const hits = paddleOcr.findTextAbs("screen", ["General"]);
if (hits.length > 0) {
action.click(hits[0].centerX, hits[0].centerY);
}-- scripts/main.lua
SetStopCallback(function(status) logi("finished: " .. status) end)
logi("Hello from ketec on iOS " .. device.getOSVersion())
system.startApp("com.apple.Preferences")
sleep(1500)
-- Find "General" with on-device OCR and tap it
local hits = paddleOcr.findTextAbs("screen", {"General"})
if #hits > 0 then
action.click(hits[1].centerX, hits[1].centerY)
end# scripts/main.py
import time
from ketec import g, device, system, paddleocr, action
g.setStopCallback(lambda status: print("finished:", status))
print("Hello from ketec on iOS", device.getOSVersion())
system.startApp("com.apple.Preferences")
time.sleep(1.5)
# Find "General" with on-device OCR and tap it
hits = paddleocr.findTextAbs("screen", ["General"])
if hits:
action.click(hits[0].centerX, hits[0].centerY)通过网络执行一段代码(仅支持 JavaScript):
curl -X POST http://<iphone-ip>:9800/api/runScript \
-H "Content-Type: application/json" \
-d '{"script":"action.click(540, 1200); device.getOSVersion()"}'两种模式跑同一套脚本,区别在于输入如何到达系统,以及能用哪些能力。
点击通过系统自动化服务送达,可用节点选择器、界面树、多指手势和 W3C Actions。需要用电脑通过 USB 运行「ketec 激活器」一次性激活(见下载页)。
USB 上的 ESP32-S3 硬件发送真实的鼠标键盘输入,使用 hid 模块或 /api/hid 接口。此模式不使用界面树,请用找图和 OCR 定位;两种指针模式分别适配新旧 iOS。
软件包就是一个文件夹:入口脚本加上它用到的资源,ketec 按入口文件选择引擎。
scripts/main.js · scripts/main.lua · scripts/main.py | 入口脚本:JavaScript、Lua 或 Python |
file.readResFile() · image.readImage() | 图片、模型、字库等资源 |
ui.show() | 可选:UI 页使用的网页配置页 |
config 模块保存的配置与 App 自身设置分开存放,跨次运行保留,并保持值的类型:存 5 读回来还是 5。
各语言的模块名和参数完全一致,只有语法不同。
模块是全局对象:action.click(x, y);日志用 logi / logd / logw / loge 或 console;定时器用 setTimeout、setInterval。
模块是全局表,对象方法用冒号调用:sel:getOneNodeInfo(3000);全局函数有 sleep、logi、SetStopCallback 等。
按需导入:from ketec import action, image, g;返回值既能 r.name 也能 r["name"];全局函数在 g 里。
脚本可用模块总览,按用途分组;三种语言函数名一致。
没有匹配的结果。
globalPython: g
延时、时间、日志、停止与异常回调、触控模式与 CPU 限流。
sleeptimeexitlogilogwlogesetStopCallbacksetExceptionCallbackrestartScripttakeMeToFrontsetAgentTouchMode
action
点击、滑动、曲线、文字输入、按键、组合键与多指构建器。
clickdoubleClickclickRandomswipeswipeCurvepressAndSwipeinputinputSimplebackspaceenterhomeScreenpressButtonsendKeyw3cActionscreateBuildersetJitterValue
node
在界面树中查找控件并操作(Agent 模式)。
createNodeSelectorlabellabelMatchtitleidentifiertypevaluexpathgetOneNodeInfogetNodeInfoclickCenterscrollToVisibleparentchildreleaseNode
image
截图、找图找色、裁剪、旋转、二值化、扫码。
captureScreenreadImagefindImagefindImageExfindColorfindMultiColorcountColorcmpColorpixelcliprotateImagebinaryzationscanCodesaveTorelease
device
电量、存储、屏幕参数、亮度、音量、方向与设备标识。
getBatteryInfogetStorageSpacegetDeviceNamegetDeviceModelgetOSVersiongetScreenRealSizegetScreenScalegetOrientationgetScreenBrightnesssetVolumegetLanIpvibrate
system
App、链接、剪贴板、锁屏、内存与 CPU、通知。
startAppstopAppactivateAppactivateAppInfogetInstalledAppListopenURLsetClipboardgetClipboardisLockedlockunlockgetMemoryInfogetCpuUsagenotify
ime
通过 ketec 键盘输入、粘贴、清空、读取文字。
isOkinputpasteclearTextgetTextpressEnterpressDeldismissswitchKeyboard
ui
显示配置页、Toast 与对话框,脚本与页面互相通信。
showhideshowToastconfirmconfirmInputalertonEventcalleval
pip
画中画悬浮窗:日志、保活、自定义文字三种模式。
isPipActiveswitchToLogModeswitchToKeepAliveModeswitchToCustomModesetCustomTextsetPositioncloseWindow
hotUpdatePython: hotupdate
检查、下载、安装脚本软件包新版本。
checkUpdatedownloadAndInstallgetCurrentVersion
hid
经 ESP32-S3 硬件模拟鼠标键盘,并查询硬件状态。
clickdoubleClickmovemouseDownmouseUpswipeswipeCurveinputinputSimplesendKeypressButtonopenAppcloseAppopenURLrecenthomeScreenisUSBConnectedgetDeviceVersionresetPositionrestartDevice
httpPython: requests
GET、POST、JSON、文件下载与 WebSocket。
httpGethttpPostpostJSONrequestdownloadFilenewWebsocket
cloud
连接云控服务器、上报数据、接收事件。
connectisConnecteddisconnectreportonEvent
mysql
连接 MySQL,执行查询、语句与事务。
connectqueryexecutebeginTransactioncommitrollbackdisconnect
sqlite
本地 SQLite 数据库的查询与事务。
openqueryexecutebeginTransactioncommitrollbackclose
file
读写与追加文件、按行操作、目录与软件包资源。
readFilewriteFileappendLinereadLinereadAllLinesdeleteLinelistDirmkdirsexistscopyfileMD5readResFilegetResFile
zipFile
列出、创建、解压 ZIP。
zipunzipgetFileListisZip
plist
读取和编辑 plist 文件。
readwritegetsetremove
config
跨次运行保存的脚本配置,保留值类型。
getsetremoveallsetAll
cryptoUtils
AES、RSA 加解密,MD5、SHA-1、SHA-256。
encryptWithAES_ECBdecryptWithAES_ECBencryptWithRSAdecryptWithRSAmd5sha1sha256
paddleOcrPython: paddleocr
端侧 PP-OCR:中英日韩与数字。
recognizeAbsfindTextAbsloadModelsetMaxSideLenfree
appleOcrPython: appleocr
系统 Vision 文字识别。
recognizeAbsrecognizeNumbersAbsfindTextAbs
tomatoOcrPython: tomatoocr
随包开源模型 OCR,带点击点查找,无需授权码。
ocrImagefindTapPointfindTapPointssetRecTypesetReturnTyperelease
dotOcrPython: dotocr
点阵 OCR,字库自行加载。
loadFontrecognizeAbsfindTextAbsfreefreeAll
yolo
在全屏或区域运行自己的 YOLO 检测模型。
loaddetectAbsfreefreeAll
yoloClsPython: yolocls
运行 YOLO 分类模型。
loadclassifyclassifyRegionfreefreeAll
cvPython: cv2
约 140 个 OpenCV 函数(Mat 对象);Python 直接用 cv2。
imreadcvtColorthresholdCannyfindContoursmatchTemplateresizeGaussianBlurinRangeORBSIFTdetectQRCode
ai
配置大模型服务,提问、判断、抽取与对话。
setProvideraskjudgeextractchatparseJson
tts
用系统语音朗读文字。
speakwaitEndstopisSpeakingsetVoicegetAvailableVoices
logger
日志级别、日志文件、大小与轮转。
debuginfowarnerrorsetLoggerLevelsetLogToFilesetMaxLogFileSize
media
保存到相册、清理照片视频、播放音频。
saveImageToAlbumsaveVideoToAlbumPathdeleteAllPhotosdeleteAllVideosplayMp3stopMp3
threadPython: sharedState
在并行线程中运行函数,用 sharedState 共享数据。
runstopAllsharedState.setgetwithBatchclear
utils
时间格式化、随机数、UUID、Base64 与十六进制。
timeFormatrandomrandomUUIDbase64Encodedbase64DecodedhexString
此外,每个选择器结果都有 label、labelMatch、type、xpath、clickCenter、scrollToVisible、parent、child 等方法。
每台手机在本机地址的 9800 端口提供 HTTP 接口。工作台用的就是这些接口,它能做的,你自己的工具也能做。
基础地址: http://<iphone-ip>:9800
| 方法 | 路径 | 作用 |
|---|---|---|
| GET | /api/status | App 状态、版本与设备信息 |
| GET | /api/screenshot · /api/screenshotBase64 | JPEG 截图(另有 Base64 版本) |
| GET | /mirror/image | MJPEG 实时画面 |
| POST | /api/runScript | 执行一段 JavaScript 并返回结果 |
| GET | /api/run · /api/stop | 运行 / 停止已加载的软件包 |
| GET | /api/apps | 已安装应用列表 |
| GET | /api/getClipboard · /api/setClipboard | 读写剪贴板 |
| GET · POST | /api/getAllConfig · /api/setConfig | 读取或修改配置 |
| 方法 | 路径 | 作用 |
|---|---|---|
| GET | /api/control/click · /doubleClick | 在 x, y 点击或双击 |
| GET | /api/control/swipe | 两点之间滑动 |
| GET | /api/control/startApp · /stopApp · /activateApp | 按 bundle ID 启动、停止、激活 App |
| GET | /api/control/home · /recent · /pressButton | 主屏、多任务、物理按键 |
| POST | /api/control/w3cActions | 标准 W3C Actions,含多指 |
| GET | /api/source | 界面树 XML |
| 方法 | 路径 | 作用 |
|---|---|---|
| GET | /api/hid/click · /doubleClick | 硬件点击或双击 |
| GET | /api/hid/move · /mouseDown · /mouseUp | 移动指针、按下、抬起 |
| GET | /api/hid/swipe | 硬件滑动 |
| POST · GET | /api/hid/sendKey · /input | 组合键与文字 |
| GET | /api/hid/openApp · /closeApp · /openURL | 按名称打开 / 关闭 App,打开链接 |
| GET | /api/hid/deviceInfo · /restartDevice | 硬件信息与重启 |
| 方法 | 路径 | 作用 |
|---|---|---|
| GET | /api/ime/input · /paste · /clearText · /getText · /pressEnter · /pressDel | 输入、粘贴、清空、读取文字,回车与删除 |
| GET | /api/ime/isOk | ketec 键盘是否在屏 |
| 方法 | 路径 | 作用 |
|---|---|---|
| GET · POST | /api/file/list · /upload · /download · /delete | 列出、上传、下载、删除文件 |
| GET · POST | /api/media/saveImageToAlbum · /deleteAllPhotos | 保存到相册或清理相册 |
| GET | /logger/current/lines · /logger/files · /logger/download | 实时日志、日志文件与下载 |
Agent 接口需 Agent 模式,HID 接口需 HID 模式。接口调用会立即执行,在真机上试探时请小心。
完整 HTTP 接口参考 · OpenAPI 3.1(openapi.yaml) · openapi.json
指南:Agent 保活 · 局域网模式 —— 用局域网里一台 Linux 主机看守所有手机,ketec 被杀或手机重启后自动恢复。
管理不在手边的手机。
工作台生成 8 位链接码,在手机「设置 › 远程调试」输入后,手机经 ketec 中继出现在工作台;任一方都可以结束会话。
手机连你自己的 frp 服务器(TCP 或 STCP 映射),可从剪贴板导入配置、启动时自动映射;空闲 5 / 10 / 30 / 60 分钟可自动断开。
填写云控地址后,手机与你的服务器保持 WebSocket 连接,服务器可运行脚本、截图、下发操作;脚本用 cloud.report 上报、cloud.onEvent 监听。
包含全部参数与返回值的完整 API 参考即将上线。