Jump to content
Macro Express Forums

Detect When Ok Appears And Has Focus Or Error


dgr7

Recommended Posts

hello,

I'm new to Macro Express and have run into my first problem with a macro I created last week that had been doing well until today. I've run into a situation where I need to implement some IF type of structure in the macro to detect when in the window I'm sending keystrokes to either:

>>a Warning windows appears inside the window (not as a separate window that the OS can see (not seen with Alt-Tab) and the Window title doesn't change any when this Warning appears or I'd just use some Detect when Warning window exists logic) that has a title of Warning, a Exclamation point graphic, text of That Entry is Not Defined, and a OK button to click which has focus when it appears, and if you send any other keystroke it's ignored, you can send only O or (enter) to make the Warning box go away

>>an Win XP Critical Stop error occurs when the Warning window appears and the associated .wav file is played

 

I've read through the ME help file and various forum postings and have had no luck as finding how to implement an IF statement that could detect either of the two above situations. I think the best route would be detection of the OK button appearing, but I'll take anything that'll work 100%!!

 

Can someone help me with the ME If statement syntax?

 

Thanks in advance,

david

Link to comment
Share on other sites

Sure, it's simple. At least for the first one. Almost all buttons and objects in Windows are controls and ME makes good use of these. In this case I would use an "If Control" with something like the "Visible" option. It's hard to say without seeing your application exactly which would be the best.

 

One warning about controls. 99% of the controls work great but there are some pitfalls and limitations. Odds are you won't run into them for some time but just be aware that they are out there. Also for most control variables are difficult for people to get their brains wrapped around. Take a little time to learn them first or you will be frustrated. There is a very good Windows Calculator tutorial on Insights support page you should try. Joe’s book is good too. The one pearl I would pass on is that it seems like “Get Control” is inappropriately named but it is not. Since Windows handles are always changing ME uses what is stored in the control var as a sort of path on how to find the handle when the macro runs. It’s important to realize that the control variable does not contain the control or its address (handle) but rather this crumb trail.

 

As for a critical stop error I think you’re SOL if you’re trying to detect it at run time. If I understand you correctly you’re talking about the BSoD (Blue Screen of Death) and although I’m not a programmer I’m pretty sure all processes stop at this point but for sure ME. I have run into cases like these when doing some harvesting routines that would blow up an application and how I handled it was to first log each attempt as a way to track failed attempts. Of course this was with an application so a system reboot would be a little different. In this case my first step in the loop would be to log the attempt. At the end of a successful attempt I would log it complete. Then if ME fired up again on reboot and started running the macro again and found an incomplete transaction it would tag that attempt as a BSoD or whatever and move on to the next record. Pretty simple actually if that’s what you’re trying to do.

Link to comment
Share on other sites

hello,

thank you for the quick reply.

I read what you said, then read through the Controls tutorial in Help and make a small macro with the keystrokes that I need to happen when the small "child" error window appears with the OK button inside the main app window I'm sending the keystrokes to, and used the Capture Window Control tool to move the crosshairs to the OK button, and captured this info about the window: VMAGIC.EXE: [button], I saved that info, then on the Properties tab, said for this small macro to Activate when the VMAGIC.EXE: [button] Control is Focused......however this isn't working, i.e. when the event happens when the small error/OK window appears, then macro doesn't launch.

 

So what am I doing wrong above? I was at first kinda confused that I'd need to make a separate macro just to handle the Error event....can't I place in my existing Main macro code that would execute *only* when the VMAGIC.EXE: [button] Control appears?

 

Next question: Why isn't the Event macro running that I created? It is set as Active? Is it because the Main macro is running and won't pause for this 2nd macro to start?

 

Or do I need to start from scratch and tackle this Error event a different way? When i was referring to ">>an Win XP Critical Stop error occurs when the Warning window appears and the associated .wav file is played", it's not the BSoD, I was just naming the type of error as described in Control Panel>Sounds...>Program Events. I was wondering if you can write an IF statement in ME that has a trigger of a Windows sound event?

 

Also, I looked around and couldn't find that Windows Calculator tutorial on Insights support page that you mentioned?

 

thanks in advance for your help,

david

Link to comment
Share on other sites

I’m sorry, I didn’t mean to suggest you create a separate macro. In you case wait a couple of seconds with a Delay and the check if the control is visible then do something if it is. Unfortunately ME doesn’t have a “Wait for control X seconds and if it doesn’t appear do this” command. If you use the wait for you will get an error when it doesn’t appear.

 

Also I would not do the mouse move you mentioned. Rather I would use the command to mouse click on the control if it has been detected.

 

If you made a separate macro this may be why it isn’t working. You can only run one macro at a time and a second will not activate.

 

As for the critical error are you saying that only a sound gets played with not dialog box or other visible feature? I’m afraid I don’t know of any way to detect a Windows sound being played if that’s the case. In this case I think you need to hunt for some sort of visible thing to interact with.

 

Again like I mentioned in the first paragraph ME doesn’t have the ability to simply wait for something to happen while the macro is running. You need to actively go out and test for it in the script.

 

Calculator tutorial: http://macros.com/tutorial/ME3Tutorial.htm Then go to the “Advanced – Using Controls” on the nav pane on the left.

Link to comment
Share on other sites

Unfortunately ME doesn’t have a “Wait for control X seconds and if it doesn’t appear do this” command. If you use the wait for you will get an error when it doesn’t appear.
Macro Express does not have a specific command to wait for a control and then do something if found and something else if not found. However you can accomplish the same thing using existing macro commands. This example should work:

// Initialize variables
Variable Set Integer %N1% to 0
Variable Set Integer %N2% to 80
Variable Set String %T1% ""

// Loop for a maximum of N2 / .25 seconds. If N2 = 80 then this will be 20 seconds
Repeat Until %N1% > %N2%
 If Control %C1% Focused
   Variable Set Integer %N1% to 81
   Variable Set String %T1% "FOUND"
 Else
   Delay 0.25 Seconds
 End If
Repeat End

If Variable %T1% = "FOUND"
 // *** The control was found. Run appropriate macro commands. ***
Else
 // *** The control was not found. Run appropriate macro commands. ***
End If

We often hear suggestions (or complaints) about commands that Macro Express is 'missing'. But it is rare that you cannot accomplish a specific task using the existing basic macro commands.

 

The Using Controls tutorial referred to by Cory can also be found within the Macro Express Help itself. Click Help, and Tutorial. Click the [+] next to 'Tutorial' in the help. Then click on 'Advanced - Using Controls'.

 

There is also a sample macro that you can study to see how controls work. The macro file samples.mex is installed in the same folder as the Macro Express program files. Click File, Open Macro File, and navigate to c:\Program Files\Macro Express3\samples.mex. Close the menu that comes up and then look at the macro titled 'Calc ulator and Note pad'.

 

We do not recommend that you change the samples.mex file and in fact, some versions of Windows will not allow it. To reload the macro file you were using click File, Reopen and click on the name of your original macro file.

Link to comment
Share on other sites

Cory & Kevin,

thanks for the replies and helpful information!

 

Kevin, you're source code does look good and something that I could use. First, I have a few questions:

 

(1) How do I place/implement the code you provided in my macro? When I look at the macro with the Scripting Editor or Direct Editor the contents of the macro are displayed in a dissimilar format to the source code you provided. You're code looks more like it's from a programming language, which I'm not seeing that type of format displayed for my macro.

 

(2)Is your example tailored to my specific problem of detecting the child Warning window that appears in the VMAGIC.EXE application when the error happens or do I need to edit your code some to make it See that type of error?

 

(3) How do I change the format of the steps that I want to happen in the True portion of the If Variable %T1% = "FOUND" statement to work in the provided source? Here they are from the Direct Editor:

<DELAY:2><TEXTTYPE:<ENTER>><DELAY:2><TEXTTYPE:1><DELAY:2><TEXTTYPE:<ENTER>>

 

(4)As far as the Else portion of this statement, I don't want anything to happen, just have the macro continue on with the remaining steps of the macro I created....will that work as it is right now?

 

thanks in advance,

david

Link to comment
Share on other sites

Sure, I’ll give it a shot. However I don’t have a lot of time so my answers might be short. If you’re interested I do hire my talents out and if you need to get something going I’m available for hire. This way you can get my full and prompt attention as well as the benefit of phone calls, web desktop sessions and the like. Sorry, just had promote myself a little.

 

1- Kevin didn’t give you any code. He copied the text from the script editor. This is not something you can copy and paste in. You will need to create it.

2- Any time one uses a control it must be for a specific window title, or at least it normally is, so you would have to tailor it to your specific control. I don’t think Kevin can make this for you.

3- Um…. You edit the macro and add whatever you want.

4- The else is there to create the delay so you need it. Otherwise it will fire off so fast you won’t see it.

 

I have to do a webinar now but if I get more time I might be back to consider all of this further.

Link to comment
Share on other sites

When I look at the macro with the Scripting Editor or Direct Editor the contents of the macro are displayed in a dissimilar format to the source code you provided. You're code looks more like it's from a programming language, which I'm not seeing that type of format displayed for my macro.

This was copied directly from the Macro Express Scripting Editor. (Highlight macro commands, right-click, and choose 'Copy Command Text'. Then paste from the clipboard.) It looks like a programming language because I used several Remark commands.

 

How do I place/implement the code you provided in my macro?

The sample macro is simply an example of how to get it to work. I did not run it. You will need to enter it into your macro and try it. Don't forget to add a Get Control command. I see that I did not include one.

 

There are ways to copy the macro from the direct editor into forum postings and we can attach macro files to forum messages. However, there are issues with each of these techniques that may cause it to not work properly. And since this is an example, and not a working macro, I chose not to include a copyable macro. You will need to type the commands in. It should only take a couple of minutes.

 

Here is what I do to key in a macro:

- Make sure the 'Switch focus to script when adding a command' is enabled. Click Options, Preferences, Miscellaneous.

- Make sure that 'Command Insertion' is set to 'Insert After Highlighted Command'. Click Options and then Command Insertion.

 

- Open your macro or start with a new blank one.

- Press and hold Alt and the Down Arrow key. This will move the cursor to the Search box.

- Type 'Rem'. The 'Remark' command will be highlighted. Press the ENTER key.

- Type 'Initialize Variables' and press the ENTER key or click the OK button.

 

- Type Alt Down Arrow.

- Type 'variable set i'. The 'Variable Set Integer' command will be highlighted. Press the ENTER key.

- Change the appropriate values in the fields.

 

- Repeat ...

 

(2)Is your example tailored to my specific problem of detecting the child Warning window that appears ...
The example shows how to wait for a specific amount of time for a control to appear and go on with the macro whether or not it appears. I do not have VMAGIC.EXE so you will have to customize what the macro does to your environment.

 

(3) How do I change the format of the steps that I want to happen in the True portion of the If Variable...
Highlight one of the commands near where you want to enter your macro commands and insert the macro commands. You can use the method I outlined above or you can use mouse clicks.

 

(4)As far as the Else portion of this statement, I don't want anything to happen, just have the macro continue on with the remaining steps of the macro I created....will that work as it is right now?
You can remove the Else protion of the macro if you want. Just highlight the lines you want to delete and press the delete key or right-click and choose 'Delete Commands'.
Link to comment
Share on other sites

hello,

 

I tried your suggestions/help, created the steps by hand and added them to my existing macro where they were needed, now the macro gets "stuck" whenever the Warning error child window displays, if it doesn't display the macro goes through the steps after the newly-added steps just fine, if the child window does appear, it gets "stuck". I let it sit there for a couple of minutes thinking it was a timer issue?, and ME never kicked in and made the error window go away, so I clicked OK, then some of the steps that needed to happen when that error window appears didn't and the macro steps got "out of sync" and keystrokes were happening at the wrong time in the application.

Please help!!

I've attached my macro file, hoping that someone can look at it and see where I made an error in it.

 

thanks in advance,

david

NHMA.mex

Link to comment
Share on other sites

It sounds like it’s looping and never seeing the control. I noticed you were using the “Is Focused” option. Often a control like a button will be visible but not focused. Might try to change that to “Visible”.

 

In cases like these I write a simple little test macro. You could write one where after you manually get it to make the error box appear check to see if it can see the button or what have you and simply display a text box like “Yup, I see it!”.

 

Wait a minute….. OK, Kevin and I differ in our approaches. Personally if the If condition was ever entered into I would simply click on the button instead of creating a “Found” to be used later. But in Kevin’s I think he forgot to add a Break to the If condition. Without that t he loop keeps going… Like this:

 

  Repeat Until %N1% > %N2%
   If Control %C1% Focused
     Variable Set Integer %N1% to 81
     Variable Set String %T1% "FOUND"
     Break
   Else
     Delay 0.25 Seconds
   End If
 Repeat End

 

But he has this N1=81 stuff so I don’t quite follow his logic because he never increments N1 as part of the loop. Maybe he’s missing a counter.

 

Personally I would do it more like this:

 

Get Control %C1% 
 Repeat Start (Repeat 40 times)
   If Control %C1% Focused
     Mouse Single Left Click on Control %C1%
     Break
   Else
     Delay 0.25 Seconds
   End If
 Repeat End

Link to comment
Share on other sites

Yep. I forgot to increment %N1%. Sorry. I did say that I did not run it. :huh:

 

I use variables outside the loop so it is easier to change the amount of delay. Here is a cleaned up version of my example macro. To increase or decrease the amount of delay you can set the value in N2 to something higher or lower than 80.

// Initialize variables
Variable Set Integer %N1% to 0
Variable Set Integer %N2% to 80
Variable Set String %T1% ""

Get Control %C1% (pgmacros.com -> Replying ... WindowClass)

// Loop for a maximum of N2 / .25 seconds. If N2 = 80 then this will be 20 seconds
Repeat Until %N1% > %N2%
 If Control %C1% Focused
   Variable Set String %T1% "FOUND"
   Break
 Else
   Delay 0.25 Seconds
   Variable Modify Integer: Inc (%N1%)
 End If
Repeat End

If Variable %T1% = "FOUND"
 // *** The control was found. Run appropriate macro commands. ***
Else
 // *** The control was not found. Run appropriate macro commands. ***
End If

Changes to the sample macro :

  • Added missing Get Control command
  • Changed to use Break instead of setting N1 to a value that would stop the repeat loop
  • Added missing Inc %N1% command

But I like Cory's example because it is more concise.

"Put 10 programmers in a room to solve a given problem and you'll wind up with 100 solutions."

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