闲置期,运行 一个脚本

Period of inactivity, run a script

我想要做的是 运行 仅当用户处于非活动状态时才执行 .exe。当屏幕再次激活时,脚本应再次启动。

逻辑:

While True:
     Is the user active:          
     NO-> Is the .exe running -> Yes: Do nothing  No: run the Program
     YES -> Close the .exe 

关于如何使用 Auto It 对此进行编程的任何建议

编辑:

Inactivity: 没有用户 activity(移动鼠标或其他方式) 运行 程序:这是一个自定义的 .exe 文件,将保存在同一文件夹中。

这是 Windows 盒子,而不是 Linux 机器

_Timer_GetIdleTime() is exactly what you need.
Returns the number of ticks since last user activity (i.e. KYBD/Mouse)

用法示例:

#include <Timers.au3>

$InactivityTrigger = 5*1000 ;inactive for 5 seconds
$myExe = "calc.exe"
$PID = 0

While True

    $InactiveFor = _Timer_GetIdleTime()

    If $InactiveFor >= $InactivityTrigger And Not $PID Then

        $PID = Run($myExe)
        ConsoleWrite("started" & @CRLF)

    ElseIf $InactiveFor < $InactivityTrigger And $PID Then

        ProcessClose($PID)
        $PID = 0
        ConsoleWrite("stopped" & @CRLF)

    EndIf

    If Not $PID And Not IsFloat($InactiveFor/10) Then ToolTip("Inactive for: " & Round($InactiveFor/1000) & " seconds." & @CRLF & @CRLF & _
                   "Will run exe in " & Round( ($InactivityTrigger-$InactiveFor)/1000 ) & " seconds." )

Wend