Code: Select all
class MyHotkey
{
__New(hkName, fn) {
this.hkName := hkName
Hotkey(this.hkName, () => this.doHotkey(fn)) ; im assuming this creates some unreleased references
}
__Delete() {
MsgBox("dtor called")
Hotkey(this.hkName, "Off")
}
doHotkey(fn) {
fn.Call()
Sleep(500)
ToolTip("did hotkey action`n" A_TickCount)
}
}
showTimeNow := () => ToolTip("time is:`n" A_Now)
myHk := new MyHotkey("q", showTimeNow)
w::myHk := "" ; doesnt call dtor
e::Hotkey("q", "Off") ; this works, but is explicit, external
r::Hotkey(myHk.hkName, "Off") ; same as above
Esc::ExitApp(0)
now, what i want to achieve is this: when myHk is blanked out or reassigned, the hotkey should be automatically deactivated via Hotkey(hotkey_name, "Off)
so i figured, i could put this in the destructor, but the destructor never gets called.
if i comment out the hotkey defining function, the destructor will get called, so reckon the hotkey defining function is creating some references and is keeping them around
question is whether thats the case, and if what i wanna do is at all feasible.
as a workaround i could deactivate the hotkey by calling Hotkey(hotkey_name, "Off") myself, but id prefer not to