Jump to content

Toggling Checkboxes With Controlcommand?

Recommended Posts

Can someone advise me how to use ControlCommand?

I am trying to test wether a checkbox in an application is enabled.

I'm not quite sure how to use ControlCommand and it's parameters correctly and if it's really intended for my purpose.

AutoItSetOption ( "WinTitleMatchMode", 2 )
    WinActivate ( "HTTPort 3.SNFM" )
    WinWaitActive("HTTPort 3.SNFM")
ControlCommand("HTTPort 3.SNFM", "Proxy requires authentication", "", "Check", "" )

The intended Control gets the focus but that's it, no toggling. :whistle:

Link to post
Share on other sites

Call this function .. (use 0 for Black, or use your AutoitSpy for custom colo(u)rs)

Func CheckBox($pX1, $pX2, $pY1, $pY2, $pOnColor, $pState)
;This function scans the pixels in the given range, 
;and if the $pColor value is found then does nothing (since it is ALREADY "on")
;otherwise it sends a mouseclick event to the middle of the range
;Set coordinates relative to active window  
    AutoItSetOption("MouseCoordMode", 0)   ;0 = relative coords to the active window
    AutoItSetOption("PixelCoordMode", 0)   ;0 = relative coords to the active window

;Ignore mouse wanderings
;See if the On-Color can be found
    $aXY = PixelSearch($pX1, $pY1, $pX2, $pY2, $pOnColor)
    If @error = 1 then
       ;pOnColor WAS NOT found
        $ynChecked = 0
       ;pOnColor WAS found
        $ynChecked = 1
    If $ynChecked = $pState then 
       ;Do nothing, since the required state matches the current status
       ;Send the mouse to click the topleft coords
        MouseClick( "left" ,$pX1 ,$pY1 ,1 ,0)       
;Back to normal

Link to post
Share on other sites

Btw: I had to use the function above for an install that used non-standard checkboxes, cos the regular method didn't work on it ..

$sTitle = "Regional Settings Properties"
    ControlCommand($sTitle, "", "Button1", "Check", "")

    ControlCommand($sTitle, "", "Button1", "UnCheck", "")
Link to post
Share on other sites

Thanks for the workaround using the pixel color.

But let's return for a moment to ControlCommand: I finally worked out how to make it function but have to admit that I'm still not sure how to set the parameters, expecially the need of the "text"-part.

The help file tells us to use it like this:

ControlCommand ( "title", "text", "classnameNN", "command" ,"option")

Take Winamp for example. I want to open the File-Info Box and uncheck the ID3v2 Tag option. After the Send ("!fv") I get a box with the title "MPEG file info box + ID3 tag editor". I now search AU3_Spy for the text which is displayed beneath the checkbox. In this case I find "ID3v&2 Tag" in the section <Visible Window Text>. Additionally I would search AU3_spy for the Checkbox name and find "Button5".

My ConctrolCommand would then be

ControlCommand("MPEG file info box + ID3 tag editor", "ID3v&2 Tag", "Button5", "UnCheck", "")

This works, but it also works when I leave out the "text" parameter, and it doesn't work when I leave it in and take out the "classnameNN"-parameter instead. Why is that?

Link to post
Share on other sites
  • Developers

This is how I understand it works up till now.....

The Title and Text fields are used to Identify the correct window. So text should contain a text that makes this particular window unique.

If the window title is unique it will work without a value in the Text field to identify the correct window.

The classnameNN parameter is the name of the control on the selected window which you want to Check/UnCheck. so thats always needed.

By the way you can also use these commands to Check / uncheck checkboxes:

; to check
ControlSend("MPEG file info box + ID3 tag editor", "ID3v&2 Tag", "Button5","{NUMPADADD}")
; to UnCheck
ControlSend("MPEG file info box + ID3 tag editor", "ID3v&2 Tag", "Button5","{NUMPADSUB}")

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
Live for the present,
Dream of the future,
Learn from the past.

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
  • Recently Browsing   0 members

    No registered users viewing this page.

  • Create New...