使用按钮启动和停止脚本循环操作

Start & stop a script a looped action with a button

脚本应如下所示:

按'C':Start/Stop脚本

鼠标左键:Start/Stop循环

循环内部:在按住鼠标左键的同时,重复鼠标左键直到我松开手指。

或者,每次单击后鼠标向下移动 X 像素,我的脚本非常慢。 它会点击 .. 点击 .. 点击而不是 ClickClickClick :(.

我现在改成了这个,但是鼠标左键即使不按住它也总是激活的,我也不能stop/start用C编写脚本。

HotKey, ~$*LButton, myLButtonAction ; Activate the hotkey by default
return

~c::    ; configure a Hotkey: c will enable / disable your LButton actions
HotKey, ~$*LButton, toggle  ; ON / OFF
return

myLButtonAction:    ;cnote: this is NOT a hotkey, it's a label
Loop
{
    Click
    Sleep 7,516  ;your loop actions (see question code)
}
return  ; don't forget your returns at the end of a label / hotkey

看来您需要使用 Hotkey 命令。

x := (A_ScreenWidth // 2)
y := (A_ScreenHeight // 2)
HotKey, ~$*LButton, myLButtonAction ; Activate the hotkey by default
setMouseDelay, 0
setKeyDelay, 0
return

~c::    ; configure a Hotkey: c will enable / disable your LButton actions
HotKey, ~$*LButton, toggle  ; ON / OFF
return

myLButtonAction:    ; note: this is NOT a hotkey, it's a label

Loop                 ;loop the script until broken
{ ;loop start
GetKeyState, var, LButton, P ;Get the state of Lbutton
If var = U                            ;has it been released?
    Break       ;its been released so break the loop
;Send {LButton}  ;It hasnt been released so send another Click
Click %x%, %y%
Sleep 100 ;time between presses, after sleep return to the top of the loop
} ;loop end

return  ; don't forget your returns at the end of a label / hotkey

my script is very slow. It goes click .. click .. click instead of ClickClickClick :(

包括 setMouseDelay, 0 into your auto-execution section。我已经在上面的代码示例中这样做了。