Register Hotkey Inside Class Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
murataygun
Posts: 104
Joined: 07 Aug 2015, 15:53

Register Hotkey Inside Class

Post by murataygun » 04 Aug 2021, 11:17

Is there any way to write that in one line or get it shortened?

Code: Select all

        eldivenBF := this.MalzemeGir.Bind(this, this.Malzemeler.eldiven)
        Hotkey, MButton & 1, % eldivenBF, On
I tried

Code: Select all

Hotkey, MButton & 1, % eldivenBF := this.MalzemeGir.Bind(this, this.Malzemeler.eldiven), On
No luck.

I have almost 30 shortcuts. Is it have to be 2 lines of code?

teadrinker
Posts: 4325
Joined: 29 Mar 2015, 09:41
Contact:

Re: Register Hotkey Inside Class

Post by teadrinker » 04 Aug 2021, 12:11

You can use this way:

Code: Select all

Inst := new MyClass
Inst.SetHotkeys()

class MyClass
{
   SetHotkeys() {
      handler := ObjBindmethod(this, "HotkeyHandler")
      Hotkey, MButton & 1, % handler, On
      Hotkey, MButton & 2, % handler, On
      Hotkey, MButton & 3, % handler, On
   }
   HotkeyHandler() {
      Switch A_ThisHotkey {
         Case "MButton & 1": MsgBox, MButton & 1
         Case "MButton & 2": MsgBox, MButton & 2
         Case "MButton & 3": MsgBox, MButton & 3
      }
   }
}

swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: Register Hotkey Inside Class  Topic is solved

Post by swagfag » 04 Aug 2021, 14:04

murataygun wrote:
04 Aug 2021, 11:17
Is it have to be 2 lines of code?
yes. dont like it? its fixed in v2

make a function wrapper and use that

Code: Select all

Hotkey(KeyName, Label := "", Options := "") {
	Hotkey % KeyName, % Label, % Options
}

murataygun
Posts: 104
Joined: 07 Aug 2015, 15:53

Re: Register Hotkey Inside Class

Post by murataygun » 04 Aug 2021, 15:21

Thank you. @Threadrinker :thumbup:
Last edited by murataygun on 04 Aug 2021, 15:24, edited 1 time in total.

murataygun
Posts: 104
Joined: 07 Aug 2015, 15:53

Re: Register Hotkey Inside Class

Post by murataygun » 04 Aug 2021, 15:23

swagfag wrote:
04 Aug 2021, 14:04
murataygun wrote:
04 Aug 2021, 11:17
Is it have to be 2 lines of code?
yes. dont like it? its fixed in v2

make a function wrapper and use that

Code: Select all

Hotkey(KeyName, Label := "", Options := "") {
	Hotkey % KeyName, % Label, % Options
}
That is the cleanest. Thank you :thumbup:

Post Reply

Return to “Ask for Help (v1)”