Sign in to follow this  
Followers 0
Guest sebiuta

How to check or uncheck items from a listbox

14 posts in this topic

Hi ....i use AutoIT from 2 days and I begin to create some automated installs that make my work easier. :ph34r: In order to install some programs i need to check or uncheck some options from a check listbox . How do I do that ?..except the mouse click because i do not know the resolution of the screen so the X and Y values are diferent for each resolution ...

Please help ....

It seems the AutoIT scripting language it become a powerful tool for everyone. I would like to thank people that working of this great project.

Share this post


Link to post
Share on other sites



You have 2 choice:

Using the command ControlCommand() using "UnCheck", "" or "Check", "" as command/option.

Sending a the key + to the control for tagging and the key - for unttagging with ControlSend().

Share this post


Link to post
Share on other sites

You have 2 choice:

Using the command ControlCommand() using "UnCheck", "" or "Check", "" as command/option.

Sending a the key + to the control for tagging and the key - for unttagging with ControlSend().

<{POST_SNAPBACK}>

I have 10 check box in the listbox. If a check only the second and the third option from the listbox how do i do that ??

Share this post


Link to post
Share on other sites

Sound strange, can you upload a screenshot?

Share this post


Link to post
Share on other sites

Sound strange, can you upload a screenshot?

<{POST_SNAPBACK}>

Yeap .....actualy is an option window from a winamp for example.

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

I see... I made few tries and I think the best idea is sending to the controls the keys you need. I Winamp5 lite installation sending {home}{down n}{SPACE} works.

e.g. In the Winamp5 installation, selection component screen this line disable the Winamp agent:

ControlSend('Winamp Setup','','SysTreeView321','{home}{down}{space}')
Edited by ezzetabi

Share this post


Link to post
Share on other sites

Funny this, I had to do this yesterday (Not for Winamp, however). What I decided to do was, pick a location on the listbox where you know the pixel will be the background color. Then find 1 pixel in each checkbox where the dark color or whatever will be if the item is checked. I then compared to see if that pixel was the background color, if it was, but I wanted that option set, then I used ControlCommand() with "SetCurrentSelection" to set focus to that item (Numbering starts at 0). Then I ControlSend() a space to toggle it.

Obviously, you can use the same logic to uncheck an item as well.

I would post my code as an example, but its pretty tricky to understand.

And before anybody askes, the reason I get the listbox's background color at run-time is to support different themese that could somehow change the listbox's background color.

Share this post


Link to post
Share on other sites

ezzetabi, this isn't a SysListView, it's exactly what sebiuta described. It's a listbox that has been owner-drawn to provide a checkbox by each item in the list. It's the class CCheckListBox is MFC, but its possible to create without MFC if you override how the control is drawn. I ran into the very same type of ListBox yesterday as I mentioned above. The new WinAmp installer very well might be using a SysListView, but the one in the screenshot above is not.

Share this post


Link to post
Share on other sites

So... Sending keys to it via ControlSend() cant work?

Share this post


Link to post
Share on other sites

#10 ·  Posted (edited)

The only key that it responds to is space which toggles its state.

Edit: And it responds to up/down, too (For navigation, obviously). However the listbox functions of ControlCommand() work as well, so I don't recommend using the potentially unreliable up/down method.

Edited by Valik

Share this post


Link to post
Share on other sites

So maybe an other idea is resizing the window to a know size and using mouse clicks... Setting the AutoItSetOption MouseCoordMode to 0 of course.

Share this post


Link to post
Share on other sites

#12 ·  Posted (edited)

So maybe an other idea is resizing the window to a know size and using mouse clicks... Setting the AutoItSetOption MouseCoordMode to 0 of course.

<{POST_SNAPBACK}>

Ummm, why would you do that? The problem is not how to toggle the state of the particular item (I've explained how to do that twice now), but how to determine the current state of that item so that you have it in the state that you want. Selecting the item via SelectString or SetCurrentSelection and then ControlSending a space to it works fine to toggle it (Provided its a "standard" version of the control, at least). That shouldn't be the problem. The problem is, not accidentally unchecking something you want, or accidentially checking something you don't want. For that, some form of pixel detection must occur because the control doesn't respond to any checkbox commands and there is no way to send a pure "check this item" or "uncheck this item"; only toggle back and forth.

Edit: Forgot to mention, determing the state of the checkbox should be the priority, because if for some reason the application is already installed, the installer might have options checked/unchecked differently than what the script/author is expecting.

Edited by Valik

Share this post


Link to post
Share on other sites

But... So I do not understand. Didint you said that the program reach to + or -? Do you mean that after clicking in the right place pressing - or + dont set the state as wanted?

Share this post


Link to post
Share on other sites

Actually, Larry, PixelCoordMode 0 is enough (Unless sending space doesn't work, then you'd need the mouse stuff, I guess). Find the center of the top-most checkbox, then calculate an offset to add to that first y-coordinate to find the center of the rest (I did all this in a loop, of course). I only have 3 coordinates hard-code; I use the same x for every check, I have a y-coordinate to get my background color, then I have a y-coordinate for my first checkbox, then I add the offset*loop number to get the rest of the checkboxes.

ezzetabi, NO, THE ONLY THING THAT IT RESPONDS TO IS SPACE. I said nothing about + or - keys on the keyboard becase... wait for it... THE ONLY THING THAT IT RESPONDS TO IS SPACE. I've said to use space 3 times before making this post.

Here's the code I use, but don't expect to understand it because it uses nothing but variables which are defined in various places:

BlockInput(1)
Opt("PixelCoordMode", 0)
WinActivate($hWnd)
$color = PixelGetColor($colorX, $colorY)
For $i = 0 To $nCom - 1
    Local $pixel = PixelGetColor($x, $yBase+($yInc*$i))
    Local $opt = Eval("FF_OPT_COM" & ($i+1))
    If ($pixel = $color And BitAND($nOpt, $opt)) Or ($pixel <> $color And Not BitAND($nOpt, $opt)) Then
        ControlCommand($hWnd, $text, $control, "SetCurrentSelection", $i)
        ControlSend($hWnd, $text, $control, "{SPACE}")
    EndIf
Next
BlockInput(0)

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