Jump to content

Trouble with getting idle state


Recommended Posts

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?

Link to comment
Share on other sites

try _Timer_GetIdleTime() , look at the help.

Signature - my forum contributions:

Spoiler

UDF:

LFN - support for long file names (over 260 characters)

InputImpose - impose valid characters in an input control

TimeConvert - convert UTC to/from local time and/or reformat the string representation

AMF - accept multiple files from Windows Explorer context menu

DateDuration -  literal description of the difference between given dates

Apps:

Touch - set the "modified" timestamp of a file to current time

Show For Files - tray menu to show/hide files extensions, hidden & system files, and selection checkboxes

SPDiff - Single-Pane Text Diff

 

Link to comment
Share on other sites

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?

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...