Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

Check if checkbox is checked



  • Please log in to reply
11 replies to this topic
heegenees
  • Members
  • 51 posts
  • Last active: May 23 2014 10:17 AM
  • Joined: 14 Apr 2014

Hallo,

 

I'm fairly new to AHK but find it a great program for atomization of bulk jobs of boring copy/pasting.

 

One thing would make the whole progress even more autonomous but I can't find out how to do it, or if it's even possible with AHK.

What I'm trying to achieve is that AHK checks if a checkbox is ticked, and if it isn't ticked AHK automatically ticks it before continuing the script.

I found some documentation about AHK and checkboxes but just don't understand them since if have no programming background at all and they are way more complex then what I require. I can't figure out what part of the code I would need.

 

I can only specify the exact location of where the checkbox is located, but adding a mouse click at that location (MouseClick, left,  26,  1170) is not enough since sometimes the box is ticked and sometimes it isn't, but it should always be ticked before the script continues.

 

Your help is greatly appreciated.



Leef_me
  • Moderators
  • 8510 posts
  • Last active: Sep 10 2015 05:50 AM
  • Joined: 08 Apr 2009

Where is the checkbox, in a program or in a webpage?

 

I will presume you need this is for an application, below is an example (I don't know how to do this for webpages)

 

There is an application in the AHk folder called "Window Spy" which can tell you the name of the control.

Both "Window Spy" and AHk refer to a checkbox in an external program with the control name "Button..." keep this in mind.

 

You need to use "Window Spy" on you application to see what the controls name is.

 

Here is my example script. The two sections can be in one script or two it does not matter.

; this is a stand-in for a real application
;------------------------------------------------------------------------------
gui, add, text,, this is test
gui, add, checkbox,, this is checkbox
gui, show, w200 h200, Example Window ; Leef_me likes bigger application windows
return
;------------------------------------------------------------------------------



; this tests the state of a checkbox in an application
;------------------------------------------------------------------------------
; if you leave the mouse cursor near the checkbox, 
;     you can see both the checkbox and the answer together

; you must press F2 >each< time you want to test

f2::
ControlGet, isitchecked, Checked , , Button1, Example Window
tooltip, isitchecked ?--> %isitchecked%
return

;------------------------------------------------------------------------------

HTH



PuppyCat
  • Members
  • 10 posts
  • Last active: Apr 28 2014 05:18 AM
  • Joined: 02 Apr 2014

If you are referring to a checkbox on a AHK form this might help:

Function:
GuiControlGet, MyCheckBox ; Retrieves 1 if it is checked, 0 if it is unchecked.
If (MyCheckBox = 0)
{
goto FunctionFlatten1
return
}
else
{
goto FunctionFlatten2
return
}


heegenees
  • Members
  • 51 posts
  • Last active: May 23 2014 10:17 AM
  • Joined: 14 Apr 2014

It's a Citrix inviroment for my work called Desktop 90%. If I check / uncheck the box with windows spy it gives the following output:

 

WinWait, Desktop 90`% - Citrix online plug-in,
IfWinNotActive, Desktop 90`% - Citrix online plug-in, , WinActivate, Desktop 90`% - Citrix online plug-in,
WinWaitActive, Desktop 90`% - Citrix online plug-in,
MouseClick, left,  27,  1020
Sleep, 100

 

It does not give a 'button'  in there.

I'll check the featback you gave me tomorrow to see if I can use it somehow.
 



heegenees
  • Members
  • 51 posts
  • Last active: May 23 2014 10:17 AM
  • Joined: 14 Apr 2014

Update, I just realised I used the AutoscriptWriter for my last post. I just used the Windows Spy and it gives the following output:
 

>>>>>>>>>>(Windows Title & Class)<<<<<<<<<<

Desktop 90% Citrix online plug-in

ahk_class wMFService000101F8000

>>>>>>>>>>>>(Mouse Position)<<<<<<<<<<<<<

On Screen:                    -1903, 1159 (less often used)

In Active Window:         26, 1168

>>>>>>>>(Now Under Mouse Cursor)<<<<<<<<<

ClassNN: CtxlCADisp1

Text:

Color:       0xFFFFFF (Blue=FF Green=FF Red=FF)

>>>>>>>>>>(Active Window Position<<<<<<<<<<

left: -1929  top:-9   width: 1938  height: 1218

>>>>>>>>>>>(Status Bar Text)<<<<<<<<<<

>>>>>>>>>>>(Visible Windows Text)<<<<<<<<<<

>>>>>>>>>>>(Hidden Windows Text)<<<<<<<<<

>>>>>(TitleMatchMode=slow Visible Text)<<<<<

>>>>>(TitleMatchMode=slow Hidden Text)<<<<<


 

What is the button in the output?



heegenees
  • Members
  • 51 posts
  • Last active: May 23 2014 10:17 AM
  • Joined: 14 Apr 2014

 

If you are referring to a checkbox on a AHK form this might help:

Function:
GuiControlGet, MyCheckBox ; Retrieves 1 if it is checked, 0 if it is unchecked.
If (MyCheckBox = 0)
{
goto FunctionFlatten1
return
}
else
{
goto FunctionFlatten2
return
}

 

If I use

 

GuiControlGet, Button1 ; Retrieves 1 if it is checked, 0 if it is unchecked.
If (MyCheckBox = 0)
{
goto FunctionFlatten1
return
}
else
{
goto FunctionFlatten2
return
}

 

(I named it Button1 since Leef_me stated that it's always a button) it wil give an error on the 8th line

 

Error: Target label does not exist.

008:Goto,FuntionFlatten1



Leef_me
  • Moderators
  • 8510 posts
  • Last active: Sep 10 2015 05:50 AM
  • Joined: 08 Apr 2009

>> I just used the Windows Spy and it gives the following output:
 

; these are the useful pieces of information I have included them with the script to be helpful

; please try the script, -->run the script, run the program, press F2, see the tooltip

;

; >>(Windows Title & Class)<<<<<<<<<<
;   Desktop 90% Citrix online plug-in
;   ahk_class wMFService000101F8000
;

;

;>>>>>>>>(Now Under Mouse Cursor)<<<<<<<<<
;
;ClassNN: CtxlCADisp1
;

;

; please notice what I selectively copied

;

; you need the control name and the wildow title ( I used a partial title which is acceptable by default)

; Please read the docs for the commands "ControlGet", and "SetTitleMatchMode" for more information

;

;

F2::
ControlGet, isitchecked, Checked , , CtxlCADisp1, Desktop 90% Citrix

tooltip, isitchecked ?--> %isitchecked%
return
 

 

>>GuiControlGet, Button1 ; Retrieves 1 if it is checked, 0 if it is unchecked.
 

; commands that start with "GuiControl..." are useless for what you want with your application

 

>>If (MyCheckBox = 0)
 

You need to use the same variables in a script. The previous command uses "Button1" for both control name and where the result is stored. Using the name "MyCheckBox" is then useless.

 

>>goto FunctionFlatten1
 

>>it wil give an error on the 8th line

>>Error: Target label does not exist.

>>008:Goto,FuntionFlatten1

The "goto" command expects a label that matches, it did not find one

 

>>(I named it Button1 since Leef_me stated that it's always a button)

 

As I stated earlier in this post, "GuiControlGet" will not help you in your task.

DId you try using "Window Spy" as I suggested?

 



heegenees
  • Members
  • 51 posts
  • Last active: May 23 2014 10:17 AM
  • Joined: 14 Apr 2014

I put this in the script:

 

-----------------------------------------------------

F2::
ControlGet, isitchecked, Checked , , CtxlCADisp1, Desktop 90% Citrix

tooltip, isitchecked ?--> %isitchecked%
return

-----------------------------------------------------

 

But it gave an error on the Desktop 90% Citrix part so I changed it to:

 

-----------------------------------------------------

F2::
ControlGet, isitchecked, Checked , , CtxlCADisp1, Desktop 90`% - Citrix online plug-in

tooltip, isitchecked ?--> %isitchecked%
return

-----------------------------------------------------

 

And then I could run the script without an issues.

However if I press F2 the only thing that happends is that I get a box on the location where my mouse is at that moment with in the box the text: isitchecked ?-->

Nothing further happend.

 

I changes the script to:

 

-----------------------------------------------------

WinWait, Desktop 90`% - Citrix online plug-in,
IfWinNotActive, Desktop 90`% - Citrix online plug-in, , WinActivate, Desktop 90`% - Citrix online plug-in,
WinWaitActive, Desktop 90`% - Citrix online plug-in,

F2::
ControlGet, isitchecked, Checked , , CtxlCADisp1, Desktop 90`% - Citrix online plug-in

tooltip, isitchecked ?--> %isitchecked%
return

-----------------------------------------------------

 

because it has to do this in the Desktop 90`% - Citrix online plug-in screen and if I do I can see the windows of Desktop 90`% - Citrix online plug-in beeing activated, it jumps up if it wasn't allready, but other then that nothing happends. If I press F2 again I get a box on the location where my mouse is at that moment with in the box the text: isitchecked ?-->

 

I used the Windows Spy tool, the only information it gave me was what I already posted 3 posts above this one.



Leef_me
  • Moderators
  • 8510 posts
  • Last active: Sep 10 2015 05:50 AM
  • Joined: 08 Apr 2009

Sorry about the problem with %, I didn't consider it

 

You still may be having trouble with it.

I suggest you try changing that parameter to "Desktop 90"  w/o quotes.



heegenees
  • Members
  • 51 posts
  • Last active: May 23 2014 10:17 AM
  • Joined: 14 Apr 2014

I changed it to Desktop 90 but then the same thing occurs, no error, I can just run it but it does nothing more then to give the text "isitchecked ?-->" at the location where my cursor is at that moment. It doesn't go to the checkbox or do anything else.



heegenees
  • Members
  • 51 posts
  • Last active: May 23 2014 10:17 AM
  • Joined: 14 Apr 2014
✓  Best Answer

Because in citrix the ClassNN and AHK_Class cannot be used if the script is ran from a normal Windows computer I had to use PixelGetColor to solve this issue.

 

I've solved it with:

xPos := 26
yPos := 1172

expectedPixel := "0xFFFFFF"
PixelGetColor, FoundPixel, %xPos%, %yPos%
If (FoundPixel = expectedPixel)
MouseClick, left, 26, 1172

Tested it and it works fine. Thanks to all.



Frio
  • Members
  • 5 posts
  • Last active: Sep 22 2015 02:19 PM
  • Joined: 13 Aug 2015

 

If you are referring to a checkbox on a AHK form this might help:

Function:
GuiControlGet, MyCheckBox ; Retrieves 1 if it is checked, 0 if it is unchecked.
If (MyCheckBox = 0)
{
goto FunctionFlatten1
return
}
else
{
goto FunctionFlatten2
return
}

Oh my god, thank you, been searching for this for a week!