Jump to content
Macro Express Forums

Navigating to controls: key sequences vs. MEP control commands


Recommended Posts

When there are two way to move the cursor to a control, by sending a sequence of keys or capturing controls, how do you decide which is the best approach?

 

For example, I am writing scripts for an application that extracts information from a field. I can do this in two ways:

 

Type <Alt><x> (move to the ABC field)

Type <Ctrl><a> (select the ABC field)

Type <Ctrl>c (copy the field)

 

or

 

Get Control ABC

Set Focus ABC

Type <Ctrl><a> (select the ABC field)

Type <Ctrl>c (copy the field)

 

The first approach is easier to implement but less reliable. For example, all hell can break lose if another window intrudes while the script is running.

 

The second approach should be more reliable, but is a more complex to implement. I thought that this approach might run faster, but I find that it may run slower. I guess it's faster to send keystrokes than to collect and manipulate control information.

 

How do you decide the best approach to capturing this kind of information when both alternatives can be made to work?

Link to comment
Share on other sites

Always use controls when available. Unless of course it's a simple one off macro. Clipboard and all the rest can have timing issues and in general this is never as reliable. Also with controls you can interact with them without setting focus. EG you can have Calculator running hidden and doing calculations with it without the user seeing it. And you can use controls for timing, EG Wait for Control to Exist, Wait for Control Ready.

 

 

Link to comment
Share on other sites

I am continuing my experiments with control-based scripts, and finding that sometimes a hybrid approach works best. In some contexts, sending keystrokes yields more reliable scripts. But I am enjoying not having to rely on the clipboard to capture control text when there are MEP commands that copy text directly to variables. Thank you Cory for the reminder that MEP has this functionality built in.

 

Now, I have two versions of the same macro -- a script to simplify command development in NaturallySpeaking. One macro sends keystrokes, the other manipulates controls. The latter runs faster, and has 25% fewer lines of code.

 

The learning curve has been steep, but it's been worth the effort.

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

×
×
  • Create New...