本帖最后由 turato 于 2024-9-16 15:42 编辑
需求分析
通过键盘控制角色原地攻击,攻击达到一定的次数时,需要移动一下,否则客户端会限制角色的攻击行为,禁止玩家继续攻击。上述流程需要通过快捷键触发和停止。
执行流程解释
- 脚本每次触发 A 键攻击,并保持 1 秒,然后暂停 1 秒,循环此过程。
- 攻击计数达到 80 次后,会执行一次特定的操作,包括按住 X 键保持 5 秒(使用金钱炸弹技能),以及使用左右方向键进行短暂的按键操作。
- 这个流程循环执行,直到满足提前退出条件。
伪代码
- 脚本由 {动作} 触发:该脚本的执行将由某个特定的“动作”触发,可以是按键、事件或系统信号等。
- 脚本开始:脚本初始化后立即开始运行。
- 初始化变量:一个名为
attackCount 的变量被创建并初始化为 0 ,这个变量用于记录攻击次数。
- 循环9999次:脚本将在一个大循环中运行,最多执行 9999 次循环。
- 检查{动作}:每次循环开始时,都会检查某个动作是否触发,如果触发则退出循环,不再执行下面的步骤。
- 增加攻击计数:每次循环执行,攻击计数
attackCount 增加 1。
- 显示攻击计数:当前的攻击计数值将被显示出来,可能是在某个界面或日志中输出。
- 按下 A 键:脚本模拟按住 A 键,保持此动作。
- 暂停 1 秒:按下 A 键后,脚本会暂停 1 秒钟。
- 释放 A 键:暂停后,A 键将被释放。
- 再次暂停 1 秒:在释放 A 键后,脚本再等待 1 秒钟。
- 检查攻击计数:当攻击计数达到或超过 80 时,进入一个特定的分支,执行额外的操作。
- 按下 X 键:脚本模拟按住 X 键,保持该动作。
- 暂停 5 秒:按下 X 键后,脚本会等待 5 秒钟。
- 释放 X 键:5 秒钟后,X 键将被释放。
- 暂停 1 秒:释放 X 键后,暂停 1 秒钟。
- 按下左方向键:按下左方向键并保持。
- 暂停 0.1 秒:按下左方向键后,等待 0.1 秒。
- 释放左方向键:等待结束后,左方向键被释放。
- 暂停 0.2 秒:接着暂停 0.2 秒。
- 按下右方向键:按下右方向键并保持。
- 暂停 0.1 秒:按下右方向键后,等待 0.1 秒。
- 释放右方向键:0.1 秒后,右方向键被释放。
结果展示:文末的图2024091601.png
参考文档
[1] 官方使用手册:快速入门 https://wiki.keyboardmaestro.com/manual/Quick_Start
[2] 官方使用手册:变量 https://wiki.keyboardmaestro.com/manual/Variables
附录
a.软件图形代码
见文末的图:2024091601.png
b.导出脚本
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<array>
<dict>
<key>Activate</key>
<string>Normal</string>
<key>CreationDate</key>
<real>748070114.26186502</real>
<key>Macros</key>
<array>
<dict>
<key>Actions</key>
<array>
<dict>
<key>ActionUID</key>
<integer>1617</integer>
<key>MacroActionType</key>
<string>SetVariableToText</string>
<key>Text</key>
<string>0</string>
<key>Variable</key>
<string>attackCount</string>
</dict>
<dict>
<key>ActionUID</key>
<integer>1210</integer>
<key>Actions</key>
<array>
<dict>
<key>ActionUID</key>
<integer>1601</integer>
<key>Conditions</key>
<dict>
<key>ConditionList</key>
<array>
<dict>
<key>ConditionType</key>
<string>Key</string>
<key>KeyCode</key>
<integer>53</integer>
<key>KeyConditionType</key>
<string>Down</string>
</dict>
</array>
<key>ConditionListMatch</key>
<string>Any</string>
</dict>
<key>ElseActions</key>
<array>
<dict>
<key>ActionUID</key>
<integer>1607</integer>
<key>MacroActionType</key>
<string>SetVariableToText</string>
<key>Text</key>
<string>%Calculate%attackCount + 1%</string>
<key>Variable</key>
<string>attackCount</string>
</dict>
<dict>
<key>Action</key>
<string>DisplayLarge</string>
<key>ActionUID</key>
<integer>1616</integer>
<key>MacroActionType</key>
<string>InsertText</string>
<key>Text</key>
<string>攻击次数:【%attackCount%】</string>
</dict>
<dict>
<key>ActionUID</key>
<integer>1602</integer>
<key>KeyCode</key>
<integer>0</integer>
<key>MacroActionType</key>
<string>SimulateKeystroke</string>
<key>Modifiers</key>
<integer>0</integer>
<key>Press</key>
<string>PressAndHold</string>
<key>ReleaseAll</key>
<false/>
<key>TargetApplication</key>
<dict/>
<key>TargetingType</key>
<string>Front</string>
</dict>
<dict>
<key>ActionUID</key>
<integer>817</integer>
<key>MacroActionType</key>
<string>Pause</string>
<key>Time</key>
<string>1</string>
<key>TimeOutAbortsMacro</key>
<true/>
</dict>
<dict>
<key>ActionUID</key>
<integer>1604</integer>
<key>KeyCode</key>
<integer>0</integer>
<key>MacroActionType</key>
<string>SimulateKeystroke</string>
<key>Modifiers</key>
<integer>0</integer>
<key>Press</key>
<string>Release</string>
<key>ReleaseAll</key>
<false/>
<key>TargetApplication</key>
<dict/>
<key>TargetingType</key>
<string>Front</string>
</dict>
<dict>
<key>ActionUID</key>
<integer>1608</integer>
<key>Conditions</key>
<dict>
<key>ConditionList</key>
<array>
<dict>
<key>ConditionType</key>
<string>Text</string>
<key>Text</key>
<string>%Variable%attackCount%</string>
<key>TextConditionType</key>
<string>GreaterThanOrEqual</string>
<key>TextValue</key>
<string>80</string>
</dict>
</array>
<key>ConditionListMatch</key>
<string>Any</string>
</dict>
<key>ElseActions</key>
<array/>
<key>MacroActionType</key>
<string>IfThenElse</string>
<key>ThenActions</key>
<array>
<dict>
<key>ActionUID</key>
<integer>1611</integer>
<key>MacroActionType</key>
<string>Pause</string>
<key>Time</key>
<string>1</string>
<key>TimeOutAbortsMacro</key>
<true/>
</dict>
<dict>
<key>ActionUID</key>
<integer>1609</integer>
<key>MacroActionType</key>
<string>SetVariableToText</string>
<key>Text</key>
<string>%Variable%attackCount%=0</string>
<key>Variable</key>
<string>attackCount</string>
</dict>
<dict>
<key>ActionUID</key>
<integer>1621</integer>
<key>KeyCode</key>
<integer>7</integer>
<key>MacroActionType</key>
<string>SimulateKeystroke</string>
<key>Modifiers</key>
<integer>0</integer>
<key>Press</key>
<string>PressAndHold</string>
<key>ReleaseAll</key>
<false/>
<key>TargetApplication</key>
<dict/>
<key>TargetingType</key>
<string>Front</string>
</dict>
<dict>
<key>ActionUID</key>
<integer>1622</integer>
<key>MacroActionType</key>
<string>Pause</string>
<key>Time</key>
<string>5</string>
<key>TimeOutAbortsMacro</key>
<true/>
</dict>
<dict>
<key>ActionUID</key>
<integer>1623</integer>
<key>KeyCode</key>
<integer>7</integer>
<key>MacroActionType</key>
<string>SimulateKeystroke</string>
<key>Modifiers</key>
<integer>0</integer>
<key>Press</key>
<string>Release</string>
<key>ReleaseAll</key>
<false/>
<key>TargetApplication</key>
<dict/>
<key>TargetingType</key>
<string>Front</string>
</dict>
<dict>
<key>ActionUID</key>
<integer>1624</integer>
<key>MacroActionType</key>
<string>Pause</string>
<key>Time</key>
<string>1</string>
<key>TimeOutAbortsMacro</key>
<true/>
</dict>
<dict>
<key>ActionUID</key>
<integer>1610</integer>
<key>KeyCode</key>
<integer>123</integer>
<key>MacroActionType</key>
<string>SimulateKeystroke</string>
<key>Modifiers</key>
<integer>196608</integer>
<key>Press</key>
<string>PressAndHold</string>
<key>ReleaseAll</key>
<false/>
<key>TargetApplication</key>
<dict/>
<key>TargetingType</key>
<string>Front</string>
</dict>
<dict>
<key>ActionUID</key>
<integer>1620</integer>
<key>MacroActionType</key>
<string>Pause</string>
<key>Time</key>
<string>0.1</string>
<key>TimeOutAbortsMacro</key>
<true/>
</dict>
<dict>
<key>ActionUID</key>
<integer>1612</integer>
<key>KeyCode</key>
<integer>123</integer>
<key>MacroActionType</key>
<string>SimulateKeystroke</string>
<key>Modifiers</key>
<integer>196608</integer>
<key>Press</key>
<string>Release</string>
<key>ReleaseAll</key>
<false/>
<key>TargetApplication</key>
<dict/>
<key>TargetingType</key>
<string>Front</string>
</dict>
<dict>
<key>ActionUID</key>
<integer>1625</integer>
<key>MacroActionType</key>
<string>Pause</string>
<key>Time</key>
<string>0.2</string>
<key>TimeOutAbortsMacro</key>
<true/>
</dict>
<dict>
<key>ActionUID</key>
<integer>1613</integer>
<key>KeyCode</key>
<integer>124</integer>
<key>MacroActionType</key>
<string>SimulateKeystroke</string>
<key>Modifiers</key>
<integer>196608</integer>
<key>Press</key>
<string>PressAndHold</string>
<key>ReleaseAll</key>
<false/>
<key>TargetApplication</key>
<dict/>
<key>TargetingType</key>
<string>Front</string>
</dict>
<dict>
<key>ActionUID</key>
<integer>1614</integer>
<key>MacroActionType</key>
<string>Pause</string>
<key>Time</key>
<string>0.1</string>
<key>TimeOutAbortsMacro</key>
<true/>
</dict>
<dict>
<key>ActionUID</key>
<integer>1618</integer>
<key>KeyCode</key>
<integer>124</integer>
<key>MacroActionType</key>
<string>SimulateKeystroke</string>
<key>Modifiers</key>
<integer>196608</integer>
<key>Press</key>
<string>Release</string>
<key>ReleaseAll</key>
<false/>
<key>TargetApplication</key>
<dict/>
<key>TargetingType</key>
<string>Front</string>
</dict>
</array>
<key>TimeOutAbortsMacro</key>
<true/>
</dict>
</array>
<key>MacroActionType</key>
<string>IfThenElse</string>
<key>ThenActions</key>
<array>
<dict>
<key>Action</key>
<string>BreakFromLoop</string>
<key>ActionUID</key>
<integer>1603</integer>
<key>MacroActionType</key>
<string>Cancel</string>
</dict>
</array>
<key>TimeOutAbortsMacro</key>
<true/>
</dict>
</array>
<key>CountExpression</key>
<string>9999</string>
<key>MacroActionType</key>
<string>Repeat</string>
<key>TimeOutAbortsMacro</key>
<true/>
</dict>
</array>
<key>CreationDate</key>
<real>748070226.17550302</real>
<key>ModificationDate</key>
<real>748078123.40468705</real>
<key>Name</key>
<string>AttackAndJump</string>
<key>Triggers</key>
<array>
<dict>
<key>FireType</key>
<string>Pressed</string>
<key>KeyCode</key>
<integer>0</integer>
<key>MacroTriggerType</key>
<string>HotKey</string>
<key>Modifiers</key>
<integer>512</integer>
</dict>
</array>
<key>UID</key>
<string>E1980A6E-1EDD-438F-AA3E-13BA68813CC3</string>
</dict>
</array>
<key>Name</key>
<string>Global Macro Group</string>
<key>ToggleMacroUID</key>
<string>4A34E079-8BF0-42D7-BE2E-D87AD14ECE28</string>
<key>UID</key>
<string>804D32AF-0B39-439F-8EF3-493A833B14CA</string>
</dict>
</array>
</plist>
|