2025-08-18 09:08:00 +03:00
|
|
|
package main
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"fmt"
|
|
|
|
|
"time"
|
|
|
|
|
|
|
|
|
|
"github.com/go-vgo/robotgo"
|
|
|
|
|
)
|
|
|
|
|
|
2025-10-09 22:29:17 +03:00
|
|
|
const (
|
|
|
|
|
CHECKING_INTERVAL_SECONDS = 10
|
|
|
|
|
MOVE_AFTER_SECONDS = 300
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func moveMouse() {
|
|
|
|
|
// Move mouse around 100px
|
|
|
|
|
robotgo.MoveSmoothRelative(100, 0)
|
|
|
|
|
time.Sleep(1 * time.Second)
|
|
|
|
|
robotgo.MoveSmoothRelative(-100, 0)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func displayStatus(lastMove *int) {
|
|
|
|
|
// Clear display, and write last move
|
|
|
|
|
fmt.Print("\033[H\033[2J")
|
|
|
|
|
fmt.Printf("Last move %d seconds ago\n", *lastMove)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func checkActive(x *int, y *int, lastMove *int) {
|
2025-08-18 09:08:00 +03:00
|
|
|
// Current x, and Current Y
|
|
|
|
|
cX, cY := robotgo.Location()
|
|
|
|
|
|
|
|
|
|
if cX == *x && cY == *y {
|
2025-10-09 22:29:17 +03:00
|
|
|
// Hasn't moved
|
|
|
|
|
*lastMove += CHECKING_INTERVAL_SECONDS
|
2025-08-18 09:08:00 +03:00
|
|
|
} else {
|
2025-10-09 22:29:17 +03:00
|
|
|
// Has moved
|
|
|
|
|
*lastMove = 0
|
2025-08-18 09:08:00 +03:00
|
|
|
}
|
|
|
|
|
|
2025-10-09 22:29:17 +03:00
|
|
|
// Set current x and y
|
2025-08-18 09:08:00 +03:00
|
|
|
*x = cX
|
|
|
|
|
*y = cY
|
|
|
|
|
|
2025-10-09 22:29:17 +03:00
|
|
|
// Check if we should move
|
|
|
|
|
if *lastMove >= MOVE_AFTER_SECONDS {
|
|
|
|
|
moveMouse()
|
|
|
|
|
*lastMove = 0
|
2025-08-18 09:15:14 +03:00
|
|
|
}
|
2025-10-09 22:29:17 +03:00
|
|
|
|
|
|
|
|
displayStatus(lastMove)
|
2025-08-18 09:08:00 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func main() {
|
2025-08-18 13:15:49 +03:00
|
|
|
// reactive variables haha (useState, or reactive(), but just pointers)
|
2025-08-18 09:08:00 +03:00
|
|
|
x := 0
|
|
|
|
|
y := 0
|
2025-10-09 22:29:17 +03:00
|
|
|
// Meant to represent seconds ago
|
|
|
|
|
lastMove := 0
|
2025-08-18 09:08:00 +03:00
|
|
|
|
|
|
|
|
// Create tickers
|
2025-10-09 22:29:17 +03:00
|
|
|
ticker := time.NewTicker(CHECKING_INTERVAL_SECONDS * time.Second)
|
|
|
|
|
fmt.Printf("Checking active every %d seconds", CHECKING_INTERVAL_SECONDS)
|
|
|
|
|
time.Sleep(5 * time.Second)
|
2025-08-18 09:08:00 +03:00
|
|
|
|
2025-10-09 22:29:17 +03:00
|
|
|
defer ticker.Stop()
|
2025-08-18 09:08:00 +03:00
|
|
|
|
|
|
|
|
// Run initial calls (optional)
|
2025-10-09 22:29:17 +03:00
|
|
|
checkActive(&x, &y, &lastMove)
|
2025-08-18 09:08:00 +03:00
|
|
|
|
|
|
|
|
// Goroutine to handle ticks
|
2025-10-09 22:29:17 +03:00
|
|
|
for range ticker.C {
|
|
|
|
|
checkActive(&x, &y, &lastMove)
|
2025-08-18 09:08:00 +03:00
|
|
|
}
|
|
|
|
|
}
|