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 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248
| #Requires AutoHotkey v2.0 #SingleInstance Force
if !A_IsAdmin { Run('*RunAs "' A_ScriptFullPath '"') ExitApp() }
DD_KEY_MAP := Map( "escape", 100, "f1", 101, "f2", 102, "f3", 103, "f4", 104, "f5", 105, "f6", 106, "f7", 107, "f8", 108, "f9", 109, "f10", 110, "f11", 111, "f12", 112, "``", 200, "1", 201, "2", 202, "3", 203, "4", 204, "5", 205, "6", 206, "7", 207, "8", 208, "9", 209, "0", 210, "-", 211, "=", 212, "\", 213, "backspace", 214, "tab", 300, "q", 301, "w", 302, "e", 303, "r", 304, "t", 305, "y", 306, "u", 307, "i", 308, "o", 309, "p", 310, "[", 311, "]", 312, "enter", 313, "capslock", 400, "a", 401, "s", 402, "d", 403, "f", 404, "g", 405, "h", 406, "j", 407, "k", 408, "l", 409, ";", 410, "'", 411, "lshift", 500, "z", 501, "x", 502, "c", 503, "v", 504, "b", 505, "n", 506, "m", 507, ",", 508, ".", 509, "/", 510, "lctrl", 600, "lwin", 601, "lalt", 602, "space", 603, "up", 709, "left", 710, "down", 711, "right", 712, "numpad0", 800, "numpad1", 801, "numpad2", 802, "numpad3", 803, "numpad4", 804, "numpad5", 805, "numpad6", 806, "numpad7", 807, "numpad8", 808, "numpad9", 809, "lb", 1, "rb", 4, "mid", 16 )
DLL_PATH := A_ScriptDir "\DD.dll" CONFIG_PATH := A_ScriptDir "\config.ini"
if !FileExist(DLL_PATH) { MsgBox "找不到 DD.dll,请确保它与脚本在同一目录下!" ExitApp() }
hModule := DllCall("LoadLibrary", "Str", DLL_PATH, "Ptr") if !hModule { MsgBox "驱动加载失败,可能是架构不匹配或被杀软拦截。" ExitApp() }
pDD_key := DllCall("GetProcAddress", "Ptr", hModule, "AStr", "DD_key", "Ptr") pDD_btn := DllCall("GetProcAddress", "Ptr", hModule, "AStr", "DD_btn", "Ptr") DllCall(pDD_btn, "Int", 0)
MyGui := Gui(, "AHK连发") MyGui.SetFont("s10", "Microsoft YaHei")
MyGui.Add("Text", "", "间隔 (ms):") EditMs := MyGui.Add("Edit", "vInterval x+10 w80", "200") EditMs.OnEvent("Change", (*) => SaveConfig())
OpFrame := MyGui.Add("GroupBox", "xm w280 h60", "按键管理") BtnRec := MyGui.Add("Button", "xp+10 yp+25 w90", "录制按键") BtnRec.OnEvent("Click", StartRecord) MyGui.Add("Button", "x+5 w50", "+左键").OnEvent("Click", (*) => AddKeyItem("lb")) MyGui.Add("Button", "x+5 w50", "+右键").OnEvent("Click", (*) => AddKeyItem("rb")) MyGui.Add("Button", "x+5 w50", "清空").OnEvent("Click", ClearList)
LV := MyGui.Add("ListView", "xm w280 h150 Checked",["", "按键名称"]) LV.ModifyCol(1, 30) LV.ModifyCol(2, 230) LV.OnEvent("ItemCheck", (*) => SaveConfig())
BtnToggle := MyGui.Add("Button", "xm w280 h40", "启动 ( `` )") BtnToggle.SetFont("bold s11") BtnToggle.OnEvent("Click", ToggleRunning)
MyGui.Add("Text", "xm w280 Center cGray", "F12 彻底退出") MyGui.OnEvent("Close", (*) => ExitApp())
Global IsRunning := false
LoadConfig() MyGui.Show()
StartRecord(*) { BtnRec.Text := "请按键..." ih := InputHook("L1 M T3") ih.KeyOpt("{All}", "E") ih.Start() ih.Wait() keyName := StrLower(ih.EndKey ? ih.EndKey : ih.Input) BtnRec.Text := "录制按键" if (keyName == "") { return }
if DD_KEY_MAP.Has(keyName) { AddKeyItem(keyName) } else { ToolTip "未定义按键: " keyName SetTimer (*) => ToolTip(), -2000 } }
AddKeyItem(name, enabled := true) { Loop LV.GetCount() { if (LV.GetText(A_Index, 2) == name) { return } } LV.Add(enabled ? "Check" : "-Check", "", name) SaveConfig() }
ClearList(*) { Global IsRunning if (LV.GetCount() > 0) { LV.Delete() SaveConfig() } if IsRunning { ToggleRunning() } }
ToggleRunning(*) { Global IsRunning if !IsRunning { hasChecked := false Loop LV.GetCount() { if LV.GetNext(A_Index - 1, "Checked") { hasChecked := true break } } if !hasChecked { ToolTip "请先在列表里【打勾】需要连发的按键" SetTimer (*) => ToolTip(), -2000 return }
IsRunning := true BtnToggle.Text := "停止 ( `` )" BtnToggle.Opt("cRed") ScheduleNext() } else { IsRunning := false BtnToggle.Text := "启动 ( `` )" BtnToggle.Opt("cDefault") SetTimer(WorkLoop, 0) } }
ScheduleNext() { interval := IsNumber(EditMs.Value) ? Integer(EditMs.Value) : 200 jitter := Random(-interval * 0.3, interval * 0.3) delay := Max(10, interval + jitter) SetTimer(WorkLoop, -delay) }
WorkLoop() { Global IsRunning Static inLoop := false if !IsRunning || inLoop { return } inLoop := true row := 0 Loop { row := LV.GetNext(row, "Checked") if !row { break } itemName := LV.GetText(row, 2) if !DD_KEY_MAP.Has(itemName) { continue } code := DD_KEY_MAP[itemName] if (itemName = "lb" || itemName = "rb" || itemName = "mid") { DllCall(pDD_btn, "Int", code) Sleep 10 DllCall(pDD_btn, "Int", code * 2) } else { DllCall(pDD_key, "Int", code, "Int", 1) Sleep 10 DllCall(pDD_key, "Int", code, "Int", 2) } } inLoop := false if IsRunning { ScheduleNext() } }
SaveConfig() { if FileExist(CONFIG_PATH) { FileDelete(CONFIG_PATH) } IniWrite(EditMs.Value, CONFIG_PATH, "Settings", "Interval") keyStr := "" Loop LV.GetCount() { name := LV.GetText(A_Index, 2) state := LV.GetNext(A_Index - 1, "Checked") ? "1" : "0" keyStr .= name ":" state "," } IniWrite(RTrim(keyStr, ","), CONFIG_PATH, "Settings", "Keys") }
LoadConfig() { if !FileExist(CONFIG_PATH) { return } try { iv := IniRead(CONFIG_PATH, "Settings", "Interval", "200") EditMs.Value := iv keysData := IniRead(CONFIG_PATH, "Settings", "Keys", "") if (keysData != "") { for , item in StrSplit(keysData, ",") { if (item = "") { continue } parts := StrSplit(item, ":") if (parts.Length == 2) { AddKeyItem(parts[1], parts[2] == "1") } } } } }
~SC029::ToggleRunning() F12::ExitApp()
|