How do I make a GUI which asks the user how many loops the script should do in AutoHotkey V2

I want to make a Program which asks the user how many times the inner loop should loop. It should also ask only once and then run indefinitely with the number of loops the user set.

Here is the code:

s::{
    loop {
        ; This loop runs indefinitely
        Loop numLoops {
            ; The user-defined inner loop
            MouseMove 64, 352
            Click
            Send "{Delete}"
            Sleep 100
            Send "{Enter}"
            Sleep 500
        }

The Script runs fine, but my problem is that you need to change the amount of loops in the code itself, which is not very good. This autoclicker script is for work, and most of my colleagues have no idea what AutoHotkey even is. So I want to make a GUI for them where they can input how many loops the program does.

I read the AutoHotkey V2 documentation extensively (here is the link to the documentation), but I don’t understand it well enough to apply the knowledge into my program.

Here is what I already tried:

global numLoops := 0 ; Variable to store the number of loops

class GUI extends Object
; Create a GUI to prompt for the number of loops for the inner loop


; Wait until the user has input the number of loops before continuing
while (numLoops = 0) {
    Sleep 100 ; Wait until the user provides input
}

LoopGUI := Gui()
LoopGUI := Gui.Call()

NumberLoopsGUI := LoopGUI.Call()
NumberLoopsGUI.Add("Text", "Please enter the number of inner loops:")

s::{
    loop {
        ; This loop runs indefinitely
        Loop numLoops {
            ; The user-defined inner loop
            MouseMove 64, 352
            Click
            Send "{Delete}"
            Sleep 100
            Send "{Enter}"
            Sleep 500
        }

Where do I put my $global numLoops and how does the $Gui.Call() operator work?

Its sometimes a pain to work with gui controls but trust me they are easier than you think. A control has a vControl value which allows you to access the control from the gui itself. Syntax is easier than it sounds: GUI_Object["myControlString"].Value

Then the updated script is:

LoopGUI := Gui()

/*
First parameter is the control type we are creating
Using "v" is required but you can use any name after the initial "v"
x y w and h are coordinates and size
last parameter is the default value to start with
*/
LoopGUI.Add("Edit", "x140 y16 w50 h21 +Number -VScroll vCtrl_numLoops","1") ;Use the Number flag to only accept natural numbers
LoopGUI.Add("Text","x16 y16 w120 h40" ,"Please enter the number of inner loops:")

LoopGUI.Show("w200 h70")

s::{
    Loop {
        ; This loop runs indefinitely
        Loop Integer(LoopGUI["Ctrl_numLoops"].Value) { ;Directly use the loop count from the gui control
            ; The user-defined inner loop
            MouseClick("Left",64,352)
            Send "{Delete}"
            Sleep 100
            Send "{Enter}"
            Sleep 500
        }
        MsgBox("Close this window to execute the inner loop again.")
    }
}

5

This may give you a point to start.

LoopGUI := Gui()

LoopGUI.Add("Text", ,"Please enter the number of inner loops:")
LoopGUI.Add("Edit","vGuiVar") ; edit field
LoopGUI.Show()  ;   show the gui

s::{
    global numLoops := 0 ; Variable to store the number of loops
    loop {
        ; This loop runs indefinitely
        Global numLoops:=loopGUi["GuiVar"].Text
        Sleep 100
        Loop numLoops {
            ; The user-defined inner loop
            MouseMove 64, 352
            Click
            Send "{Delete}"
            Sleep 100
            Send "{Enter}"
            Sleep 500
        }
    }
}
^END::Exitapp(0) ; Force stop the script..

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật