Setting up multiple timers for a window monitoring class.

Get help with using AutoHotkey (v2 or newer) and its commands and hotkeys
XMCQCX
Posts: 224
Joined: 14 Oct 2020, 23:44

Setting up multiple timers for a window monitoring class.

Post by XMCQCX » 31 Mar 2023, 08:22

Hi,
I'm trying to make a class to monitor windows. I can't figure out how to identify separate timers to turn them individually on and off for the different windows, since they use the same binding calling the same method. It's hard to explain, the code is short and self-explanatory.

Code: Select all

MyEvents := WindowMonitoring()

MyEvents.Add({Window:"wordpad.exe", Function:"wordpad", Period:1000, WindowMonitoring:1})
MyEvents.Add({Window:"notepad.exe", Function:"notepad", Period:3000, WindowMonitoring:1})

class WindowMonitoring {

    aEvents := []

    Add(oEvent)
    {
        this.aEvents.push(oEvent)
        eventIndex := this.aEvents.Length
        function := this.CheckIfWinExist.bind(this, this.aEvents[eventIndex])
        SetTimer function, oEvent.Period
    }

    CheckIfWinExist(oEvent)
    {
        ; Debug(oEvent)
    }
}
Is there a way to bind some kind of parameter to “identify” them to be able to turn them individually on and off ? I'm trying to nest a timer class inside it to create different timers, but I can't figure out how to do it. I would be grateful for any help.

Code: Select all

MyEvents := WindowMonitoring()

MyEvents.Add({Window:"wordpad.exe", Function:"wordpad", Period:1000, WindowMonitoring:1})
MyEvents.Add({Window:"notepad.exe", Function:"notepad", Period:3000, WindowMonitoring:1})

class WindowMonitoring {

    aEvents := []
    Timer := WindowMonitoring.Timer()

    Add(oEvent)
    {
        this.aEvents.push(oEvent)
        eventIndex := this.aEvents.Length
        thisEvent := this.aEvents[eventIndex]
        thisEvent.EventIndex := eventIndex
        this.Timer.AddTimer(thisEvent)
    }

    CheckIfWinExist(thisEvent)
    {
        ; Debug(thisEvent)
    }

    class Timer {
        
        AddTimer(thisEvent) 
        {
            ; Set different timers calling the method "CheckIfWinExist"
        }

        StartStopTimer(State, Timer) 
        {

        }
    }
}

Return to “Ask for Help (v2)”