Jump to content

Send keystroke only if window is open


Recommended Posts

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.

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

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

Link to comment
Share on other sites

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.

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

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...