feat: detect when inactive
This commit is contained in:
56
main.go
Normal file
56
main.go
Normal 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)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user