Jump to content

Need help with ControlClick


Flou
 Share

Recommended Posts

Hi all,

I've been working with AutoIt for a few days and I have a weird problem using ControlClick.

This is my code that works in a loop :

If ($flag = 0) Then
    WinActive("S_Fix");
    Sleep(2000); Waiting for the program to be completely launched
    If ControlCommand("Vaccin_USB", "", "[CLASS:ThunderRT6CommandButton; INSTANCE:1]", 'IsVisible', '') Then
        Write("IsVisible")
        If (ControlGetText("Vaccin_USB", "", "[CLASS:ThunderRT6CommandButton; INSTANCE:1]") = "Fixer") Then
            $test = ControlClick("Vaccin_USB", "", "[CLASS:ThunderRT6CommandButton; INSTANCE:1]")
            Write($test)
            If ($test = 1) Then
                $flag = 1
                Write("Fixer2")
            EndIf
        EndIf
    EndIf
EndIf

If ControlCommand("Vaccin_USB", "", "[CLASS:ThunderRT6CommandButton; INSTANCE:2]", 'IsVisible', '') Then
    ;Write("IsVisible")
    If (ControlGetText("Vaccin_USB", "", "[CLASS:ThunderRT6CommandButton; INSTANCE:2]") = "Fermer") Then
        If (ControlClick("Vaccin_USB", "", "[CLASS:ThunderRT6CommandButton; INSTANCE:2]") = 1) Then
            Write("Fermer")
            ExitLoop
        EndIf
    EndIf
EndIf

I know the code is not "nice" but I decomposed each if just to be sure that I was going in each one and for debugging.

The Vaccin_USB is a little program that I launch via my script, there's a button (CLASS:ThunderRT6CommandButton) with the text "Fixer" when I click on it, this button disappears while the program copies files, when the program finishes it's copy, the same button appears but with the text "Fermer"

The weird thing is the ControlClick("Vaccin_USB", "", "[CLASS:ThunderRT6CommandButton; INSTANCE:1]") never works. The ControlClick is executed, the return code = 1 but the button on my program isn't pressed.

If I manually click on the button, the rest of my code works good (The ControlClick("Vaccin_USB", "", "[CLASS:ThunderRT6CommandButton; INSTANCE:2]") works!).

Any ideas how come with INSTANCE:1 it doesn't work and with INSTANCE:2 it does ? :s

With AutoIt Window Info, the "Fixer" button is on INSTANCE 1 [CLASS:ThunderRT6CommandButton; INSTANCE:1]

I also tried different options with ControlClick : using coordinates, without the INSTANCE option or with the CLASSNN of the button...but didn'g get it working either.

Thanks for any help.

Link to comment
Share on other sites

What is WinActive("S_Fix") supposed to do for you? Are you expecting that to wait for something, like you should have used WinWaitActive() instead?

:graduated:

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

S_Fix is the program name of Vaccin_USB.exe (the prog that I launch)

I used Vaccin_USB in the ControlClick function because that's what Au Window Info gave me.

PS : I also tried ControlClick with S_Fix instead of Vaccin_USB, to test, I get 0 as return code each time.

What I don't understand is why I have 1 in return code but the button doesn't get "cliked" ?!

Edited by Flou
Link to comment
Share on other sites

Getting return = 1 from ControlClick() only means AutoIt was able to find a matching control, and that it sent the "click" message. It doesn't necessarily mean the window process would accept and process the synthetic "click" message.

Post the contents of the "Summary" tab in AU3Info.exe while pointed at the button. That should help clarify what exactly you are working with, since you didn't answer the question about why you are using WinActive() at all.

:graduated:

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

According to helpfile

Remarks

Some controls will resist clicking unless they are the active window. Use the WinActivate() function to force the control's window to the top before using ControlClick().

Try this

If ($flag = 0) Then
    WinActivate("S_Fix");
    WinWaitActive("S_Fix");
    Sleep(2000); Waiting for the program to be completely launched
    If ControlCommand("Vaccin_USB", "", "[CLASS:ThunderRT6CommandButton; INSTANCE:1]", 'IsVisible', '') Then
        Write("IsVisible")
        If (ControlGetText("Vaccin_USB", "", "[CLASS:ThunderRT6CommandButton; INSTANCE:1]") = "Fixer") Then
            ControlFocus("Vaccin_USB", "", "[CLASS:ThunderRT6CommandButton; INSTANCE:1]")
            $test = ControlClick("Vaccin_USB", "", "[CLASS:ThunderRT6CommandButton; INSTANCE:1]")
            Write($test)
            If ($test = 1) Then
                $flag = 1
                Write("Fixer2")
            EndIf
        EndIf
    EndIf
EndIf

If ControlCommand("Vaccin_USB", "", "[CLASS:ThunderRT6CommandButton; INSTANCE:2]", 'IsVisible', '') Then
    ;Write("IsVisible")
    If (ControlGetText("Vaccin_USB", "", "[CLASS:ThunderRT6CommandButton; INSTANCE:2]") = "Fermer") Then
        ControlFocus("Vaccin_USB", "", "[CLASS:ThunderRT6CommandButton; INSTANCE:2]")
        If (ControlClick("Vaccin_USB", "", "[CLASS:ThunderRT6CommandButton; INSTANCE:2]") = 1) Then
            Write("Fermer")
            ExitLoop
        EndIf
    EndIf
EndIf

I also added also ControlFocus()

Edited by Zedna
Link to comment
Share on other sites

Zedna : Thanks for your help, it works now !

To answer PsaltyDS, I did a mistake on WinActive, it was supposed to be WinWaitActive that I had in mind :s I was focused on the ControlClick problem and didn't see that the WinActive function used like I did, couldn't do anything.

Thanks for your help guys. Really appreciate your fast answers.

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...