Sign in to follow this  
Followers 0
Dae

Sleep

13 posts in this topic

I've got a proggy that I want to send the key SPACE to 2 windows. Afterwards it will sleep for 2 minutes, and send the key to those 2 windows again.

However, the way its programmed is it sends the key to window #1, then sleeps for 2 minutes, then sends the key to window #2, and sleeps for 2 minutes.

Obviously that's problematic. I need 2 different instances of sleep. So the sleep for window #1 won't effect window #2.

Also, is there any way to interrupt a sleep? Because it appears if you send a message to the GUI it will process it, but won't operate any functions until the sleep ends. I'd like to interrupt the sleep if there is one when a command is send to the GUI like exit and such.

Thanks!

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Why don't you just have it send the spaces to the two windows, then initiate the sleep phase.

Unless if there's something in your code that won't allow you to do that, if so, do explain.

Edited by BALA

[font="Comic Sans MS"]BA-LA[/font]http://ba-la.110mb.comJoin my community, CLICK HEREAlternative links to my site:http://www.ba-la.tkhttp://www.ba-la.co.nrContact me if you would like to help with some of my projects: joeythepirate@gmail.com

Share this post


Link to post
Share on other sites

Why don't you just have it send the spaces to the two windows, then initiate the sleep phase.

Unless if there's something in your code that won't allow you to do that, if so, do explain.

There is something in my code that won't allow me to do that.

If I give code people aren't going to answer me.

Best I can say is.. it's a while loop that goes through the IDs, 1 and 2, and does a long switch case (if statements) and if it's state is "jump" it will send the SPACE key. So I can't put the sleep after the switch case, because I don't want it sleeping that long after say a "turn" case. I only want it sleeping that long for the "jump" case. And since it's a while loop, it's going to do that "jump" case twice, and therefore the sleep twice.

Share this post


Link to post
Share on other sites

If I give code people aren't going to answer me.

Simple addition property of equality

Code = Help

No = No

No+Code = No+Help

Share this post


Link to post
Share on other sites

Come one guys, I explained what I'm trying to do. My code is a little complex, not very self explanatory, and not optimized yet.

Here's the important parts: (theres no point in giving the entire program because it only works if you have the game running)

Func SetupGUI()
    $g_Menu[0][0][0] = GUICtrlCreateMenu("&File")

    $g_Menu[0][1][0] = GUICtrlCreateMenuitem("Load", $g_Menu[0][0][0])
    $g_Menu[0][2][0] = GUICtrlCreateMenuitem("", $g_Menu[0][0][0])    ; create a separator line
    GUICtrlSetState(-1, $GUI_DISABLE)
    $g_Menu[0][3][0] = GUICtrlCreateMenuitem("Exit", $g_Menu[0][0][0])
    
    GUICtrlSetOnEvent($g_Menu[0][3][0], "Event")
    GUISetOnEvent($GUI_EVENT_CLOSE, "Event")

    $g_Menu[1][0][0] = GUICtrlCreateMenu("&Command") ;change 5 to 0

    For $id = 1 To UBOUND($g_Account) - 1
        GUICtrlCreateMenu("Account " & $id, $g_Menu[1][0][0])
        $g_Menu[1][$id][0] = GUICtrlCreateMenuitem("Queue", $g_Menu[1][$id][0])
        $g_Menu[1][$id][1] = GUICtrlCreateMenuitem("Position", $g_Menu[1][$id][0])
        $g_Menu[1][$id][2] = GUICtrlCreateMenuitem("Roam", $g_Menu[1][$id][0])
        GUICtrlCreateMenu("Guard", $g_Menu[1][$id][0])
        $g_Menu[1][$id][3] = GUICtrlCreateMenuitem("Graveyard", $g_Menu[1][$id][4])
        $g_Menu[1][$id][4] = GUICtrlCreateMenuitem("Bunker", $g_Menu[1][$id][4])
        $g_Menu[1][$id][5] = GUICtrlCreateMenuitem("Halt", $g_Menu[1][$id][0])
        GUICtrlSetState($g_Menu[1][$id][5], $GUI_CHECKED)
        
        GUICtrlSetOnEvent($g_Menu[1][$id][0], "Event")
        GUICtrlSetOnEvent($g_Menu[1][$id][1], "Event")
        GUICtrlSetOnEvent($g_Menu[1][$id][2], "Event")
        GUICtrlSetOnEvent($g_Menu[1][$id][3], "Event")
        GUICtrlSetOnEvent($g_Menu[1][$id][4], "Event")
        GUICtrlSetOnEvent($g_Menu[1][$id][5], "Event")
        
        $g_Menu[1][$id][8] = GUICtrlCreateMenuitem("", $g_Menu[1][$id][0])
        $g_Menu[1][$id][9] = GUICtrlCreateMenuitem("Unload", $g_Menu[1][$id][0])
    Next
    
    GUICtrlSetOnEvent($g_Menu[3][1][0], "Event")

    For $id = 1 To UBOUND($g_Account) - 1
        ;$g_Menu[4][$id][0] = GUICtrlCreateLabel("Account " & $id, 15 + 110 * ($id - 1), 10)
        
        GUICtrlCreateGroup("Account " & $id, 15 + 110 * ($id - 1), 10, 95, 200)
            $g_Menu[4][$id][0] = GUICtrlCreateRadio("Queue", 25 + 110 * ($id - 1), 25)
            $g_Menu[4][$id][1] = GUICtrlCreateRadio("Position", 25 + 110 * ($id - 1), 45)
            $g_Menu[4][$id][2] = GUICtrlCreateRadio("Roam", 25 + 110 * ($id - 1), 65)
            ;$g_Menu[4][$id][4] = GUICtrlCreateLabel("Guard", 25 + 110 * ($id - 1), 90)
            GUICtrlCreateGroup("Guard", 22 + 110 * ($id - 1), 90, 81, 63)
                $g_Menu[4][$id][3] = GUICtrlCreateRadio("Graveyard", 30 + 110 * ($id - 1), 105)
                $g_Menu[4][$id][4] = GUICtrlCreateRadio("Bunker", 30 + 110 * ($id - 1), 125)
            GUICtrlCreateGroup ("", -99, -99, 1, 1)
            $g_Menu[4][$id][5] = GUICtrlCreateRadio("Halt", 25 + 110 * ($id - 1), 157)
        GUICtrlCreateGroup ("", -99, -99, 1, 1)
        
        GUICtrlSetState($g_Menu[4][$id][5], $GUI_CHECKED)
        
        GUICtrlSetOnEvent($g_Menu[4][$id][0], "Event")
        GUICtrlSetOnEvent($g_Menu[4][$id][1], "Event")
        GUICtrlSetOnEvent($g_Menu[4][$id][2], "Event")
        GUICtrlSetOnEvent($g_Menu[4][$id][3], "Event")
        GUICtrlSetOnEvent($g_Menu[4][$id][4], "Event")
        GUICtrlSetOnEvent($g_Menu[4][$id][5], "Event")

        $g_Menu[6][$id][0] = GUICtrlCreateButton("Start", 20 + 110 * ($id - 1), 185, 40, 20)
        $g_Menu[6][$id][1] = GUICtrlCreateButton("Stop", 65 + 110 * ($id - 1), 185, 40, 20)
        
        GUICtrlSetState($g_Menu[6][$id][0], $GUI_FOCUS)
        
        GUICtrlSetOnEvent($g_Menu[6][$id][0], "Event")
        GUICtrlSetOnEvent($g_Menu[6][$id][1], "Event")
    Next

    $g_Menu[7][2][0] = GUICtrlCreateLabel("Ready", 0, 225, 125 + 125 * ($g_Window[0][0] - 1),  16, BitOr($SS_SIMPLE, $SS_SUNKEN))

    GUISetState(@SW_SHOW, $g_GUI)
EndFunc

Func Event()
    Local $msg = @GUI_CtrlId
    
    For $id = 1 To UBOUND($g_Account) - 1
        Switch $msg
            Case $g_Menu[6][$id][0]
                ContinueCase
                
            Case $g_Menu[1][$id][0]
                ContinueCase
                
            Case $g_Menu[4][$id][0]
                If UpdateStatus($id, 0) Then
                    ;SetWindowState($id, "Hide")
                EndIf
                
            Case $g_Menu[1][$id][1]
                ContinueCase
                
            Case $g_Menu[4][$id][1]
                If UpdateStatus($id, 1) Then
                    ;SetWindowState($id, "Hide")
                EndIf
                
            Case $g_Menu[1][$id][2]
                ContinueCase
                
            Case $g_Menu[4][$id][2]
                If UpdateStatus($id, 2) Then
                    ;SetWindowState($id, "Hide")
                EndIf
            
            Case $g_Menu[1][$id][3]
                ContinueCase
                
            Case $g_Menu[4][$id][3]
                If UpdateStatus($id, 3) Then
                    ;SetWindowState($id, "Hide")
                EndIf
                
            Case $g_Menu[1][$id][4]
                ContinueCase
                
            Case $g_Menu[4][$id][4]
                If UpdateStatus($id, 4) Then
                    ;SetWindowState($id, "Hide")
                EndIf
                
            Case $g_Menu[6][$id][1]
                ContinueCase
                
            Case $g_Menu[1][$id][5]
                ContinueCase
                
            Case $g_Menu[4][$id][5]
                If UpdateStatus($id, 5) Then
                    ;SetWindowState($id, "Show")
                EndIf
                
            Case Else
                
        EndSwitch
    Next
EndFunc

Func UpdateStatus($id, $change)
    Local $status = GetStatus($id)
    
    If $status == $change Then
        Return False
    Else
        ;Msgbox(0, "State", $status & " " & $change)

        If BitAnd(GUICtrlRead($g_Menu[1][$id][$status]), $GUI_CHECKED) Then
            GUICtrlSetState($g_Menu[1][$id][$status], $GUI_UNCHECKED)
        EndIf
        
        If BitAnd(GUICtrlRead($g_Menu[4][$id][$status]), $GUI_CHECKED) Then
            GUICtrlSetState($g_Menu[4][$id][$status], $GUI_UNCHECKED)
        EndIf

        SetStatus($id, $change)

        If BitAnd(GUICtrlRead($g_Menu[1][$id][$change]), $GUI_UNCHECKED) Then
            GUICtrlSetState($g_Menu[1][$id][$change], $GUI_CHECKED)
        EndIf
        
        If BitAnd(GUICtrlRead($g_Menu[4][$id][$change]), $GUI_UNCHECKED) Then
            GUICtrlSetState($g_Menu[4][$id][$change], $GUI_CHECKED)
        EndIf
        
        Return True
    EndIf
EndFunc

Func Jump($id)
    SendKey($id, "{SPACE down}")
    Sleep(100 + Rand(1, 50))
    SendKey($id, "{SPACE up}")

    Sleep(150000 + Rand(5000, 10000))
EndFunc

If $g_Window[0][0] > 0 Then
    SetupGUI()

    While 1
        For $id = 1 To UBOUND($g_Account) - 1
            Local $status = GetStatus($id)
            
            Switch $status
                Case 0
                    Queue($id)
                    
                    UpdateStatus($id, 1)
                
                Case 1
                    Position($id)
                
                    UpdateStatus($id, 2)
                
                Case 2
                    Roam($id)
                    
                    UpdateStatus($id, 3)
                    
                Case 3
                    Jump($id)

                Case 4
                    Jump($id)
                    
                Case 5
                    Halt($id)
            EndSwitch
        Next
    WEnd
EndIf

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

I told you. No one would answer when I post my code because it's over 500 lines long, not very standard scripting, and I only understand it because its a project I've been doing for the past week.

Now I saw in the notes that GUI operations will not be effected by Sleep. So that's why my GUI responds, but my functions aren't being called when Sleep is running.

Just imagine you have a program running, and it gets to Sleep, and you hit a hotkey, F5, and expect it to move the mouse, but it's still sleeping. Now that I'm thinking, I don't even think what I want is possible. This is no good..

Is there a GetTime function I could manipulate to essentially pause what I'm doing? BUT not the program, like Sleep does.

Edited by Dae

Share this post


Link to post
Share on other sites

Write a loop that checks if messages need to be processed while sleeping SMALL amounts of time that add up to 2 seconds.

$timer = TimerInit()
Do
    CheckProcessQueue()
    Sleep(50)
Until TimerDiff($timer) >= 2000

I'm sure you can figure something out.

Share this post


Link to post
Share on other sites

Write a loop that checks if messages need to be processed while sleeping SMALL amounts of time that add up to 2 seconds.

$timer = TimerInit()
Do
    CheckProcessQueue()
    Sleep(50)
Until TimerDiff($timer) >= 2000oÝ÷ ØýË«{*.q©ß«zÊ&zØb
.·ú®¢×©äʯz¼¦¹ÈwÝ8Z·l{¶­ên²'yç^v)íêâ]·¶*'"Ö¶æ¥(^+-®ç-º·¨ºÖ¥¢ÓhÂ'èºÚNrV¬±ë, (ºW`zÚâvÚ[aÈ¥«,x ¶[IºËaiÛh¦V{*.­Êz)Ú~éܶ*'¶Þ¦Vy)^z§u§]jèqë,rú+y§!Â)Ý£Þ~Þ¶¬©e²W¥«­¢+ÙÕ¹]¥Ð ÀÌØíÑ¥µ¤(%¥´ÀÌØíÍÑÑÕÍmU  =U9 ÀÌØí}½Õ¹Ð¤¬Åt($(%½ÈÀÌØí¥ôÄQ¼U  =U9 ÀÌØí}½Õ¹Ð¤´Ä($$ÀÌØíÍÑÑÕÍlÀÌØí¥tôÑMÑÑÕÌ ÀÌØí¥¤(%9áÐ($(%1½°ÀÌØíÑ¥µÈôQ¥µÉ%¹¥Ð ¤($(%]¡¥±Q¥µÉ¥ ÀÌØíÑ¥µÈ¤±ÐìôÀÌØíÑ¥µ($%½ÈÀÌØí¥ôÄQ¼U =U9 ÀÌØí}½Õ¹Ð¤´Ä($$%%ÑMÑÑÕÌ ÀÌØí¥¤±ÐìÐìÀÌØíÍÑÑÕÍlÀÌØí¥tQ¡¸($$$$ÀÌØíÍÑÑÕÍlÀÌØí¥tôÑMÑÑÕÌ ÀÌØí¥¤(($$$%AɽÍÌ ÀÌØí¥¤($$%¹%($%9áÐ($$($%M±À ÔÀÀ¤(%]¹)¹Õ¹

Share this post


Link to post
Share on other sites

Simple addition property of equality

Code = Help

No = No

No+Code = No+Help

The exact kind of unhelpful comment used solely for incrementing your post count..At least be a dear and help the man out if he has complied to your crudely-stated demands..Or is that too much of a hassle for a {post_count++;} you can achieve by posting one-liners in the Chat Forum?

[quote]Together we might liveDivided we must fall[/quote]

Share this post


Link to post
Share on other sites

Thank you very much! That's exactly the push I needed in the right direction. It actually helped my structure out a lot. Now if only AutoIT had classes so I could get rid of all this id passing. :)

Just had to place your code in a function to replace Sleep(), and add a process check for each window before the small sleep:

Dim $status[UBOUND($g_Account) + 1]
    
    For $id = 1 To UBOUND($g_Account) - 1
        $status[$id] = GetStatus($id)
    Next
You're very welcome :D By the way, not that it matters -at all-, but it's good to get into the habit of formatting loops with the UBound of the array you're actually looping on, instead of another. I know that the UBound of $status and $g_Account are going to be the same, but in some other program somewhere down the road, $g_Account is going to change while you're looping on $status and you'll run into errors. For $id = 1 To UBound($status) - 1 will avoid that, even though it's probably not a problem in this particular script. Just nitpicking, now; sorry :D

The exact kind of unhelpful comment used solely for incrementing your post count..At least be a dear and help the man out if he has complied to your crudely-stated demands..Or is that too much of a hassle for a {post_count++;} you can achieve by posting one-liners in the Chat Forum?

I've been reading coding forums too long: I read that as 'compiled' six or seven times and couldn't figure out what the hell you were trying to say :P

Share this post


Link to post
Share on other sites

Good point, and there is a case in my app that that could have caused an error.

Share this post


Link to post
Share on other sites

Better yet, don't worry about process checking and sleeping, just make sure Jump doesn't go through more than once every x seconds, without pausing.

If GetJumpState($id) Then
                If TimerDiff(GetLastJump($id)) > (150000 + Rand(5000, 10000)) Then
                    Jump($id)
                    SetLastJump($id, TimerInit())
                EndIf
            EndIf

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