Maps keys in a DD-list, how? Topic is solved

Get help with using AutoHotkey (v2 or newer) and its commands and hotkeys
Krd
Posts: 405
Joined: 10 Mar 2020, 02:46

Maps keys in a DD-list, how?

Post by Krd » 26 May 2023, 10:24

Hallo everyone :)

I have this:

Code: Select all

F12::function_name()

function_name()
{
    Test(&Test2)
    MyGui := Gui()
    MyGui.Add("DropDownList", "vSelectedKey", ['First','Second'])
    MyGui.Add("Button", , "Submit").OnEvent("Click", Submit)
    MyGui.Show()

Submit(*)
{
Saved := MyGui.Submit(true)
MsgBox Test2[Saved.SelectedKey]
}
}



Test(&Test2)
{
Test2 := Map(
'First', 'First value',
'Second', 'Second value',
)
}
And this becomes a problem when my maps have hundreds of keys, making it difficult to manage and update the GUI efficiently.

Code: Select all

   MyGui.Add("DropDownList", "vSelectedKey", ['First','Second'])
And then I don't want to duplicate every key if I do this:

Code: Select all

Test_only_keys(&Test3)
{
Test3 :=
[
'First', 
'Second'
]
}
And is it possible to dynamically retrieve the keys and display them in the dropdown list, along with showing the corresponding value upon submission, like a pro? :D

The dropdownlist would only show the existing keys in the map.

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

Re: Maps keys in a DD-list, how?

Post by mikeyww » 26 May 2023, 10:58

Hello,

You can assign your DDL object to a variable and then use the Add and Delete methods to change the values.

Read: https://www.autohotkey.com/docs/v2/lib/GuiControl.htm#Add

just me
Posts: 9495
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: Maps keys in a DD-list, how?  Topic is solved

Post by just me » 28 May 2023, 08:39

Code: Select all

F12::SelectKey("TestKeys")
F11::SelectKey("OtherKeys")

SelectKey(KeyFuncName) {
   KeyMap := %KeyFuncName%()
   KeyArr := []
   For Key In KeyMap
      KeyArr.Push(Key)
   MyGui := Gui()
   MyGui.OnEvent("Close", (*) => MyGui.Destroy())
   MyGui.Add("DropDownList", "vSelectedKey Choose1", KeyArr)
   MyGui.Add("Button", , "Submit").OnEvent("Click", Submit)
   MyGui.Show()
   WinWaitClose(MyGui.Hwnd)
   Submit(*) {
      Saved := MyGui.Submit()
      MsgBox KeyMap[Saved.SelectedKey]
      MyGui.Destroy()
   }
}

TestKeys() {
   Return Map('First', 'First value',
              'Second', 'Second value')
}
OtherKeys() {
   Return Map('Third', 'Third value',
              'Fourth', 'Fourth value')
}
?

Krd
Posts: 405
Joined: 10 Mar 2020, 02:46

Re: Maps keys in a DD-list, how?

Post by Krd » 28 May 2023, 10:47

Thank you both! Sorry for bad explanation again from me, mikey, I see that I did a bad job there. ;)

"just me" that's exactly what I wanted, a for loop does that! I just didn't know how to do it.

This way I do not have to duplicate keys for a map and maintain two maps that work for the same goal.
This makes it more error free and easier to edit.

Much appreciated!

Post Reply

Return to “Ask for Help (v2)”