-
-
Save obonyojimmy/a8b94f7baa4c12bf28cf5facce6a2cbe to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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