Sign in to follow this  
Followers 0
RogerRabbitsClone

"if ($nTimer >= 100) Then" user idle problem

8 posts in this topic

#1 ·  Posted (edited)

i am trying to make a script that will wait for me to be idle then start, and if the i do something it will stop then wait for me to be idle again. i want to have the computer doing something constantly.

the first function waits for me to be idle successfully, but once the script starts running, it doesnt stop until i exit. what i tried to do is take the first function and reverse it (i found it in an old help section in the forum), but i dont understand part of the function:

;these are the vartiables
Global $OldMousePosition = MouseGetPos()
$NewMousePosition = MouseGetPos()
;this is what i dont understand
if (($NewMousePosition[0] == $OldMousePosition[0]) and ($NewMousePosition[1] == $OldMousePosition[1])) Then

ive tried the help section, and google to find an example of "stop when the user does something", and i know about _Timer_GetIdleTime() but i cant figure out how to apply that here. (_Timer_GetIdleTime() only recognizes key strokes?)

im not looking for somebody to code for me, i really want to figure this out. help file/function i missed?

here is my code:

#include <timers.au3>
AdLibEnable("_UpdateTimer", 100)

Global $nTimer = 0
Global $OldMousePosition = MouseGetPos()
GLobal $NewMousePosition
Global $Time = _Timer_GetIdleTime()

While(1)
    sleep(10)
WEnd

;\/ if they dont move, then start
Func _UpdateTimer()
    $nTimer += 100 ;100 ms
    
    $NewMousePosition = MouseGetPos()
    if (($NewMousePosition[0] == $OldMousePosition[0]) and ($NewMousePosition[1] == $OldMousePosition[1])) Then
        ; The user is still idle (you might also want to check for key presses
    Else
        ; The user moved, we should start the timer over.
        $OldMousePosition = $NewMousePosition
        $nTimer = 0
    EndIf
    
    if ($nTimer >= 5000) Then ;Change the '5000' to the number in milliseconds you want to wait, with your user being idle.
        _OnTimerFinish()
        $nTimer = 0
    EndIf
EndFunc

Func _OnTimerFinish()
    $nTimer += 100 ;100 ms
    
    $NewMousePosition = MouseGetPos()
    if (($NewMousePosition[0] == $OldMousePosition[0]) and ($NewMousePosition[1] == $OldMousePosition[1])) Then
        ; The user is still idle (you might also want to check for key presses
    Else
        ; The user moved, we should start the timer over.
        $OldMousePosition = $NewMousePosition
        $nTimer = 0
    EndIf
    
    if ($nTimer >= 100) Then 
            
            While sleep (3000)
                ;various different scripts here
                if ($OldMousePosition = $NewMousePosition) Then ExitLoop 
                    _UpdateTimer()
            wend 
         $nTimer = 0
    EndIf
EndFunc

EDIT:

this is where i got the original help:

http://www.autoitscript.com/forum/index.php?showtopic=66087&st=20

Edited by RogerRabbitsClone

<--a good way to start you day

Share this post


Link to post
Share on other sites



what exactly are you trying to do while the user is idle?

Share this post


Link to post
Share on other sites

i have a few different scripts written for different computers. one of them is a loop that renames files in a specific order and drops them to a folder in the server at my job. and another deletes files from the desktop of customer computers. there are allot of students that come into my store and just leave things like rental applications and scaned passports on the desktops of our computers. so i have a script that selects things on the desktop and our servers scans folder and deletes them after a certain amount of time.


<--a good way to start you day

Share this post


Link to post
Share on other sites

i messed with _Timer_GetIdleTime() it works very well determining idle time for mouse movements or keystrokes heres a small smiple example just to see how it works

#Include <Timers.au3>

While 1
     sleep(10)
     $idle = _Timer_GetIdleTime()
     ToolTip($idle)
WEnd

just sits and idles around puts a tooltip the the idle time in ms next to the mouse

you can see what happens when you move the mouse and type on the keyboard ect...

Share this post


Link to post
Share on other sites

so in theory, this should keep opening notepad until i move the mouse?

#Include <Timers.au3>

Global $Time = _Timer_GetIdleTime()
while run ("notepad.exe")
sleep (3000)
;
if $time > 100 then exitloop
wend

<--a good way to start you day

Share this post


Link to post
Share on other sites

so in theory, this should keep opening notepad until i move the mouse?

#Include <Timers.au3>

Global $Time = _Timer_GetIdleTime()
while run ("notepad.exe")
sleep (3000)
;
if $time > 100 then exitloop
wend

the one above wouldn't really work but i thought of this one

this will open Notepad after 10 seconds of being idle and then close it if you move the mouse then if your idle another 10 seconds it'll open it again

#include <Timers.au3>
while 1
    $Timer = _Timer_GetIdleTime()
    if $Timer = 10000 Then
        $pid = Run("Notepad.exe")
        Do
            $Timer = _Timer_GetIdleTime()
        Until $Timer < 10000
        ProcessClose($pid)
    EndIf
WEnd

Share this post


Link to post
Share on other sites

You would want "if $Timer >= 10000 Then" because you are unlikely to hit it at exactly 10000.

;)


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

You would want "if $Timer >= 10000 Then" because you are unlikely to hit it at exactly 10000.

;)

yeah i guess lol

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  
Followers 0