acantor Posted November 22, 2010 Report Share Posted November 22, 2010 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? Quote Link to comment Share on other sites More sharing options...
Cory Posted November 22, 2010 Report Share Posted November 22, 2010 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. Quote Link to comment Share on other sites More sharing options...
acantor Posted November 23, 2010 Author Report Share Posted November 23, 2010 Thank you, Cory, for your thoughts. I find that manipulating controls can result in elegant solutions, but the learning curve is long, the coding tends to be more complex, and the need to write clear comments is greater. I will press on with controls… Quote Link to comment Share on other sites More sharing options...
acantor Posted November 23, 2010 Author Report Share Posted November 23, 2010 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. 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.