Jump to content
Sign in to follow this  
makolosz

Trouble with getting idle state

Recommended Posts

makolosz

Hello,

I started using autoit and wanted to run a script only when the pc is idle. As the windows 7 scheduler run I guess on the basis of cpu usage I wanted to write an idle check by autoit itself before it starts clicking all over the windows:

Global $StartTime

Call("StartTimer")

  $MPos1 = MouseGetPos()
  $CPos1 = WinGetCaretPos()
  Sleep(1000)
  $MPos2 = MouseGetPos()
  $CPos2 = WinGetCaretPos()

  If $MPos1[0] <> $MPos2[0] Then
    Call("StartTimer")
  ElseIf $CPos1[0] <> $CPos2[0] Then
    Call("StartTimer")
  EndIf

  $EndTime = TimerStop($StartTime)
  
  If $EndTime > 5000 Then
    MsgBox(0, "System Idle Time", "System Idle Time exceeded 5 seconds", 2)
else
exit
  EndIf

In place of:

MsgBox(0, "System Idle Time", "System Idle Time exceeded 5 seconds", 2)

I wanted to put the proper actions, but I guess it's some old format as it's not working. I found the idle check on some old thread, so maybe some definitions has changed and you can help me to figure it out?

Share this post


Link to post
Share on other sites
orbs

try _Timer_GetIdleTime() , look at the help.

Share this post


Link to post
Share on other sites
makolosz

try _Timer_GetIdleTime() , look at the help.

 

Ok. I want to run my script only once in case there is no mouse activity for like 8 seconds, otherwise it should exit as I am triggering it every 10 minutes via windows scheduler. Here's what I have now:

#include <Timers.au3>
global $i = 0
While $i < 1
sleep(8000)
$idletime = _Timer_GetIdleTime()
   If $idletime > 7000 Then
   MsgBox(0, "idle time", $idletime)
   $i = $i + 1
   Else
   Exit
WEnd

But I get "Wend" statement with no matching "While" statement.:

Am I missing some brackets here? Or cannot use if statement in a loop?

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×