如何每3分钟移动一次鼠标?

How to move the mouse every 3 minutes?

我试图每 2 分钟移动一次鼠标,这样会话就不会超时。但是尽管没有语法错误,它还是行不通。

我的代码:

global $x = 1
global $y = 1
If Mod(@MIN, 3) = 0 Then
    MouseMove (global $x, global $y, 2)
    global $x++
    global $y++
endif
 

当您在 SciTE 中 运行 您的脚本时,您应该会看到以下错误消息:

只有在声明变量时才需要 global 关键字。使用变量时,您必须省略 global 关键字。您应该相应地更改您的脚本,然后它可能会起作用。

定时调用回调函数比较有用

AdlibRegister('_MouseMove', 2000*60)   ; calls the function every 2000*60 ms
OnAutoItExitRegister('_UnRegister')    ; unregister the callback function when the script ends

Func _MouseMove()
    Local $aPos = MouseGetPos()
    ; move 1px right and back after a short brake - so that your interface can detect the movement
    MouseMove($aPos[0]+1, $aPos[1])
    Sleep(50)
    MouseMove($aPos[0], $aPos[1])
EndFunc

Func _UnRegister()
    AdlibUnRegister('_MouseMove')
EndFunc

顺便说一句:用 AutoIt 增加值是这样的

$x += 1   

编辑: 我不确定,如果你想要 2 或 3 分钟(你都写过)。所以你可以在 AdlibRegister() 的时间参数中改变它。间隔必须以毫秒为单位给出。

以下脚本每 3 分钟将鼠标移动一个像素,防止会话超时,对计算机使用的影响最小。

HotKeySet( "{ESC}" , "Sair")

While True
    MouseMove(MouseGetPos(0)+1,MouseGetPos(1))
    Sleep(180000)
    MouseMove(MouseGetPos(0)-1,MouseGetPos(1))
    Sleep(180000)
WEnd


Func Sair()
    Exit
EndFunc