让我们说我想创建一个每82毫秒点击一次的宏。 我知道第一次睡眠是点击之间的延迟,但是让我们将它设置为82。 但是Lmclickup之后的延迟应该是点击之间的延迟。 我把它放在1上,所以我有大约83毫秒的延迟,但实际上它偶尔会像我将它放在100(睡梦中的睡眠)那样结实。它会爆炸。
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn ; Enable warnings to assist with detecting common errors.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
#SingleInstance Force
Process, Priority,,High
SetMouseDelay -1
~insert::Suspend
~RButton & ~LButton::
Loop {
Send {LButton down}
Sleep, 82
Send {LButton up}
if (GetKeyState("LButton", "P") = 0)
break
sleep, 1
}
return
答案 0 :(得分:0)
我建议增加睡眠。
1ms的时间远远少于人类点击和点击所需的时间,您的游戏(或者您发送这些点击的任何内容)可能不会设计为如此快速地处理输入。
尝试20ms。
答案 1 :(得分:0)
根据Autohotkey documentation for sleep,Sleep命令的时间不准确:
由于操作系统的计时系统的粒度,延迟通常四舍五入到最接近的10或15.6毫秒的倍数(取决于安装的硬件和驱动程序的类型)。例如,在大多数Windows 2000 / XP系统上,1到10(含)之间的延迟相当于10或15.6。要缩短延迟时间,请参阅Examples。
如果CPU处于负载状态,实际延迟时间可能会比请求的时间长。这是因为在为脚本提供另一个时间片之前,操作系统会为每个需要的进程提供一段CPU时间(通常为20毫秒)。
这与你的83毫秒大约为100排成一行。如果你按照那个示例链接,你会发现一个例子,旨在使睡眠时间短于基于系统硬件的10或15.6毫秒限制:
SetBatchLines -1 ; Ensures maximum effectiveness of this method.
SleepDuration = 1 ; This can sometimes be finely adjusted (e.g. 2 is different than 3) depending on the value below.
TimePeriod = 3 ; Try 7 or 3. See comment below.
; On a PC whose sleep duration normally rounds up to 15.6 ms, try TimePeriod=7 to allow
; somewhat shorter sleeps, and try TimePeriod=3 or less to allow the shortest possible sleeps.
DllCall("Winmm\timeBeginPeriod", uint, TimePeriod) ; Affects all applications, not just this script's DllCall("Sleep"...), but does not affect SetTimer.
Iterations = 83
StartTime := A_TickCount
Loop %Iterations%
DllCall("Sleep", UInt, SleepDuration) ; Must use DllCall instead of the Sleep command.
DllCall("Winmm\timeEndPeriod", UInt, TimePeriod) ; Should be called to restore system to normal.
MsgBox % "Sleep duration = " . (A_TickCount - StartTime) / Iterations
您可以尝试改编它。我已经开始了:
SetBatchLines -1 ; This makes your script run at the fastest speed possible, thereby increasing the likelihood that you'll get exactly what time you want to get.
SleepDuration = 1 ; This and the line before it should go at the beginning of your script.
DllCall("Winmm\timeBeginPeriod", uint, TimePeriod) ; this must be before the actual sleep DllCall
Iterations = 83
StartTime := A_TickCount ; You can delete this once you know it works
Loop %Iterations%
DllCall("Sleep", UInt, SleepDuration) ; Must use DllCall instead of the Sleep command.
DllCall("Winmm\timeEndPeriod", UInt, TimePeriod) ; Should be called to restore system to normal, after the middle DllCall.
MsgBox % "Sleep duration = " . (A_TickCount - StartTime) / IterationsMsgBox % "Sleep duration = " . (A_TickCount - StartTime) / Iterations ; Also delete this once you know it works