简体   繁体   中英

How to bind a hotkey to a class method in AutoHotkey

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

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
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM