1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143
| ; =================================================================== ; 自动战斗宏脚本(适用于 AHK v1) ; 功能:自动释放技能、左右横移、自动攻击,并支持暂停/恢复 ; 适用窗口:ahk_class Diablo IV Main Window Class ; ===================================================================
#IfWinActive, ahk_class Diablo IV Main Window Class
; === 配置区(可根据角色/技能调整)=== SetKeyDelay, 20 ; 按键发送延迟(毫秒) SetMouseDelay, 20 ; 鼠标点击延迟(毫秒)
; === 全局状态变量 === vEnable := 0 ; 宏总开关:0=关闭,1=开启 vWinActive := 0 ; 是否游戏主页面激活 direction := 0 ; 横移方向:0=向右(按 d),1=向左(按 a)
; ------------------------------------------------------------------- ; F2:启用 ; ------------------------------------------------------------------- $F2:: if (vEnable) return ; 已经启用,忽略按键 vEnable := 1 ; 切换宏启用状态 Gosub, EnsureGameIsActive ; 先检查游戏窗口是否激活 if (vEnable) { Gosub, StartCombatLoop ; 启动所有自动行为 } return
; ------------------------------------------------------------------- ; F3:停止 ; ------------------------------------------------------------------- $F3:: vEnable := 0 Gosub, StopCombatLoop ; 停止所有定时器并释放按键 return
; ------------------------------------------------------------------- ; 暂停/恢复快捷键 ; 仅在宏已启用时生效,用于临时中断循环(如拾取物品、对话) ; -------------------------------------------------------------------
~*Tab:: ~A:: ~C:: vEnable := 0 Gosub, StopCombatLoop ; 停止所有定时器并释放按键 return
; ------------------------------------------------------------------- ; 技能与操作子程序(每个对应一个游戏内动作) ; -------------------------------------------------------------------
; 技能 1: CastSkill1: if(vEnable && vWinActive){ Send {1} }
return
; 技能 4: CastSkill4: if(vEnable && vWinActive){ Send {4} } return
; 自动左键攻击(主攻,高频触发) CastSkillLeft: if(vEnable && vWinActive){ Send {Shift down} Click Send {Shift up} } Gosub, EnsureGameIsActive ; 每次点击后检查窗口是否仍激活 return
; 右键技能(通常为闪避、互动或次要技能) CastSkillRight: if(vEnable && vWinActive){ Click Right } return
; ------------------------------------------------------------------- ; 子程序:左右横移 ; ------------------------------------------------------------------- ActionMove: if (vEnable && vWinActive) { if (direction = 0) { ; 当前向右 → 切换为向左 Send {a down} Send {d up} direction := 1 } else { ; 当前向左 → 切换为向右 Send {a up} Send {d down} direction := 0 } } return
; ------------------------------------------------------------------- ; 子程序:启动所有自动战斗行为(设置定时器) ; ------------------------------------------------------------------- StartCombatLoop: SetTimer, CastSkill1, 5000 SetTimer, CastSkill4, 5000 SetTimer, CastSkillLeft, 500 SetTimer, CastSkillRight, 5000 return
; ------------------------------------------------------------------- ; 子程序:停止所有自动行为(关闭定时器 + 释放按键) ; ------------------------------------------------------------------- StopCombatLoop: SetTimer, CastSkill1, Off SetTimer, CastSkill4, Off SetTimer, CastSkillLeft, Off SetTimer, CastSkillRight, Off ; 显式释放移动键,防止角色卡住 Send {a up} Send {d up} return
; ------------------------------------------------------------------- ; 子程序:确保当前激活窗口是 Diablo IV ; 若不是,则暂停宏,防止误操作其他程序 ; ------------------------------------------------------------------- EnsureGameIsActive: IfWinActive, ahk_class Diablo IV Main Window Class { vWinActive := 1 }else{ vWinActive := 0 } return
; 结束条件编译指令 #IfWinActive
|