Jump to content
Sign in to follow this  

Global Variable And Func While Loop

Recommended Posts


I'm trying to think of a good user-defined function for pausing, and I cannot figure out why the following code fails this task. Once paused, I cannot unpase.....

Global $PAUSE_STATE = 0 ;1 = pause, 0 = not paused

HotKeySet("{PAUSE}", "PauseScript")
HotKeySet("{ESC}", "UnPauseScript")  

; body of script would go here

Func PauseScript()
   while $PAUSE_STATE  ;this is global, isn't it?

Func UnPauseScript()
   Exit ;for debugging purposes to test unpause function

Use Mozilla | Take a look at My Disorganized AutoIt stuff | Very very old: AutoBuilder 11 Jan 2005 prototype I need to update my sig!

Share this post

Link to post
Share on other sites

tried this before as well... but assumed you could only have 1 hotkey activated at one time...

Edited by JdeB

Visit the SciTE4AutoIt3 Download page for the latest versions  - Beta files                                How to post scriptsource        Forum Rules
Live for the present,
Dream of the future,
Learn from the past.

Share this post

Link to post
Share on other sites

This seems to work fine:

hotkeyset("{Pause}","Start"); Initially this will start the macro
hotkeyset("!^e","exit1"); this exits the macro from memory

$vsleep = IniRead("config.ini","Delay","delay",1000)
$vjump = IniRead("config.ini","Jump","jump","")

While 1
If $x=1 Then
 send($vjump)  ; send chars defined in INI
 sleep(1)          ; Just incase $vsleep is not defined
 sleep($vsleep) ; sleep amount of msec defined in INI

Func Stop()
hotkeyset("{Pause}","Start"); changes to make Pause start macro

Func Start()
hotkeyset("{Pause}","Stop"); changes to make Pause stop macro

Func exit1()

Larry wrote something like this that works great as well:

AdlibEnable("pause"); this keeps running at all times till you exit.

HotKeySet("{pause}","pauseset"); uses the pause key to change the value of $Pause
$Pause = -1

While 1
 send("4"); this sends the number 4 key to the active program.
 sleep(1000) ; sleep for 1 second before repeating

Func pauseset()
   $Pause = $Pause * -1

Func pause()
   While $Pause = -1

It seems more that you can only have one function at one time, kinda of a funtion in a function loop. The adlib is a good way to circumvent it because autoit seems to stop what it is doing and check this. (correct me if I am wrong.) So you can see that both aproaches use the um..features of AutoIt to thier advantage. I tried to keep it simple. The adlib function works better because it can pause a script at any point, where the changing of hotkey aproach stops at the next breakpoint.

AutoIt3, the MACGYVER Pocket Knife for computers.

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  


Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.