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

时间:2019-05-21 14:21:55

标签: autohotkey

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

class MyClass
{
    SayHi()
    {
        MsgBox Hi!
    }

    BindHotkey()
    {
        Hotkey, Enter, this.SayHi, On
    }
}

错误:

  

目标标签不存在

1 个答案:

答案 0 :(得分:2)

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

class MyClass
{
    SayHi()
    {
        MsgBox Hi!
    }

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

        Hotkey, Enter, % SayHiFunc, On
    }
}