Jump to content

Stopping the loop


nf67
 Share

Recommended Posts

Hello there, I am trying to make a WaveMaker for MSN, it sends the text you type in the inputfield to the other person with increasing ( and later decreasing ) numbers of spaces. This creates a funny "waving" effect. Now I can't really get the Stop button to work, please help:

#include <GUIConstants.au3>

#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 312, 61, 193, 125)
$Text = GUICtrlCreateInput("texttotype", 8, 8, 297, 21)
$Spam = GUICtrlCreateButton("Spam", 208, 32, 99, 25, 0)
$Stop = GUICtrlCreateButton("Stop", 8, 32, 49, 17)
$StopValue = 0; Stopvalue starts below 1 for the Spam Loop
AutoItSetOption ( "SendKeyDelay", 1 )
GUISetState(@SW_SHOW)
#EndRegion ### START Koda GUI section ### Form=

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit

        Case $Spam
            Sleep ( 5000 )           ; Time to put cursor somewhere
               While $StopValue <= 1; Loop from here to WEnd if StopValue is below 1
            Send(GUICtrlRead($Text))                                  ;Start of the wave effect ( not important for problem )
            Send("{ENTER}") 
            Send("{SPACE}" & GUICtrlRead($Text))     
            Send("{ENTER}") 
            Send("{SPACE}{SPACE}" & GUICtrlRead($Text))  
            Send("{ENTER}")
            Send("{SPACE}{SPACE}{SPACE}" & GUICtrlRead($Text))     
            Send("{ENTER}") 
            Send("{SPACE}{SPACE}{SPACE}{SPACE}" & GUICtrlRead($Text))    
            Send("{ENTER}")
            Send("{SPACE}{SPACE}{SPACE}{SPACE}{SPACE}" & GUICtrlRead($Text))       
            Send("{ENTER}") 
            Send("{SPACE}{SPACE}{SPACE}{SPACE}{SPACE}{SPACE}" & GUICtrlRead($Text))  
            Send("{ENTER}")
            Send("{SPACE}{SPACE}{SPACE}{SPACE}{SPACE}" & GUICtrlRead($Text))        
            Send("{ENTER}") 
            Send("{SPACE}{SPACE}{SPACE}{SPACE}" & GUICtrlRead($Text))    
            Send("{ENTER}")
            Send("{SPACE}{SPACE}{SPACE}" & GUICtrlRead($Text))      
            Send("{ENTER}") 
            Send("{SPACE}{SPACE}" & GUICtrlRead($Text))  
            Send("{ENTER}")
            Send("{SPACE}" & GUICtrlRead($Text))       
            Send("{ENTER}")                  ;End of the wave effect ( not important for problem ), should start at begin again.
               WEnd                 ;End of the loop from While
        
        Case $Stop                   ; If $Stop is pressed
             $StopValue = 2         ; Make $StopValue more than 1 to break the Spam Loop
    EndSwitch
WEnd

Thanks a lot!

Chris

Edited by nf67
Link to comment
Share on other sites

  • Replies 43
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

The problem is you're starting a new Loop within the While statement for gathering GuiGetMSG, so it never gets back to GuiGetMSG. Make the wave part of the first While Loop rather than start a new one.

Here's how I would do it.

#include <GUIConstants.au3>

#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 312, 61, 193, 125)
$Text = GUICtrlCreateInput("texttotype", 8, 8, 297, 21)
$Spam = GUICtrlCreateButton("Spam", 208, 32, 99, 25, 0)
$Stop = GUICtrlCreateButton("Stop", 8, 32, 49, 17)
$StopValue = 1;
AutoItSetOption ( "SendKeyDelay", 1 )
GUISetState(@SW_SHOW)
#EndRegion ### START Koda GUI section ### Form=

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Spam
            $StopValue = 0
        Case $Stop
            $StopValue = 1
    EndSwitch
         
    If $StopValue = 0 Then
        Sleep ( 5000 )
        Send(GUICtrlRead($Text))
        Send("{ENTER}") 
        Send("{SPACE}" & GUICtrlRead($Text))     
        Send("{ENTER}") 
        Send("{SPACE}{SPACE}" & GUICtrlRead($Text))     
        Send("{ENTER}")
        Send("{SPACE}{SPACE}{SPACE}" & GUICtrlRead($Text))       
        Send("{ENTER}") 
        Send("{SPACE}{SPACE}{SPACE}{SPACE}" & GUICtrlRead($Text))     
        Send("{ENTER}")
        Send("{SPACE}{SPACE}{SPACE}{SPACE}{SPACE}" & GUICtrlRead($Text))       
        Send("{ENTER}") 
        Send("{SPACE}{SPACE}{SPACE}{SPACE}{SPACE}{SPACE}" & GUICtrlRead($Text))     
        Send("{ENTER}")
        Send("{SPACE}{SPACE}{SPACE}{SPACE}{SPACE}" & GUICtrlRead($Text))        
        Send("{ENTER}") 
        Send("{SPACE}{SPACE}{SPACE}{SPACE}" & GUICtrlRead($Text))     
        Send("{ENTER}")
        Send("{SPACE}{SPACE}{SPACE}" & GUICtrlRead($Text))        
        Send("{ENTER}") 
        Send("{SPACE}{SPACE}" & GUICtrlRead($Text))     
        Send("{ENTER}")
        Send("{SPACE}" & GUICtrlRead($Text))       
        Send("{ENTER}")
    EndIf
WEnd
Edited by spudw2k
Link to comment
Share on other sites

Test a FOR TO STEP NEXT loop like this:

#include <GUIConstants.au3>

#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 312, 61, 193, 125)
$Text = GUICtrlCreateInput("texttotype", 8, 8, 297, 21)
$Spam = GUICtrlCreateButton("Spam", 208, 32, 99, 25, 0)
$Stop = GUICtrlCreateButton("Stop", 8, 32, 49, 17)
$StopValue = 0; Stopvalue starts below 1 for the Spam Loop
AutoItSetOption ( "SendKeyDelay", 1 )
GUISetState(@SW_SHOW)
#EndRegion ### START Koda GUI section ### Form=

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit

        Case $Spam
            Sleep ( 5000 )             ; Time to put cursor somewhere
            FOR $loop = $StopValue TO 1 STEP 1 ;;This starts the loop from $StopValue, and sets +1 every "round" until it reaches 1
            Send(GUICtrlRead($Text))                                  ;Start of the wave effect ( not important for problem )
            Send("{ENTER}")
            Send("{SPACE}" & GUICtrlRead($Text))    
            Send("{ENTER}")
            Send("{SPACE}{SPACE}" & GUICtrlRead($Text))    
            Send("{ENTER}")
            Send("{SPACE}{SPACE}{SPACE}" & GUICtrlRead($Text))      
            Send("{ENTER}")
            Send("{SPACE}{SPACE}{SPACE}{SPACE}" & GUICtrlRead($Text))    
            Send("{ENTER}")
            Send("{SPACE}{SPACE}{SPACE}{SPACE}{SPACE}" & GUICtrlRead($Text))      
            Send("{ENTER}")
            Send("{SPACE}{SPACE}{SPACE}{SPACE}{SPACE}{SPACE}" & GUICtrlRead($Text))    
            Send("{ENTER}")
            Send("{SPACE}{SPACE}{SPACE}{SPACE}{SPACE}" & GUICtrlRead($Text))        
            Send("{ENTER}")
            Send("{SPACE}{SPACE}{SPACE}{SPACE}" & GUICtrlRead($Text))    
            Send("{ENTER}")
            Send("{SPACE}{SPACE}{SPACE}" & GUICtrlRead($Text))        
            Send("{ENTER}")
            Send("{SPACE}{SPACE}" & GUICtrlRead($Text))    
            Send("{ENTER}")
            Send("{SPACE}" & GUICtrlRead($Text))      
            Send("{ENTER}")                     ;End of the wave effect ( not important for problem ), should start at begin again.
            NEXT ;;NEXT
        
        Case $Stop                     ; If $Stop is pressed
             $StopValue = 2            ; Make $StopValue more than 1 to break the Spam Loop
    EndSwitch
WEnd
Link to comment
Share on other sites

Yes a hotkey would do it, but it doesnt just look professional.

You could try with putting the spam in one process (another exe), and kill it when you need to stop (it isnt that profession either).

Or add another GUI that can handle it, and then control it with the mainGUI.

Link to comment
Share on other sites

Would that be:

HotKeySet ( {ESC}, Terminate )

or

HotKeySet ( {ESC}, TogglePause )

?

Please correct me if both things are wrong, there is no AutoIt on this PC, nor a help file.

Thanks

P.S: What about HotKey -> Scriptpause ----&---- Button -> Hotkey ( which pauses the script )

Edited by nf67
Link to comment
Share on other sites

You can setup the hotkeys like this.

HotKeySet ("{ESC}", "Terminate")
Func Terminate()
    If MsgBox(4,"Exit","Are you sure you want to exit?") = 6 Then
        Exit 0                          
    EndIf
EndFunc

HotKeySet("p", "Pausenow")
Func Pausenow()
    MsgBox(0,"Paused","The program is now paused. Press OK to start again")
   Do
        Sleep(500)
   Until 1
EndFunc

I havent tested this, sorry, just created it in notepad.. but hope it works for you

Regards

Link to comment
Share on other sites

Hey I got it! It was bugging me that I couldn't do the script working as you wanted it to do so this is how you stop the loop with the button:

#include <GUIConstants.au3>

#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 312, 61, 193, 125)
$Text = GUICtrlCreateInput("texttotype", 8, 8, 297, 21)
$Spam = GUICtrlCreateButton("Spam", 208, 32, 99, 25, 0)
$Stop = GUICtrlCreateButton("Stop", 8, 32, 49, 17)
$StopValue = 0; Stopvalue starts below 1 for the Spam Loop
AutoItSetOption ( "SendKeyDelay", 1 )
GUISetState(@SW_SHOW)
#EndRegion ### START Koda GUI section ### Form=

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit

        Case $Spam
            Sleep ( 5000 )             ; Time to put cursor somewhere
               While $StopValue <= 1; Loop from here to WEnd if StopValue is below 1
            $nMsg = GUIGetMsg()
            If $nMsg = $Stop Then ExitLoop ;HEUREKA :P
            Send(GUICtrlRead($Text))                                  ;Start of the wave effect ( not important for problem )
            Send("{ENTER}")
            Send("{SPACE}" & GUICtrlRead($Text))    
            Send("{ENTER}")
            Send("{SPACE}{SPACE}" & GUICtrlRead($Text))    
            Send("{ENTER}")
            Send("{SPACE}{SPACE}{SPACE}" & GUICtrlRead($Text))      
            Send("{ENTER}")
            Send("{SPACE}{SPACE}{SPACE}{SPACE}" & GUICtrlRead($Text))    
            Send("{ENTER}")
            Send("{SPACE}{SPACE}{SPACE}{SPACE}{SPACE}" & GUICtrlRead($Text))      
            Send("{ENTER}")
            Send("{SPACE}{SPACE}{SPACE}{SPACE}{SPACE}{SPACE}" & GUICtrlRead($Text))    
            Send("{ENTER}")
            Send("{SPACE}{SPACE}{SPACE}{SPACE}{SPACE}" & GUICtrlRead($Text))        
            Send("{ENTER}")
            Send("{SPACE}{SPACE}{SPACE}{SPACE}" & GUICtrlRead($Text))    
            Send("{ENTER}")
            Send("{SPACE}{SPACE}{SPACE}" & GUICtrlRead($Text))        
            Send("{ENTER}")
            Send("{SPACE}{SPACE}" & GUICtrlRead($Text))    
            Send("{ENTER}")
            Send("{SPACE}" & GUICtrlRead($Text))      
            Send("{ENTER}")                     ;End of the wave effect ( not important for problem ), should start at begin again.
               WEnd                    ;End of the loop from While
        
        Case $Stop                     ; If $Stop is pressed
             $StopValue = 2            ; Make $StopValue more than 1 to break the Spam Loop
    EndSwitch
WEnd

$nMsg = GUIGetMsg()
If $nMsg = $Stop Then ExitLoop
= was added in the spam loop, I hope it works! (I cant test it on this computer) Edited by LinuZ
Link to comment
Share on other sites

Yes LinuZ that's better than the hotkeys..

well nf67 I would might have send the text from the input raw or else it would crash when you insert something like !

What I would do is:

#include <GUIConstants.au3>

#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 312, 61, 193, 125)
$Text = GUICtrlCreateInput("texttotype", 8, 8, 297, 21)
$Spam = GUICtrlCreateButton("Spam", 208, 32, 99, 25, 0)
$Stop = GUICtrlCreateButton("Stop", 8, 32, 49, 17)
$StopValue = 0; Stopvalue starts below 1 for the Spam Loop
AutoItSetOption ( "SendKeyDelay", 1 )
GUISetState(@SW_SHOW)
#EndRegion ### START Koda GUI section ### Form=

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit

        Case $Spam
            Sleep ( 5000 )             ; Time to put cursor somewhere
               While $StopValue <= 1; Loop from here to WEnd if StopValue is below 1
            $nMsg = GUIGetMsg()
            If $nMsg = $Stop Then ExitLoop ;HEUREKA 
            Send(GUICtrlRead($Text),1) ;Start of the wave effect ( not important for problem )
            Send("{ENTER}")
            Send("  " & GUICtrlRead($Text),1)    ; 2spaces
            Send("{ENTER}")
            Send("    " & GUICtrlRead($Text),1)    ;4 spaces
            Send("{ENTER}")
            Send("      " & GUICtrlRead($Text),1)    ;6 spaces  
            Send("{ENTER}")
            Send("        " & GUICtrlRead($Text),1)    ;8 spaces
            Send("{ENTER}")
            Send("          " & GUICtrlRead($Text),1)     ;10 spaces 
            Send("{ENTER}")
            Send("            " & GUICtrlRead($Text),1)    ;12 spaces
            Send("{ENTER}")
            Send("          " & GUICtrlRead($Text),1)     ;10 spaces 
            Send("{ENTER}")
            Send("        " & GUICtrlRead($Text),1)    ;8 spaces
            Send("{ENTER}")
            Send("      " & GUICtrlRead($Text),1)    ;6 spaces 
            Send("{ENTER}")
            Send("    " & GUICtrlRead($Text),1)    ;4 spaces
            Send("{ENTER}")
            Send("  " & GUICtrlRead($Text),1)   ; 2 spaces     
            Send("{ENTER}")         ;End of the wave effect ( not important for problem ), should start at begin again.
               WEnd                 ;End of the loop from While
        
        Case $Stop                  ; If $Stop is pressed
             $StopValue = 2         ; Make $StopValue more than 1 to break the Spam Loop
    EndSwitch
WEndoÝ÷ Ù.q©í¯+^²Ü¨ºº0­©÷Þ)ì×Ûaz{{Z¶©¥éìjwméí¯+aƧvÇ°«b²©¥éâ^ªÝ°@ÈLò¢çhm)¶ÛazÊZqë+k¨¹Æ§j[(vbëaÆ®¶­se6VæBgV÷C·´TåDU'ÒgV÷C²¥6VæBgV÷C·µ54W×µ54WÒgV÷C²¥6VæBuT7G&Å&VBb33cµFWBÃ
Edited by newbiescripter
Link to comment
Share on other sites

The problem here is that you're doing alot of other stuff while also trying to handle the gui, that's why the stop button doesn't "work".

To get around this, you could do like LinuZ did in his code, but it would still not be really responsive(as it only checks if stop was pressed before executing all the sends, etc.),

the other solution is using GUIOnEventMode(look at Opt in the helpfile), or perhaps(if you would like to take it that far) create a separate script that does the Sending. :)

Good Luck

Edit:

Also

$nMsg = GUIGetMsg()
            If $nMsg = $Stop Then ExitLoop;HEUREKA tongue.gif

Could be shortened to

If GUIGetMsg() = $Stop Then ExitLoop
Edited by FreeFry
Link to comment
Share on other sites

Yes, now when I tested the code I see my example must complete the While loop to stop, and it is not so handy :/

Hey FreeFry (föresten e jag finlandsvensk :)) if I add the Opt (GUIOnEventMode, 1), I cant control the GUI at all it doesnt respond to me, not even when closing it. Why? Thanks/Tack

Link to comment
Share on other sites

Hehe, jag föredrar o ha diskussionen på engelska, eftersom då kan andra lära sej utav det man surrar om. ;) // Swedish

Anyways, when you're using GUIOnEventMode, you also have to use GUICtrlSetOnEvent, and GUISetOnEvent to 'handle' the gui instead(no need to use GUIGetMsg)

As stated in the helpfile:

If the GUIOnEventMode option is set to 1 then the return from GUIGetMsg is always 0 and the @error is set to 1.

I suggest you have a look in the helpfile regarding GUICtrlSetOnEvent and GUISetOnEvent, it's explained there how to use it. :)

Link to comment
Share on other sites

Linuz script works after his edit :-) that was indeed the "magic missing piece" I was looking for.

It still finishes the loop after pressing stop but I really don't care about that.

I'll edit the stopvalue crap so it can Spam again after pressing stop ( right now stop also raises the StopValue and it won't loop when it's > 1 ).

FreeFry, have you also watched DeathNote?

Link to comment
Share on other sites

Hehe, jag föredrar o ha diskussionen på engelska, eftersom då kan andra lära sej utav det man surrar om. :) // Swedish

[swedish]Samma här, dessutom passar termerna bättre [/swedish]

Thanks! I havent used it before, but I will try it now. Nice explanation.

No I haven't watched DeathNote, what is it about?

Surely something alike Bleach from your sig. Edited by LinuZ
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...