在AutoHotkey(1.1.29.01)中,如何动态将热键绑定到类方法?
class MyClass
{
SayHi()
{
MsgBox Hi!
}
BindHotkey()
{
Hotkey, Enter, this.SayHi, On
}
}
错误:
目标标签不存在
答案 0 :(得分:2)
在函数上调用Bind
,传递this
,并将结果存储在变量中。然后将变量传递到Hotkey
。
class MyClass
{
SayHi()
{
MsgBox Hi!
}
BindHotkey()
{
SayHiFunc := this.SayHi.Bind(this)
Hotkey, Enter, % SayHiFunc, On
}
}