Created
March 29, 2016 22:37
-
-
Save billyoverton/5ea20400d30ec3f5d2a3b4cf144f17dd 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