Jump to content

Can't get AFK script to work!


Recommended Posts

#include <File.au3>

Sleeper()


Func Sleeper()
_FileWriteLog("C:\AutoIt3\afk.dat", "-AFK-")
$How_long = 3000; 3 seconds
$pos1 = MouseGetPos()
$Time = TimerInit()
While 1
    $dif = TimerDiff($Time)
    If $dif > $How_long Then; if not moved for 3 seconds then>
        $pos2 = MouseGetPos()
        If $pos1[0] = $pos2[0] Then
            Msgbox(0, "Away", "Away")
            Return
        EndIf
    EndIf
    Sleep(20)
WEnd
EndFunc

It only works for that pixel, move your mouse to 1,1 then run it then quickly move it to a different pixel, then stop moving it.........doesn't work. Move it back to 1,1 then it pops up, I can't figure out how to fix it.

Edited by Firestorm

[left][sub]We're trapped in the belly of this horrible machine.[/sub][sup]And the machine is bleeding to death...[/sup][sup][/sup][/left]

Link to comment
Share on other sites

A very simple logic error:

Func Sleeper()
_FileWriteLog("C:\AutoIt3\afk.dat", "-AFK-")
$How_long = 3000; 3 seconds
$pos1 = MouseGetPos()
$Time = TimerInit()
While 1
    $dif = TimerDiff($Time)
    If $dif > $How_long Then; if not moved for 3 seconds then>
        $pos2 = MouseGetPos()
        If $pos1[0] = $pos2[0] Then
            Msgbox(0, "Away", "Away")
            Return
        EndIf
        $pos1 = MouseGetPos()
    EndIf
    Sleep(20)
WEnd
EndFunc

#)

Link to comment
Share on other sites

Hmm, It doesn't work. I can't find out why! Run it then keep moving your mouse, in 3 seconds the 'away' msgbox pops up...

[left][sub]We're trapped in the belly of this horrible machine.[/sub][sup]And the machine is bleeding to death...[/sup][sup][/sup][/left]

Link to comment
Share on other sites

  • Moderators

Makes sense to reset the timer if the coords didn't match? Otherwise after the initial TimerDiff($Time) it's always > than 3 seconds.

Func Sleeper()
    ;_FileWriteLog("C:\AutoIt3\afk.dat", "-AFK-")
    $How_long = 3000; 3 seconds
    $pos1 = MouseGetPos()
    $Time = TimerInit()
    While 1
        $dif = TimerDiff($Time)
        If $dif >= $How_long Then; if not moved for 3 seconds then>
            $pos2 = MouseGetPos()
            If $pos1[0] == $pos2[0] Then
                Msgbox(0, "Away", "Away" & @CR & $pos1[0] & @CR & $pos1[1] & @CR & @CR & $pos2[0] & @CR & $pos2[1] & @CR & 'Time Elapsed = ' & TimerDiff($Time) / 1000)
                Return 1
            Else
                $Time = TimerInit() ;~ Reset Timer if not = coords (reason for the msgbox keep going off
                $pos1 = $pos2 = ;~ Reset to new coords
            EndIf
        EndIf
        Sleep(20)
    WEnd
EndFunc

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

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...