Reputation: 4759
In AutoHotkey (1.1.29.01), how can I dynamically bind a hotkey to a class method?
class MyClass
{
SayHi()
{
MsgBox Hi!
}
BindHotkey()
{
Hotkey, Enter, this.SayHi, On
}
}
Error:
Target label does not exist
Upvotes: 2
Views: 710
Reputation: 4759
Call Bind
on the function, passing this
, and store the result in a variable. Then pass the variable to Hotkey
.
class MyClass
{
SayHi()
{
MsgBox Hi!
}
BindHotkey()
{
SayHiFunc := this.SayHi.Bind(this)
Hotkey, Enter, % SayHiFunc, On
}
}
Upvotes: 5