Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions pkg/util/inactivity_tracker.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package main

import ( "fmt" "time"

"github.com/go-vgo/robotgo"
"github.com/micmonay/keybd_event"

)

var lastActivityTime time.Time

func detectKeyboardActivity() { kb, err := keybd_event.NewKeyBonding() if err != nil { fmt.Println("Error setting up keyboard listener:", err) return }

for {
time.Sleep(1 * time.Second) // Check every second
if kb.HasCTRL() || kb.HasALT() || kb.HasSHIFT() {
lastActivityTime = time.Now()
}
}

}

func detectMouseActivity() { lastX, lastY := robotgo.GetMousePos() for { time.Sleep(1 * time.Second) // Check every second x, y := robotgo.GetMousePos() if x != lastX || y != lastY { lastActivityTime = time.Now() lastX, lastY = x, y } } }

func inactivityWatcher(timeout time.Duration) { for { time.Sleep(1 * time.Second) if time.Since(lastActivityTime) > timeout { fmt.Println("User is inactive!") break } } }

func main() { lastActivityTime = time.Now()

go detectKeyboardActivity()
go detectMouseActivity()
go inactivityWatcher(10 * time.Second) // Set timeout to 10s

select {} // Keep running

}