Sign in to follow this  
Followers 0
Frit

What's the problem there?

14 posts in this topic

#1 ·  Posted (edited)

$GUI = GUICreate("Title", 150 , 40)
$CheckBox1 = GUICtrlCreateCheckBox('Start', 10, 10)
$window = "Client"
GUISetState ()


; When check box is marked, call function "Go"
While 1
    $msg = GUIGetMsg()
    If $msg = - 3 Then Exit
    If $msg = $CheckBox1 And GUICtrlRead($CheckBox1) = 1 Then
    WinActivate($window)
    Call ("Go")
    Endif
Wend

; Send Ctrl + left and Ctrl + right 9999 times with a pause between them.
Func Go()
For $x = 1 to 9999
Send("^+{LEFT}")
Sleep(1000)
Send("^+{RIGHT}")
Sleep(1000)
Next
EndFunc

I really don't know whats the problem (maybe with the For inside Function...)

Help me, please.

Edited by Frit

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

I really don't know whats the problem (maybe with the For inside Function...)

Help me, please.

There is no problem with your script... when you Check the checkbox the func go will be run and loop 9999 times...

Unless that's not what you want ....

by the why... its standard practice to do Go() in stead of Call("go")

Edited by JdeB

Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

Aww..

Just forget it, I putted the wrong "send" command xD

But now, i have another problem: The window don't close when i click "X".

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Thats becasue.. its is looping 99999 times, with no cheecking to see if the Exit button was pressed.

You should set a HotKey like ESC or someting at the beginning of your script to close it...

HotKeySet("{ESC}", "ExitPrg")
$GUI = GUICreate("Title", 150 , 40)
$CheckBox1 = GUICtrlCreateCheckBox('Start', 10, 10)
$window = "Client"
GUISetState ()


; When check box is marked, call function "Go"
While 1
    $msg = GUIGetMsg()
    If $msg = - 3 Then Exit
    If $msg = $CheckBox1 And GUICtrlRead($CheckBox1) = 1 Then
    WinActivate($window)
    Call ("Go")
    Endif
Wend

; Send Ctrl + left and Ctrl + right 9999 times with a pause between them.
Func Go()
For $x = 1 to 9999
Send("^+{LEFT}")
Sleep(1000)
Send("^+{RIGHT}")
Sleep(1000)
Next
EndFunc

Func ExitPrg()
    Exit
EndFunc

this way, u can exit.. while inside that for loop

Edited by CHRIS95219

Share this post


Link to post
Share on other sites

Hmm.. okay, thanks...

Everything is going well now, just one more question: How do I stop that function?

Share this post


Link to post
Share on other sites

what do u mean stop it? after the loop is done, it will return to the While statement...

Share this post


Link to post
Share on other sites

I mean, if the function "go" is running, and i do something (in this case, unmark the checkbox) it stops.

Share this post


Link to post
Share on other sites

I mean, if the function "go" is running, and i do something (in this case, unmark the checkbox) it stops.

Instead of a For loop, just use a While loop:

While GUICtrlRead($CheckBox1) == 1
   ;Do loop stuff
WEnd

[u]My UDFs[/u]Coroutine Multithreading UDF LibraryStringRegExp GuideRandom EncryptorArrayToDisplayString"The Brain, expecting disaster, fails to find the obvious solution." -- neogia

Share this post


Link to post
Share on other sites

same idea

; Press Esc to terminate script, Pause/Break to "pause"

#include <GuiConstants.au3>

Global $Paused, $Go
HotKeySet("{PAUSE}", "TogglePause")
HotKeySet("{ESC}", "ExitPrg")
HotKeySet("{F9}", "Go")


$GUI = GUICreate("Title", 150, 40)
$CheckBox1 = GUICtrlCreateCheckbox('Start', 10, 10)
$window = "Client"
GUISetState()


; When check box is marked, call function "Go"
While 1
    $msg = GUIGetMsg()
    If $msg = -3 Then Exit
    
    $ans = GUICtrlRead($CheckBox1)
    If $ans = 1 Then
        WinActivate($window)
        $Go = 1
    Else
    ;WinActivate($window); other window ???
        $Go = 0
    EndIf
    
    If $Go Then Go()
    
WEnd

; =================== Functions =============


Func TogglePause()
    $Paused = Not $Paused
    While $Paused
        Sleep(100)
        ToolTip('Script is "Paused"', 0, 0)
    WEnd
    ToolTip("")
EndFunc  ;==>TogglePause

; Send Ctrl + left and Ctrl + right 9999 times with a pause between them.

Func Go()
    Send("^+{LEFT}")
    Sleep(1000)
    Send("^+{RIGHT}")
    Sleep(1000)
EndFunc  ;==>Go


Func ExitPrg()
    Exit
EndFunc  ;==>ExitPrg

8)


NEWHeader1.png

Share this post


Link to post
Share on other sites

#10 ·  Posted (edited)

Instead of a For loop, just use a While loop:

While GUICtrlRead($CheckBox1) == 1
 ;Do loop stuff
WEnd
That's a good point neogia:
HotKeySet("{ESC}", "ExitPrg")
Global $window = "Client", $cCount = ''

$GUI = GUICreate("Title", 150 , 40)
$CheckBox1 = GUICtrlCreateCheckBox('Start', 10, 10)
GUISetState ()


; When check box is marked, call function "Go"
While 1
    $msg = GUIGetMsg()
    If $msg = - 3 Then Exit
    If $msg = $CheckBox1 And GUICtrlRead($CheckBox1) = 1 Then
        While GUICtrlRead($CheckBox1) = 1 And $cCount <= 9999
            $CKMsg = GUIGetMsg(); The 2 sleep 1000's really make this a moot point, the check box or hotkey is still the best way to exit if you need the sleeps()
            If $CKMsg = - 3 Then Exit; See above
            If Not WinActive($window) Then WinActivate($window)
            Send("^+{LEFT}")
            Sleep(1000)
            Send("^+{RIGHT}")
            Sleep(1000)
            $cCount = $cCount + 1
        WEnd
    Endif
Wend

Func ExitPrg()
    Exit
EndFunc
Might also want to look at maybe OnEventMode options rather than GUIGetMsg() if this is going to be your entire script. Edited by SmOke_N

[center]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.[/center]

Share this post


Link to post
Share on other sites

with mine you can do other things while it is doing the loop

8)


NEWHeader1.png

Share this post


Link to post
Share on other sites

with mine you can do other things while it is doing the loop

8)

Talking about exiting the function Val... do you BitAnd() the GUIGetMsg() too :)

[center]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.[/center]

Share this post


Link to post
Share on other sites

Talking about exiting the function Val... do you BitAnd() the GUIGetMsg() too :)

i did find it in help

For Checkbox, Radio control several states can be returned as $GUI_FOCUS and $GUI_CHECKED,. So use BitAnd(GUICtrlRead($Item),$GUI_CHECKED) to test if the control is checked.

most times i just try to fix the problem at hand

.... if they SHOW ME SOME SCRIPT

8)


NEWHeader1.png

Share this post


Link to post
Share on other sites

i did find it in help

most times i just try to fix the problem at hand

.... if they SHOW ME SOME SCRIPT

8)

LOL... well, I'll say this.. I will lay even odds that even BitAnd() is going to have to wait the 2 seconds before those 2 commands are done to work :)

[center]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.[/center]

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