Jump to content
Macro Express Forums

How to Monitor a Condition While Waiting for an Action?


Eg6Xpm18cs

Recommended Posts

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?

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...