dickjones007 Posted November 8, 2011 Posted November 8, 2011 how can i make a button to end the While 1 Wend loop
Moderators Melba23 Posted November 8, 2011 Moderators Posted November 8, 2011 dickjones, Do you seriously expect any concrete help with a question like that? How do you get into the loop? Do you have a GUI to hold the button? Any number of questions spring to mind. How about posting the code you are using and giving a bit more explanation. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
dickjones007 Posted November 8, 2011 Author Posted November 8, 2011 i thought it was something more of a general thing this is the code for which i need the button While 1 $changepixel = PixelChecksum(320, 100, 320, 100) While $changepixel = PixelChecksum(320, 100, 320, 100) Sleep(1000) WEnd $randtim = Random(1300, 4800, 1) Sleep($randtim) $checksum0 = PixelChecksum(89, 76, 130, 103) $checksum1 = PixelChecksum(160, 78, 201, 105) $checksum2 = PixelChecksum(202, 78, 243, 105) $checksum3 = PixelChecksum(244, 78, 285, 105) $checksum4 = PixelChecksum(286, 78, 327, 105) ;~ MsgBox(0, 0, $checksum0) ;~ MsgBox(0, 0, $checksum1) ;~ MsgBox(0, 0, $checksum2) ;~ MsgBox(0, 0, $checksum3) ;~ MsgBox(0, 0, $checksum4) $randomx1 = Random(162, 198, 1) $randomx2 = Random(203, 241, 1) $randomx3 = Random(245, 283, 1) $randomx4 = Random(287, 324, 1) $randomy1 = Random(79, 104, 1) If $checksum0 = $checksum1 Then Sleep(1000) MouseClick("primary", $randomx1, $randomy1) ElseIf $checksum0 = $checksum2 Then Sleep(1000) MouseClick("primary", $randomx2, $randomy1) ElseIf $checksum0 = $checksum3 Then Sleep(1000) MouseClick("primary", $randomx3, $randomy1) ElseIf $checksum0 = $checksum4 Then Sleep(1000) MouseClick("primary", $randomx4, $randomy1) EndIf WEnd this is a part of a whole GUICreate i am making
kylomas Posted November 8, 2011 Posted November 8, 2011 dickjones, If some condition then exitloop, or, some hotkey, or, some accelerator key, or, some event... Lot's of stuff in the help files kylomas Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill
Moderators Melba23 Posted November 8, 2011 Moderators Posted November 8, 2011 dickjones,Is the Help file example for GUICtrlCreateButton that difficult to understand? #include <GUIConstantsEx.au3> $hGUI = GUICreate("Test", 500, 500) $hButton = GUICtrlCreateButton("Exit Loop", 10, 10, 80, 30) GUISetState() While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit Case $hButton ExitLoop ; Exit the loop EndSwitch WEnd MsgBox(0, "Here", "I have exited the loop")All clear? M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
dickjones007 Posted November 9, 2011 Author Posted November 9, 2011 yes but will the code run until it comes to exit button code or will the code stop immediately after the button is pushed?
Moderators Melba23 Posted November 9, 2011 Moderators Posted November 9, 2011 dickjones, If you put the Switch GUIGetMsg() structure in the While...WEnd loop the code will run until the message queue is polled. I see you have a lot of Sleep lines in yoru loop - you can speed up the polling by replacing these lines by somethin gliek this: ; Sleep(1000) ; Get a timestamp $iBegin = TimerInit() ; Until the time reaches the required number of msec since the timestamp While TimerDiff($iBegin) < 1000 ; Poll the message queue Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit Case $hButton ExitLoop 2 ; Exit both loops - this one and the external one EndSwitch WEnd This way the script remains responsive during the delay period of the internal loop and a button click is honoured as soon as possible. All clear? M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
dickjones007 Posted November 11, 2011 Author Posted November 11, 2011 expandcollapse popupWhile 1 $changepixel = PixelChecksum(320, 100, 320, 100) While $changepixel = PixelChecksum(320, 100, 320, 100) Sleep(1000) WEnd $randtim = Random(1300, 4800, 1) Sleep($randtim) $checksum0 = PixelChecksum(89, 76, 130, 103) $checksum1 = PixelChecksum(160, 78, 201, 105) $checksum2 = PixelChecksum(202, 78, 243, 105) $checksum3 = PixelChecksum(244, 78, 285, 105) $checksum4 = PixelChecksum(286, 78, 327, 105) $randomx1 = Random(162, 198, 1) $randomx2 = Random(203, 241, 1) $randomx3 = Random(245, 283, 1) $randomx4 = Random(287, 324, 1) $randomy1 = Random(79, 104, 1) If $checksum0 = $checksum1 Then Sleep(1000) MouseClick("primary", $randomx1, $randomy1) ElseIf $checksum0 = $checksum2 Then Sleep(1000) MouseClick("primary", $randomx2, $randomy1) ElseIf $checksum0 = $checksum3 Then Sleep(1000) MouseClick("primary", $randomx3, $randomy1) ElseIf $checksum0 = $checksum4 Then Sleep(1000) MouseClick("primary", $randomx4, $randomy1) EndIf Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit Case $GUI_Button_exitloop ExitLoop 2 EndSwitch WEnd am i getting something wrong here? i keep pressing exitloop button but the code still continues. how so? btw i am beginner here. for now i will keep my Sleep lines and will consider your timerinit suggestion for something else. thanx for that. also i mostly take parts of finished codes and put it together for something i need. but i am learning that way. just dont hate me for my newb question and problems
Moderators Melba23 Posted November 11, 2011 Moderators Posted November 11, 2011 dickjones, dont hate me for my newb question and problemsOf course not. The problem with your loop is that the script becomes totally unresponsive during the Sleep lines - absolutely nothing happens at all. You have to wait until you get to the GUIGetMsg line before your button press will be seen and acted upon. That is why I suggested replacing them with TimerInit/Diff loops - these give you a pretty instant response. You can write a short function to hold the Timer loop which makes it very easy to code - like this: expandcollapse popupWhile 1 $changepixel = PixelChecksum(320, 100, 320, 100) While $changepixel = PixelChecksum(320, 100, 320, 100) ; Wait for a sec - but look for the button being pressed by using the function If _My_Sleep(1000) = True Then ; If it was then exit the 2 loops and carry on ExitLoop 2 EndIf WEnd $randtim = Random(1300, 4800, 1) If _My_Sleep($randtim) = True Then ; Only the 1 loop to exit this time ExitLoop EndIf $checksum0 = PixelChecksum(89, 76, 130, 103) $checksum1 = PixelChecksum(160, 78, 201, 105) $checksum2 = PixelChecksum(202, 78, 243, 105) $checksum3 = PixelChecksum(244, 78, 285, 105) $checksum4 = PixelChecksum(286, 78, 327, 105) $randomx1 = Random(162, 198, 1) $randomx2 = Random(203, 241, 1) $randomx3 = Random(245, 283, 1) $randomx4 = Random(287, 324, 1) $randomy1 = Random(79, 104, 1) If $checksum0 = $checksum1 Then If _My_Sleep(1000) = True Then ExitLoop EndIf MouseClick("primary", $randomx1, $randomy1) ElseIf $checksum0 = $checksum2 Then If _My_Sleep(1000) = True Then ExitLoop EndIf MouseClick("primary", $randomx2, $randomy1) ElseIf $checksum0 = $checksum3 Then If _My_Sleep(1000) = True Then ExitLoop EndIf MouseClick("primary", $randomx3, $randomy1) ElseIf $checksum0 = $checksum4 Then If _My_Sleep(1000) = True Then ExitLoop EndIf MouseClick("primary", $randomx4, $randomy1) EndIf ; And there is no need to check again here as we are doing it often enough as we call the _My_Sleep function ;Switch GUIGetMsg() ; Case $GUI_EVENT_CLOSE ; Exit ; Case $GUI_Button_exitloop ; ExitLoop 2 ;EndSwitch WEnd Func _My_Sleep($iDelay) $iBegin = TimerInit() ; Until the time reaches the required number of msec since the timestamp While TimerDiff($iBegin) < $iDelay ; Poll the message queue Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit Case $hButton Return True ; Tell the main loop the button was pressed and return immediately EndSwitch WEnd ; We are here because the loop has waited for the required time ; Tell the main loop the button was not pressed Return False EndFunc Please ask if you have any questions. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
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