Jump to content

If Script Paused, Shut Down Script and all Windows


TJ3
 Share

Recommended Posts

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
Link to comment
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.
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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