0
votes

So, I want my function to create a HotKey and returns the corresponding text of the hotkey when i press here is my code below

global Object := {a:[1,"a","alexa"],b:[2,"b","battle"]}
global key_var1 :="!a"
global key_var2 := "!b"
create(key)
{
    HotKey, %key%, myKey
    return
        myKey:
            MsgBox, % Object.key[3]
    return
}

create(key_var1)
create(key_var2)

The issue here is, when i press the hotkey, the message box displays nothing just empty. When i press the HotKey the message box must display the corresponding text inside my Object array (text is in position 3)

1

1 Answers

1
votes

Displays associative array element keyed to current hotkey:

global Object := {"!a":[1,"a","alexa"], "!b":[2,"b","battle"]}
global key_var1 := "!a"
global key_var2 := "!b"
create(key)
{
    HotKey, %key%, myKey
    return
        myKey:
            MsgBox, % A_ThisHotkey ":" Object[A_ThisHotkey][3]
    return
}

create(key_var1)
create(key_var2)

Output:

enter image description here