Check if a box is checked in an other program

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Zurydix
Posts: 21
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

		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: 203
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

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: 21
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

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: 557
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: 203
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

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: 21
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

		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: 6902
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
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
Zurydix
Posts: 21
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: 6902
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.
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
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: 21
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: 6902
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

;Acc library (MSAA) and AccViewer download links - AutoHotkey Community
;https://autohotkey.com/boards/viewtopic.php?f=6&t=26201

q:: ;e.g. Notepad Find dialog toggle Match case checkbox
ControlGet, hCtl, Hwnd,, Button2, A
oAcc := Acc_Get("Object", "4", 0, "ahk_id " hCtl)
vAccName := oAcc.accName(0)
vAccValue := oAcc.accValue(0)
vAccAction := oAcc.accDefaultAction(0)
oRect := Acc_Location(oAcc)
vAccLocation := "x" oRect.x " y" oRect.y " w" oRect.w " h" oRect.h
oAcc.accDoDefaultAction(0)
MsgBox, % vAccName "`r`n" vAccValue "`r`n" vAccAction "`r`n" vAccLocation
oAcc := oRect := ""
return

e:: ;get GUI element relative to control
;note: replace ClassNN with appropriate ClassNN e.g. 'Button1'
ControlGet, hCtl, Hwnd,, ClassNN, A
oAcc := Acc_Get("Object", "10.2.7.3.5.1", 0, "ahk_id " hCtl)
oAcc.accDoDefaultAction(0)
oAcc := ""
return
Last edited by jeeswg on 07 Mar 2018, 13:29, edited 4 times in total.
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
Zurydix
Posts: 21
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

q:: ;e.g. Notepad Find dialog toggle Match case checkbox
ControlGet, hCtl, Hwnd,, Button2, A
oAcc := Acc_Get("Object", "4", 0, "ahk_id " hCtl)
vAccName := oAcc.accName(0)
vAccValue := oAcc.accValue(0)
vAccAction := oAcc.accDefaultAction(0)
oAcc.accDoDefaultAction(0)
MsgBox, % vAccName "`r`n" vAccValue "`r`n" vAccAction
oAcc := ""
return

w:: ;get GUI element relative to window
WinGet, hWnd, ID, A
oAcc := Acc_Get("Object", "10.2.7.3.5.1", 0, "ahk_id " hWnd)
oAcc.accDoDefaultAction(0)
oAcc := ""
return

e:: ;get GUI element relative to control
;note: replace ClassNN with appropriate ClassNN e.g. 'Button1'
ControlGet, hCtl, Hwnd,, ClassNN, A
oAcc := Acc_Get("Object", "10.2.7.3.5.1", 0, "ahk_id " hCtl)
oAcc.accDoDefaultAction(0)
oAcc := ""
return
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: 6902
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.
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
Zurydix
Posts: 21
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 (v1)”

Who is online

Users browsing this forum: Descolada, tiska and 130 guests