【问题标题】:Start & stop a script a looped action with a button使用按钮启动和停止脚本循环动作
【发布时间】:2015-03-21 05:45:48
【问题描述】:

脚本应该如下:

按“C”:启动/停止脚本

鼠标左键:开始/停止循环

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

  • 每次点击鼠标都会回到屏幕中心。

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

我现在把它改成了这个,但是即使不按住鼠标左键,它也总是被激活,我也不能用 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

【问题讨论】:

  • “停止/启动”是什么意思?
  • 当按下“C”时,脚本会停止,以便我可以正常使用鼠标。再次按“C”激活脚本,这样我就可以在按住 LMB 的同时左键单击。

标签: autohotkey


【解决方案1】:

看来您需要使用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

我的脚本很慢。它会点击 .. 点击 .. 点击 而不是 ClickClickClick :(

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

【讨论】:

  • 添加了上面的代码,但是现在LMB即使不按住也总是被点击。我也不能用“C”停止脚本。
  • 是的,因为我跳过了循环内的部分。我更新了我的帖子,再试一次。
  • 咕! :) 你可能会接受这个答案,因为否则这个问题将被视为未解决。相反,如果您仍在寻找其他答案,请保持打开状态
猜你喜欢
  • 2018-03-20
  • 2021-03-11
  • 1970-01-01
  • 2012-09-05
  • 2014-03-12
  • 1970-01-01
  • 2013-12-25
  • 1970-01-01
  • 2016-03-19
相关资源
最近更新 更多