Skip to content

Instantly share code, notes, and snippets.

@obonyojimmy
Forked from billyoverton/idleMonitor.go
Created January 2, 2017 00:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save obonyojimmy/a8b94f7baa4c12bf28cf5facce6a2cbe to your computer and use it in GitHub Desktop.
Save obonyojimmy/a8b94f7baa4c12bf28cf5facce6a2cbe to your computer and use it in GitHub Desktop.
package main
import (
"fmt"
"syscall"
"time"
"unsafe"
)
func main() {
user32 := syscall.MustLoadDLL("user32.dll")
kernel32 := syscall.MustLoadDLL("kernel32.dll")
getLastInputInfo := user32.MustFindProc("GetLastInputInfo")
getTickCount := kernel32.MustFindProc("GetTickCount")
var lastInputInfo struct {
cbSize uint32
dwTime uint32
}
lastInputInfo.cbSize = uint32(unsafe.Sizeof(lastInputInfo))
for {
r1, _, err := getLastInputInfo.Call(uintptr(unsafe.Pointer(&lastInputInfo)))
if r1 == 0 {
panic("error getting last input info: " + err.Error())
}
tick, _, err := getTickCount.Call()
msSinceLastInput := time.Duration(uint32(tick)-lastInputInfo.dwTime) * time.Millisecond
fmt.Printf("Time Since Last Input: %v\n", msSinceLastInput)
time.Sleep(5 * time.Second)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment