Check if a box is checked in an other program

Get help with using AutoHotkey and its commands and hotkeys
Zurydix
Posts: 11
Joined: 12 Jul 2017, 06:15

Check if a box is checked in an other program

10 Aug 2017, 06:48

Hello,

I would like to know if there is a way to check if a box is checked in an program (not ahk one).
Image

I tried with PixelGetColor function but I didn't find how to :(

Code: [Select all] [Download] GeSHi © Codebox Plus

		WinActivate ahk_exe NLClientApp.exe
{
PixelGetColor, color, %MouseX%, %MouseY%
if (color="0x212121") ; color of the tick if checked
{
MouseClick, left, 59, 584 ; so if it's checked, click to uncheck it
}

}


Thanks for help :)
Vh_
Posts: 152
Joined: 17 Mar 2017, 22:06

Re: Check if a box is checked in an other program

10 Aug 2017, 07:33

Code: [Select all] [Download] GeSHi © Codebox Plus

ControlGet, IsChecked, Checked,, CheckBox8, WinTitle ;IsChecked = OutputVar, Checked = CMD value,, Checkbox8=Class, WinTitle

Msgbox, % IsChecked ;Checked: Sets OutputVar to be 1 if the checkbox or radio button is checked or 0 if not.




Edit: removed original code.
ControlGet, Checked,, Checkbox1, WinTitle.
Zurydix
Posts: 11
Joined: 12 Jul 2017, 06:15

Re: Check if a box is checked in an other program

10 Aug 2017, 13:04

Vh_ wrote:

Code: [Select all] [Download] GeSHi © Codebox Plus

ControlGet, IsChecked, Checked,, CheckBox8, WinTitle ;IsChecked = OutputVar, Checked = CMD value,, Checkbox8=Class, WinTitle

Msgbox, % IsChecked ;Checked: Sets OutputVar to be 1 if the checkbox or radio button is checked or 0 if not.



Thanks for helping, but how can I know wich checkbox is it? The checkbox isnt in an AHK script, its in an other software.
Image

I'm sorry I am new with AHK :?
MaxAstro
Posts: 381
Joined: 05 Oct 2016, 13:00

Re: Check if a box is checked in an other program

10 Aug 2017, 15:28

Mouse over the checkbox and see what the ClassNN listed is in the "Control Under Mouse Position" section in WindowSpy. If it is blank, then you will need to use PixelSearch to determine the state of the checkbox, but that is definitely the harder method.
Vh_
Posts: 152
Joined: 17 Mar 2017, 22:06

Re: Check if a box is checked in an other program

10 Aug 2017, 18:18

This particular checkbox is called "Button1", but a lot are called "Checkbox1" or something.


[img]
https://gyazo.com/56d9dfcff426c92860883b99fa30e6d5[/img]

Code: [Select all] [Download] GeSHi © Codebox Plus

ControlGet, IsChecked, Checked,, Button1, Snipping Tool Options ;IsChecked = OutputVar, Checked = CMD value,, Checkbox8=Class, WinTitle


the program does not need to be an AHK program.

Hope this helps!
Zurydix
Posts: 11
Joined: 12 Jul 2017, 06:15

Re: Check if a box is checked in an other program

12 Aug 2017, 05:25

Thanks for helping, I learned something :D
But ClassNN is blank so I can't use this method :x
Anyone can clarify how to resolve my problem using PixelSearch function, I already tested it before but I failed

This is what I did :

Code: [Select all] [Download] GeSHi © Codebox Plus

		WinActivate ahk_exe NLClientApp.exe
{
PixelSearch, Px, Py, 481, 212, 490, 219, 0x3B3C3D, RGB ; "0x3B3C3D" is the grey of the tick
if ErrorLevel = 0 ; if the color is found in the region
MouseClick, left, 486, 217 ; tick again to disable
}
User avatar
jeeswg
Posts: 3000
Joined: 19 Dec 2016, 01:58
Location: UK

Re: Check if a box is checked in an other program

12 Aug 2017, 07:07

You could try Acc. See if AccViewer can retrieve the checked state, and if it can, you can use Acc functions to retrieve the state.
Acc library (MSAA) and AccViewer download links - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=6&t=26201
Zurydix
Posts: 11
Joined: 12 Jul 2017, 06:15

Re: Check if a box is checked in an other program

12 Aug 2017, 11:42

jeeswg wrote:You could try Acc. See if AccViewer can retrieve the checked state, and if it can, you can use Acc functions to retrieve the state.
Acc library (MSAA) and AccViewer download links - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=6&t=26201

Thanks for help, but ClassNN is the same for all boxes :/
User avatar
jeeswg
Posts: 3000
Joined: 19 Dec 2016, 01:58
Location: UK

Re: Check if a box is checked in an other program

12 Aug 2017, 12:22

Where available, Acc can do things with subelements *within* controls. In short, if AccViewer can get a red square around the checkbox, and if there is some number/string that changes in AccViewer depending on whether the checkbox is ticked/unticked, then you should be able to retrieve the ticked state via the Acc functions.
TimeHorizon
Posts: 13
Joined: 02 Aug 2017, 17:59

Re: Check if a box is checked in an other program

12 Aug 2017, 19:34

You might also try image search.
Zurydix
Posts: 11
Joined: 12 Jul 2017, 06:15

Re: Check if a box is checked in an other program

13 Aug 2017, 04:04

jeeswg wrote:Where available, Acc can do things with subelements *within* controls. In short, if AccViewer can get a red square around the checkbox, and if there is some number/string that changes in AccViewer depending on whether the checkbox is ticked/unticked, then you should be able to retrieve the ticked state via the Acc functions.

Thanks for help, I tried but I don't know how can I use it it my script :/

This is what I get
Image

Only path and position aren't same between all boxes.
User avatar
jeeswg
Posts: 3000
Joined: 19 Dec 2016, 01:58
Location: UK

Re: Check if a box is checked in an other program

13 Aug 2017, 09:49

I have provided some code to toggle the checkbox in Notepad's Find dialog.

I have also provided two bits of script that you may be able to use, or adapt, to apply to your program. Note: I have used the 'path' shown in your screenshot.

Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus

Last edited by jeeswg on 13 Aug 2017, 12:59, edited 2 times in total.
Zurydix
Posts: 11
Joined: 12 Jul 2017, 06:15

Re: Check if a box is checked in an other program

13 Aug 2017, 12:48

jeeswg wrote:I have provided some code to toggle the checkbox in Notepad's Find dialog.

I have also provided two bits of script that you may be able to use, or adapt, to apply to your program. Note: I have used the 'path' shown in your screenshot.

Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus



Thanks for replying :)
I tried things with what you provided but I failed, I don't understand so much things about Acc library, I don't know wich script should I choose, I just want to check if this box is checked or no, if yes then click on it to uncheck it :/
User avatar
jeeswg
Posts: 3000
Joined: 19 Dec 2016, 01:58
Location: UK

Re: Check if a box is checked in an other program

13 Aug 2017, 13:03

Would you mind providing the full ClassNN? 'HwndWrapper[NL...'

In your screenshot it says 'Cocher' (check). If you untick the box, perhaps it will say 'uncheck'. That would mean that AccViewer could tell whether the box is ticked/unticked. If that is the case, then you can use Acc to retrieve that text, using accDefaultAction, which will tell you whether the box is ticked/unticked. Then you could use accDoDefaultAction to untick the box if it's ticked.

If that doesn't work, the screenshot shows that you could use Acc to retrieve the coordinates of the element. (I've updated my script above to retrieve the coordinates.)

Hopefully you can at least get my example, that works on Notepad's Find dialog, to work.
Zurydix
Posts: 11
Joined: 12 Jul 2017, 06:15

Re: Check if a box is checked in an other program

13 Aug 2017, 16:42

jeeswg wrote:Would you mind providing the full ClassNN? 'HwndWrapper[NL...'

In your screenshot it says 'Cocher' (check). If you untick the box, perhaps it will say 'uncheck'. That would mean that AccViewer could tell whether the box is ticked/unticked. If that is the case, then you can use Acc to retrieve that text, using accDefaultAction, which will tell you whether the box is ticked/unticked. Then you could use accDoDefaultAction to untick the box if it's ticked.

If that doesn't work, the screenshot shows that you could use Acc to retrieve the coordinates of the element. (I've updated my script above to retrieve the coordinates.)

Hopefully you can at least get my example, that works on Notepad's Find dialog, to work.

ClassNN is HwndWrapper[NLClientApp.exe;;30a2f01e-34c8-45f1-ad91-3581bf77cae5]

Return to “Ask For Help”

Who is online

Users browsing this forum: TAC109 and 55 guests