Control Names and Controllist

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
WantToKnow
Posts: 64
Joined: 28 Mar 2020, 08:46

Control Names and Controllist

Post by WantToKnow » 30 Nov 2021, 09:32

Hello there,

Code: Select all

#SingleInstance Force 
Gui Add, Button, x10 y5 w60 h20 vTest, Press Me
Gui Add, Button, x+0 yP w60 h20 vNice, Press Me
Gui Add, Button, x+0 yP w60 h20 vNope, Press Me
Gui,show,, % A_ScriptName
return

F1::
WinGet, idWindow, ID, A
WinGet, arrControls, ControlList, ahk_id %idWindow%
MsgBox % arrControls
return
ControlList, retrieves the control name for each control in a window. The result is
Button1, Button2 and Button3. On the other hand I named my Buttons Test,Nice, Nope in my example above.

What is the code, so I know that vTest corresponds to Button1 from the Controllist?
( and vNice corresponds to Button2 from Controllist, vNope corresponds to Button3)

Thanks!

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

Re: Control Names and Controllist

Post by mikeyww » 30 Nov 2021, 09:44

Code: Select all

Gui, +LastFound
Gui, Add, Button,    w60 vTest, Press Me1
Gui, Add, Button, ym wp  vNice, Press Me2
Gui, Add, Button, ym wp  vNope, Press Me3
Gui, Show,, Test
WinGet, controlList, ControlList
For each, control in StrSplit(controlList, "`n") {
 GuiControl, Focus, %control%
 GuiControlGet, varName, FocusV
 list .= (list ? "`n" : "") control ": " varName
}
MsgBox, 64, Control list, %list%

WantToKnow
Posts: 64
Joined: 28 Mar 2020, 08:46

Re: Control Names and Controllist

Post by WantToKnow » 30 Nov 2021, 10:09

Thanks a lot Mike. I'm looking forward to learn from your code.
I too have found a solution to my problem.

Code: Select all

#F12::
GuiControlGet, Button1, Name
GuiControlGet, Button2, Name
GuiControlGet, Button3, Name
MsgBox % Button1  "  "  Button2   "   "  Button3

GuiControlGet, out1,, Test
GuiControlGet, out2,, Nice
GuiControlGet, out3,, Nope
MsgBox % out1  "  "  out2   "   "  out3
return

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

Re: Control Names and Controllist

Post by mikeyww » 30 Nov 2021, 10:42

Good. Your way is better, I would say, because it does not require refocusing on controls.

Post Reply

Return to “Ask for Help (v1)”