Label: Turn on and off with checkbox.

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Oblivion Deleted
Posts: 2
Joined: 11 Apr 2021, 05:14

Label: Turn on and off with checkbox.

Post by Oblivion Deleted » 11 Apr 2021, 05:45

Hello everyone!
I would like to learn how to give functions for each marked or unmarked checkbox.
However, the language limits me a lot for now, but knowing AHK makes me want to learn English as soon as possible.

Problem:
- I have 3 imagesearch labels in my script, but I don't know how to turn the labels on / off with the GUI checkbox.

Code: Select all

Gui, Add, Text, x12 y9 w100 h20 , Macro1
Gui, Add, CheckBox, x12 y29 w100 h30 , On/Off ; Turn on and off the macro1

Gui, Add, Text, x12 y69 w100 h30 , Macro2
Gui, Add, CheckBox, x12 y99 w100 h30 , On/Off ; Turn on and off the macro2

Gui, Add, Text, x12 y139 w100 h30 , Macro3
Gui, Add, CheckBox, x12 y159 w100 h30 , On/Off ; Turn on and off the macro3

Gui, Add, Text, x192 y9 w110 h30 , Pause ; Turn on to PAUSE everything
Gui, Add, CheckBox, x192 y39 w110 h30 , Pause

Gui, Add, Text, x192 y89 w110 h30 , Exit ;Turn on to Exitapp/close the script
Gui, Add, CheckBox, x192 y119 w110 h30 , Exit

Gui, Show, w436 h314, OblivionGUI
return

GuiClose:
ExitApp


SetTimer, Macro1, 300		
SetTimer, Macro2, 100	
SetTimer, Macro3, 50	


;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~SCRIPTS~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Macro1:
If WinActive("ahk_class Qt5QWindowOwnDCIcon")
{
	ImageSearch, FirstStageX, FirstStageY, A_ScreenWidth - 368, 0, A_ScreenWidth, A_ScreenHeight - A_ScreenHeight + 470, *15, Imagens\HP%Porcentagem_Para_Healar_Vida1%Percent.png		;% Primeiro Estagio [LIFE]
	if ErrorLevel = 1
	{
	ImageSearch, SecondStageX, SecondStageY, A_ScreenWidth - 368, 0, A_ScreenWidth, A_ScreenHeight - A_ScreenHeight + 470, *15, Imagens\HP%Porcentagem_Para_Healar_Vida2%Percent.png	;% Segundo Estagio [LIFE]
	if ErrorLevel = 1
	{
	ImageSearch, ThirdStageX, ThirdStageY, A_ScreenWidth - 368, 0, A_ScreenWidth, A_ScreenHeight - A_ScreenHeight + 470, *15, Imagens\HP%Porcentagem_Para_Healar_Vida3%Percent.png		;% Terceiro Estagio [LIFE]
	if ErrorLevel = 1
	{
		Send, {F2}
		Sleep 200
		goto Macro1
	}
		Send, {F5}
		Sleep 200
		goto Macro1
	}
		Send, {F4}
		Sleep 200
		goto Macro1
	}
}
return


;===============Macro 2=================

Macro2:
If WinActive("ahk_class Qt5QWindowOwnDCIcon")
{
	ImageSearch, FirstStageX, FirstStageY, A_ScreenWidth - 368, 0, A_ScreenWidth, A_ScreenHeight + 470, *15, Imagens\HP%Porcentagem_HP_Para_Ignorar_Mana%Percent.png	;% CHECAR HP
	if ErrorLevel = 0
	{
		ImageSearch, SecondStageX, SecondStageY, A_ScreenWidth - 368, 0, A_ScreenWidth, A_ScreenHeight + 470, *15, Imagens\MP%Porcentagem_Para_Healar_Mana%Percent.png	;% Primeiro Estagio [MANA]
		if ErrorLevel = 1
		{
			Send, {F12}
			Sleep 800
			goto Macro2
		}
	}
}
return

;=============Macro3=============
Macro3:
If WinActive("ahk_class Qt5QWindowOwnDCIcon")
{
	ImageSearch, HurX, HurY, A_ScreenWidth - 368, 0, A_ScreenWidth, A_ScreenHeight - A_ScreenHeight + 480, *35, Imagens\Hur.png
	If ErrorLevel = 1
	{
		Send, {F10}
		Sleep 200
		goto, Macro3
	}
	ImageSearch, LyzeX, LyzeY, A_ScreenWidth - 368, 0, A_ScreenWidth, A_ScreenHeight - A_ScreenHeight + 480, *35, Imagens\paralyze.png
	If ErrorLevel = 0
	{
		Send, {F9}
		Sleep 200
		goto, Macro3
	}
}
return

I thank you for your time and I would like to wish you a great day. :D
Last edited by Oblivion Deleted on 11 Apr 2021, 06:09, edited 1 time in total.
User avatar
mikeyww
Posts: 26936
Joined: 09 Sep 2014, 18:38

Re: Label: Turn on and off with checkbox.

Post by mikeyww » 11 Apr 2021, 05:58

Code: Select all

Gui, Font, s10
Gui, Add, Edit, vttext
Gui, Add, Checkbox, vbox1 gDisplay, Display value
Start:
GuiControl, Focus, ttext
Gui, Show, w220, Test GUI
Return

Display:
Gui, Submit
MsgBox, 64, Value, %ttext%
GuiControl,, ttext
GuiControl,, box1, 0
Gosub, Start
Return
Last edited by mikeyww on 11 Apr 2021, 06:01, edited 1 time in total.
User avatar
boiler
Posts: 16951
Joined: 21 Dec 2014, 02:44

Re: Label: Turn on and off with checkbox.

Post by boiler » 11 Apr 2021, 06:01

You can also determine whether the checkbox is checked or not, and if you're using functions, make sure to address the scope of the variables in order to access them:

Code: Select all

Gui, Add, CheckBox, gMyFunc1 vCh1, My checkbox 1
Gui, Add, CheckBox, gMyFunc2 vCh2, My checkbox 2
Gui, Show
return

MyFunc1() {
	global Ch1
	Gui, Submit, NoHide
	MsgBox, % "Box 1 has been " . (Ch1 ? "checked" : "unchecked")
}

MyFunc2() {
	global Ch2
	Gui, Submit, NoHide
	MsgBox, % "Box 2 has been " . (Ch2 ? "checked" : "unchecked")
}

GuiClose:
ExitApp
Post Reply

Return to “Ask for Help (v1)”