Jump to content

[help]How to add pause button and continue?


MrSWABE
 Share

Recommended Posts

i have my first script made but i dont know how to add pause and continue button.

can you help me add pause and contiue to this?

;
; AutoIt Version: 3.0
; Language:       English
; Platform:       Win9x/NT
; Author:         Jonathan Bennett (jon@hiddensoft.com)
;
; Script Function:
;   Opens Notepad
;

; Run Notepad
Run("notepad.exe")


; Wait for the Notepad become active - it is titled "Untitled - Notepad" on English systems
WinWaitActive("Untitled - Notepad")


; Now that the Notepad window is active type some text

Send("1")
Sleep(250)
Send("2")
Sleep(80)
Send("3")
Sleep(50)
Send("1")
Sleep(250)
Send("2")
Sleep(80)
Link to comment
Share on other sites

Forgive me MrSWABE, no intention of hijacking your thread, but my question is almost identical to yours so I figured I would ask it here and whatever Auto-it Guru answers yours can answer mine as well.

I'm running a very simple infinitely looping script utilizing only the Send and Sleep functions.

I need to know if there is a snippet of code or a function that allows for a currently running script to be toggled on/off with a specific assigned hotkey.

Thank you :)

Edited by zanthal
Link to comment
Share on other sites

You should check out HotKeySet in the help file. I have modified the example slightly as an illustration. Read my comments (in green) carefully, as they explain what each part of the code is doing. Don't forget to press escape to exit the script when you have finished.

Local $Paused ; Declare this variable, which a flag to indicate the current status - paused or NOT paused.
HotKeySet("{PAUSE}", "TogglePause") ; Call a function to interrupt the script (press pause again to resume).
HotKeySet("{ESC}", "Terminate") ; Call a function to exit the script.

; Start of Example Script. Replace this example with your own code.
While 1 ; Repeat the following two lines until the script is interrupted or terminated.
    Sleep(3000)
    MsgBox(0, "Test", "This is a message!") ; Sends a message every 3 seconds.
WEnd ; End of Example Script

; Function to pause and resume.
Func TogglePause()
    $Paused = NOT $Paused ; Set the paused flag.
    While $Paused
       ; Do nothing until the paused flag is reset.
   WEnd
EndFunc

; Function to stop the script.
Func Terminate()
    Exit
EndFunc
Link to comment
Share on other sites

can you lend me an example sir where can i put this? if i press my pause button on my

keyboard does it appears this message?

Oh, sorry... I thought you wanted the program to pause itself and resume when you click OK in the message box. What I gave zanthal is more what you want, except it uses the "A" key. Here it will work with pause instead:

#include <Misc.au3>
HotKeySet("{PAUSE}", "myfunc")

(your code here)

myfunc()

Func myfunc()
    While 1
        If _IsPressed(13) Then ExitLoop
        Sleep(50)
    WEnd
EndFunc

If you press the PAUSE key while the "your code here" portion is executing, it will jump to the myfunc function and just loop doing nothing until you press PAUSE again.

Edited by Dana
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...