Jump to content

how to use a single hot key to pause and continue the script?


Go to solution Solved by Musashi,

Recommended Posts

  • Solution

Try this as an example :

#include <Timers.au3>

HotKeySet("{PAUSE}", _TogglePause)
HotKeySet("{ESC}", _Terminate)

Global $g_bPaused  = False
Global $hStarttime = _Timer_Init() ; *** just as an info

While True
    ToolTip("Time : " & StringFormat("%.2f", _Timer_Diff($hStarttime) / 1000) & " sec")
    Sleep(100)
WEnd

Func _TogglePause()
    $g_bPaused = Not $g_bPaused
    While $g_bPaused
        Sleep(50)
        ToolTip('Script is paused', 10, 10, "Status :", 1, 1)
    WEnd
    ToolTip("")
EndFunc   ;==>_TogglePause

Func _Terminate()
    Exit
EndFunc   ;==>_Terminate

 

Musashi-C64.png

"In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move."

Link to post
Share on other sites
29 minutes ago, Musashi said:

Try this as an example :

#include <Timers.au3>

HotKeySet("{PAUSE}", _TogglePause)
HotKeySet("{ESC}", _Terminate)

Global $g_bPaused  = False
Global $hStarttime = _Timer_Init() ; *** just as an info

While True
    ToolTip("Time : " & StringFormat("%.2f", _Timer_Diff($hStarttime) / 1000) & " sec")
    Sleep(100)
WEnd

Func _TogglePause()
    $g_bPaused = Not $g_bPaused
    While $g_bPaused
        Sleep(50)
        ToolTip('Script is paused', 10, 10, "Status :", 1, 1)
    WEnd
    ToolTip("")
EndFunc   ;==>_TogglePause

Func _Terminate()
    Exit
EndFunc   ;==>_Terminate

 

IT WORKS MAN, THANK U😁

Link to post
Share on other sites
  • Developers
5 minutes ago, jacky998877 said:

IT WORKS MAN, THANK U😁

You could also have simply have opened the Helpfile and search for the term hotkey. You would have found an example that exactly does what you requested!

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

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

    No registered users viewing this page.

×
×
  • Create New...