跳到主要内容

步骤引擎

引擎为步骤的操作是由 [[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"