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.
- Host: GitHub
- URL: https://github.com/iamfaizankhalid/lock
- Owner: IamFaizanKhalid
- License: mit
- Created: 2023-06-17T13:36:02.000Z (about 3 years ago)
- Default Branch: master
- Last Pushed: 2023-06-19T06:20:48.000Z (about 3 years ago)
- Last Synced: 2025-08-17T16:34:38.852Z (10 months ago)
- Topics: golang, os, screenlock, sleep
- Language: Go
- Homepage:
- Size: 39.1 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# lock
[](https://goreportcard.com/report/github.com/IamFaizanKhalid/lock) [](https://github.com/IamFaizanKhalid/lock/releases) [](./LICENSE)

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)