Sign in to follow this  
Followers 0
titouille

Problem with "waiting loop"

3 posts in this topic

Hello everybody !

I discover AutoIt this day, and have tried some samples and my own tests for my need.

My case :

I have a Flash animation to launch.

In some cases, this animation launch an external wma player via FSCommand

When this player (media player classic) is launched, it take focus, so my animation lost the focus, and key pad navigation is out.

So I have tried to build a script to make the following things :

1. hide trayIcon AutoIt

2. Launch Loader.exe (swf stand-alone executable)

3. Create a loop who wait and test if "Media Player Classic" is launched. if it's case, pass the focus to the Flash animation.

4. If animation is closed, test if "Media Player Classic" is launched. If it's case, close it, and

5. Close AutoIt3.exe process (shown in task manager)

here is my script :

#NoTrayIcon

; var to exit
Dim $exit = 0

; run main application
Run("Loader.exe")

; wait for running
WinWaitActive("Macromedia Flash Player 7")

; set the loop
While $exit < 1
    If WinWaitClose( "Macromedia Flash Player 7" ) = 1 Then
        MsgBox( 0, 'test', 'test 1' )
        $exit = 1
    EndIf

    winWaitActive( "Media Player Classic" )
;WinSetOnTop( "Macromedia Flash Player 7", "", 1)
    WinActivate( "Macromedia Flash Player 7" )

WEnd


If WinExists( "Media Player Classic" ) = 1 Then
    WinClose( "Media Player Classic" )
    WinWaitClose( "Media Player Classic" )
    MsgBox( 0, 'exit', 'exit...' )
Else
    MsgBox( 0, 'exit without mpc close', 'exit without mpc close;)' )
EndIf

So I want to construct a loop which stop if main animation is closed.

My problems are :

1. The WinActivate function plays only one time

2. If the $exit variable is set to 1, code after the loop is executed only if Media Player Classic is launched

3. The AutoIt3.exe process isn't killed after closing the animation

If anyone have some suggestions about my script, or alternative solutions, I'm waiting for...

Thanks in advance for any answer ;)

Thierry

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Ok, it was a misunderstanding of the winWait*** methods...

I have now understand that theses methods stop all other process and wait for an event. So I have rewrited my script and it's really simple to do it :

replace main loop by this code :

Dim $animationTitle = "Macromedia Flash Player 7"

While $exit < 1

    if WinWaitNotActive( $animationTitle ) = 1 Then
        if WinExists( $animationTitle ) Then
            WinActivate( $animationTitle )
        Else
            $exit = 1
        EndIf
    EndIf

WEnd

and all work.

mplayerc.exe seems to close automatically when Flash player is closed, without pass in the final if statement. I don't know why, but this is good for me ;)

If anyone find a mistake or know an optimisation, I listen :P

Edited by titouille

Share this post


Link to post
Share on other sites

If anyone find a mistake or know an optimisation, I listen ;)

LxP posted a good one in this thread:

http://www.autoitscript.com/forum/index.php?showtopic=16788

Following that example:

Dim $animationTitle = "Macromedia Flash Player 7"

While WinExists($animationTitle)
    WinActivate($animationTitle)
    WinWaitNotActive($animationTitle)
WEnd

[font="Tahoma"]"Tougher than the toughies and smarter than the smarties"[/font]

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