问题
Assume this code:
Loop { if enabled Send, / } m:: enabled := !enabled Return
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)
回答1:
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
来源:https://stackoverflow.com/questions/30101897/hotkeys-does-not-work-when-send-is-in-loop