Sign in to follow this  
Followers 0
gustavo21

Send keystroke only if window is open

6 posts in this topic

Hello everyone. Im trying to do a script to do the next:

1- Run a program (and wait til it close, because i call the autoit script with scart /wait from CMD)

2- Check if a window is opened (not allways happens), focus and send keys

I wrote this, and obviously its not working:

Run("wpi2.exe")
WinWait("[CLASS:HTML Application Host Window Class]")

 If WinActive("[CLASS:#32770]") Then
   Send("{TAB}")
   Send ("{SPACE}")
EndIf

WinWaitClose("[CLASS:HTML Application Host Window Class]")

The windows i need to close (#32770) sometimes is opened before this script is executed, Its not the result of the program im calling in first line.

I will apreciate your help!

 

Thanks in advance.

Share this post


Link to post
Share on other sites



Hello everyone. Im trying to do a script to do the next:

1- Run a program (and wait til it close, because i call the autoit script with scart /wait from CMD)

2- Check if a window is opened (not allways happens), focus and send keys

I wrote this, and obviously its not working:

Run("wpi2.exe")
WinWait("[CLASS:HTML Application Host Window Class]")

 If WinActive("[CLASS:#32770]") Then
   Send("{TAB}")
   Send ("{SPACE}")
EndIf

WinWaitClose("[CLASS:HTML Application Host Window Class]")

The windows i need to close (#32770) sometimes is opened before this script is executed, Its not the result of the program im calling in first line.

I will apreciate your help!

 

Thanks in advance.

 

you tried alredy

winwaitactive ?

;Wait for the window "[CLASS:Notepad]" to exist and be active
WinWaitActive("[CLASS:Notepad]")

;Wait a maximum of 5 seconds for "[CLASS:Notepad]" to exist and be active
WinWaitActive("[CLASS:Notepad]", "", 5)

you use autoit window info to get de correct title or class?

Share this post


Link to post
Share on other sites

Yes, The problem i have is to send key only if the window is active, because i have to send tab and space and if the windows in not active theese commands will close another app.

Also i need to wait until the first app i run (wpi.exe) close.

 

Thanks!!

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Try this then..

RunWait("wpi2.exe")

While 1
    If WinActive("[CLASS:#32770]") Then
        Send("{TAB}{SPACE}")
        ExitLoop
    EndIf
    Sleep(100)
WEnd

Note that if the window in question is not active, it will have to be activated manually (IOW, by you). Also, the ExitLoop statement can be replaced by Exit, if there is not going to be any code added after the While loop.

Edited by somdcomputerguy

- 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

Can I use "WinActivate" to active the window?

Share this post


Link to post
Share on other sites

Can I use "WinActivate" to active the window?

What does the Help file say about that function?


- 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

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  
Followers 0