如何在 AutoHotkey 中将热键绑定到类方法

Eri*_*sen 1 autohotkey

在 AutoHotkey (1.1.29.01) 中,如何动态地将热键绑定到类方法?

class MyClass
{
    SayHi()
    {
        MsgBox Hi!
    }

    BindHotkey()
    {
        Hotkey, Enter, this.SayHi, On
    }
}
Run Code Online (Sandbox Code Playgroud)

错误:

目标标签不存在

Eri*_*sen 5

调用Bind该函数,传递this,并将结果存储在变量中。然后将变量传递给Hotkey.

class MyClass
{
    SayHi()
    {
        MsgBox Hi!
    }

    BindHotkey()
    {
        SayHiFunc := this.SayHi.Bind(this)

        Hotkey, Enter, % SayHiFunc, On
    }
}
Run Code Online (Sandbox Code Playgroud)