Jump to content

Pause Script with a hotkey


Recommended Posts

Ok, so I've been looking at this script (below), and I must say I'm quite confused. All it seems to do is display a little tooltip box with "Script is Paused", but I'm guessing that's all it is meant to do.

What I'm looking for is to actually pause a script on a hotkey (eg. F2) and then resume it using the same hotkey (or different, not too important)

But what I need is a code to pause it, then resume on a hotkey. I get how hotkeyset works, but I don't know how to pause it. (sorry if this is a silly question, I'm a bit new to this thing)

Thanks in advance ;)

; Press Esc to terminate script, Pause/Break to "pause"

Global $Paused
HotKeySet("{PAUSE}", "TogglePause")
HotKeySet("{ESC}", "Terminate")
HotKeySet("+!d", "ShowMessage") ;Shift-Alt-d

;;;; Body of program would go here;;;;
While 1
    Sleep(100)
WEnd
;;;;;;;;

Func TogglePause()
    $Paused = NOT $Paused
    While $Paused
        sleep(100)
        ToolTip('Script is "Paused"',0,0)
    WEnd
    ToolTip("")
EndFunc

Func Terminate()
    Exit 0
EndFunc

Func ShowMessage()
    MsgBox(4096,"","This is a message.")
EndFunc
Link to comment
Share on other sites

try this for better understanding:

; Press Esc to terminate script, Pause/Break to "pause"

Global $Paused
HotKeySet("{PAUSE}", "TogglePause")
HotKeySet("{ESC}", "Terminate")
HotKeySet("+!d", "ShowMessage") ;Shift-Alt-d

;;;; Body of program would go here;;;;
While 1
    MsgBox (0, "This script is running!", "This script is currently running thus you will see this message every second second ;-)")
    Sleep (2000)
WEnd
;;;;;;;;

Func TogglePause()
    $Paused = NOT $Paused
    While $Paused
        sleep(100)
        ToolTip('Script is "Paused = SCRIPT IS NOT RUNNING = you wont get another message if you dont unpause it"',0,0)
    WEnd
    ToolTip("")
EndFunc

Func Terminate()
    Exit 0
EndFunc

Func ShowMessage()
    MsgBox(4096,"","This is a message.")
EndFunc

and put all you want inside the while-wend loop

Edited by chmod777
Link to comment
Share on other sites

try this for better understanding:

; Press Esc to terminate script, Pause/Break to "pause"

Global $Paused
HotKeySet("{PAUSE}", "TogglePause")
HotKeySet("{ESC}", "Terminate")
HotKeySet("+!d", "ShowMessage") ;Shift-Alt-d

;;;; Body of program would go here;;;;
While 1
    MsgBox (0, "This script is running!", "This script is currently running thus you will see this message every second second ;-)")
    Sleep (2000)
WEnd
;;;;;;;;

Func TogglePause()
    $Paused = NOT $Paused
    While $Paused
        sleep(100)
        ToolTip('Script is "Paused = SCRIPT IS NOT RUNNING = you wont get another message if you dont unpause it"',0,0)
    WEnd
    ToolTip("")
EndFunc

Func Terminate()
    Exit 0
EndFunc

Func ShowMessage()
    MsgBox(4096,"","This is a message.")
EndFunc

and put all you want inside the while-wend loop

Thank you so much for that ;)

I see what to do now!

Again, many thanks for helping a newbie like me out :D

Link to comment
Share on other sites

Maybe a little clearer..

; Press Esc to terminate script, Pause/Break to "pause"

Global $Paused, $counter = 0
HotKeySet("{PAUSE}", "TogglePause")
HotKeySet("{ESC}", "Terminate")
HotKeySet("+!d", "ShowMessage") ;Shift-Alt-d

;;;; Body of program would go here;;;;
While 1
    $counter +=1
    ToolTip('Script is "Running"',0,0, $counter, 1)
    Sleep(700)
WEnd
;;;;;;;;

Func TogglePause()
    $Paused = NOT $Paused
    While $Paused
        sleep(100)
        ToolTip('Script is "Paused"',0,0, $counter, 1)
    WEnd
    ToolTip("")
EndFunc

Func Terminate()
    Exit 0
EndFunc

Func ShowMessage()
    MsgBox(4096,"","This is a message.")
EndFunc

8)

NEWHeader1.png

Link to comment
Share on other sites

  • 4 years later...

Maybe a little clearer..

; Press Esc to terminate script, Pause/Break to "pause"

Global $Paused, $counter = 0
HotKeySet("{PAUSE}", "TogglePause")
HotKeySet("{ESC}", "Terminate")
HotKeySet("+!d", "ShowMessage") ;Shift-Alt-d

;;;; Body of program would go here;;;;
While 1
$counter +=1
ToolTip('Script is "Running"',0,0, $counter, 1)
Sleep(700)
WEnd
;;;;;;;;

Func TogglePause()
[color=#00ff00]$Paused = NOT $Paused
While $Paused
sleep(100)[/color]
ToolTip('Script is "Paused"',0,0, $counter, 1)
WEnd
ToolTip("")
EndFunc

Func Terminate()
Exit 0
EndFunc

Func ShowMessage()
MsgBox(4096,"","This is a message.")
EndFunc

8)

hi, is there anyway you could explain the use and purpose of the array is it? $counter... i executed this bit of code and paused my script and i recieve the 0 from $counter, im just wondering what is this for, is it just an example for what could be a timer

?

also i highlighted some code above and don't understand the operater NOT, which is notEqual ? im just wondering the process

'cause i dont understand u start by calling the function toggle then it says $paused not equal to $ paused i just don't get it 'cause there's nothing in that variable either? so how is the script taking action and know what it has to do?

sorry for all my questions, i've tryed looking at the operator and looking at other examples but i just dont understand how all the things work together...

I hope to get better with each thing and start to understand the processes a little better.

does the variable automatically take on any result i shud say if inside the function/anyfunction 'cause global??

ahh i really dont understand

thanks everyone if u can help

Link to comment
Share on other sites

This thread is nearly 4 years old. It's sugggested not to necro such an old thread but to open a new one

You will get much more attention and answers.

BTW: The help file is a very good ressource to understand how AutoIt works.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

This thread is nearly 4 years old. It's sugggested not to necro such an old thread but to open a new one

You will get much more attention and answers.

BTW: The help file is a very good ressource to understand how AutoIt works.

thanks waters, i've had a look at helpfile but i just dont get how things correspond work with each other sometimes, i will try look harder and start a new thread in future.

thanks

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