Jump to content
Macro Express Forums
acantor

Is there an alternative way to repeat keystrokes

Recommended Posts

I am scripting a macro that presses the down arrow key %x% times, where x is between 1 and 1300.

 

In some scripting languages I can repeat a key press %x% times:

 

<DOWN %x%>

 

Is there a way to do this in Macro Express? Or should I make peace with repeating %x% times?

Repeat with Variable: Repeat %x% times
    Text Type (Simulate Keystrokes): <ARROW DOWN>
End Repeat

 

Thanks!

Share this post


Link to post
Share on other sites

Make peace. :)
I don't understand why this is a problem.
If you want fewer passes through the Repeat loop -- lower processing overhead -- do something like
    Variable Modify Integer: %x% = %x% / 10
    Repeat with Variable: Repeat %x% times
        Text Type: <ARROW DOWN><ARROW DOWN><ARROW DOWN><ARROW DOWN><ARROW DOWN><ARROW DOWN><ARROW DOWN><ARROW DOWN><ARROW DOWN><ARROW DOWN>
    End Repeat

Or put the loop in a separate macro that you call (run) from your main macro.  It will at least LOOK a little cleaner.

Share this post


Link to post
Share on other sites

It's not really a problem, except, perhaps, of aesthetics! <Down %x%> is neater than a repeat loop. But I will get used to it!

 

The macro extracts every item from a 1300-item long drop-down list. To navigate to all of list items, the macro needs to press the down arrow key over 800,000 times: 1 + 2 + 3 ... + 1300.  It runs in about 15 minutes. I can't imagine how long the task would have taken had I done it manually, but I know I only spent 60 or 90 minutes scripting and debugging the MEX macro.

Thank you, Insight Software Solutions, you saved me days (possibly weeks) of mind-numbing boring effort, as well as significant upper body wear-and-tear!

Share this post


Link to post
Share on other sites

If you have to do it on a regular basis, experiment with Page Down followed by Arrow Down -- loop within loop.  It might work if Page Down consistently advances by a predictable number of rows.  (What the heck, you have solved your problem, but aesthetics demands an elegant solution instead of brute force.) :P 

Share this post


Link to post
Share on other sites

Well, I actually considered your approach! It think it's workable, although it would be a pain to code. I might try it one day just to see if I can.

But I found an alternative way to solve the problem that reduced the number of simulated keystrokes by a significant amount, maybe by a factor of 50 or 100. Instead of pressing down arrow keys, I now do incremental searches on the drop down list to navigate to the item I want. So to navigate to the 1000th item on the list, instead of pressing down arrow 1000 times, the macro types its name exactly how it appears. The length of the item names vary between three and 32 characters. So to reach the 1000th item, I only need to send as many characters are in its name.

Share this post


Link to post
Share on other sites

Very clever.  So when you have extracted an item from the list, on the next pass you can type the item then <ARROW DOWN> to get the subsequent item, and so on???

Share this post


Link to post
Share on other sites

That's exactly how it works. I'm not sure how long I will be able to use this technique, as I've noticed that drop-down lists in Windows 10 are less likely to support incremental searches. Which is really unfortunate. It's a very speedy way to manually navigate to a target on a long list. It works when typing, and especially, it works when automating via macros. There is no way that I would have been able to make it work for the items that are 32 characters long if I had to type them manually. (The way that Microsoft implemented the incremental search, you cannot pause while typing. A pause of a fraction of a second resets the search.)

The macro now executes more slowly. I had to add an IF statement within the repeat loop to check for one special case. There is an issue with one item on the list that causes the incremental search to fail. The extra test noticeably slows down the macro. However, that's the trade-off I needed to make so the macro run reliably from start to finish. Nevertheless, the development time for this macro, plus the extra five or ten minutes it takes to run it, still represents a tiny proportion of the mental and physical effort I would have expended to perform the task manually.

Share this post


Link to post
Share on other sites

Is the drop-down list on a web page?

If so, you might be better viewing the HTML code and parsing that instead.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×