Jump to content
Ian_Mac

Pause or stop the script if the button is cilicked

Recommended Posts

Ian_Mac

Okey guys , here's the thing, My script is running fine, but when it's already running i cant   turn it off or pause by clicking the on/off button  unless i manually close it on my taskbar. What i wanted to happen is "if i click the ($switch = turn On and Off Button) to Off the script will STOP Running but not closing the entire GUI because i tried to use Exit and ExitLoop but it closes the entire GUI. and i don't want that to happen.  

BTW. I'm new in AutoIT and practice scripting hope somebody could help me :) Godbless. feel free to view my script

Practice.au3

Share this post


Link to post
Share on other sites
MattHiggs
23 minutes ago, Ian_Mac said:

Okey guys , here's the thing, My script is running fine, but when it's already running i cant   turn it off or pause by clicking the on/off button  unless i manually close it on my taskbar. What i wanted to happen is "if i click the ($switch = turn On and Off Button) to Off the script will STOP Running but not closing the entire GUI because i tried to use Exit and ExitLoop but it closes the entire GUI. and i don't want that to happen.  

BTW. I'm new in AutoIT and practice scripting hope somebody could help me :) Godbless. feel free to view my script

Practice.au3

So I am looking at your "onOff" function.  This line:
If $readInput ==  $readInput Then

What is that meant to accomplish?  First, since it is going to be a number (since that is what the control style specified), it would be "If $readinput = $readinput then", but why is this even in the script.  It will always return true.  That being the case, why is it there?  Go into some more detail as to what you want "onoff" to do...

Edited by MattHiggs

Share this post


Link to post
Share on other sites
Ian_Mac

 

15 hours ago, MattHiggs said:

So I am looking at your "onOff" function.  This line:
If $readInput ==  $readInput Then

What is that meant to accomplish?  First, since it is going to be a number (since that is what the control style specified), it would be "If $readinput = $readinput then", but why is this even in the script.  It will always return true.  That being the case, why is it there?

 i got what u mean i can do it "If $readInput then" isntead of using == but that's not the problem. what i wanted is to stop the while loop if i turn off the button but not closing the entire gui. because exit and exitloop totally close the entire GUI

Edited by Ian_Mac

Share this post


Link to post
Share on other sites
MattHiggs
8 minutes ago, Ian_Mac said:

 

its,  take the inputted number or the value from the ($time = the input box ) then after taking  it multiply it to 1000 then it send msgbox of the answer which means if i input 1 it will multiply to 1000 so 1*1000 = msgbox "You Inputed: 1000"  then after that run the while loop. and that's where my problem is i cant stop the loop  by turing off button by clicking the button to off. 

The reason that it won't turn back off is because of this code here:

While 1
                        Send("0")
                        Sleep($readInput)
                     WEnd

While 1 creates an infinate loop, and the contents of the loop are to press the "0" key and then pause the script for the amount of time entered into the input with no way to break out of the loop.  You have given me a summary of only the first couple of lines of code.  In order for me to help, I need to know what you are trying to accomplish in its entirety, otherwise when I see code like the above, I don't know what you are trying to do

Share this post


Link to post
Share on other sites
Ian_Mac

im just practicing the buttons . just trying to stop the while loop. but if u mean asking me what program im gonna do. idont have idea im just trying to learn the autoit for future use. 

i newbie and trying to learn programming

Share this post


Link to post
Share on other sites
MattHiggs

Ah I see.  In that case, that while loop is what is causing the issue.  I can appreciate you are trying to learn, so I would recommend, rather than go about it like this, take a look at these resources first.  These will help:

https://www.autoitscript.com/forum/files/file/351-learn-to-program-using-free-tools-with-autoit/

https://www.autoitscript.com/forum/files/file/100-welcome-to-autoit-1-2-3/

And to just explore the other resources that the community has created:

https://www.autoitscript.com/forum/files/

I would also highly recommend going over the help file in great detail (if you are using SciteforAutoIt then just press F1 when you have clicked inside the text editor window.

Share this post


Link to post
Share on other sites
Ian_Mac

i have tried to read , googled watch vids.  but i cant find answers.  please help me what code to use. just to stop that loop without exiting.

Share this post


Link to post
Share on other sites
MattHiggs
4 minutes ago, Ian_Mac said:

i have tried to read , googled watch vids.  but i cant find answers.  please help me what code to use. just to stop that loop without exiting.

Dude.  I can't help you if I don't know what you want to accomplish.  If you are simply trying to display a message box with the number entered into the GUI's input box multiplied by 1000, then there is not need for that loop.  Like I said, " While 1 creates an infinate loop, and the contents of the loop are to press the "0" key and then pause the script for the amount of time entered into the input with no way to break out of the loop."  If you want to break the infinate loop, you need to either a) change the conditions of the While loop or B) put an "exitloop" statement somewhere in the while loop.  But if I don't know what you are trying to accomplish, then I can't help you.  I would need to know why you wanted to put the loop there in order to help you fix it.  I need to be able to follow your logic, or else, its like trying to catch smoke with my bare hands.

Share this post


Link to post
Share on other sites
Ian_Mac

okey, ahhm, i wanted to auto press that 0 key while  my button is on and i already did it using while 1 right?.. and then now  i wanted it to stop if i turned it off .

maybe your right to change the condition of the while loop. so how to code it or change it i'm stock ? thanks for the reply sir i really appreciated it :) 

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

  • Similar Content

    • nacerbaaziz
      By nacerbaaziz
      Hello
      Can we pause and resume the download in the InetGet function?
      If is possible, what is the solution please?
      I used this code To manage the download

      #include <INet.au3> func _downloader($name, $linc, $filepath, $RTLF = false, $link = false) global $downloader = GUICreate("downloader", 400, 200, -1, -1, $WS_CLIPCHILDREn, $RTLF, $link) global $path = $filePath $labelTxt = GUICtrlCreateLabel("downloading " & $name, 50, 10, 200, 20) global $labelTxt0 = GUICtrlCreateLabel("downloaded size 0 MB " & "OF 0 MB", 50, 60, 300, 20) global $Progress = "" global $sText = ""     For $i = 1 To Random(5, 20, 1) ; Return an integer between 5 and 20 to determine the length of the string.         $sText &= Chr(Random(65, 122, 1)) ; Return an integer between 65 and 122 which represent the ASCII characters between a (lower-case) to Z (upper-case). next global $labelTxt2 = GUICtrlCreateInput("0%", 50, 80, 50, 20) _GUICtrlEdit_SetReadOnly(-1, true) GUIStartGroup("") global $beep = GUICtrlCreateCheckBox("use the progress beep notification", 150, 120, 200, 20) GUIStartGroup("") $button = GUICtrlCreateButton("Cancel', 130, 150, 180, 25, 0x01) $iIndex = 0 global $Target global $url GUIStartGroup("") global $Progress = GUICtrlCreateProgress(50, 90, 150, 20) global $Target = $filepath global $url = $linc global $path = $filepath global $hDownloadNo = _RSMWare_GetData($url, $Target) global $status = false AdlibRegister("SetProgress") global $onprogress = false, $curent = false GUISetState(@sw_Show) While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE, $button $asc = MsgBox(4132,"exit download?","if you click yes the downloading will be cancel, do you want to cancel it ?") if $asc = 6 then AdlibUnRegister("SetProgress") GUIDelete() If $hDownloadNo <> 0 Then InetClose($hDownloadNo) exitLoop endIf EndSwitch if $status = -1 then $status = 0 $hDownloadNo = _RSMWare_GetData($url, $Target) $onprogress = false $curent = false elseIf $Status = 1 then $status = $path GUIDelete() AdlibUnRegister("SetProgress") exitLoop endIf WEnd return $status endFunc Func _RSMWare_GetData($url, $Target) Local $hDownload = InetGet($url, $Target, 1, 1) Return $hDownload EndFunc ;==>_RSMWare_GetData Func SetProgress() Local $state If $hDownloadNo <> 0 Then $state = InetGetInfo($hDownloadNo) If @error = 0 Then $infor = "downloaded size " & Round(Execute(InetGetInfo($hDownloadNo, $INET_DOWNLOADREAD) / 1048576), 2) & " MB of " & Round(Execute(InetGetInfo($hDownloadNo, $INET_DOWNLOADSIZE) / 1048576), 2) & " MB " $onprogress = Round(Ceiling(($state[0] / $state[1]) * 100)) if not (InetGetInfo($hDownloadNo, $INET_DOWNLOADSIZE) = 0) then if $onProgress <= 0 then $onProgress = 0 GUICtrlSetData($Progress, $onProgress) GUICtrlSetData($labelTxt0, $infor) GUICtrlSetData($labelTxt2, $onProgress & "%") if _isChecked($beep) then if $onprogress > $curent then beep((100 + $onprogress * 20), 100) $curent = $onprogress endIf endIf endIf If $state[2] Then If $state[3] Then InetClose($hDownloadNo) $status = 1 else InetClose($hDownloadNo) $status = -1 endIf endIf EndIf endIf EndFunc ;==>SetProgress
    • Pike
      By Pike
      Hello Everyone,
      New Guy here. This is a two-part question, hopefully easy enough though. I know it's ugly coding, this is because I have only a couple hours worth of coding experience and could really use some help.
      1) When I single click the button I want one action (like playing a sound clip) and when I double click the button I want a different action (such as opening dialogue box to ask for soundclip directory address). At the bottom of the script I made a comment which one I would like single click versus double click.
      2) I can not get the FileOpenDialogue to save the file address to the config.ini file at the 'One' position on the .ini.
      #include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <MsgBoxConstants.au3> #include <FileConstants.au3> #include <AutoItConstants.au3> #include <Sound.au3> Opt('MustDeclareVars', 1) Opt("GUIOnEventMode", 1) Global $OneID _Main() Func _Main() GUICreate("Form1", 156, 86, 281, 276) $OneID = GUICtrlCreateButton("Button", 15, 17, 122, 37) GUICtrlSetOnEvent($OneID, "OnOne") GUISetOnEvent($GUI_EVENT_CLOSE, "OnExit") GUISetState() While 1 While 1 Sleep(1000) WEnd WEnd EndFunc ;---------------Functions------------- While 1 Sleep(100) WEnd Func OnOne() ; ******************Single Click for this action**************** $OneID = IniRead("config.ini", "Config", "One", $OneID) If $OneID = True Then SoundPlay($OneID, @HotKeyPressed) Else ; *******Double Click for this action*****And Help Saving File Address to config.ini 'One'*********** $OneID = FileOpenDialog("Select file", @WorkingDir, "All (*.*)") IniWrite("config.ini", "Config", "One", $OneID) $OneID = InputBox("Enter Information", "Short Name for File?", "") IniWrite("config.ini", "Config", "NameOne", $OneID) EndIf EndFunc Any help would be greatly appreciated, and if you need anymore clarity as to what exactly I'm trying to do, please do not hesitate to ask. Thanks so much!
      Pike
    • kcvinu
      By kcvinu
      Hi all,
      I have a button created with _GUICtrlButton_Create function. I know that this function returns a handle of button instead of an ID. So i have obtain control ID by calling _WinAPI_GetDlgCtrlID function. After that i have tried the GUICtrlSetBkColor function. But it didnt worked. Any suggestions will be appreciated. Thanks in advance. 
      Note : - The window which carries this button is not created with native gui create function. Instead, it is created with CreateWindowEx api function.
    • Robdog1955
      By Robdog1955
      I'm trying to click a button on a web page. I have added a couple of MsgBox lines to allow me to watch what happens on the page. As you can see the first half of my script enters data into text boxes on the page. I have no problem there. I just cannot click on the region buttons. The "set focus" line causes an outline to appear around the EU button and the "click button" line causes the "Pick a Region" text to disappear. Here is the code I have so far.
      #include <IE.au3> Local $oIE = _IECreate("http://questchecker.com/") Local $iQuestID = "123456" Local $sCharacterName = "CharacterName" Local $colForms = _IEFormGetCollection($oIE) $iCount = 0 For $oForm In $colForms $oFormElements = _IEFormElementGetCollection($oForm) For $oFormElement In $oFormElements $iCount = $iCount + 1 Local $sTagName = StringLower($oFormElement.tagName) Local $sElementType = $oFormElement.type Local $sElementName = $oFormElement.name Switch $iCount Case 6 _IEFormElementSetValue($oFormElement, "MyRealm", 0) ; realm Case 7 _IEFormElementSetValue($oFormElement, $sCharacterName, 0) Case 8 _IEFormElementSetValue($oFormElement, $iQuestID, 0) EndSwitch Next Next Local $oButtons = _IEGetObjByName($oIE, "questForm") For $oButton In $oButtons If _IEFormElementGetValue($oButton) = "US" Then MsgBox(0, "", "Click Okay to set focus") _IEAction($oButton, "focus") MsgBox(0, "", "Click Okay to click button") _IEAction($oButton, "click") ExitLoop EndIf Next MsgBox(0, "", "Click Okay to quit") _IEQuit($oIE) Exit  
    • thoms
      By thoms
      Hello Forum,
      As said in the title, I'm searching a way to disable all tabstops in a GUI. My GUI includes 15 buttons and 3 edit controls.
      My questions:
      - is there a way to disable all tabstops at a time
      - is there a way to list all controls of a GUI and then disable tabstops one by one
      - or should I use the following line after each button creation:
      _WinAPI_SetWindowLong(GUICtrlGetHandle(-1), $GWL_STYLE, BitAND(_WinAPI_GetWindowLong(GUICtrlGetHandle(-1), $GWL_STYLE), BitNOT($WS_TABSTOP))) Thanks in advance for your valuable help!
      Thoms
      Edit: or maybe disable TAB key? I don't remember how to do!
×