trnew Posted April 16, 2013 Share Posted April 16, 2013 (edited) Hi.I need some help with a GUI.I have one button which I attached a function to, but I want to stop a loop at some point (by pressing a key) and run it again later by pressing the button again, so I made use of ExitLoop.. After a while I noticed that when I click the button again it won't loop anymore, but do only one cycle and I don't understand why.I want to know what I should write to make it work( like press button>loops>press key>stops>press button again>loops and so on) My script: expandcollapse popup#include #include #include #Region ### START Koda GUI section ### Form= $Form1 = GUICreate("Autodevelop", 301, 301) $Button1 = GUICtrlCreateButton("b1", 50, 16, 201, 41) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### Global $Paused Func TogglePause() ; the pause function $Paused = NOT $Paused While $Paused ToolTip('Please press "F8" to resume!',700,400,"",1,2) sleep(1000) WEnd ToolTip("") EndFunc Func Terminate() ; the exit function Exit EndFunc Func Stop() EndFunc HotKeySet("{F8}", "TogglePause") ; pause HotKeySet("{ESC}", "Terminate") ; close HotKeySet("{s}", "Stop") While 1 $do=GUIGetMsg() switch $do case $GUI_EVENT_CLOSE Exit Case $Button1 While 1 mousemove(615,555) mouseclick("") sleep(800) mousemove(620,556) mouseclick("") sleep(800) mousemove(580,556) If @HotKeyPressed = "{s}" Then ExitLoop EndIf WEnd EndSwitch WEnd I appreciate any help regarding this script. Edited April 16, 2013 by trnew Link to comment Share on other sites More sharing options...
FireFox Posted April 16, 2013 Share Posted April 16, 2013 Hi, Welcome to the autoit forum I would do it this way : expandcollapse popup#include <GUIConstantsEx.au3> Global $blPaused = False, $blStopped = False HotKeySet("{F8}", "TogglePause") ; pause HotKeySet("{ESC}", "Terminate") ; close HotKeySet("{s}", "Stop") #region ### START Koda GUI section ### Form= $hGUI = GUICreate("Autodevelop", 301, 301) $iButton1 = GUICtrlCreateButton("b1", 50, 16, 201, 41) GUISetState(@SW_SHOW, $hGUI) #endregion ### END Koda GUI section ### While 1 $iMsg = GUIGetMsg() Switch $iMsg Case $GUI_EVENT_CLOSE ExitLoop Case $iButton1 $blStopped = False While Not $blStopped MouseMove(615, 555) MouseClick("") Sleep(800) MouseMove(620, 556) MouseClick("") Sleep(800) MouseMove(580, 556) WEnd EndSwitch Sleep(10) WEnd GUIDelete($hGUI) Func TogglePause() ; the pause function $blPaused = Not $blPaused If $blPaused Then ToolTip('Please press "F8" to resume!', 700, 400, "", 1, 2) While $blPaused Sleep(10) WEnd Else ToolTip("") EndIf EndFunc ;==>TogglePause Func Terminate() ; the exit function Exit EndFunc ;==>Terminate Func Stop() $blStopped = True EndFunc ;==>Stop Take a look at the script structure to keep it clear. Br, FireFox. Link to comment Share on other sites More sharing options...
trnew Posted April 17, 2013 Author Share Posted April 17, 2013 Thank you.This is definitely what I am looking for.I wouldn't have thought about using booleans. Also, I have some questions : What's the role of GUIDelete ( what kind of "delete" is this, cause it doesn't seem to delete/close the GUI windows or buttons )? What's the role of sleep(10) after EndSwitch?(it seems to run fine without it) Link to comment Share on other sites More sharing options...
FireFox Posted April 17, 2013 Share Posted April 17, 2013 What's the role of GUIDelete ( what kind of "delete" is this, cause it doesn't seem to delete/close the GUI windows or buttons )?It's a good coding pratice to delete the GUIs before exiting the script to release the ressources yourself.What's the role of sleep(10) after EndSwitch?(it seems to run fine without it)Less CPU usage.Br, FireFox. Link to comment Share on other sites More sharing options...
trnew Posted April 17, 2013 Author Share Posted April 17, 2013 Thanks for explaining.It uses less CPU because it pauses for a while there, right? And I got something else, not related to loops.I want to background to this GUI to make nice, so I found this would work -GUICtrlCreatePic('...abc.jpg', 0, 0, 0, 0)- It's good, but it makes my buttons disappear, though when I click the area where the button should be, the button appears.Any idea why that happens and how to make the area where buttons are visible? Link to comment Share on other sites More sharing options...
BrewManNH Posted April 17, 2013 Share Posted April 17, 2013 Read the remarks in the help file for GUICtrlCreatePic, it tells you what to do. If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator Link to comment Share on other sites More sharing options...
trnew Posted April 17, 2013 Author Share Posted April 17, 2013 Yeah, alreay looked into that before, but I didn't read that part.. I also checked out other topic to see how it's done (if somebody will ever be interested : )Anyway if this will be of help here is what I added ( order is important: GUI window 1st>GUI pic 2nd>disable GUI pic |so other controls won't overlap| 3rd>Controls 4th>GUI show 5th ) :$hGUI = GUICreate("Autodevelop", 301, 301)GUICtrlCreatePic('...abc.jpg', 0, 0, 0, 0) GuiCtrlSetState(-1, $GUI_DISABLE)$iButton1 = GUICtrlCreateButton("b1", 50, 16, 201, 41)GUISetState(@SW_SHOW, $hGUI) Link to comment Share on other sites More sharing options...
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