A background desktop agent for Windows that quietly tracks how you spend time on your machine. Every few minutes it records your activity — keystrokes, mouse clicks, the active window and app, and a compressed screenshot — and stores everything locally in SQLite.
Built as a hands-on systems project to learn background services, OS integration, thread-safe state, and database migrations in Python.
- 🖼️ Captures a compressed WebP screenshot of the desktop on a configurable interval
- ⌨️ Counts keystrokes and 🖱️ mouse clicks per interval (thread-safe)
- 🪟 Detects the active window title and the owning process name
- 🗄️ Persists every snapshot to a local SQLite database
- 🔁 Resets counters each interval so every row reflects only that window of time
- 🕶️ Runs completely headless (no console window) and auto-starts on login
- 📁 Stores all data under
%LOCALAPPDATA%— never mixed with the code
| Concern | Library |
|---|---|
| Config & validation | pydantic-settings |
| Database / ORM | SQLAlchemy 2.0 |
| Schema migrations | Alembic |
| Screenshots | mss + Pillow (WebP) |
| Keyboard / mouse hooks | pynput |
| Active window / process | pywin32 + psutil |
| Scheduling | APScheduler |
| Packaging | uv |
Three independent collectors are tied together by a scheduled job that writes one row per interval:
┌──────────────── main.py (orchestrator) ─────────────────┐
│ starts listeners · schedules job · graceful shutdown │
└───────────────┬───────────────────────┬─────────────────┘
│ │
InputTracker (pynput, background threads) APScheduler (every N seconds)
on_press / on_click → counts (Lock-guarded) │
│ ▼
│ take_snapshot():
└── snapshot_and_reset() ──► + active window (pywin32/psutil)
+ screenshot (mss/Pillow → WebP)
→ INSERT ActivitySnapshot (SQLite)
Keyboard and mouse listeners run on their own threads, so the shared counters are protected with a threading.Lock, and the per-interval read is an atomic read-and-reset to avoid losing events at the interval boundary.
app/
core/ config.py (pydantic-settings), logging_config.py
database/ db.py (engine, session, Base)
models/ activity_snapshot.py
services/ active_window.py · screenshot.py · input_tracker.py · collector.py
main.py entry point
alembic/ migrations
run_hidden.vbs hidden launcher for Task Scheduler
Requires Python 3.13+ and uv.
# 1. install dependencies
uv sync
# 2. create the database schema
uv run alembic upgrade head
# 3. run it
uv run python -m app.mainConfiguration is optional (sensible defaults are built in). To override, create a .env — see .env.example:
SCREENSHOT_INTERVAL=300 # seconds between snapshots
SCREENSHOT_QUALITY=20 # WebP quality 1-100
Data is written to %LOCALAPPDATA%\WindowsActivityAgent\ (database, screenshots, and logs).
The agent is designed to run silently. Windows Task Scheduler launches run_hidden.vbs, which starts pythonw with a hidden window so no console ever appears.
- Create a task (Task Scheduler → Create Task)
- Trigger: At log on
- Action → Start a program:
wscript.exe, arguments"<path>\run_hidden.vbs" - Run only when logged on (the input hooks need an interactive session)
Note:
run_hidden.vbscontains an absolute path — update it to wherever you cloned the project.
This is a local-only tool intended for monitoring your own machine. Nothing is uploaded anywhere; all data stays on disk under your user profile.