TEAM ENVI^ ENVIMODE=1| ENVI^ ForceLocal=1
@ IFEX %&CurFile%.LOG, LOGS  * %&CurFile%.LOG
//GetLastInputMs 时间名  有效名
//获得最后输入时间MS （键盘鼠标等）
_SUB GetLastInputMs
    SET$#  &Info=08 00 00 00 *16 00
    SET inputms=0
    CALL $**qd **ret:&&r user32.dll,GetLastInputInfo,*&Info
    IFEX  $1=%&r%, ENVI?long   &Info=&&inputms:4 
    ENVI-ret %1=%&inputms% //返回最后输入时间ms
    ENVI-ret %2=%&&r%  //返回有效标志, 0无效 
_END

//GetCurMs  时间名
//获得当前时间MS 
_SUB GetCurMs
    CALL $**qd **ret:&&CurMs Kernel32.dll,GetTickCount
    ENVI-ret %1=%&&&CurMs%
_END
    
    

SET-def IDLEMS=6000  //空闲关机时间6000ms演示  
SET-def idle=0
SET RUN=1
LOOP #%&RUN%=1,
{
    TEAM CALL GetLastInputMs &&inputms &&r| CALL GetCurMs &&CurMs| WAIT 100 
    IFEX $%&r%==0, EXIT -  //无效 continue
    IFEX $%&CurMs%=, EXIT - //无效
    CALC &idle=%&CurMs% - %&inputms%
    IFEX $%&idle%<0, CALC &&idle=%&idle% + 0x100000000 //溢出，反转
    IFEX $%&idle%>=%IDLEMS%, GuanJi
}

_SUB GuanJi
    MESS 关机#YN  // SHUT 
    SET RUN=0 
_END


MESS   空闲[%&idle%]ms


