Skip to content

A simple Golang package to get notified when the screen gets locked.

License

Notifications You must be signed in to change notification settings

IamFaizanKhalid/lock

Repository files navigation

lock

Go Report Card Release License

Nishan Pakistan

A simple Golang package to get notified when the screen gets locked.

⚠️ Warnings:

  1. This was developed as an experiment and may not always work.
  2. It currently supports only macOS, Windows and Linux.
  3. Not tested on all linux desktops

Installation

go get -u github.com/IamFaizanKhalid/lock

Usage Example

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")
	}
}

License

MIT License