Jump to content
Sign in to follow this  
BlueOrange

Pause Script with a hotkey

Recommended Posts

BlueOrange

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

Share this post


Link to post
Share on other sites
chmod777

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

Share this post


Link to post
Share on other sites
BlueOrange

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

Share this post


Link to post
Share on other sites
Valuater

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

Share this post


Link to post
Share on other sites
JamesDover

Excellent, I've never seen pause used that way before.

Share this post


Link to post
Share on other sites
cookiekiller89

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

Share this post


Link to post
Share on other sites
water

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 (2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2018-09-01 - Version 1.3.4.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
cookiekiller89

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

Share this post


Link to post
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
Sign in to follow this  

×