下面的脚本在无限循环内以15秒的间隔将鼠标键移动到屏幕的不同位置:
Loop
{
MouseMove, 200, 100, 50, R
Sleep, 15000
MouseMove, -200, -100, 50, R
Sleep, 10000
}
当检测到用户手动移动鼠标时,如何摆脱此循环?
答案 0 :(得分:1)
您可以使用A_TimeIdlePhysical,但请记住您需要安装鼠标钩才能使用它。
#InstallMouseHook
loop,
{
MouseMove, 100, 500
sleep 15000
if (A_TimeIdlePhysical <= 15000) ; if the mouse was moved while the script was sleeping
break
MouseMove, 500, 100
sleep 10000
if (A_TimeIdlePhysical <= 10000) ; if the mouse was moved within the last 10 secs
break
}
return
希望有所帮助
注意:来自http://ahkscript.org
的req版本1.1+答案 1 :(得分:0)
这比我想象的要困难。
当按下 Esc 时,代码将突然出现循环:
Loop
{
MouseMove, 200, 100, 50, R
Sleep, 15000 ; 15 second
MouseMove, -200, -100, 50, R
Sleep, 15000 ; 15 second
}
Esc::ExitApp
答案 2 :(得分:0)
也许是这样的:( reedited 21.01.2015)
F1::
Loop
{
MouseGetPos, X0, Y0
MouseMove, 200, 100, 50, R
GoSub, BreakLoop
MouseMove, -200, -100, 50, R
GoSub, BreakLoop
}
return
BreakLoop:
Loop, 1000
{
Sleep, 15
MouseGetPos, X1, Y1
If (X1-X0>200 || X0-X1>200 || Y1-Y0>100 || Y0-Y1>100)
exit
}
return
Esc::ExitApp