在按下其他键时发送一个键不会向按下的键发送垃圾邮件

Sending a key while other key is pressed doesn't spam the pressed key

我正在尝试制作一个脚本来在按下另一个按钮时发送一个按钮,比如

$c::
    send {c down}
    sendQ()
    send {c up}
return
sendQ()
{
    if GetKeyState("c","P") {
        sendinput {q}
        sleep 2222
    }
}

它有效,但不是预期的那样。 它以 2222 间隔发送 cq,如 cq..cq..cq 我需要这样的结果:cqcccccccqccccccccqcccc 有没有办法在间隔按 'q' 时发送垃圾邮件 'c'?

这似乎有效:

isCPressed := 0

c::
    Send c
    if (!isCPressed) { ; Avoid resetting the timer
        SetTimer, SendQ, 2222
    }
    isCPressed := 1
Return

c Up::
    SetTimer, SendQ, Delete
    isCPressed := 0
Return

SendQ() {
    SendInput q
}

在大多数情况下,您也可以替换

c::
    Send c

~c::

在 ahk 中模拟多线程可以产生所需的输出。这样,脚本可以在等待指定时间后在各自的 线程 中发送 c 和 q。

#Persistent

~c::
    Send, q ;~ for initial cq
    SetTimer, sendC, 100 ;~ frequency of sending c
    SetTimer, sendQ, 2222 ;~ frequency of sending q
return

;~ Sending c
sendC:
    Send, c
return

;~ Sending q
sendQ:
    Send, q
return