Sign in to follow this  
Followers 0
TJ3

If Script Paused, Shut Down Script and all Windows

6 posts in this topic

Hi, first off excellent forum and hallo all. First post so bit of a noob question, but I'd really appreciate it.

I want a script to run automatically, but I want to include a fail safe so that:

a ) If Script pauses for some odd reason, exit script.

b ) AND exit all windows.

I was thinking something along the lines of the following for (a) but it doesn't really work. I thought hotkeyset might recognise "pause" and then go on to exit, but it doesn't?

And I haven't how to go about closing all windows.

Thanks very much :)

HotkeySet("{pause}", "Exit")

Body of Code Here

Func Exit()
Exit
EndFunc

Share this post


Link to post
Share on other sites



Hi, first off excellent forum and hallo all. First post so bit of a noob question, but I'd really appreciate it.

I want a script to run automatically, but I want to include a fail safe so that:

a ) If Script pauses for some odd reason, exit script.

b ) AND exit all windows.

I was thinking something along the lines of the following for (a) but it doesn't really work. I thought hotkeyset might recognise "pause" and then go on to exit, but it doesn't?

And I haven't how to go about closing all windows.

Thanks very much :)

HotkeySet("{pause}", "Exit")

Body of Code Here

Func Exit()
Exit
EndFunc
I think you might have been unlucky by choosing a reserved word for your function name.

Call it MyExit or anything else not reserved and it should work.


Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

You can try something like this: (untested tho should work)

Global $Paused
HotKeySet("{PAUSE}", "TogglePause")
$var = WinList()

While 1
    Sleep(1000)
WEnd

Func TogglePause()
    
    For $i = 1 to $var[0][0]
  If $var[$i][0] <> "" AND IsVisible($var[$i][1]) Then
    winkill($var[$i][0], "")
  EndIf
Next
    Exit
EndFunc

Func IsVisible($handle)
  If BitAnd( WinGetState($handle), 2 ) Then 
    Return 1
  Else
    Return 0
  EndIf

endfunc
Edited by Orgins

I'm a newbie.Sorry if I don't reposed to your replays very fast.

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Fantastic, thanks ...

However, I only learnt today that what I thought was a script pausing, was actually AutoIT losing focus and waiting for itself to regain focus. :)

Sorry. How would you adjust the code so that:

a ) If script loses focus (i.e. hangs and waits for focus), Exit.

b ) AND close all windows.

Orgins, where would you put the main body of the scripts for your code. I tried all kinds of ways but I think I bodged it.

Thanks guys.

Edited by TJ3

Share this post


Link to post
Share on other sites

I'd like to see the code for "if a script hangs, then get it to do anything..." :)

Share this post


Link to post
Share on other sites

I'd like to see the code for "if a script hangs, then get it to do anything..." :)

So it's not possible? Cheers,

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  
Followers 0