Skip to content
This repository was archived by the owner on Dec 4, 2026. It is now read-only.
austinhttpsPublic archive

About

Win11 eye-tracking window focus application

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

EyeFocus Tracker

An Electron desktop application with MediaPipe face and iris tracking that automatically switches Windows OS application window focus based on your gaze.


Features

  1. MediaPipe FaceMesh & Iris Tracking (478 Landmarks):

    • GPU-accelerated tracking running at >30 FPS with offline bundled model (public/models/face_landmarker.task) and local WebAssembly binaries (public/wasm/).
    • Automatic 4-tier fallback: local GPU -> local CPU -> CDN GPU -> CDN CPU.
    • Eye Aspect Ratio (EAR) blink detection with a 300ms grace period to prevent accidental focus switching during blinks.
    • Normalized pupil coordinates fused with head-pose yaw and pitch compensation.
  2. Webcam Selection & Contention Handling:

    • Enumerates video devices via navigator.mediaDevices.enumerateDevices with hot-plug support.
    • Gracefully handles camera contention (NotReadableError, TrackStartError) with diagnostic guidance and one-click camera re-query.
    • Built-in simulation mode for testing gaze tracking without an active camera.
  3. Gaze Calibration & Screen Mapping:

    • 5-point calibration wizard (Center, Left, Right, Top, Bottom) that saves boundary boxes to localStorage.
    • Pupil coordinates map to physical screen space: looking left targets Window 1 (0.0 to 0.50), looking right targets Window 2 (0.50 to 1.0).
    • Instant invertX toggle.
  4. Debounced Dwell Time Tracking:

    • Configurable dwell threshold (default 300ms) with visual progress ring/bar feedback.
    • Natural blink rejection preserves dwell progress without triggering while eyes are closed.
    • Cooldown period prevents rapid back-and-forth window switching.
  5. Windows OS Window Enumeration & Focus Activation:

    • scripts/get-desktop-windows.ps1 enumerates top-level windows with screen bounds (X, Y, Width, Height), filtering system noise (explorer, TextInputHost, Antigravity, background tool windows).
    • Open windows are sorted left-to-right to bind to Window 1 and Window 2.
    • scripts/focus-window.ps1 bypasses Windows LockSetForegroundWindow restrictions via AttachThreadInput, simulated keyboard events, ShowWindow(SW_RESTORE), BringWindowToTop, and SetForegroundWindow.
    • Supports focus matching by PID first, then title substring, then process name, with a retry loop for minimized windows.
  6. Display Mirroring UI:

    • Numbered display monitor badges matching Microsoft Display Settings: [ 1 ] Window 1 and [ 2 ] Window 2.
    • Secondary badges showing connected applications (App: chrome, App: slack).
    • One-click "Auto-Assign by Screen Position" and "⇄ Swap Window 1 & 2" controls.
    • Web Audio API chime on successful focus switch.
  7. Multi-Environment Support:

    • Electron Desktop: Native IPC via contextBridge.
    • Browser Dev Server: Custom Vite middleware endpoints (/api/windows and /api/focus) for browser development without launch errors.

Quick Start

Prerequisites

  • Node.js 18+
  • Windows 10 or 11 (for native Win32 window switching)

Installation

npm install

Running the App

Web Development Mode

npm run dev

Open http://localhost:5173.

Standalone Electron App

npm run electron

Production Build

npm run build

Testing

Run unit tests via Vitest:

npm test

Test Suites

  • tests/gazeEngine.test.ts: EAR calculation, iris ratio bounds, exponential moving average smoothing, head pose estimation, physical screen orientation mapping, and invertX toggling.
  • tests/dwellTracker.test.ts: Debounce timing, threshold triggers, cooldown windows, natural blink preservation (150-250ms), and expired grace period cleanup.
  • tests/calibration.test.ts: Screen coordinate mapping, dual/triple zone classification, sample statistics, calibration bounding box finalization, and horizontal window sorting (including negative multi-monitor coordinates).

Project Structure

FocusTracker/
├── electron/
│   ├── main.ts              # Electron process, IPC handlers, local server
│   ├── preload.ts           # Context bridge exposing electronAPI
│   └── windowManager.ts     # OS window enumeration & focus activation
├── scripts/
│   ├── get-desktop-windows.ps1 # Win32 window enumeration with true screen coordinates
│   ├── focus-window.ps1        # Win32 foreground activation & LockSetForeground bypass
│   └── build-electron.mjs      # esbuild bundler for main and preload scripts
├── src/
│   ├── components/
│   │   ├── CameraSelector.tsx    # Device selection, contention banner, simulator
│   │   ├── VideoCanvas.tsx       # Video feed and MediaPipe landmark canvas overlay
│   │   ├── FocusHUD.tsx          # Display monitor badges & dwell progress
│   │   ├── WindowConfig.tsx      # Window assignment & Microsoft display simulator
│   │   ├── CalibrationWizard.tsx # 5-point calibration wizard
│   │   └── SettingsModal.tsx     # Dwell, EAR, and smoothing settings
│   ├── core/
│   │   ├── gazeEngine.ts         # Eye geometry, EAR, iris ratios, smoothing
│   │   ├── dwellTracker.ts       # Debounce and dwell state machine
│   │   ├── calibration.ts        # Calibration bounds, zone detection, window sorting
│   │   ├── mediapipeManager.ts   # 4-tier model initialization fallback
│   │   ├── windowBridge.ts       # IPC / Vite HTTP bridge for window operations
│   │   └── audioFeedback.ts      # Web Audio synthesized chime feedback
│   ├── App.tsx                   # Main dashboard component
│   └── types/                    # Shared TypeScript interfaces
├── tests/                        # Vitest test suite
└── public/
    ├── models/face_landmarker.task # Offline MediaPipe model
    └── wasm/                       # Offline WASM binaries

About

Win11 eye-tracking window focus application

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Used by

Contributors

Languages