Detecting if check box is checked Topic is solved

Get help with using AutoHotkey and its commands and hotkeys
SilverGaiden
Posts: 13
Joined: 08 Jun 2018, 01:39

Detecting if check box is checked

13 Jun 2018, 19:19

Hello!

Again thank you in advance for all the help.

I seem to be having some trouble with check boxes. I know that the state is detected after being checked, but when the check box is checked (Private=1) THEN you change the dropdown menu to firefox or chrome, it will not bring up the private/incognito window.

If you change the drop down menu first, and THEN check the box second, it will pull up the private/incognito window.

Any help with why this is? or if there is a different way to perform this?

Code: Select all

#NoEnv
#SingleInstance Force
SetWorkingDir %A_ScriptDir%


Gui Font, s10 Bold, Segoe UI
Gui Add, Text, x3 y90 w110 h23, Domain Name
Gui Font
Gui Add, Edit, vdomain x115 y90 w180 h20, https://google.com


Gui Add, DropDownList, x175 y120 gBrowserType vSelectedBrowser, Default Browser||Firefox|Chrome


Gui, Add, CheckBox, x180 y150 gIncognitoGroup vPrivate, Incognito/Private


Gui Add, Button, xp+25 yp+30 w50 h50, Browse


Gui Show, w481 h381, Window
Return

GuiEscape:
GuiClose:
    ExitApp




ButtonBrowse:
Gui, submit, nohide
Run, %PassthroughBrowser% %PassthroughPrivate% %domain%
return


BrowserType:
    Gui, Submit, NoHide
    If (SelectedBrowser="Firefox")
        {
        PassthroughBrowser="firefox.exe"
        }
    Else If (SelectedBrowser="Chrome")
        {
        PassthroughBrowser="chrome.exe"
        }
    Else
        {
        PassthroughBrowser=
        }
Return


IncognitoGroup:
    GuiControlGet, Private
    If (Private=0)
        {
        PassthroughPrivate=
        }
    Else If (Private=1)
        {
        If (SelectedBrowser="Firefox")
            {
            PassthroughPrivate="-private-window"
            }
        Else If (SelectedBrowser="Chrome")
            {
            PassthroughPrivate="-incognito"
            }
        Else
            {
            PassthroughPrivate=
            }
        }
    Return
SilverGaiden
Posts: 13
Joined: 08 Jun 2018, 01:39

Re: Detecting if check box is checked

13 Jun 2018, 19:20

Corrected Grammar with last edit
Hellbent
Posts: 143
Joined: 23 Sep 2017, 13:34

Re: Detecting if check box is checked

14 Jun 2018, 01:24

When you add a control, even though you have told it what should or not be selected, the associated variables don't have a clue about what those values are. You have two options if you want to keep using "GuiControlGet".

1. Create your variables above your gui and give them a starting value
ie.
SelectedBrowser:= "Defalut Browser"

2. After you have added all your controls but before the return, do a gui, submit to make sure the values are in the associated variables.

ie.
Gui,show
Gui,submit,nohide
return

**Edit: Also, you have this
PassthroughPrivate="-incognito"
What you want is:
PassthroughPrivate:="-incognito"
or
PassthroughPrivate=-incognito
SilverGaiden
Posts: 13
Joined: 08 Jun 2018, 01:39

Re: Detecting if check box is checked

14 Jun 2018, 13:28

Hellbent wrote:When you add a control, even though you have told it what should or not be selected, the associated variables don't have a clue about what those values are. You have two options if you want to keep using "GuiControlGet".

1. Create your variables above your gui and give them a starting value
ie.
SelectedBrowser:= "Defalut Browser"

2. After you have added all your controls but before the return, do a gui, submit to make sure the values are in the associated variables.

ie.
Gui,show
Gui,submit,nohide
return
Thank you Hellbent, but I think I am a little lost on that. I changed it and tried to position along the top but it either doesn't show or it doesn't change anything. Sory I am a nub when it comes to this. I did change the GuiControlGet to "Gui, Submit, Nohide". I don't know which is better and I am open to revamp my entire code to do it properly and efficiently.

Code: Select all

BrowserType:
    Gui, Submit, NoHide
    If (SelectedBrowser="Firefox")
        {
        PassthroughBrowser:="firefox.exe"
        }
    Else If (SelectedBrowser="Chrome")
        {
        PassthroughBrowser:="chrome.exe"
        }
    Else
        {
        PassthroughBrowser:=""
        }
Return

IncognitoGroup:
    Gui, Submit, NoHide
    If (Private=0)
        {
        PassthroughPrivate:=""
        }
    Else If (Private=1)
        {
        If (SelectedBrowser="Firefox")
            {
            PassthroughPrivate:="-private-window"
            }
        Else If (SelectedBrowser="Chrome")
            {
            PassthroughPrivate:="-incognito"
            }
        Else
            {
            PassthroughPrivate:=""
            }
        }
    Return
Hellbent wrote: **Edit: Also, you have this
PassthroughPrivate="-incognito"
What you want is:
PassthroughPrivate:="-incognito"
or
PassthroughPrivate=-incognito
Thank you on the code help! that explains a few things I was encountering in the past.


Would you be able to provide a coding example? I'm just not understanding how to structure it. (like I said earlier, I'll scrap the whole thing to code it properly and efficiently, I like to learn)

THANK YOU!
Hellbent
Posts: 143
Joined: 23 Sep 2017, 13:34

Re: Detecting if check box is checked  Topic is solved

14 Jun 2018, 13:58

Here is what I am talking about in regards to the associated variable.

Code: Select all


; In the next control I am going to associate it with the variable Var1

Gui, Add, DropDownList, vVar1 ,item 1||item 2|item 3|

; If you were to run this you would see that item one has been selected, and you would assume that if you checked the value 
; of Var1 that it would have a value of "item 1", but it doesn't, it has a value of null/nothing. To get it to have that value you need to submit it.
; This is the reason why when you have been selecting another item in your lists etc that you don't have any problems. It's 
; because when you select another item it launches a thread that has "Gui, Submit" in it.

; The fix in this case is simple.

; Option one:

; Before you make the control, create the Var1 variable and set it to have a value that matches your default.
; and then create the control. (or at the least, set it before your first "return")

Var1:="item 1"
Gui, Add, DropDownList, vVar1 ,item 1||item 2|item 3|

; In the example above, Var1 now has the value you are expecting it to have.

; Option 2:

;After you have added all your gui controls, but before the first return add a "Gui,Submit,NoHide"

; Like this

gui,add,some control
gui,add,some control
gui,show
gui,submit,nohide
return

;With the example above, all the associated variables will be set with their values as soon as your gui is built.


; The last thing that you could change is the "GuiControlGet" with "Gui,Submit,NoHide", but if you make at least one of the changes as seen above you should be fine.
SilverGaiden
Posts: 13
Joined: 08 Jun 2018, 01:39

Re: Detecting if check box is checked

14 Jun 2018, 15:30

Sweet that explains the GuiControlGet situation

From what I gather then, gui submit causes it to actually recognize it's own variable the moment it's selected, no matter the position in the script. I changed it back to Gui, Submit, NoHide.

If I understand this correctly, the SelectedBrowser variable, is not submitting the Private variable. How do I get the drop-down menu to submit the Private variable as well?
SilverGaiden
Posts: 13
Joined: 08 Jun 2018, 01:39

Re: Detecting if check box is checked

14 Jun 2018, 18:21

WOOT WOOT! I FIGURED IT OUT!

Thank you Hellbent!!! you gave me what I needed!

I changed the group on the checkbox to gBrowserType and then just placed the privacy check in the same group.

:dance: :dance: :dance: :dance: :dance:

Code: Select all

#NoEnv
#SingleInstance Force
SetWorkingDir %A_ScriptDir%


Gui Font, s10 Bold, Segoe UI
Gui Add, Text, x3 y90 w110 h23, Domain Name
Gui Font
Gui Add, Edit, vdomain x115 y90 w180 h20, https://google.com


Gui Add, DropDownList, x175 y120 gBrowserType vSelectedBrowser, Default Browser||Firefox|Chrome


Gui, Add, CheckBox, x180 y150 gBrowserType vPrivate, Incognito/Private


Gui Add, Button, xp+25 yp+30 w50 h50, Browse


Gui Show, w481 h381, Window
Return

GuiEscape:
GuiClose:
    ExitApp




ButtonBrowse:
Gui, submit, nohide
Run, %PassthroughBrowser% %PassthroughPrivate% %domain%
return


BrowserType:
    Gui, Submit, NoHide
    If (SelectedBrowser="Firefox")
        {
        PassthroughBrowser:="firefox.exe"
        }
    Else If (SelectedBrowser="Chrome")
        {
        PassthroughBrowser:="chrome.exe"
        }
    Else
        {
        PassthroughBrowser:=""
        }

    Gui, Submit, NoHide
    If (Private=0)
        {
        PassthroughPrivate:=""
        }
    Else If (Private=1)
        {
        If (SelectedBrowser="Firefox")
            {
            PassthroughPrivate:="-private-window"
            }
        Else If (SelectedBrowser="Chrome")
            {
            PassthroughPrivate:="-incognito"
            }
        Else
            {
            PassthroughPrivate:=""
            }
        }
    Return

Return to “Ask For Help”

Who is online

Users browsing this forum: Google [Bot], JoeWinograd and 65 guests