A simple Golang package to get notified when the screen gets locked.
- This was developed as an experiment and may not always work.
- It currently supports only macOS, Windows and Linux.
- Not tested on all linux desktops
go get -u github.com/IamFaizanKhalid/lock
package main
import (
"fmt"
"time"
"github.com/IamFaizanKhalid/lock"
)
func main() {
if lock.IsScreenLocked() {
fmt.Println("Screen is locked...")
} else {
fmt.Println("Screen is not locked...")
}
lock.HandleEvents(lockEventHandler)
}
func lockEventHandler(e lock.Event) {
fmt.Print(e.Time.Format(time.TimeOnly), "\t")
if e.Locked {
fmt.Println("screen locked")
} else {
fmt.Println("screen unlocked")
}
}