Jump to content

How do I pause a script?


ags911
 Share

Recommended Posts

 

You could change the pause function for something like this.

Make sure you have the includes in your script

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

Func _Pause()
    $Form1 = GUICreate("Form1", 179, 42, @DesktopWidth - 182, 3, $WS_POPUP, BitOR($WS_EX_TRANSPARENT, $WS_EX_WINDOWEDGE, $WS_EX_TOPMOST))
    $Button1 = GUICtrlCreateButton("Resume", 8, 8, 75, 25)
    $Button2 = GUICtrlCreateButton("Exit", 96, 8, 75, 25)

    GUISetState(@SW_SHOW)

    While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
            Case $GUI_EVENT_CLOSE
                Exit
            Case $Button2
                Exit
            Case $Button1
                ExitLoop
        EndSwitch
    WEnd
EndFunc   ;==>_Pause

 Thanks for the reply John, but I have no idea how to put this into my script. It messes with my other while loop and says Line 48 Endfunc then, Error:"Func" statement has no matching "EndFunc". That line is the end of this function:

While $UnPaused ; Loop 2

ToolTip("1")

MouseClick("Left", @DesktopWidth *0.926, @DesktopHeight *0.962, 1, 10)

ToolTip("2")

MouseClick("Left", @DesktopWidth *0.0869, @DesktopHeight *0.809, 1, 20)

ToolTip("3")

MouseClick("Left", @DesktopWidth *0.625, @DesktopHeight *0.522, 2, 20)

ToolTip("4")

MouseClick("Left", @DesktopWidth *0.463, @DesktopHeight *0.644, 2, 20)

ToolTip("5")

MouseClick("Left", @DesktopWidth *0.306, @DesktopHeight *0.607, 1, 20)

ToolTip("6")

MouseClick("Left", @DesktopWidth *0.503, @DesktopHeight *0.644, 1, 20)

Link to comment
Share on other sites

All you do is swap your old _Pause() func for the above one.

The func is everything between and including.

Func _Pause()

   ;everything 

EndFunc

Edited by JohnOne

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Link to comment
Share on other sites

All you do is swap your old _Pause() func for the above one.

The func is everything between and including.

Func _Pause()

   ;everything 

EndFunc

Thanks man, I added this but now it does not pause but I get that GUI on the top right of my screen but I cannot click on it since the mouse is still running the script. Also, my code has a toggle pause function script that might be broken now so I am not sure what to do but here is that bit of script so far.

Func _TogglePause()

    $Form1 = GUICreate("Form1", 179, 42, @DesktopWidth - 182, 3, $WS_POPUP, BitOR($WS_EX_TRANSPARENT, $WS_EX_WINDOWEDGE, $WS_EX_TOPMOST))

    $Button1 = GUICtrlCreateButton("Resume", 8, 8, 75, 25)

    $Button2 = GUICtrlCreateButton("Exit", 96, 8, 75, 25)

    GUISetState(@SW_SHOW)

    While 1

        $nMsg = GUIGetMsg()

        Switch $nMsg

            Case $GUI_EVENT_CLOSE

                Exit

            Case $Button2

                Exit

            Case $Button1

                ExitLoop

        EndSwitch

MouseClick("Left", @DesktopWidth *0.93, @DesktopHeight *0.92, 1, 10)

MouseClick("Left", @DesktopWidth *0.084, @DesktopHeight *0.785, 1, 20)

MouseClick("Left", @DesktopWidth *0.625, @DesktopHeight *0.523, 2, 20)

MouseClick("Left", @DesktopWidth *0.462, @DesktopHeight *0.628, 2, 20)

MouseClick("Left", @DesktopWidth *0.3, @DesktopHeight *0.606, 1, 20)

MouseClick("Left", @DesktopWidth *0.506, @DesktopHeight *0.628, 1, 20)

WEnd

EndFunc

Link to comment
Share on other sites

By the way my script uses the toggle pause to remain in a suspended state till a hotkey is pressed so that the user can decide when to start the script.

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
Global $sHeight = @DesktopHeight
Global $sWidth = @DesktopWidth
Global $UnPaused
HotKeySet("+1","_TogglePause") ; Press Shift+1 to start script
HotKeySet("+2", "_Terminate") ; Press Shift+2 to terminate script

I think by removing that Unpaused state and the while function might have broken the pause function, I'm not sure.

Link to comment
Share on other sites

I'm going to hijack this thread because I have a similar question.

I'm a day or two into writing out a quite intricate and multi function script with tons of gui controls stuff for work, I'm familiar with the fundamentals of scripting, but this is my first stab at using Autoit (and it's been pretty exciting opening my mind to all this)

The GUI has about 50 options and settings to chose from that you will chose before you run which will dictate what happens along the main path, and eventually I'd like to add completely different paths with there own settings down the road on new GUI tabs.

I think I understand the difference between an OnEvent and a GetMsg GUI, and since I haven't had experience with both, I'm sort of just going forward with an OnEvent since it sounds more correct to me.

So if I understand this right, using an OnEvent lets me build my GUI, and then dictate functions at the end of my script that will be associated with buttons on my GUI and in those functions (such as the Main path (Run button), pause button, aswell as some functions for making sure clashing settings aren't selected) I will be reading data from GUI controls.

So the thing I'm stuck on as far as pausing and resuming my script revolves around my entire main path being a function, and if I were to hit the pause button, which is another function, would hop out of my mainpath function into the pause function, how would I get back to where I was inside my main path function after the run button was hit again?

I've tried to give a lot of maybe unnecessary details to give a picture of what I'm doing and hopefully someone can intervene if my logic is critically wrong or I am just at a mental block. 

Ok so I just had a revelation as I was about to click on the post button. I was thinking about the progress bar and status box I've made that sends ctrl data along the script for visual feedback of what the scripts doing on the GUI. Well, if I add a global variable, something like $location and along my main path at various points (But honestly it would have to be before every action) I updated that, so if the pause function was called and the script exited my mainpath function, I would have a reference point of where it was when it left. As far as reentering that, I cant think of an efficient way. I could have a Select/case argument at the very start of the function that would perform the step the script left on and the remaining code, but that would be TONS of code if I had 75+ actions (The main path will be around 1000 lines by my guess at this point). 

Ugh I feel so close to the solution (I hope!). Much appreciation for any advice anyone can offer!

Edited by Prime03
Link to comment
Share on other sites

When you pause a script with some sort of blocking code via a hotkey, the last native function will end and will return t o it's very next step when you resume.

 

:huggles:

All that frustration ... that's what I get for skimming over the function reference! And wow was I way out there with my thinking earlier lol.

Edited by Prime03
Link to comment
Share on other sites

:huggles:

All that frustration ... that's what I get for skimming over the function reference! And wow was I way out there with my thinking earlier lol.

 

I guess the edit button goes away after a certain amount of time on this forum, so excuse the double post.

So now that I've gotten a chance to start trying to apply this I'm still hazy implementing this. I'd like to avoid having to use some sort of blocking code like a MsgBox inside the Pause hotkey, I'd like to be able to just hit the hotkey(and/or button on the GUI, which I don't think would do what I want, hotkey is an exception here) and toggle without anything appearing on the screen. All while still falling back into the previous running function at the location it left at. I'm actually having a pretty hard time with this as I sit here flipping through the references. 

Using a MsgBox does do what I want to have happen as far as handling re-entering the main function where it left off, I'd just prefer it a cleaner way from a users perspective. They're going to be modifying things on screen, so I think it would be instinctive for them to automatically close it out of habit regardless of what the box says, and it would be a pain to have to drag a window around each time you pause.

Edited by Prime03
Link to comment
Share on other sites

  • Moderators

Prime03,

 

I guess the edit button goes away after a certain amount of time on this forum, so excuse the double post

Once you reach a certain number of posts you get a permanent "Edit" button. :)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

The help file has a ready made example for that, See HotkeySet example, just remove the tooltip.

 

Ugh, I feel ridiculous! Thank you for pointing that out. How I've even gotten as far as I have with this project is beyond me! I have a problem with not FULLY reading things.

Prime03,

 

Once you reach a certain number of posts you get a permanent "Edit" button. :)

M23

 

LOL, that's going to be handy, I just hope its not after like 100 or something!

Link to comment
Share on other sites

  • Moderators

Prime03,

I think it is 5, but I am not going to delve into the server to check it. ;)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...