发送处于循环状态时,热键不起作用 [英] hotkeys does not work when send is in loop
问题描述
假设此代码:
Loop
{
if enabled
Send, /
}
m::
enabled := !enabled
Return
例如,我想切换将/
发送到记事本.但是,如果我通过在键盘上按 M 来运行此代码,则再次按M键不会禁用发送.
由于Ive尝试使用不禁用m键的msgbox
,因此看起来像循环中的send
命令会导致此问题.
如何使此代码正常工作? (SendInput和Play也不起作用)
I want to toggle sending /
to a Notepad for example. But if I run this code by pressing M on keyboard, then pressing the M key again does not disable sending.
Looks like the send
command in the Loop cause this issue since Ive tried using msgbox
which does not disable the m key.
How can I make this code to work? (SendInput and Play does not work too)
推荐答案
这是因为您的循环阻止了任何其他执行.除非该循环是脚本中唯一的内容,否则您通常希望避免使用循环,而使用计时器 a>代替.
It's because your loop is blocking any other execution. Unless that loop is the only thing in your script, you generally want to avoid using loops and use timers instead.
计时器不会阻止进一步的执行,但其行为更像是自己的线程.这是一个使用计时器的示例:
Timers don't block further execution but act more like their own thread. Here's an example using a timer:
slashTimerActive := 0
m::
if (!slashTimerActive)
SetTimer, SendSlash, 100 ; Call the sub every 100ms
else
SetTimer, SendSlash, Off
slashTimerActive := !slashTimerActive ; Flip the variable
return
; Subroutine
SendSlash:
SendInput, /
return
这篇关于发送处于循环状态时,热键不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!