Why make a typing test pupil‑aware?
Your pupils aren’t just reacting to light—they also dilate with mental effort and ebb with fatigue. That makes pupillometry a powerful signal for adaptive typing: when cognitive load spikes, the test can slow pacing or pick an easier passage; when drowsiness sets in, it can nudge a micro‑break. Decades of research connect pupil dilation to cognitive control and workload, with one review noting that pupil size alone could classify high vs. low load with up to 75% accuracy in lab tasks. (link.springer.com)
Today, you don’t need a lab eye‑tracker. Modern, in‑browser models can segment the iris and estimate pupil diameter from a standard webcam, and recent work shows super‑resolution upscaling further improves accuracy on low‑res webcam images. That means a privacy‑friendly, no‑install typing test can adapt in real time on the user’s device. (mediapipe.readthedocs.io)
The science in a (pupil) nutshell
- Cognitive load: Larger pupils track rising task demands in working‑memory, conflict (Stroop), and attention tasks; when demands exceed capacity, dilation often plateaus or even drops—useful for detecting overload. (link.springer.com)
- Brain chemistry link: Pupil size covaries with activity in the locus coeruleus (LC), a norepinephrine hub involved in arousal and control—why pupil signals are such good “how hard is this?” meters. (pmc.ncbi.nlm.nih.gov)
- Fatigue: PERCLOS—the percentage of time eyes are ≥80% closed—is a validated drowsiness marker used in transportation safety and research. (nhtsa.gov)
Why webcams are finally good enough
- Robust eye landmarks in the browser: MediaPipe’s face/iris models estimate 3D eye landmarks on ordinary RGB cameras and rely on a near‑constant human iris diameter (~11.7 ± 0.5 mm) to help derive metric estimates. In practice, many systems work with a normalized pupil‑to‑iris ratio for distance robustness. (mediapipe.readthedocs.io)
- All on‑device, private by design: Projects like MEYE (a web pupillometry app) and WebGazer (browser‑based eye tracking) process video locally; no camera frames need to leave the page. (pmc.ncbi.nlm.nih.gov)
- Better signals from low‑res inputs: A 2024 study found that super‑resolution and upscaling (e.g., Real‑ESRGAN, SRResNet) consistently reduced error when predicting pupil diameter from webcam eyes—handy when your user’s camera is just “okay.” (arxiv.org)
What an adaptive, pupil‑aware typing test can do
1) Auto‑tune difficulty
- Watch for short‑lived pupil dilations above a user’s rolling baseline (think: z‑score > ~1.5 sustained for a couple of seconds) during a drill; if they persist, temporarily switch to an easier passage, enlarge hints, or relax WPM targets. Research shows dilation scales with difficulty in n‑back, digit span, and conflict paradigms. (link.springer.com)
2) Pace intelligently
- If dilation rises and stays elevated across sentences, treat it as sustained cognitive load; decrease target pace or swap to a simpler text genre (narrative instead of legalese) until pupils settle back near baseline. The plateau/drop under overload is a tell for backing off. (link.springer.com)
3) Insert restorative micro‑breaks
- Track eyelid closure via PERCLOS and blink patterns. When PERCLOS climbs (eyes ≥80% closed for a meaningful slice of the last 30–60 s) or blinks lengthen, suggest a 20–60 s break and a hydration/stretch prompt. PERCLOS is a mature, validated index for drowsiness. (nhtsa.gov)
Implementation blueprint (browser‑only)
- Capture: Use getUserMedia for video; run MediaPipe Face Landmarker/Iris (or a comparable model) to crop eye regions. Consider ONNX Runtime Web or WebGPU/WebAssembly for speed. Normalize measurements by reporting pupil/iris ratio to cancel distance/zoom effects (a common practice in iris‑based pipelines). (mediapipe.readthedocs.io)
- Upscale for fidelity: If the eye crops are tiny, upscale 2–4× or apply super‑resolution before regression; recent results show consistent accuracy gains on webcam datasets. (arxiv.org)
- Clean the signal: Follow established pupillometry hygiene—mark blinks and missing samples; use subtractive baseline correction; be skeptical of “effects” within ~200 ms of an event (too early for a true pupil response). (pmc.ncbi.nlm.nih.gov)
- Control luminance: Keep the typing UI’s brightness/contrast consistent; sudden white/black flashes can swamp the cognitive signal. Guidelines emphasize luminance matching or adaptation to avoid light‑reflex confounds. Lock webcam auto‑exposure where possible. (onlinelibrary.wiley.com)
- Guard against camera tricks: Auto‑exposure can fake a convincing “pupil response.” If you can’t disable it, down‑weight suspect segments or run a quick PLR check to verify you can measure real changes. Practitioner notes highlight this pitfall. (github.com)
- Privacy by default: Process everything client‑side; store only derived metrics (e.g., z‑scored dilation, PERCLOS) with user consent. MEYE/WebGazer show that fully local processing is practical. (pmc.ncbi.nlm.nih.gov)
Practical tips you can ship this week
- Calibration, 20–30 s: Ask users to sit 50–70 cm from the screen in steady room light; collect a quiet baseline while showing a uniform, mid‑gray background and the first practice sentence. Use this to set each user’s rolling median and SD. (onlinelibrary.wiley.com)
- Keep the scene steady: Fixed theme (no dark↔light flips), font, and contrast across drills. If you need visual feedback, use small luminance‑neutral cues (e.g., subtle outlines) rather than big color flashes. (onlinelibrary.wiley.com)
- Blink/PERCLOS tracking: Compute eye‑aspect ratio (EAR) from landmarks and derive PERCLOS over a 30–60 s window; trigger a micro‑break when it crosses your validated threshold (tune per cohort). The canonical definition uses the ≥80% closure criterion. (nhtsa.gov)
- Gentle adaptation: Change one thing at a time (pace or difficulty, not both) and decay back toward the user’s target settings as dilation normalizes.
- Explain the “why”: Show a simple banner—“We noticed signs of high mental load; slowing down for a moment.” Transparency builds trust.
Limitations and how to handle them
- Light confounds are real: Pupil reacts strongly to luminance. Keep your UI constant, and use within‑user baselines and relative change metrics rather than raw millimeters. (onlinelibrary.wiley.com)
- Person‑to‑person variability: Age, iris color, and screen distance all matter. Normalizing by iris size and using per‑user calibration helps. MediaPipe’s iris landmarks and the roughly constant iris diameter assumption are helpful context. (mediapipe.readthedocs.io)
- Not a medical device: Pupil and blink data are probabilistic workload/fatigue signals, not diagnoses.
What you’ll measure
- Cognitive load: rolling z‑score of pupil dilation relative to a 20–60 s baseline; slope and recovery time after errors; overload plateaus/drops. (link.springer.com)
- Fatigue: PERCLOS over 30–60 s, blink duration/frequency trends, and increased recovery times after mistakes. (nhtsa.gov)
The bottom line
Pupil‑aware typing is now practical with standard webcams. Solid science links pupil dynamics to mental effort and arousal; modern web ML can estimate pupil size on‑device; and well‑known fatigue metrics like PERCLOS translate cleanly to browser video. Build in careful baseline and luminance control, and your typing test can feel uncannily “tuned” to each person—helping them push when they’re ready and pause when they’re not. (link.springer.com)