Walk away from your laptop and it locks itself. That's the whole idea. π
It watches your webcam and only locks when you actually get up and leave. Looking down, turning your head or reading with your head bowed? Totally fine, it won't bug you. π
| You do this | What happens |
|---|---|
| Sit in front of the laptop π§βπ» | Nothing |
| Look down, turn your head, lean sideways π | Nothing |
| Get up and leave for 10 seconds πΆ | Windows locks π |
| Come back | It re-arms itself β |
Two safety rules:
- π€ It only starts working after it has seen a person, so an empty room never triggers a lock.
- π If the room is too dark to see, it never locks, because it can't tell.
- Install Python and tick "Add Python to PATH" during installation.
- Download this project, open a terminal in its folder and run:
pip install -r requirements.txt
- Test it with a preview window:
You should see a blue box around your face and the text ARMED. Walk away for 10 seconds and your PC locks. Press
python autolock.py --show
qto quit.
Happy with it? Run it without the window:
python autolock.py| Option | Default | What it does |
|---|---|---|
--away |
10 | Seconds you must be gone before it locks |
--body-grace |
60 | Seconds you still count as "here" if only your upper body is seen (head down, reading) |
--min-brightness |
25 | Below this brightness (0-255) it is too dark to judge and never locks |
--camera |
0 | Camera number, try 1 if you have more than one |
--show |
off | Show the preview window |
Example: python autolock.py --away 15
- Press
Win + R, typeshell:startupand press Enter. - In that folder create
autolock.batwith this content (change the path):@echo off pythonw "C:\path\to\autolock.py"
Windows doesn't allow scripts to unlock the screen (it's a security rule). Use Windows Hello for that: Settings, Accounts, Sign-in options. This project locks, Windows Hello unlocks. Teamwork. π€
- "Could not open the camera": another app (Zoom, Teams, the Camera app) is using it. Close it, or try
--camera 1. - It locks while I'm sitting there: make the room brighter, face the camera, or raise
--awayto 15 or 20. - It never locks: run with
--show. If it saysWAITING FOR A HUMAN, it hasn't seen you yet. A poster or photo of a face behind you can also keep it from locking. pip installgives an OpenCV error: this project needs OpenCV 4.x (OpenCV 5 removed the face detector it uses).requirements.txtalready pins the right version.
OpenCV Haar cascades look for a face (front and side) and an upper body, about twice per second. A small state machine decides when a person has really left. When they have, it calls the Windows LockWorkStation function once.
No picture is ever saved and nothing is sent over the internet. Everything runs on your laptop.
The "has the person left?" logic is covered by unit tests:
python -m unittest discover testsMIT