Jump to content

Sleeping without the sleeping


Rad
 Share

Recommended Posts

Im stuck, I dont really get a way to work with this. I mean sleep() pauses the entire script and I dont see a work around. I want it so that my infinite loop will still run even while its waiting, because my function waits ~2500ms then simulates a keystroke, but if I wait and try to push "stop" or "Exit" it has no effect until it clicks, which COULD... but probrably wont be bad. I just dont like the whole idea.

I also thought of doing AdLibEnable(), then the first part of the func to do AdLibDisable()... And a little about the TimerInit()/Diff() functions, but those examples confused me.

Any suggestions?

Actually i dont think adlibenable would work either, because my func have the parameters like _LeftClick($x,$y)... but not all of them do _Enter()

Edited by Rad
Link to comment
Share on other sites

Hi,

post the script with a little explanation where you want to sleep/wait. There are several commands which can automatically wait until they are done and so on.

So long,

Mega

Scripts & functions Organize Includes Let Scite organize the include files

Yahtzee The game "Yahtzee" (Kniffel, DiceLion)

LoginWrapper Secure scripts by adding a query (authentication)

_RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...)

Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc.

MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times

Link to comment
Share on other sites

Well the script isnt really ready, at all.. lol... not really anything to fix or add yet.. I just need an alternate wait method where I can still count the time between the keys to wait later on.

Azu - that doesnt seem to be accurate. I dont really know why but it almost never is 2.5 seconds for some reason. I think sleep() relies on the refresh rate of the program or something...hehe...

Ill try messing with TimerInit right now, although it still looks like its setup wierd

Link to comment
Share on other sites

func PauseThatIsn'tAPause($x)

$t=timerinit()

do

sleep(10)

until timerdiff($t)>$x

endfunc

Use:

PauseThatIsn'tAPause(2500)

Or simply

$t=timerinit()

do

sleep(10)

until timerdiff($t)>2500

If you only wanna use it once.

Edited by Azu
Link to comment
Share on other sites

Oh hey that will work for the playback, but I need it to record the time between each clicks first, which wouldnt be a preset... Any idea?

Example:

I click a button

I wait for something to popup

I press esc

How could I record the time in between?

Link to comment
Share on other sites

Oh hey that will work for the playback, but I need it to record the time between each clicks first, which wouldnt be a preset... Any idea?

Example:

I click a button

I wait for something to popup

I press esc

How could I record the time in between?

Oh here we go:

$timer = TimerInit()
    Do
        $msg = GUIGetMsg()
        If $msg = $GUI_EVENT_CLOSE or $msg = $exit Then Exit
    Until _IsPressed("01") = 1 Or  _IsPressed("02") = 1 Or _IsPressed("0D") = 1
    $sleep[0] = TimerDiff($timer)
    $time = TimerStop($timer)

Thanks I think I can finish it now! .... although I'd have to rewrite the loop... for the func

Edited by Rad
Link to comment
Share on other sites

Oh hey that will work for the playback, but I need it to record the time between each clicks first, which wouldnt be a preset... Any idea?

Example:

I click a button

I wait for something to popup

I press esc

How could I record the time in between?

$y=timerinit()

Click

Pop

Esc

$j=timerdiff($y) ;$j is the time passed, in miliseconds

Edit: oops sorry I didn't see post #7 =/

Edited by Azu
Link to comment
Share on other sites

  • Moderators

Global $TimesUp
AdlibEnable('_CheckTime', 2500)

While 1
    If $TimesUp Then
        AdlibDisable()
        MsgBox(64, 'Info', '2500 milliseconds are up, and you never had to slow down your script.')
        $TimesUp = Not $TimesUp
        AdlibEnable('_CheckTime', 2500)
    EndIf
    Sleep(10)
WEnd

Func _CheckTime()
    $TimesUp = Not $TimesUp
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

Ok I got it to work pretty well, but theres some bugs... Im not really sure whats causing them these methods are new to me...

#Include <Constants.au3>
#include <GUIConstants.au3>
#include <Array.au3>
#include <IE.au3>
#Include <Misc.au3>
#Include <GUIButton.au3>

Dim $Click[50]
Dim $Pos[50][2]
Dim $Sleep[50]
Dim $Time[50]
Dim $timer[50]
Dim $Delay = 500
Global $list, $mouse, $time, $timer, $current
$current = 0

$window = GUICreate("test macro",258,228+18)

$edit = GUICtrlCreateEdit("",2,2,254,206,$ES_READONLY)
$start = GUICtrlCreateButton("Start",2,208,64,18)
$stop = GUICtrlCreateButton("Stop",2+(64*1),208,64,18)
$record = GUICtrlCreateButton("Record",2+(64*2),208,64,18)
$exit = GUICtrlCreateButton("Exit",2+(64*3),208,64,18)
$status = GUICtrlCreateLabel("Ready...",2,228,254,16,$SS_SUNKEN)
GUISetstate()
$recording = 0
$started = 0

while 1
    $msg = GUIGetMsg()
    Select
    Case $msg = $GUI_EVENT_CLOSE or $msg = $exit 
        Exit
    Case $msg = $record
        ResetValues()
        If $recording = 0 Then
            $recording = 1
            WinSetOnTop("test macro","",0)
            GUICtrlSetdata($edit,"")
            WinSetOnTop("test macro","",1)
;~      Record()
            AdLibEnable("Record",200)
        Else
            AdLibDisable()
            GUICtrlSetData($edit,$list)
            $recording = 0
        Endif
    Case $msg = $start
        If $current > 0 Then
            $started = 1
            Start()
        Else
            SoundPlay(@WindowsDir & "\Media\Windows XP Error.wav")
        Endif
    Case $msg = $stop
        ResetValues()
    Endselect
Wend

Func Record()
    If _IsPressed("01") = 0 AND  _IsPressed("02") = 0 AND _IsPressed("00") = 0 Then
        $timer = TimerInit()
        Do
            BasicLoop()
        Until _IsPressed("01") = 1 Or  _IsPressed("02") = 1 Or _IsPressed("0D") = 1
        $sleep[$current] = TimerDiff($timer)
        $time[$current] = StringFormat("%.2f",TimerStop($timer)) + 1500
        StatusWrite($time[$current])
        If _IsPressed("01") Then
            $Click[$current] = "Left"
            $mouse = MouseGetPos()
            $Pos[$current][0] = $mouse[0]
            $Pos[$current][1] = $mouse[1]
            If $list = "" Then 
                $list = $Click[$current] & "-Click (" & $pos[$current][0] & ", " & $pos[$current][1] & ")" & @CRLF
            Else
                $list = $list & "Sleep: " & $time[$current] & @CRLF & $Click[$current] & "-Click (" & $pos[$current][0] & ", " & $pos[$current][1] & ")" & @CRLF
            Endif
            $current = $current + 1
            GUICtrlSetData($edit,$list)
        Else
            If _IsPressed("02") Then
                $Click[$current] = "Right"
                $mouse = MouseGetPos()
                $Pos[$current][0] = $mouse[0]
                $Pos[$current][1] = $mouse[1]
                If $list = "" Then 
                    $list = $Click[$current] & "-Click (" & $pos[$current][0] & ", " & $pos[$current][1] & ")" & @CRLF
                Else
                    $list = $list & "Sleep: " & $time[$current] & @CRLF  & $Click[$current] & "-Click (" & $pos[$current][0] & ", " & $pos[$current][1] & ")" & @CRLF
                Endif
                $current = $current + 1
                GUICtrlSetData($edit,$list)
            Else
                AdLibDisable()
                GUICtrlSetData($edit,$list)
                $recording = 0
            Endif
        Endif
    EndIf
EndFunc

Func Statuswrite($Temp)
    GUICtrlSetData($status,$temp)
EndFunc

Func Start()
    if $started = 1 Then
        WinSetOnTop("test macro","",1)
        sleep(1000)
        For $i = 0 to $current - 1
            If $Click[$i] = "Left" Then MouseClick("left",$pos[$i][0],$pos[$i][1],1,0)
            If $Click[$i] = "Right" Then MouseClick("right",$pos[$i][0],$pos[$i][1],1,0)
            sleep(250)
            $timer = TimerInit()
            Do
                BasicLoop()
            Until TimerDiff($timer) > $sleep[$i]
        Next
        Start()
    Else
        WinSetOnTop("test macro","",0)
    Endif
EndFunc

Func BasicLoop()
    $msg = GUIGetMsg()
    If $msg = $GUI_EVENT_CLOSE or $msg = $exit Then Exit
    If $msg = $stop Then
        AdLibDisable()
        $Started = 0
    Endif
    StatusWrite("Sleeping - " & StringFormat("%.2f",TimerDiff($timer)))
EndFunc

Func ResetValues()
    $current = 0
    GUICtrlSetData($Edit,"")
    $list = ""
    WinSetOnTop("test macro","",0)
Endfunc

It should work enough to get it to click a few times, but theres alot of bugs. Try launching it and pressing "Record", then click a few areas on the screen that wont mess anything up (with different delays). If it happened like it did for me, the first time, the delays are totally messed up. I think its taking the wrong arrays or something.. no idea :P

Not sure if it was just me, but it also seems like it didnt click the same spot as the cordinates...

Any help or tips are appreciated

Oh yea, press Enter when your done recording... then click start

Edited by Rad
Link to comment
Share on other sites

Hi, I tried running your script to see the problem, but I seem to be getting a different error then you;

---------------------------

AutoIt

---------------------------

Error reading the file:

IE.au3

---------------------------

OK

---------------------------

Link to comment
Share on other sites

You could probrably just take out most of the includes, I just used all of the ones from the program I need this for

I got it to 'work'... by making it wait twice as long between the clicks... I dont really like having to do this, as now it would be impossible to make timing perfect. But, it works... When you start it should sleep alot longer than it says... try it out:

#Include <Constants.au3>
#include <GUIConstants.au3>
#include <Array.au3>
#include <IE.au3>
#Include <Misc.au3>
#Include <GUIButton.au3>

Dim $Click[50]
Dim $Pos[50][2]
Dim $Sleep[50]
Dim $Time[50]
Dim $timer[50]
Dim $Delay = 500
Global $list, $mouse, $time, $timer, $current
$current = 0

$window = GUICreate("test macro",258,228+18)

$edit = GUICtrlCreateEdit("",2,2,254,206,$ES_READONLY)
$start = GUICtrlCreateButton("Start",2,208,64,18)
$stop = GUICtrlCreateButton("Stop",2+(64*1),208,64,18)
$record = GUICtrlCreateButton("Record",2+(64*2),208,64,18)
$exit = GUICtrlCreateButton("Exit",2+(64*3),208,64,18)
$status = GUICtrlCreateLabel("Ready...",2,228,254,16,$SS_SUNKEN)
GUISetstate()
$recording = 0
$started = 0

while 1
    $msg = GUIGetMsg()
    Select
    Case $msg = $GUI_EVENT_CLOSE or $msg = $exit 
        Exit
    Case $msg = $record
        ResetValues()
        If $recording = 0 Then
            $recording = 1
            WinSetOnTop("test macro","",0)
            GUICtrlSetdata($edit,"")
            WinSetOnTop("test macro","",1)
            Record()
;~          AdLibEnable("Record",200)
        Else
            AdLibDisable()
            GUICtrlSetData($edit,$list)
            $recording = 0
        Endif
    Case $msg = $start
        If $current > 0 Then
            $started = 1
            Start()
        Else
            SoundPlay(@WindowsDir & "\Media\Windows XP Error.wav")
        Endif
    Case $msg = $stop
        ResetValues()
    Endselect
Wend

Func Record()
    If _IsPressed("01") = 0 AND  _IsPressed("02") = 0 AND _IsPressed("00") = 0 Then
        $timer = TimerInit()
        Do
            BasicLoop()
        Until _IsPressed("01") = 1 Or  _IsPressed("02") = 1 Or _IsPressed("0D") = 1
        $sleep[$current] = TimerDiff($timer)
        $time[$current] = StringFormat("%.2f",TimerStop($timer)) + 5500
        StatusWrite($time[$current])
        If _IsPressed("01") Then
            $Click[$current] = "Left"
            $mouse = MouseGetPos()
            $Pos[$current][0] = $mouse[0]
            $Pos[$current][1] = $mouse[1]
            If $list = "" Then 
                $list = $Click[$current] & "-Click (" & $pos[$current][0] & ", " & $pos[$current][1] & ")" & @CRLF
            Else
                $list = $list & "Sleep: " & $time[$current] & @CRLF & $Click[$current] & "-Click (" & $pos[$current][0] & ", " & $pos[$current][1] & ")" & @CRLF
            Endif
            $current = $current + 1
            GUICtrlSetData($edit,$list)
                Do
                Until _IsPressed("01") = 0 AND  _IsPressed("02") = 0 AND _IsPressed("00") = 0
                Record()
        Else
            If _IsPressed("02") Then
                $Click[$current] = "Right"
                $mouse = MouseGetPos()
                $Pos[$current][0] = $mouse[0]
                $Pos[$current][1] = $mouse[1]
                If $list = "" Then 
                    $list = $Click[$current] & "-Click (" & $pos[$current][0] & ", " & $pos[$current][1] & ")" & @CRLF
                Else
                    $list = $list & "Sleep: " & $time[$current] & @CRLF  & $Click[$current] & "-Click (" & $pos[$current][0] & ", " & $pos[$current][1] & ")" & @CRLF
                Endif
                $current = $current + 1
                GUICtrlSetData($edit,$list)
                Do
                Until _IsPressed("01") = 0 AND  _IsPressed("02") = 0 AND _IsPressed("00") = 0
                Record()
            Else
;~              AdLibDisable()
                GUICtrlSetData($edit,$list)
                $recording = 0
            Endif
        Endif
    EndIf
EndFunc

Func Statuswrite($Temp)
    GUICtrlSetData($status,$temp)
EndFunc

Func Start()
    if $started = 1 Then
        WinSetOnTop("test macro","",1)
        sleep(1000)
        For $i = 0 to $current - 1
            If $Click[$i] = "Left" Then MouseClick("left",$pos[$i][0],$pos[$i][1],1,0)
            If $Click[$i] = "Right" Then MouseClick("right",$pos[$i][0],$pos[$i][1],1,0)
            sleep(250)
            $timer = TimerInit()
            Do
                BasicLoop()
            Until TimerDiff($timer) * .5 > $sleep[$i]
        Next
        Start()
    Else
        WinSetOnTop("test macro","",0)
    Endif
EndFunc

Func BasicLoop()
    $msg = GUIGetMsg()
    If $msg = $GUI_EVENT_CLOSE or $msg = $exit Then Exit
    If $msg = $stop Then
        AdLibDisable()
        $Started = 0
    Endif
    StatusWrite("Sleeping - " & StringFormat("%.2f",TimerDiff($timer)))
EndFunc

Func ResetValues()
    $current = 0
    GUICtrlSetData($Edit,"")
    $list = ""
    WinSetOnTop("test macro","",0)
Endfunc
Edited by Rad
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...