gpt4 book ai didi

autohotkey - 如何在 AutoHotkey 中的 SendInput 命令之间添加延迟?

转载 作者:行者123 更新时间:2023-12-02 01:08:39 27 4
gpt4 key购买 nike

我有一个使用 SendInput 的 AutoHotkey 脚本发送MouseClick命令太快,我的程序无法处理。我的脚本将发送 MouseClick 以聚焦输入字段,然后在该字段完成聚焦之前开始输入。

我试过使用 SetKeyDelay让我的脚本运行得慢一点,但这不适用于 SendInput

Note: SetKeyDelay is not obeyed by SendInput; there is no delay between keystrokes in that mode. This same is true for Send when SendMode Input is in effect.
Documentation for SetKeyDelay

我目前的解决方法是在每次输入后使用 sleep 命令,但这不太理想。

SendMode Input
F1::
MouseClick, left, 61, 50 ; select title field
sleep 100 ; artificial delay to prevent misfocused inputs

SendInput %user_input%{Enter} ; enter job title
sleep 100 ; artificial delay

MouseClick, left, 67, 408 ; select job
sleep 100 ; artificial delay
Return

理想情况下,我想要一个更优雅的解决方案,用于在每个 SendInput 命令之间添加延迟,而无需每次都手动使用 sleep 命令。

如何在不重复使用 sleep 的情况下在 AutoHotkey 中的 SendInput 命令之间添加延迟?

最佳答案

尝试使用 SendPlay而不是 SendInput .

这会在每次点击后延迟 100 毫秒发送文本和鼠标点击

user_input := "hello world"
SetMouseDelay 100, Play
SendPlay {Click 61,50}%user_input%{enter}{click 67,408}

来自documentation for SendPlay .

SendPlay

Note: SendPlay may have no effect at all if UAC is enabled, even if the script is running as an administrator. For more information, refer to the FAQ.

Like SendInput, SendPlay's keystrokes do not get interspersed with keystrokes typed by the user. Thus, if the user happens to type something during a SendPlay, those keystrokes are postponed until afterward.

Although SendPlay is considerably slower than SendInput, it is usually faster than the traditional SendEvent mode (even when KeyDelay is -1).

SendPlay does not use the standard settings of SetKeyDelay and SetMouseDelay. Instead, it defaults to no delay at all, which can be changed as shown in the following examples:

SetKeyDelay, 0, 10, Play  ; Note that both 0 and -1 are the same in SendPlay mode.
SetMouseDelay, 10, Play

关于autohotkey - 如何在 AutoHotkey 中的 SendInput 命令之间添加延迟?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46326144/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com