Jump to content

my little brain doesnt understand


Recommended Posts

ive been using autoit for a while, but have just recently been trying to wrap my brain around functions, variables and conditional statements.

im trying to make a script to wait until im inactive, then run a program until im active again. then start again when im done. this is the code i have. (also attached it.) i thought this would work.... but it doesnt. anything would be greatly appreciated.

oh yeah, and everything works until the second function. 1st func is borrowed from an old fourm.

AdLibEnable("_UpdateTimer", 100)

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


While(1)
    sleep(10)
WEnd

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()
Do
run ("photoshopedit.exe")
wend
until <$OldMousePosition = $NewMousePosition>
EndFunc
Edited by RogerRabbitsClone
<--a good way to start you day
Link to comment
Share on other sites

I would suggest you first of all to change your AdLibEnable statement ...

as it is now, it will run every 100 milliseconds, and since the called function

looks like it might take some time, there will be trouble, it will try to run

the same function that is still executing ...

Also, in _OnTimerFinish, what's that 'wend' doing there in your Do ... Until loop ;)

hth,

whim

Link to comment
Share on other sites

i think i missed the point of the do..until. i was trying to tell it to run "photoshopeditor.exe" until i was active again...but after re-reading my code, do...until is its own loop.

i think i need to go back to the help files for a while. i dont think ive got a grasp on this yet.

thanks anyway.

<--a good way to start you day
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...