Jump to content

Recommended Posts

Posted

Hi, I have made a script but I am having trouble pausing it. I have made a toggle pause hotkey on it so I can simply pause and restart it with one press. The problem is when I pause it the loop still completes the whole cycle. Is it possible to stop the loop immediately without using exitloop or terminating the program?

This is my code so far thanks.

Global $UnPaused
HotKeySet("{1}","_TogglePause") ; Press 1 to start script
HotKeySet("{ESC}", "Terminate") ; Press Esc to terminate script
    
    MsgBox(64, "Hello!")

While 1   ; Loop 1
Sleep(100) ; Waiting for function call. Pressing the Start hotkey ends this loop
ToolTip("Paused. Press 1 to resume or Esc to exit.",0,0)
WEnd

Func _TogglePause()
   ToolTip("Script has started. Press 1 to pause or Esc to terminate.",0,0)
   $UnPaused = NOT $UnPaused
While $UnPaused ; Loop 2
MouseClick("left", 1146, 691, 1, 14)
MouseClick("left", 317, 618, 1, 32)
MouseClick("left", 844, 451, 2, 14)
MouseClick("left", 684, 518, 2, 25)
MouseClick("left", 517, 498, 1, 10)
MouseClick("left", 724, 519, 1, 0)
WEnd
EndFunc

Func _Pause()
   $Paused = NOT $Paused
        While $Paused
            sleep(100)
            ToolTip('Paused. Press 1 to resume or Esc to exit."',0,0)
             WEnd
        ToolTip("")         
    EndFunc

Func Terminate()
    Exit 0
EndFunc

  • Developers
Posted

Thanks, but where do I insert that into my code? It says error, duplicate function code when I run the script.

think a little here..... what should you do next ?

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.
  :)

Posted

The code does not stop the loop immediately, the code consists of 6 mouse clicks so for example if I start the code the mouse will start clicking each co-ordinate until it reaches mouse click number 6. The thing is when I pause it, it will not stop till all 6 clicks have been completed, I would like the code to pause as soon as the last click completed instead of carrying on till the 6th click. Does that make sence now?

  • Developers
Posted

Correct as you have coded it to only check the status of $pause at the beginning of each loop ....or didn't you write this code?

Have you looked at the helpfile example?

Jos

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.
  :)

Posted

Yes thanks, I checked the helpfile but I didn't specifically see how I could pause the script part way through the loop?

And I did write the script by the way but I'm still pretty new to this.

Thanks.

Posted

Looks a little complicated for what you say you want.

HotKeySet("{PAUSE}","_Pause")

While 1 ; Loop 2
    ToolTip("1")
    MouseClick("left", 1146, 691, 1, 14)
    ToolTip("2")
    MouseClick("left", 317, 618, 1, 32)
    ToolTip("3")
    MouseClick("left", 844, 451, 2, 14)
    ToolTip("4")
    MouseClick("left", 684, 518, 2, 25)
    ToolTip("5")
    MouseClick("left", 517, 498, 1, 10)
    ToolTip("6")
    MouseClick("left", 724, 519, 1, 0)
WEnd

Func _Pause()
    If MsgBox(1, 'Paused', 'Press ok to resume, or cancel to exit') = 2 Then Exit
EndFunc   ;==>_Pause

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

Monkey's are, like, natures humans.

Posted

 

Looks a little complicated for what you say you want.

HotKeySet("{PAUSE}","_Pause")

While 1 ; Loop 2
    ToolTip("1")
    MouseClick("left", 1146, 691, 1, 14)
    ToolTip("2")
    MouseClick("left", 317, 618, 1, 32)
    ToolTip("3")
    MouseClick("left", 844, 451, 2, 14)
    ToolTip("4")
    MouseClick("left", 684, 518, 2, 25)
    ToolTip("5")
    MouseClick("left", 517, 498, 1, 10)
    ToolTip("6")
    MouseClick("left", 724, 519, 1, 0)
WEnd

Func _Pause()
    If MsgBox(1, 'Paused', 'Press ok to resume, or cancel to exit') = 2 Then Exit
EndFunc   ;==>_Pause

Thanks John, what is complicated about it? I thought I put all that needed to be in there to get the script and the pause toggle but do I get rid of the other code below that then. This stuff:

Func _Pause()

   $Paused = NOT $Paused

        While $Paused

            sleep(100)

            ToolTip('Paused. Press 1 to resume or Esc to exit."',0,0)

             WEnd

        ToolTip("")         

    EndFunc

And will the new code you have added stop the script before it completes all 6 mouse clicks?

Posted

Maybe if you run the code yourself

You aren't referencing that function, so yes you can lose it.

Yes it will, you only have to run it to see.

I just ran the isolated code and it added numbers on each mouse click but you removed the pause toggle and start and stop, so I don't know how I would put it together? Any reason why?

Posted

Thanks but I have added your code to the final code and it still completes the full loop before pausing, try it for yourself? What specifically do you press for the pause button because I have assigned key 1 for start/pause toggle and 2 to exit application if that means anything.

Posted

I'll assume you have no pause button on your keyboard

Change this

HotKeySet("{PAUSE}","_Pause")

To

HotKeySet("{2}","_Pause")

And use the 2 key.

OMG thanks it worked! Now I get a message box that pops up maybe I could change that to a tooltip to be less intrusive, one more question though. Can I use a better hotkey than just 1 or 2 because I accidentally turn it on when I forget it is still running in the background, maybe something like shift+1 or something? BTW I don't know how to write Shift+1 in the part that has the 2 here: HotKeySet("{2}","_Pause"). Many thanks again.

Posted

Thank you, do you think that the OK, cancel menu should be reversed? Click OK to exit and cancel to stay in? Thank you for all your help I think I am asking too many questions now but I have learnt alot already.

Posted

Thanks I have just made one with this:

Func _Terminate()
    If MsgBox(4, 'Do you want to exit?', 'Click Yes to exit, or No to continue') = 6 Then Exit
EndFunc   ;==>_Pause

Works a treat. So I take it that the only way of stopping the script midway through is a msgbox? I have my script set to shift+1 start/pause toggle, which has to complete the whole loop before it stops and shift+2 for the yes/no msgbox that stops it instantly.

Posted (edited)

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
Edited by JohnOne

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

Monkey's are, like, natures humans.

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
  • Recently Browsing   0 members

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