GUI with check boxes that execute scripts based on which are checked

Get help with using AutoHotkey (v2 or newer) and its commands and hotkeys
ivanbin
Posts: 1
Joined: 27 Nov 2023, 19:41

GUI with check boxes that execute scripts based on which are checked

Post by ivanbin » 27 Nov 2023, 19:45

Hello,

Super new to AHK but trying to get into it by creating a simple script that I can use for work. Below is what I have so far. Basically, we have multiple areas that each has a number of codes assosiated with them.
What I want to do is on clicking a button (F1) to get a popup with Check Boxes I can tick to select one or more areas. Then depending on which of the boxes are selected I want to execute a simple script that I already made and tested (Just a combination of MouseClick with coordinates and some SendText). However im struggling with figuring out how GUI works and a lot of the online videos (as well as chatgpt 3.5) only feature v1 as opposed to v2. What should I add to the script in order to check for checked boxes and execute scripts based on that? Feel free to point me to some YouTube videos as well ❤️

As you can see the below scrips is... well not close to finished but I ran out of understanding

Code: Select all

#Requires AutoHotkey v2.0
#SingleInstance Force

F1::
{
MyGui := Gui()
MyGui.Add("CheckBox", "vWestVillage", "West Village")
MyGui.Add("CheckBox", "vCentralManor", "Central Manor")
MyGui.Add("CheckBox", "vDorset", "Dorset")
MyGui.Add("CheckBox", "vStarLane", "Star Lane")
MyGui.Add("CheckBox", "vGrandBoulevard", "Grand Boulevard")

okbtn := MyGui.Add("Button", "w80", "OK")

MyGui.show()
}
And here is the code I want to be able to run (with slight modifications based on checkbox. I tested the below code when just having it execute via a hotkey and it works well, but reason im trying to get the GUI going is:
1) We have 13 such areas and remembering which hotkey is which one would be hard (esp for my coworkers that I also want to let use this)
2) I hope to be able to select multiple areas and have them added in at the same time if i so wish

Code: Select all

#Requires AutoHotkey v2.0
#SingleInstance Force
CoordMode "Mouse", "Window"

f1::
{
MouseClick "left", 673, 179
Sleep 500
MouseClick "left", 1044, 823
Sleep 200
MouseClick "left", 521, 569
Sleep 200
MouseClick "left", 566, 625
Sleep 200
MouseClick "left", 531, 695
Sleep 200
MouseClick "left", 729, 626
Sleep 200
SendText "cm"
Sleep 200
send "{Enter}"

SendText "h1"
Sleep 200
send "{Enter}"

SendText "d1c"
Sleep 200
send "{Enter}"

SendText "d19"
Sleep 200
send "{Enter}"
Sleep 100
MouseClick "left", 993, 823
}

User avatar
mikeyww
Posts: 27686
Joined: 09 Sep 2014, 18:38

Re: GUI with check boxes that execute scripts based on which are checked

Post by mikeyww » 27 Nov 2023, 21:16

Welcome to this AutoHotkey forum!

Code: Select all

#Requires AutoHotkey v2.0
city := 'West Village,Central Manor,Dorset,Star Lane,Grand Boulevard'
cb   := Map()
gui1 := Gui(, 'Cities'), gui1.SetFont('s10')
Loop Parse city, 'CSV'
 cb[A_LoopField] := gui1.AddCheckbox('w230', A_LoopField)
gui1.AddButton('wp Default', 'OK').OnEvent('Click', OK_Click)

F1::gui1.Show

OK_Click(btn, info) {
 gui1.Submit
 If cb['West Village'].Value {
  MsgBox 'West Village'
 }
 If cb['Central Manor'].Value {
  MsgBox 'Central Manor'
 }
}
Or:

Code: Select all

#Requires AutoHotkey v2.0
city := 'West Village,Central Manor,Dorset,Star Lane,Grand Boulevard'
gui1 := Gui(, 'Cities'), gui1.SetFont('s10')
Loop Parse city, 'CSV'
 gui1.AddCheckbox 'w230 v' StrReplace(A_LoopField, ' '), A_LoopField
gui1.AddButton('wp Default', 'OK').OnEvent('Click', OK_Click)

F1::gui1.Show

OK_Click(btn, info) {
 g := gui1.Submit()
 If g.WestVillage {
  MsgBox 'West Village'
 }
 If g.CentralManor {
  MsgBox 'Central Manor'
 }
}

Post Reply

Return to “Ask for Help (v2)”