Eg6Xpm18cs Posted March 1, 2010 Report Share Posted March 1, 2010 Specifically, I want to stop a macro upon closure of a window while the macro is waiting for user input (Enter key). Closing the window leaves the macro hanging waiting for input. This issue seems so simple that I suspect I'm missing something basic. Is there a way to monitor a condition (window state) while waiting for an action (user input) using only one macro? I was thinking of an endless IF loop to constantly test both conditions, using a short waiting period (would Control be used for the Enter key?), but that doesn't seem like the cleanest approach. Suggestions? Quote Link to comment Share on other sites More sharing options...
paul Posted March 1, 2010 Report Share Posted March 1, 2010 Specifically, I want to stop a macro upon closure of a window while the macro is waiting for user input (Enter key). Closing the window leaves the macro hanging waiting for input. This issue seems so simple that I suspect I'm missing something basic. Is there a way to monitor a condition (window state) while waiting for an action (user input) using only one macro? I was thinking of an endless IF loop to constantly test both conditions, using a short waiting period (would Control be used for the Enter key?), but that doesn't seem like the cleanest approach. You can't do this in ME v3. But in MEP, you can get pretty close. You'll need 2 macros; one for waiting for your user input (Macro M1), and one to detect the closing of the specified window (Macro M2). In reverse order, Macro M2 is activated when the relevant window title is closed. It creates a file called, say, StopMacro.txt in, say, your temp folder (e.g. C:\Temp). Macro M1 looks like this: 1) Repeat Until %n[1]% Does not Equal "%n[1]%" 2) Wait for Key Press: ENTER -- waits for one second only, and handles the error that occurs when Enter is not pressed within one second 3) On Error -- this code (lines 3 - 11) executes only when Enter was not pressed within one second 4) Catch Error: The condition was not met within the specified amount of time 5) If File Exists: "C:\Temp\StopMacro.txt" -- stops the macro if this file exists 6) Macro Return 7) Else 8) Continue -- repeat waiting for one second for the Enter key 9) End If 10) End Catch Error 11) End Error 12) Repeat Exit -- This code executes only if Enter was pressed within one second 13) End Repeat 14) macro code to execute when Enter was pressed within one second Quote Link to comment Share on other sites More sharing options...
Yehnfikm8Gq Posted March 1, 2010 Report Share Posted March 1, 2010 All the "Wait for" commands are "dead ends". You cannot go anywhere else until the condition is met. Loops are out of the question with "Wait for". In ME3 you don't have the choice of running more than one macro or using Catch Error as a crude switch for the two "Wait for" commands. Quote Link to comment Share on other sites More sharing options...
paul Posted March 1, 2010 Report Share Posted March 1, 2010 All the "Wait for" commands are "dead ends". You cannot go anywhere else until the condition is met. Loops are out of the question with "Wait for". In ME3 you don't have the choice of running more than one macro or using Catch Error as a crude switch for the two "Wait for" commands. Au contraire! You can impose a waiting time of as little as 1 second on ALL Wait For commands in MEP AND handle the error condition that is raised when the timeout occurs. This means you can usefully include any of them in a Repeat loop. Quote Link to comment Share on other sites More sharing options...
Yehnfikm8Gq Posted March 1, 2010 Report Share Posted March 1, 2010 This is the ME3 forum. "Wait for" are all dead-end. I had a post prepared for the MEPro forum since there's not point in posting here. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.