erloyaamit Posted August 27, 2014 Posted August 27, 2014 (edited) Need help on following requirement Code to automatically pause the script if a new window open or existing active window crashes Scenario: We've a tool where we add server entries based on the inputs in Excel sheet. Now the requirement is whenever a new window (e.g Notepad, Browser) is opened OR the tool itself crashes, the script should Pause immediately. The script should resume from that point again once the active window is switched to tool that I am using. Thanks in Advance Edited August 27, 2014 by erloyaamit
JohnOne Posted August 27, 2014 Posted August 27, 2014 Define "existing active window crashes" AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans.
MikahS Posted August 27, 2014 Posted August 27, 2014 Wouldn't checking with a WinActive to see what the title is and if its not your 'window' then put it into a function that checks the active window, instead of running the rest of the script. Snips & Scripts My Snips: graphCPUTemp ~ getENVvarsMy Scripts: Short-Order Encrypter - message and file encryption V1.6.1 ~ AuPad - Notepad written entirely in AutoIt V1.9.4 Feel free to use any of my code for your own use. Forum FAQ
232showtime Posted August 27, 2014 Posted August 27, 2014 WinWaitActive Pauses execution of the script until the requested window is active. WinWaitActive ( "title" [, "text" [, timeout = 0]] ) You should check the help file for example script.... :thumbsup: ill get to that... i still need to learn and understand a lot of codes Correct answer, learn to walk before you take on that marathon.
tlman12 Posted August 27, 2014 Posted August 27, 2014 If i'm understanding you correctly, your going to need 2 scripts. in your script (the one you want to pause) you'll need to add these lines (or something similar) HotKeySet("{1}","_Pause") $paused = False "{1}" being whatever key you can get away with stealing from the computer and this function Func _Pause() If $paused Then $paused = False Else $paused = True EndIf While $paused Sleep(50) ; so you don't overrun your cpu, you can increase this to suite your needs but if you want near real time leave it at 50 WEnd EndFunc then in the other script you'll need to write the winactive monitor portion in a while loop and send the hot key based on your logic once your logic has passed use a Send("{1}") and that should pause your other script, using a Send("{1}") again should un-pause it and allow it to pick up at the exact spot it left off.
JohnOne Posted August 27, 2014 Posted August 27, 2014 How should the OP handle the "crashed window" you guys? AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans.
MikahS Posted August 27, 2014 Posted August 27, 2014 @JohnOne use WinList() to check to read all windows and put it into a for loop to check the 2D array made, if this "tool" has crashed it will not be there, if it's crashed re-open it with a Run() call. This can be done simply with an AdlibRegister every couple of seconds. @232showtime I'm very sure we are checking to see what is active, not trying to make it active, as per OP's statement. @tlman12 toooo much this is simply done with putting it into a function with a simple while loop that checks to see what window is active, then if the window we want becomes active, get out of the function. Snips & Scripts My Snips: graphCPUTemp ~ getENVvarsMy Scripts: Short-Order Encrypter - message and file encryption V1.6.1 ~ AuPad - Notepad written entirely in AutoIt V1.9.4 Feel free to use any of my code for your own use. Forum FAQ
jdelaney Posted August 27, 2014 Posted August 27, 2014 (edited) Is the new window an enabled popup of the application window? If the application 'crashes' (hangs) the winstate probably get's modified to NOT be enabled. You can create functions to check for both conditions via: AdlibRegister One function that checks for the enabled popups: _WinAPI_GetWindow(); where the option = 6 One function to check the window state: $iState = WinGetState If Not BitAND ($iState,4) Then ; check for about 10 seconds...if it fails, then exit...you crashed EndIf Edit; just saw your post...You should be using the handle of the window, then you can check if it doesn't exist: If Not WinExists($hYourWindow) Then Run() Edited August 27, 2014 by jdelaney IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.
JohnOne Posted August 27, 2014 Posted August 27, 2014 Would have looked at using _WinAPI_IsHungAppWindow() AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans.
MikahS Posted August 27, 2014 Posted August 27, 2014 @JohnOne yes I would use that also, but what if a window crashed and closes right away Snips & Scripts My Snips: graphCPUTemp ~ getENVvarsMy Scripts: Short-Order Encrypter - message and file encryption V1.6.1 ~ AuPad - Notepad written entirely in AutoIt V1.9.4 Feel free to use any of my code for your own use. Forum FAQ
JohnOne Posted August 27, 2014 Posted August 27, 2014 Well that is the question I asked the OP, only they know what happens to it. AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans.
MikahS Posted August 27, 2014 Posted August 27, 2014 Absolutely, you are right. I just gave explanation of what to do on either a hanging crash or an actual closing application crash. Snips & Scripts My Snips: graphCPUTemp ~ getENVvarsMy Scripts: Short-Order Encrypter - message and file encryption V1.6.1 ~ AuPad - Notepad written entirely in AutoIt V1.9.4 Feel free to use any of my code for your own use. Forum FAQ
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now