lock

package module
v0.0.0-...-b7c5d27 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 19, 2023 License: MIT Imports: 5 Imported by: 0

README

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func HandleEvents

func HandleEvents(h EventHandler)

func IsScreenLocked

func IsScreenLocked() bool

func Notify

func Notify() <-chan Event

Types

type Event

type Event struct {
	Time   time.Time
	Locked bool
}

type EventHandler

type EventHandler func(e Event)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL