An open API service indexing awesome lists of open source software.

https://github.com/iamfaizankhalid/lock

A simple Golang package to get notified when the screen gets locked.
https://github.com/iamfaizankhalid/lock

golang os screenlock sleep

Last synced: 9 months ago
JSON representation

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

Awesome Lists containing this project

README

          

# lock
[![Go Report Card](https://goreportcard.com/badge/github.com/IamFaizanKhalid/lock)](https://goreportcard.com/report/github.com/IamFaizanKhalid/lock) [![Release](https://img.shields.io/github/v/release/IamFaizanKhalid/lock.svg?style=flat-square)](https://github.com/IamFaizanKhalid/lock/releases) [![License](https://img.shields.io/badge/license-MIT-blue.svg)](./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

```console
go get -u github.com/IamFaizanKhalid/lock
```

## Usage Example

```go
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](./LICENSE)