Key press script not 100% reliable

Hints, tips and tricks for newbies

Moderators: Dorian (MJT support), JRL

Post Reply
billtubbs
Junior Coder
Posts: 32
Joined: Thu Dec 07, 2006 10:00 pm
Location: Vancouver
Contact:

Key press script not 100% reliable

Post by billtubbs » Wed Jan 24, 2007 10:10 pm

Hi

I've written a script to automate a research application that runs repeated simulations. Usually it works perfectly, executing 400+ simulations overnight.

Occasionally when I come in in the morning I find the process has stalled. Here's an example from the script log.

Code: Select all

1/23/2007 21:22:50:734 - // Close CIMS window
1/23/2007 21:22:50:734 - IfWindowOpen>CIMS Simulation*
1/23/2007 21:22:50:765 - SetFocus>CIMS Simulation*
1/23/2007 21:22:50:781 - Press ALT
1/23/2007 21:22:50:781 - Send>fx
1/23/2007 21:22:50:796 - Release ALT
1/24/2007 11:03:16:781 - WaitWindowClosed>CIMS Simulation*
1/24/2007 11:03:16:796 - Endif
1/24/2007 11:03:16:812 - 
1/24/2007 11:03:16:812 - Label>End
1/24/2007 11:03:16:843 - End>RunSimulation
In this instance I came in to find the respective window still open after the ALT-F-X command which normally selects 'Exit' from the 'File' menu. Clearly from the log, Macro Scheduler got to the WaitWindowClosed command without the window closing.

Any ideas why the window may not have closed? Can anyone see a more robust way to write this script?

I notice some people use 'Send Character/Text>' instead of 'Send>' but I don't think this is the cause.

thanks
Bill.

User avatar
Bob Hansen
Automation Wizard
Posts: 2475
Joined: Tue Sep 24, 2002 3:47 am
Location: Salem, New Hampshire, US
Contact:

Post by Bob Hansen » Wed Jan 24, 2007 11:29 pm

This may be a good location to use Wait

Code: Select all

Press ALT
Wait>.3
Send>f
Wait>.3
Send>x
Wait>.3
Release ALT
The time of .3 is arbitrary, you can change it to what is best for you.
You can also use a variable to change in multiple lines at once, like this:

Code: Select all

Let>delay=.3
...
...
Wait>%delay%
...
...
Wait>%delay%
Now, just change the value of %delay% in the one line to have it effective in all Wait> lines.
Hope this was helpful..................good luck,
Bob
A humble man and PROUD of it!

billtubbs
Junior Coder
Posts: 32
Joined: Thu Dec 07, 2006 10:00 pm
Location: Vancouver
Contact:

Post by billtubbs » Thu Jan 25, 2007 12:43 am

Thanks Bob

I'll try that. I was thinking about repeating the key sequence if the WaitWindowClosed command timed out. But this is simpler if it works.

Bill.

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts