贫民会员
- UID
- 2508523
- 积分
- 404
- 可用积分
- 点
- 威望
- 个
- 水滴
- 滴
- 存在感
- 点
- NB
- 点
- 豆币
- 点
- 帖子
- 主题
- 好友
- 精华
- APP积分
- 点
|
本帖最后由 topology 于 2023-12-1 19:03 编辑
前言
最近尝试破韧玩法时,我发现使用wegame联招的时候左侧总是提示剩余时间,人物还会不停地鬼畜抖动-_-||
正如dalao 指出,想要同时连发多个技能,往往会出现意料之外的按键冲突,导致错误释放某个技能。
因此,我考虑是否可以使用AHK(AutoHotkey)自编一个脚本,在合适的时间自动释放合适的技能,以避免这种鬼畜抖动和错误释放。
成果演示:(gif过大 无法上传,略)

如何编译运行
Step 0: 必要文件与非必要配置
1) 下载dalao的AHK项目 "DNF x AHK (V2)"
链接: https://bbs.colg.cn/thread-8768714-1-1.html
下载后解压即可。
2) 下载并安装AHK v2.0
链接: https://www.autohotkey.com/download/ahk-v2.exe
3) 配置游戏
将游戏画面比例调整为16:10 分辨率设置为1440*900
把CP武器释放的技能1设置为F键,技能2设置为A键
Step 1: 复制代码
将Test.ahk用记事本打开,并将其原来的内容替换成以下代码:
- ; ------------------------------------------------------------------
- ; Initial Setup, Includes
- ; ------------------------------------------------------------------
- #SingleInstance Force ; Ensures only one instance of the script runs at a time
- #MaxThreadsPerHotkey 100 ; Sets maximum threads per hotkey to allow rapid triggers
- #Include <Kbd> ; Includes keyboard handling library
- #Include <UI> ; Includes User Interface related functions
- #Include <Color> ; Includes Color manipulation functions
- ; Elevates the script to run with admin privileges if not already running as admin
- if not A_IsAdmin
- Run '*RunAs "' A_ScriptFullPath '"'
- ; ------------------------------------------------------------------
- ; Configuration, and Global Variables
- ; ------------------------------------------------------------------
- SendMode "Event" ; Sets the send mode to 'Event' for synthetic keyboard/mouse events
- SetKeyDelay(22, -1) ; Sets the delay between key presses and releases, default is 22 ms
- ; Monitor work area calculation for tooltip positioning
- MonitorGetWorkArea(, , , &MonitorWorkAreaRight, &MonitorWorkAreaBottom)
- tooltip_x := Floor(MonitorWorkAreaRight * 0.95) ; X-coordinate for tooltip
- tooltip_y := Floor(MonitorWorkAreaBottom * 0.95) ; Y-coordinate for tooltip
- ; Configuration for interval (mili)seconds
- intervalSeconds := 100 ; Check whether a skill is avaliable for every 100ms
- activated := False ; State variable to track activation status
- ; Timers for cooldown monitoring, with a suggested additional delay
- timers := [] ; Array to hold timer objects
- timers.Push(SkillTrigger(737, 875, 606, 875, 0.7, 0.7)) ; Adding a skilltrigger with specific parameters
- ; ------------------------------------------------------------------
- ; SkillTrigger Class Definition
- ; ------------------------------------------------------------------
- class SkillTrigger {
- ; Constructor for the SkillTrigger class
- ; Initializes the timer with given screen coordinates for 2 different skills, gray threshold
- __New(screenX1, screenY1, screenX2, screenY2, grayThreshold1, grayThreshold2) {
- global intervalSeconds
- this.screenX1 := screenX1
- this.screenY1 := screenY1
- this.screenX2 := screenX2
- this.screenY2 := screenY2
- this.grayThreshold1 := grayThreshold1
- this.grayThreshold2 := grayThreshold2
- this.intervalSeconds := intervalSeconds
- this.timer := ObjBindMethod(this, "Tick")
- }
- ; Starts the timer with the specified interval
- Start() {
- timer := this.timer
- SetTimer(timer, this.intervalSeconds)
- this.Tick()
- }
- ; Stops the timer
- Stop() {
- timer := this.timer
- SetTimer(timer, 0)
- }
- ; The function that gets called on each timer tick
- Tick() {
- global tooltip_x
- global tooltip_y
- ; Check if the current window is active
- if (WinActive("ahk_exe DNF.exe") ) {
-
- ; Color detection at specified screen coordinates
- gray1 := Color_RGB2Gray(PixelGetColor(this.screenX1, this.screenY1))
- gray2 := Color_RGB2Gray(PixelGetColor(this.screenX2, this.screenY2))
- ; Perform skills based on gray thresholds
- if (gray1 > this.grayThreshold1) {
- ; Skill1 Ready
- ToolTip "Skill1 Ready", tooltip_x, tooltip_y, 20
- ; Perform Skill1
- Sleep 2
- Kbd_RobustSend("CapsLock")
- Sleep 10
- Kbd_RobustSend("F")
- Sleep 10
- Kbd_RobustSend("CapsLock")
- Sleep 2
- } else if (gray2 > this.grayThreshold2) {
- ; Skill2 Ready but Skill1 on CD
- ToolTip "Skill2 Ready", tooltip_x, tooltip_y, 20
- ; Perform Skill2
- Sleep 2
- Kbd_RobustSend("CapsLock")
- Sleep 10
- Kbd_RobustSend("A")
- Sleep 10
- Kbd_RobustSend("CapsLock")
- Sleep 2
- } else {
- ; Both on cooldown
- ToolTip "Both on CD", tooltip_x, tooltip_y, 20
- }
- }
- }
- }
- ; ------------------------------------------------------------------
- ; Hotkeys Definitions
- ; ------------------------------------------------------------------
- #HotIf WinActive("ahk_exe DNF.exe") ; Conditional hotkeys active only when DNF is focused
- $-:: ; Hotkey '-'
- {
- ; Toggles the activation state and starts/stops timers
- global activated
- activated := !activated
- if (activated) {
- ; Start all timers
- for _, timer in timers {
- timer.Start()
- }
- }
- else {
- ; Stop all timers
- for _, timer in timers {
- timer.Stop()
- }
- ToolTip , , , 20 ; Clears the tooltip
- }
- }
- #HotIf ; End of conditional hotkeys
复制代码
Step 2:编译运行
打开AutoHotkey Dash,点击Compile(从上到下第二个按钮)进行自动安装。安装好后再点一次Compile 在Browse找到test.ahk,按下面的Convert编译得到.exe文件并 以管理员权限运行。

在游戏里按"-"即可开启/关闭连发。
进入修炼场愉快的测试吧~
代码解释 -- 全局变量
每次按键所需时间为22ms,可根据电脑配置调整
每次检查技能使用与否的间隔为100ms,可根据电脑配置修改。
注意:因为每次CP武器释放技能需要按键3次,因此修改时一定保证100 > 3*22以增加容错
- timers.Push(SkillTrigger(737, 875, 606, 875, 0.7, 0.7)) ; Adding a timer with specific parameters
复制代码
(737, 875) 对应的是dnf游戏界面技能F的坐标
(606, 875) 对应的是dnf游戏界面技能A的坐标
两个0.7,分别是F技能和A技能对应坐标的灰度值的阈值 ,之后有空再解释
这些都可以调整。如果您希望使用其它分辨率以及技能按键,可以自行调整坐标值以及阈值。
代码解释 -- SkillTrigger
- ; Perform skills based on gray thresholds
- if (gray1 > this.grayThreshold1) {
- ; Skill1 Ready
- ToolTip "Skill1 Ready", tooltip_x, tooltip_y, 20
- ; Perform Skill1
- Sleep 2
- Kbd_RobustSend("CapsLock")
- Sleep 10
- Kbd_RobustSend("F")
- Sleep 10
- Kbd_RobustSend("CapsLock")
- Sleep 2
- }
复制代码
如果技能1可以释放,则 优先释放技能1
技能1的快捷键是F ,可以按需更改
Sleep 10就是两次按键的间隔。让程序更稳定,也可自行更改
- ; Perform skills based on gray thresholds
- else if (gray2 > this.grayThreshold2) {
- ; Skill2 Ready but Skill1 on CD
- ToolTip "Skill2 Ready", tooltip_x, tooltip_y, 20
- ; Perform Skill2
- Sleep 2
- Kbd_RobustSend("CapsLock")
- Sleep 10
- Kbd_RobustSend("A")
- Sleep 10
- Kbd_RobustSend("CapsLock")
- Sleep 2
- }
复制代码
当技能1无法释放时,我们考虑释放技能2
技能2的快捷键是A,可以按需更改
代码解释 -- 连发启动键
$-::的意思就是按减号启动
你可以换成别的键。比如F1, F2, ... 或者组合键,比如ctrl+A就是$^a:: ctrl对应^ A对应a
Remark
0) AHK连发并非系统自带。请自行斟酌是否使用。
1) 号太小,又没朋友,没有办法实战测试。本文仅指出理论的可行性,不保证实战效果。
2) 如果只是想连发一个技能,可以自行修改代码
3) 可以简单修改,使其适用于多个技能(按照 优先级顺序释放可释放的技能)
希望这个脚本能帮助到大家,祝大家生活愉快!
( 大部分内容为chatgpt辅助创作)
|
|