Jump to content
Macro Express Forums

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!

Link to comment
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.

Link to comment
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!

Link to comment
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 

Link to comment
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.

Link to comment
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.

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