无法使用 AutoHotkey 按住某个键

Can't hold down a key with AutoHotkey

我有一个简单的脚本,但似乎没有按预期运行:

^j::
  Send, {Down down}
  Sleep, 10000
  Send, {Down up}
Return

我希望它按住向下箭头键 10 秒,然后松开。相反,它按一次向下键,然后中断脚本直到重新加载。我做错了什么?

根据文档,这应该有效:

To hold down or release a key: Enclose in braces the name of the key followed by the word Down or Up. For example:

Send {b down}{b up}
Send {TAB down}{TAB up}
Send {Up down}  ; Press down the up-arrow key.
Sleep 1000  ; Keep it down for one second.
Send {Up up}  ; Release the up-arrow key.

关于按住键的文档:https://www.autohotkey.com/docs/commands/Send.htm

Send documentation 说:

When a key is held down via the method above, it does not begin auto-repeating like it would if you were physically holding it down (this is because auto-repeat is a driver/hardware feature).

使用SetKeyDelay并指定重复次数:

SetKeyDelay, 30
Send {Down 333}

333 大约是 10000/30

或者您可以在 loop 中执行此操作并检查其他密钥以停止发送 Down 密钥。

找到了一个很好的解决方法,试试这样的脚本(根据自己的喜好调整 Mynumber 变量和 Sleep)

a::
Mynumber = 10
While Mynumber > 0
{
Send {Down DOWN}
Sleep 10
Send {Down UP}
Mynumber--
}