57 lines
944 B
Go
57 lines
944 B
Go
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)
|
|
}
|
|
}
|
|
}
|