DEV Community

Cover image for Engineering "The Human Test": Simulating Biometric Stress with React, Humanized Latency, and Dom-Shaking CSS Glitches
Harish Kotra (he/him)
Harish Kotra (he/him)

Posted on

Engineering "The Human Test": Simulating Biometric Stress with React, Humanized Latency, and Dom-Shaking CSS Glitches

Most human-verification systems are boring checkboxes or pixelated pictures of traffic lights. But what if we made a satirical, high-stress CAPTCHA game designed to audit compliance under extreme temporal duress?

Enter The Human Test — a 10-level gamified frontend suite that challenges players to prove they are carbon-based lifeforms. Beneath its dual-themed visual styles lies a robust React, TypeScript, and Tailwind engine designed to mimic actual biometric calibration.

In this architectural overview, we'll dive deep into the technical design, the state-driven stress logic, custom mechanical delays, and state-of-the-art UI techniques used to build this responsive test suite.

Technical Architecture Diagram

The frontend architecture utilizes solid unidirectional data flow, synchronizing user keystrokes, task conditions, sound modules, and an administrative telemetry ledger:

                  +----------------------------------------------+
                  |                 USER ACTIONS                 |
                  |  [Keystrokes, Sliders, Rotants, Navigations] |
                  +----------------------+-----------------------+
                                         |
                                         v
                  +----------------------------------------------+
                  |         HUMANIZED KEYSTROKE DECOY            |
                  |  - Captures raw keypress event               |
                  |  - Fires preventDefault() to block input API |
                  |  - Computes random latency (20ms - 80ms)     |
                  +----------------------+-----------------------+
                                         |
                                         v
                  +----------------------------------------------+
                  |              LEVEL STATE CONTROLLER          |
                  |  - Validates user input matching buffers    |
                  |  - Fires error event if constraint fail      |
                  +------------------+---------------+-----------+
                                     |               |
               On Success Match      |               | On Biometric Violation
                                     v               v
                  +--------------------+   +---------------------+
                  | NEXT LEVEL TRICKLE |   |   GLITCH MODIFIERS  |
                  | - Level++          |   | - Error Shake CSS   |
                  | - Extends timer    |   | - +4.0s penalty     |
                  | - Logs callback    |   | - Screen shake lock |
                  +--------------------+   +---------------------+
Enter fullscreen mode Exit fullscreen mode

🎹 1. Humanizing Technical Input: Simulated Mechanical Latency

To pass dystopian verification standards, keyboard inputs must not look mechanical. Pure machine inputs are instantaneous and perfectly spaced, whereas human typing of characters exhibits inherent, irregular muscle-timing differences.

To simulate this biological behavior, we override standard input handlers, block default browser event dispatching, and run a custom delay-buffered state queue:

// Inside Level 5 Input Override Handler
onKeyDown={(e) => {
  if (e.key === "Enter" || e.key === "Tab" || e.metaKey || e.ctrlKey || e.altKey) {
    return; // Allow standard operations
  }

  // Prevent immediate browser placement to block instantaneous machine injection
  e.preventDefault(); 

  const key = e.key;
  // Calculate a randomized human typing delay between 20ms and 75ms
  const delay = Math.floor(Math.random() * 55) + 20;

  setTimeout(() => {
    if (key === "Backspace") {
      sound.tick();
      setTypedValue((prev) => prev.slice(0, -1));
      if (logAdminAction) logAdminAction('INFO', 'Subject corrected input via character rollback.');
    } else if (/^[0-9]$/.test(key)) {
      setTypedValue((prev) => {
        if (prev.length >= 5) return prev;
        sound.tick();
        if (logAdminAction) logAdminAction('INFO', `Subject input digit [${key}]. Simulated mechanical delay: ${delay}ms.`);
        return prev + key;
      });
    }
  }, delay);
}}
Enter fullscreen mode Exit fullscreen mode

Why this is effective:

  • e.preventDefault() disconnects the UI thread from the browser's immediate typing API, rendering standard robotic macro key injections useless.
  • The randomized setTimeout acts as a client-side micro-buffer, forcing even instant hardware macros to register inputs with a synthetic human-reaction latency.

🌋 2. System Interruption: High-Performance CSS-Based Glitch Overlays

When players make a mistake or step outside biometric bounds, the environment must convey extreme corporate disappointment. The application deploys a temporary glitch overlay state for 500ms, triggering violent screen tremors, extreme chromatic shifts, and canvas rotation.

Instead of writing expensive, frame-dropping canvas re-renders, the entire effect is achieved via hardware-accelerated CSS keyframe animations and computed composite styles:

/* src/index.css */
@keyframes severe-shake {
  0% { transform: translate(0px, 0px) rotate(0deg); }
  10% { transform: translate(-2px, -3px) rotate(-1deg); }
  25% { transform: translate(3px, 1px) rotate(1deg); }
  40% { transform: translate(-3px, 2px) rotate(0deg); }
  65% { transform: translate(2px, -1px) rotate(-1deg); }
  85% { transform: translate(-1px, 3px) rotate(1deg); }
  100% { transform: translate(0px, 0px) rotate(0deg); }
}

.glitch-overlay-active {
  animation: crt-flicker 0.05s infinite, severe-shake 0.15s infinite;
  background: rgba(239, 68, 68, 0.22);
}
Enter fullscreen mode Exit fullscreen mode

In the main component, the top-level element utilizes React states to inject dynamic GPU-bound styling:

const getGlitchStyle = () => {
  if (glitchActive) {
    return {
      // Invert, force strong contrast saturation overlays, and randomize translations using inline CSS
      filter: 'invert(0.15) contrast(1.9) saturate(2.2) hue-rotate(95deg) blur(0.4px)',
      transform: `translate(${(Math.random() - 0.5) * 18}px, ${(Math.random() - 0.5) * 18}px) scale(1.025)`,
    };
  }

  // Slower, subtle persistent stress shake when time gets low
  const stress = getStressPct();
  if (stress < 25) return {};

  const intensity = (stress - 25) / 75; // 0.0 to 1.0 multiplier
  return {
    transform: `translate(${(Math.random() - 0.5) * 2 * intensity}px, ${(Math.random() - 0.5) * 2 * intensity}px)`,
    filter: `contrast(${1.0 + intensity * 0.15})`
  };
};
Enter fullscreen mode Exit fullscreen mode

Using standard transform matrices ensures that the screen elements can slide and vibrate smoothly at $60\text{fps}$ without causing page layout calculations.


📊 3. Real-Time Telemetry: The Administrative Cognitive Metrics Console

To mock dystopian telemetry analysis, separate game levels transmit fine-grain events back to the parent component. This decoupled logging framework connects child-level tasks with a global Event Log State:

// Shared Interface Contract
interface LevelProps {
  onSuccess: () => void;
  onFail: (penaltySeconds: number, reason: string) => void;
  sound: SoundEngine;
  theme: 'windows' | 'sterile';
  currentLevelIndex?: number;
  logAdminAction?: (level: 'INFO' | 'WARN' | 'CRITICAL', message: string) => void;
}
Enter fullscreen mode Exit fullscreen mode

Whenever action occurs inside a level (e.g., in Level 6, when a random letter is converted to a machine-like BEEP), we push an event message to the telemetry logger:

if (logAdminAction) {
  logAdminAction(
    'CRITICAL',
    `Key injection glitch triggered! Transmitted: ${noise}. Keyboard compliance: FAILED.`
  );
}
Enter fullscreen mode Exit fullscreen mode

The parent App.tsx records these messages inside an active array, appending a high-resolution sub-second milliseconds stamp to keep things looking highly precise:

const addAdminLog = (level: 'INFO' | 'WARN' | 'CRITICAL', message: string) => {
  const now = new Date();
  const ms = now.getMilliseconds().toString().padStart(3, '0');
  const timeStr = `${now.toTimeString().split(' ')[0]}.${ms}`;
  const newLog = {
    id: Math.random().toString(36).substring(2, 11),
    timestamp: timeStr,
    level,
    message
  };
  setAdminLogs((prev) => [newLog, ...prev].slice(0, 100)); // Cap log array history
};
Enter fullscreen mode Exit fullscreen mode

📈 4. Multi-Tier Chronometric Scaling (Difficulty Selection)

Different human carbon structures have vastly different coordination and reaction tolerances. We developed three specific operational modes adjusting baseline game timing variables:

$$\text{Timelimit}{\text{Easy}} = \text{BaseTime} \times 1.5$$
$$\text{Timelimit}
{\text{Medium}} = \text{BaseTime} \times 1.0$$
$$\text{Timelimit}_{\text{Robot}} = \text{BaseTime} \times 0.60$$

On the intro screen, the difficulty selection adjusts the React configuration state difficulty:

const getLevelTimeLimit = (levelIdx: number) => {
  const base = Math.max(12, 45 - (levelIdx * 3.0)); // Base scaling range
  if (difficulty === 'easy') return Math.round(base * 1.5);
  if (difficulty === 'hard') return Math.round(base * 0.6); // Shrinks time aggressively
  return base;
};
Enter fullscreen mode Exit fullscreen mode

This mathematical modification propagates throughout the level countdown hooks dynamically, creating an intense, nail-biting, and hilarious speedrun experience for the hardcore "Robot-Mode" challenger.


Join the Conformance Taskforce!

The Human Test is fully open-source and easy to modify. You can easily extend this architecture by making a pull request, adding your own twisted CAPTCHA puzzles, or integrating advanced gaze mapping APIs on top of the established level protocol.

Happy hacking, carbon lifeforms! Keep those keystrokes snappy, and don't let the administrative scanner detect any compliance faults.

Screenshots

The Human Test 1

The Human Test 2

The Human Test 3

The Human Test 4

The Human Test 5

Try it here: https://the-human-test.vercel.app/
Code & more: https://www.dailybuild.xyz/project/145-the-human-test

Top comments (0)