Frit Posted March 10, 2006 Posted March 10, 2006 (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 March 10, 2006 by Frit
Developers Jos Posted March 10, 2006 Developers Posted March 10, 2006 (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 March 10, 2006 by JdeB SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past.
Frit Posted March 10, 2006 Author Posted March 10, 2006 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".
cppman Posted March 10, 2006 Posted March 10, 2006 (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 March 10, 2006 by CHRIS95219 Miva OS Project
Frit Posted March 10, 2006 Author Posted March 10, 2006 Hmm.. okay, thanks... Everything is going well now, just one more question: How do I stop that function?
cppman Posted March 10, 2006 Posted March 10, 2006 what do u mean stop it? after the loop is done, it will return to the While statement... Miva OS Project
Frit Posted March 10, 2006 Author Posted March 10, 2006 I mean, if the function "go" is running, and i do something (in this case, unmark the checkbox) it stops.
neogia Posted March 10, 2006 Posted March 10, 2006 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
Valuater Posted March 10, 2006 Posted March 10, 2006 same idea expandcollapse popup; 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)
Moderators SmOke_N Posted March 10, 2006 Moderators Posted March 10, 2006 (edited) Instead of a For loop, just use a While loop: While GUICtrlRead($CheckBox1) == 1 ;Do loop stuff WEndThat'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 EndFuncMight also want to look at maybe OnEventMode options rather than GUIGetMsg() if this is going to be your entire script. Edited March 10, 2006 by SmOke_N 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.
Valuater Posted March 10, 2006 Posted March 10, 2006 with mine you can do other things while it is doing the loop 8)
Moderators SmOke_N Posted March 10, 2006 Moderators Posted March 10, 2006 with mine you can do other things while it is doing the loop8)Talking about exiting the function Val... do you BitAnd() the GUIGetMsg() too 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.
Valuater Posted March 10, 2006 Posted March 10, 2006 Talking about exiting the function Val... do you BitAnd() the GUIGetMsg() too i did find it in helpFor 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 SCRIPT8)
Moderators SmOke_N Posted March 10, 2006 Moderators Posted March 10, 2006 i did find it in helpmost times i just try to fix the problem at hand.... if they SHOW ME SOME SCRIPT8)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 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.
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now