我正在编写这个脚本。
#Persistent
Random , timerval , 7800 , 8460
SetTimer, PressTheKey, %timerval%
Return
PressTheKey:
Send, {d}
Return
这是每8秒钟按下“d”的基本间隔。有用。问题是,如果按下另一个键,如鼠标右键,则不会触发“d”,我将不得不等待剩余的持续时间。
我需要让脚本等待鼠标右键被按下,或者每隔10ms左右运行一次检查以检查是否按下了鼠标右键,如果不是,则可以发送,{d} 。
所以,我正在考虑使用GetKeyState(),KeyWait或While循环来克服它。
#Persistent
Random , timerval , 7800 , 8460
SetTimer, PressTheKey, %timerval%
Return
GetKeyState, state, RButton
if state = D
KeyWait, RButton
PressTheKey:
Send, {d}
Return
我试过这个和其他人,但我无法将其付诸实践,不是编码专家,但我试图学习。
有人可以帮我弄这个吗?
编辑:按住键一段时间修复此问题。
#Persistent
Random , timerval , 7800 , 8460
Random , timerval2 , 180 , 250
SetTimer, PressTheKey, %timerval%
Return
PressTheKey:
Send, {t down}
Sleep, %timerval2%
Send, {t up}
Return
F1::
Pause
Suspend
return
GetKeyState在你的AHK示例中不起作用的原因是,它不是insite循环。
(第一次回归会阻止这种情况)
你可以用这个例子解决这个问题:
Example.ahk
;#notrayicon
#SingleInstance force
#Persistent
#MaxThreadsPerHotkey 10
Random , timerval , 7800 , 8460
SetTimer, PressTheKey, %timerval%
Return
PressTheKey:
GetKeyState, state, RButton
if state = U
{
KeyWait, RButton
send {esc}
;ControlSend, , {esc}, ahk_exe NOTEPAD.EXE ;you can use this codeline for specific Application.
}
Send, {d}
;ControlSend, , {d}, ahk_exe NOTEPAD.EXE ;you can use this codeline for specific Application.
Return
f1::exitapp
注意 - 如果你点击鼠标右键,那么光标将消失在弹出菜单中,你只能使用代码行qazxsw poi解决这个问题,或者写一个代码行将光标聚焦到那个窗口!
你几乎拥有它。
send {esc}
我能看到的唯一问题是,如果#Persistent
Random , timerval , 7800 , 8460
SetTimer, PressTheKey, %timerval%
Return
PressTheKey:
KeyWait, RButton, U
Send, {d}
Return
被按下的时间超过计时器的2倍。在这种情况下,我相信它只会触发一个额外的RButton
而不是它应该的总量。无论如何,根据你所说的,这似乎是一种不太可能的情况。