Gui Checkbox Subroutine fail

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Lockleaf
Posts: 2
Joined: 24 Apr 2018, 11:50

Gui Checkbox Subroutine fail

24 Apr 2018, 12:33

I'm working on a very simple GUI. 4 buttons and a checkbox. The four buttons all function just fine. They are simply click the button and they copy text to the clipboard. My failure is in the checkbox operation.

I modified a piece of code I found online so that one push of Capslock copies the highlighted text on the screen, opens an internet tab to google, and runs a search on that text. The code itself works fine.

What I am trying to do is make that bit of code activate and deactivate based on the checkbox. What I am having happen is the code is active and running regardless of whether or not the checkbox is checked. My Capslock Search function will not turn off. I cannot figure out how to disable the function. I would appreciate any advice on what I am doing wrong in this code.

This code has been parsed down from my full code. This is the test sample I am working with to get the function to work. It does not have any code for the buttons.

Code: Select all

; Headlines
Gui, Font, Verdana s10 Bold ; SET HEADLINES FONT
Gui, Add, Text, x175 y30  +BackgroundTrans, Quickcopy
Gui, Font, Norm s8 ; DISABLE HEADLINES FONT, RESET TO NORMAL, SIZE 8 (DEFAULT SIZE AND FONT)

; Buttons Line 1
Gui, Add, Button, x42  y69 w70 h50 ,  Reviewed PQ w/ RF
Gui, Add, Button, x142 y69 w70 h50 ,  Reviewed Totals w/ RF
Gui, Add, Button, x242 y69 w70 h50 ,  Auth Amount
Gui, Add, Button, x342 y69 w70 h50 , Called RF. Left VM.
Gui, Add, Checkbox, x180 y130 vCheckbox gCAPS , Capslock Search


; Generated using SmartGUI Creator 4.0
Gui, Show, x1000 y75 h150 w450, Quickcopy
Return

; Setup CAPSLOCK SEARCH FUNCTION

CAPS:   ; Capslock button searches google with highlighted info
	Gui, Submit, Nohide
	MsgBox, Value is %Checkbox% ; Pop up to tell me if I am returning a value in the variable, I had some issues with getting no value early on.
	If Checkbox = 1
		{
		Capslock::  ; Capslock button searches google with highlighted info
			{
			Send, ^c
			Sleep 50
			Run, http://www.google.com/search?q=%clipboard%
			}
		^Capslock::Capslock   ;CNTL Capslock will do normal capslock function
		}
return

GuiClose:
ExitApp
swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: Gui Checkbox Subroutine fail

24 Apr 2018, 13:09

Code: Select all

; Headlines
Gui, Font, Verdana s10 Bold ; SET HEADLINES FONT
Gui, Add, Text, x175 y30  +BackgroundTrans, Quickcopy
Gui, Font, Norm s8 ; DISABLE HEADLINES FONT, RESET TO NORMAL, SIZE 8 (DEFAULT SIZE AND FONT)

; Buttons Line 1
Gui, Add, Button, x42  y69 w70 h50 ,  Reviewed PQ w/ RF
Gui, Add, Button, x142 y69 w70 h50 ,  Reviewed Totals w/ RF
Gui, Add, Button, x242 y69 w70 h50 ,  Auth Amount
Gui, Add, Button, x342 y69 w70 h50 , Called RF. Left VM.
Gui, Add, Checkbox, x180 y130 visCapsSearchEnabled gCAPS , Capslock Search


; Generated using SmartGUI Creator 4.0
Gui, Show, x1000 y75 h150 w450, Quickcopy
Return

; Setup CAPSLOCK SEARCH FUNCTION
#If, isCapsSearchEnabled
^Capslock::Capslock   ;CNTL Capslock will do normal capslock function
Capslock::  ; Capslock button searches google with highlighted info
{
	Send, ^c
	Sleep 50
	Run, http://www.google.com/search?q=%clipboard%
return
}
#If

CAPS:   ; Capslock button searches google with highlighted info
{
	Gui, Submit, Nohide
	MsgBox, % "isCapsSearchEnabled:" . isCapsSearchEnabled ; u dont have to do anything in here besides update the value via Gui, Submit
return
}

GuiClose:
ExitApp
Lockleaf
Posts: 2
Joined: 24 Apr 2018, 11:50

Re: Gui Checkbox Subroutine fail

24 Apr 2018, 14:23

Thanks Swag. That definitely works. I appreciate the code.

Could anyone tell me what my code was doing wrong? Was it just a syntax issue, or was I using the wrong version of IF to put a subroutine into? I would like to not only know that my code works, but why, if someone is willing to explain why my original code doesn't work.

Also, is there a functional difference between assigning a variable as "vVariable" vs "visVariable" or are those totally interchangeable?
swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: Gui Checkbox Subroutine fail

24 Apr 2018, 16:30

no, it has nothing to do with how the variables are called, i changed it to give it some meaning. imagine u l8r down the road put 20 more checkboxes 1 through 20, what a cf that would be.

the issue with the original piece of code is that you cant just stuff hotkeys/labels in an regular if-statement(well, technically u could, but that requires another construct, see the Hotkey command in the docs). When u define a hotkey the old fashioned way its active by default and to make it respond to changing condition yo need to surround it with a special kind of if-statement, the #If directive.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Araphen, doanmvu, uchihito, zvit and 285 guests