什么时候应该在 Autohotkey 中使用 `Sent` 而不是 `SentInput`?

When should `Sent` be used over `SentInput` in Autohotkey?

Autohotkey documentation 写道:

SendInput is generally the preferred method to send keystrokes and mouse clicks because of its superior speed and reliability. Under most conditions, SendInput is nearly instantaneous, even when sending long strings. Since SendInput is so fast, it is also more reliable because there is less opportunity for some other window to pop up unexpectedly and intercept the keystrokes. Reliability is further improved by the fact that anything the user types during a SendInput is postponed until afterward.

如果通常首选 SendInput,那么在 ahk 中 sent 更好的用例是什么? Sent 什么时候赢得 SentSentInput 的决定?

我一般用SendInput,因为我喜欢近乎瞬时的输入。但是我遇到了一些实际限制:

  • 有些应用程序如游戏不喜欢这么快的击键,因为可能有禁止botting的规则。

  • 某些应用程序无法处理如此快速的击键接收,它们只会陷入困境。

  • 我有一个应用程序允许按 Tab 键在字段之间移动光标。

    • 当使用 Tab 键进入一个字段时,应用程序需要时间来确认光标的到达,然后才能接受任何输入。 SendInput 命令只是为此禁食,并经常导致混合结果
    • 多次按 Tab 键也有问题,应用程序经常会漏掉一些 Tab 键,光标会停在意外的字段上。
  • SendInput 速度太快,无法重播某些内容以进行调试。例如,当我想观察如何将文本插入到非常复杂的表单中时。

  • 理论上,使用 Send,您可以插入一团文本,并在键入字符时随机按住 shift 键以增加熵。可以说我想不出为什么这会有用。

只有在当前设置有问题时才应考虑在 SendPlaySendInput 之间切换。如果您在激活长宏时键入,SendInput 会导致问题。您的命令可能会与宏混合使用,从而导致意外行为。教程说 SendPlay 是 "not supported in older games",但我从来没有遇到过这个问题。有人可能会评论 "you haven't used AHK enough"。也许会。

此外,在从 SendPlay 切换到 SendInput 之前,您应该尝试将宏一分为二。例如,"save control group, do stuff, recall control group" 在 Starcraft2 中失败。将其拆分为 Send "save control group, do stuff"; Sleep 10; Send "recall control group"; 有效。