Jump to content

How to pause or restart a script with key strokes?


Recommended Posts

I'm writing a script to click and type in different areas of the screen. That's easy to figure out, no problem.

What I'm having trouble with is figuring out how to pause or restart a script when I press a hotkey.

Global $Paused
HotKeySet("{PAUSE}", "Pause")

While 1
    *The 'action' part of the script goes here*
WEnd

Func Pause()
    $Paused = Not $Paused
    While $Paused
        Sleep(1000)
        ToolTip("Script is paused.")
    WEnd
EndFunc

I'm sure that will work for pausing the script, because I've used the exact same lines in a few other scripts. What I don't know how to do is make the script restart from the beginning when I press another hotkey. Any ideas?

Link to comment
Share on other sites

Global $Paused = 0
HotKeySet("{PAUSE}", "Pause")

While 1
sleep (100) ; to keep CPU usage down
WEnd

Func Pause()
    If $Paused = 0 then
        $Paused = 1
    ElseIf $Paused = 1 then
        $Paused = 0
    Endif
    While $Paused = 1
        Sleep(1000)
        ToolTip("Script is paused.")
    WEnd
EndFunc

EDIT as for the starting over again... there are a few ways... if its a small size script.. make what you want to restart in a funciton and just recall that function

Edited by CodyBarrett
Link to comment
Share on other sites

Global $Paused = 0
HotKeySet("{PAUSE}", "Pause")

While 1
sleep (100) ; to keep CPU usage down
WEnd

Func Pause()
    If $Paused = 0 then
        $Paused = 1
    ElseIf $Paused = 1 then
        $Paused = 0
    Endif
    While $Paused = 1
        Sleep(1000)
        ToolTip("Script is paused.")
    WEnd
EndFunc

EDIT as for the starting over again... there are a few ways... if its a small size script.. make what you want to restart in a funciton and just recall that function

You can write a more simple.

$Paused = Not $Paused
Link to comment
Share on other sites

Link to comment
Share on other sites

I'm abit confused, did u want to use the same hotkey for the pause button and to resume the script? or use a different hotkey to start the script from the start?

Also when u meant restart the script did u mean the first while loop?

One hotkey for pausing, and one for restarting, and yes restarting the first while loop. Thanks for asking, I wasn't sure if it was clear.
Link to comment
Share on other sites

One hotkey for pausing, and one for restarting, and yes restarting the first while loop. Thanks for asking, I wasn't sure if it was clear.

Ahh cool, well you just need to make ur action a function and set a hotkey to it then.

Global $Paused
HotKeySet("{PAUSE}", "Pause")
HotKeySet("{HOME}", "Action")
Func Action()
    While 1
    *The 'action' part of the script goes here*
WEnd
EndFunc
Action() ; so action starts when script is opened

Func Pause()
    $Paused = Not $Paused
    While $Paused
        Sleep(1000)
        ToolTip("Script is paused.")
    WEnd
EndFunc
Link to comment
Share on other sites

One hotkey for pausing, and one for restarting, and yes restarting the first while loop. Thanks for asking, I wasn't sure if it was clear.

Ahh cool, well you just need to make ur action a function and set a hotkey to it then.

Global $Paused
HotKeySet("{PAUSE}", "Pause")
HotKeySet("{HOME}", "Action")
Func Action()
    While 1
      *The 'action' part of the script goes here*
    WEnd
EndFunc
Action() ; so action starts when script is opened

Func Pause()
    $Paused = Not $Paused
    While $Paused
        Sleep(1000)
        ToolTip("Script is paused.")
    WEnd
EndFunc
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...