根据用户行为打出鼠标移动

Break out of mouse movement according to user behavior

下面的脚本在无限循环中以 15 秒的间隔将鼠标键移动到屏幕的不同位置:

Loop
{
MouseMove, 200, 100, 50, R
Sleep, 15000
MouseMove, -200, -100, 50, R
Sleep, 10000
}

当检测到用户手动移动鼠标时,如何跳出这个循环?

这比我想象的要难

当按下 Esc 时,下面的代码将跳出循环:

   Loop
{
MouseMove, 200, 100, 50, R
Sleep, 15000  ; 15 second
MouseMove, -200, -100, 50, R
Sleep, 15000  ; 15 second
}

Esc::ExitApp

也许是这样的:(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

您可以使用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

版本 1.1+