Skip to content

Instantly share code, notes, and snippets.

@koenbollen
Created October 3, 2017 14:44
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save koenbollen/2f4dfed6a21347dd758b273abcde7ae4 to your computer and use it in GitHub Desktop.
Save koenbollen/2f4dfed6a21347dd758b273abcde7ae4 to your computer and use it in GitHub Desktop.
Golang example of detecting user activity (using CGEventSourceSecondsSinceLastEventType from CoreGraphics)
package main
// #cgo LDFLAGS: -framework CoreGraphics
// #include <CoreGraphics/CoreGraphics.h>
import "C"
import (
"fmt"
"math"
)
func main() {
// Returns the number of seconds a osx user is idle!
result := C.CGEventSourceSecondsSinceLastEventType(1, math.MaxInt32)
fmt.Println(result)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment