feat: detect when inactive

This commit is contained in:
Leons Aleksandrovs
2025-08-18 09:08:00 +03:00
parent 4f06308c93
commit 57ad4954ce
3 changed files with 165 additions and 0 deletions

56
main.go Normal file
View File

@@ -0,0 +1,56 @@
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
fmt.Printf("Active: %v \n", *active)
} else {
*active = true
fmt.Printf("Active: %v \n", *active)
}
*x = cX
*y = cY
}
func moveMouse(x *int, y *int) {
fmt.Printf("Mouse at: %v, %v \n", *x, *y)
}
func main() {
x := 0
y := 0
active := true
// Create tickers
// ticker1 := time.NewTicker(1 * time.Minute)
// ticker2 := time.NewTicker(2 * time.Minute)
ticker1 := time.NewTicker(10 * time.Second)
ticker2 := time.NewTicker(20 * time.Second)
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(&x, &y)
}
}
}