Jump to content
Sign in to follow this  
skyhawk

Problem with WinActive() and Send Keys

Recommended Posts

skyhawk

Hi everyone I'm a new user to AutoIt and keep running into an issue I keep seem to correct. I'm pulling information from an old system, AS400. The program doesn’t have any visible text, so I assume I have to use the Send() command to emulate key strokes. I have my code make AS400 active, copy some text, go to Excel and paste the data. It then goes back to AS400 pulls some more data, pastes it in Excel, and keeps doing it until I have all the data I need. For the most part the script runs really really well, however maybe 1 out of 15 times, it messes up.

From what I can gather is, it tries to make the AS400 window active, but before it does so it sends the command to Excel (Excel hasn't finished pasting yet?). So when it comes back to Excel the incorrect active cell is selected. I have posted a small example of my code, and ideas would be greatly appreciated.

_WinWaitActivate("AS400H","")
Send("{UP}{UP}{UP}{UP}{UP}{UP}{UP}{UP}{UP}{UP}{UP}{UP}{UP}{UP}{UP}{UP}{UP}{UP}{UP}{UP}{RIGHT}{RIGHT}{RIGHT}{RIGHT}{RIGHT}{RIGHT}{RIGHT}{RIGHT}{RIGHT}{RIGHT}{RIGHT}{RIGHT}{RIGHT}{RIGHT}{RIGHT}{RIGHT}{RIGHT}{RIGHT}{RIGHT}{RIGHT}{RIGHT}{RIGHT}{RIGHT}{RIGHT}{RIGHT}{RIGHT}{RIGHT}{RIGHT}{RIGHT}{RIGHT}{RIGHT}{RIGHT}{RIGHT}{RIGHT}{RIGHT}{RIGHT}{SHIFTDOWN}{RIGHT}{RIGHT}{RIGHT}{RIGHT}{SHIFTUP}{ALTDOWN}{ALTUP}ec")
_WinWaitActivate("Microsoft Excel - AS400 Input file.xls  [Compatibility Mode]","AS400 Input file.xls ")
Sleep(300)
Send("{CTRLDOWN}v{CTRLUP}{DOWN}")
Sleep(300)
_WinWaitActivate("AS400H","")
Send("{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{RIGHT}{SHIFTDOWN}{LEFT}{LEFT}{LEFT}{LEFT}{SHIFTUP}{ALTDOWN}{ALTUP}ec{F6}")
_WinWaitActivate("Microsoft Excel - AS400 Input file.xls  [Compatibility Mode]","AS400 Input file.xls ")
Send("{CTRLDOWN}v{CTRLUP}{UP}{RIGHT}")
Sleep(300)
_WinWaitActivate("AS400H","")
Send("{UP}{UP}{UP}{UP}{UP}{UP}{UP}{UP}{UP}{UP}{UP}{UP}{UP}{UP}{UP}{UP}{UP}{UP}{UP}{UP}{RIGHT}{RIGHT}{RIGHT}{RIGHT}{RIGHT}{RIGHT}{RIGHT}{RIGHT}{RIGHT}{RIGHT}{RIGHT}{RIGHT}{RIGHT}{RIGHT}{RIGHT}{RIGHT}{RIGHT}{RIGHT}{RIGHT}{RIGHT}{RIGHT}{RIGHT}{RIGHT}{RIGHT}{RIGHT}{RIGHT}{RIGHT}{RIGHT}{RIGHT}{RIGHT}{RIGHT}{RIGHT}{RIGHT}{RIGHT}{RIGHT}{RIGHT}{SHIFTDOWN}{RIGHT}{RIGHT}{RIGHT}{RIGHT}{SHIFTUP}{ALTDOWN}{ALTUP}ec")
_WinWaitActivate("Microsoft Excel - AS400 Input file.xls  [Compatibility Mode]","AS400 Input file.xls ")
Send("{CTRLDOWN}v{CTRLUP}{DOWN}")
Sleep(300)
_WinWaitActivate("AS400H","")
Send("{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{RIGHT}{SHIFTDOWN}{LEFT}{LEFT}{LEFT}{LEFT}{SHIFTUP}{ALTDOWN}{ALTUP}ec{F6}")
_WinWaitActivate("Microsoft Excel - AS400 Input file.xls  [Compatibility Mode]","AS400 Input file.xls ")

I tried using the Sleep() command inbetween WinWaitActivate but that didnt really help....

Share this post


Link to post
Share on other sites
somdcomputerguy

What is _WinWaitActivate()? Maybe the problem is there..

Edited by snowmaker

- Bruce /*somdcomputerguy */  If you change the way you look at things, the things you look at change.

Share this post


Link to post
Share on other sites
skyhawk

What is _WinWaitActivate()? Maybe the problem is there..

It was a function that automatically was put there when I used the AutoIt Recoder, to figure out how to write my script. The function is below....

#region --- Internal functions Au3Recorder Start ---
Func _WinWaitActivate($title,$text,$timeout=0)
    WinWait($title,$text,$timeout)
    If Not WinActive($title,$text) Then WinActivate($title,$text)
    WinWaitActive($title,$text,$timeout)
EndFunc
#endregion --- Internal functions Au3Recorder End ---

Is there something else I should use to make the window(s) active instead?

Thanks for the quick reply!

Share this post


Link to post
Share on other sites
somdcomputerguy

Increase $timeout to 3 or 5, that may get rid of the occasional 'not work right' thing, but it will wait longer to see if the window is there, unless that window is already open..


- Bruce /*somdcomputerguy */  If you change the way you look at things, the things you look at change.

Share this post


Link to post
Share on other sites
skyhawk

Increase $timeout to 3 or 5, that may get rid of the occasional 'not work right' thing, but it will wait longer to see if the window is there, unless that window is already open..

Thanks, I'll give that a go and see what happens. Does that make it 3 dignifiy 3 secounds?

Share this post


Link to post
Share on other sites
somdcomputerguy

Yep. Timeout is in seconds. So maybe more or less than 3 or 5 will work better.

Function WinWaitActive

Edited by snowmaker

- Bruce /*somdcomputerguy */  If you change the way you look at things, the things you look at change.

Share this post


Link to post
Share on other sites
skyhawk

Yep. Timeout is in seconds. So maybe more or less than 3 or 5 will work better.

Function WinWaitActive

Thanks, I'll give that ago.

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
Sign in to follow this  

×