步骤引擎
引擎为步骤的操作是由 [[steps]] 表组成的 TOML 列表,而不是文本。它调用相同的内置函数,遵循相同的值和真值规则。不同之处如下:
-
每个步骤都有一个唯一的整数
id和一个op:call(fn、args)、set(local加上一个value,或一个call = { fn, args })、if、goto、end、repeat/end_repeat、exit_repeat、else/end_if。 -
if要么按 id 跳转(then_goto/else_goto),要么在不带这两项时开启一个由end_if关闭的块。 -
repeat只接受times、while或until中的一个。 -
条件只能是以下之一:内置函数调用(
fn/args)、value(按真值判断),或带left/right的compare("=="、"!="、"<"、"<="、">"、">=")。添加not = true可将其取反。 -
以
$开头的字符串参数会读取变量("$target")。其他所有内容都是字面量,其类型即其 TOML 类型,并且该类型必须与参数完全匹配,与脚本中相同。 -
{ const = "VirtualKey.MediaPlayPause" }是命名常量,与脚本中相同,在步骤编译时会被替换为对应的数字。拼写相同的普通字符串(如"VirtualKey.F5")仍是文本。 -
{ fn = "MouseGetCursorX" }这样只含fn的表,表示一个不带参数的内置函数的结果。凡是可以放值的地方都可以使用它:- 调用的
args:args = [{ fn = "WindowGetActive" }] - 条件的
left/right:left = { fn = "ContextGetPointCount" }, right = 20 - 条件的
value:value = { fn = "EngineIsSafeMode" } repeat的times:times = { fn = "FolderWatchGetCount" }set步骤的value:value = { fn = "UtilityGetTickCount" }
它不接受
args。对于需要参数的内置函数,请先用set将其结果存入变量,再传递"$name"。 - 调用的
-
没有运算符表达式。算术运算和字符串构造需要使用脚本操作。
[[steps]]
id = 1
op = "set"
local = "target"
call = { fn = "WindowGetActive", args = [] }
[[steps]]
id = 2
op = "if"
condition = { fn = "WindowContainsTitle", args = ["$target", "Notepad"] }
[[steps]]
id = 3
op = "call"
fn = "WindowMaximize"
args = ["$target"]
[[steps]]
id = 4
op = "end_if"