1

假设我想制作一个每 82 毫秒点击一次的宏。我知道第一次睡眠是点击之间的延迟,但是让我们将其设置为 82。但是 Lmclickup 之后的延迟应该是点击之间的延迟。我把它放在 1 上,所以我会有大约 83 毫秒的延迟,但实际上它偶尔会卡顿,就像我把它放在 100 时一样(lmbutton up sleep)它会起火。

#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
4

2 回答 2

0

建议增加睡眠。

1ms 比人类点击和点击实际所需的时间要少得多,您的游戏(或您将这些点击发送到的任何东西)可能不是为了如此快速地处理输入而设计的。

尝试 20 毫秒。

于 2013-12-22T06:19:26.913 回答
0

根据sleep 的 Autohotkey 文档, Sleep 命令的时间不准确:

由于操作系统计时系统的粒度,延迟通常向上舍入到最接近的 10 或 15.6 毫秒的倍数(取决于安装的硬件和驱动程序的类型)。例如,在大多数 Windows 2000/XP 系统上,1 到 10(含)之间的延迟相当于 10 或 15.6。要实现更短的延迟,请参阅示例

如果 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
于 2015-06-30T04:04:21.770 回答