跳到主要内容

全局快捷方式

除了类方法之外,Android Macro 还提供了一些 Lua 快捷方式。它们是常见调用的更旧、更短的名称,为了兼容性而保留。

屏幕快捷方式​

快捷方式等价写法
click(x, y)Screen:click(x, y)
click(template)Screen:click(template)
find(template)Screen:find(template)
exist(template)Screen:exist(template)
existClick(template)Screen:existClick(template)
swipe(points, params)Screen:swipe(points, params)
getScreenSize()带有 width() 和 height() 函数的表

工具快捷方式​

快捷方式等价写法
toast(text, ms)Utils:toast(text, ms)
alert(text, title)Utils:alert(text, title)
sleep(ms)Utils:sleep(ms)
wait(ms)Utils:sleep(ms)
Point(x, y)point:newInstance(x, y)
Color(hex)color:newInstance(hex)

示例​

local size = getScreenSize()
toast("Screen: " .. size.width() .. " x " .. size.height())

if exist("home.png") then
click("home.png")
end

说明​

  • 旧的带两个参数的分数形式 click(template, score)、exist(template, score) 和 existClick(template, score) 会调用 Screen:setMatchingSimilarity,而该方法不属于 当前 SDK。请改用 FinderParams():setScore(score)。
  • wait(template, timeout) 不是 Screen:wait() 的快捷方式;该名称用于睡眠形式。等待图像或文本时,请显式使用 Screen:wait(template, timeout)。