package main import ( "fmt" "time" "github.com/go-vgo/robotgo" ) func checkActive(x *int, y *int, active *bool) { // Current x, and Current Y cX, cY := robotgo.Location() if cX == *x && cY == *y { *active = false } else { *active = true } *x = cX *y = cY } func moveMouse(active *bool) { // If inactive, move mouse to 100px right, and back if !*active { fmt.Println("Moving mouse") robotgo.MoveSmoothRelative(100, 0) time.Sleep(1 * time.Second) robotgo.MoveSmoothRelative(-100, 0) } } func main() { // reactive variables haha (useState, or reactive(), but just pointers) x := 0 y := 0 active := true // Create tickers ticker1 := time.NewTicker(10 * time.Second) ticker2 := time.NewTicker(5 * time.Minute) defer ticker1.Stop() defer ticker2.Stop() // Run initial calls (optional) checkActive(&x, &y, &active) // Goroutine to handle ticks for { select { case <-ticker1.C: checkActive(&x, &y, &active) case <-ticker2.C: moveMouse(&active) } } }