Human-Like
Usage

Constants

Timing constants, behavior rates, and helper utilities for Human-Like

Import predefined constants and utilities for consistent typing behavior configuration.

import { 
  TIMING_CONSTANTS, 
  BEHAVIOR_RATES, 
  DESKTOP_ADJACENT,
  MOBILE_ADJACENT,
  QWERTY_ADJACENT,
  getAdjacentKeys,
  DEFAULT_CONFIG,
  COMMON_TYPOS,
  SPECIAL_CHARS
} from '@ertekinno/human-like'

Timing Constants

TIMING_CONSTANTS

Predefined timing values for realistic typing behavior.

const TIMING_CONSTANTS = {
  // Core Speed
  BASE_SPEED: 80,              // Average milliseconds per character
  SPEED_VARIATION: 40,         // Random timing variation (±40ms)
  MIN_CHAR_DELAY: 25,          // Minimum delay between characters
  
  // Punctuation and Structure
  SENTENCE_PAUSE: 500,         // Pause after . ! ?
  COMMA_PAUSE: 200,            // Pause after , ; :
  WORD_SPACE: 150,             // Pause between words
  LINE_BREAK: 800,             // Pause for new paragraphs
  
  // Mistake Handling
  REALIZATION_DELAY: 300,      // Time to notice mistake
  CORRECTION_PAUSE: 250,       // Pause before retyping
  BACKSPACE_SPEED: 60,         // Speed of corrections
  
  // Human Behavior
  THINKING_PAUSE: 400,         // Pause before complex words
  FATIGUE_INCREMENT: 0.5,      // Gradual slowdown per 100 chars
  BURST_SPEED_MULTIPLIER: 0.6, // Speed multiplier during bursts
  CONCENTRATION_PAUSE: 800,    // Duration of concentration lapses
  
  // Enhanced Realism
  SHIFT_HESITATION: 100,       // Extra delay for shift key characters
  CAPS_LOCK_ON_DELAY: 150,     // Delay when turning CAPS LOCK on
  CAPS_LOCK_OFF_DELAY: 100,    // Delay when turning CAPS LOCK off
  CAPS_SEQUENCE_THRESHOLD: 3,  // Min consecutive caps to trigger CAPS LOCK
  NUMBER_ROW_PENALTY: 35,      // Extra delay for number characters
  SYMBOL_BASE_PENALTY: 25,     // Base extra delay for symbols
  LOOK_AHEAD_CHANCE: 0.08,     // 8% chance of look-ahead typing
}

Usage Examples

Custom Speed Configuration

import { TIMING_CONSTANTS } from '@ertekinno/human-like'

<HumanLike
  text="Custom timing based on constants"
  config={{
    speed: TIMING_CONSTANTS.BASE_SPEED * 0.8,        // 20% faster
    speedVariation: TIMING_CONSTANTS.SPEED_VARIATION, // Keep default variation
    sentencePause: TIMING_CONSTANTS.SENTENCE_PAUSE * 1.5, // 50% longer pauses
    wordPause: TIMING_CONSTANTS.WORD_SPACE,
    backspaceSpeed: TIMING_CONSTANTS.BACKSPACE_SPEED * 0.7 // Faster corrections
  }}
/>

Professional Typing Profile

const professionalConfig = {
  speed: TIMING_CONSTANTS.BASE_SPEED * 0.6,          // Faster base speed
  speedVariation: TIMING_CONSTANTS.SPEED_VARIATION * 0.5, // Less variation
  mistakeFrequency: 0.01,                            // Fewer mistakes
  sentencePause: TIMING_CONSTANTS.SENTENCE_PAUSE * 0.8,   // Shorter pauses
  thinkingPause: TIMING_CONSTANTS.THINKING_PAUSE * 0.5    // Less thinking time
}

Beginner Typing Profile

const beginnerConfig = {
  speed: TIMING_CONSTANTS.BASE_SPEED * 1.8,          // Slower base speed
  speedVariation: TIMING_CONSTANTS.SPEED_VARIATION * 1.5, // More variation
  sentencePause: TIMING_CONSTANTS.SENTENCE_PAUSE * 2,     // Longer pauses
  realizationDelay: TIMING_CONSTANTS.REALIZATION_DELAY * 1.5, // Slower mistake detection
  correctionPause: TIMING_CONSTANTS.CORRECTION_PAUSE * 2     // Longer correction pauses
}

Behavior Constants

BEHAVIOR_RATES

Predefined probability rates for human-like behaviors.

const BEHAVIOR_RATES = {
  MISTAKE_FREQUENCY: 0.03,     // 3% base mistake rate
  CONCENTRATION_LAPSE: 0.03,   // 3% random pause chance
  BURST_TYPING: 0.15,          // 15% rapid sequence chance
  FATIGUE_FACTOR: 0.0001,      // Gradual slowdown rate
  OVERCORRECTION_RATE: 0.2,    // 20% chance of making mistake while correcting
}

Usage Examples

High Accuracy Typing

<HumanLike
  text="High accuracy typing simulation"
  config={{
    mistakeFrequency: BEHAVIOR_RATES.MISTAKE_FREQUENCY * 0.5, // Half the mistakes
    concentrationLapses: false,                               // No random pauses
    overcorrection: false,                                    // No correction mistakes
    fatigueEffect: false                                      // No gradual slowdown
  }}
/>

Realistic Human Behavior

<HumanLike
  text="Realistic human typing with all behaviors enabled"
  config={{
    mistakeFrequency: BEHAVIOR_RATES.MISTAKE_FREQUENCY,       // Default mistake rate
    concentrationLapses: true,                                // Enable random pauses
    overcorrection: true,                                     // Enable correction mistakes
    fatigueEffect: true                                       // Enable gradual slowdown
  }}
/>

Adjacent Key Maps

Platform-Specific Adjacent Keys

Maps for realistic adjacent key mistakes based on keyboard layout.

// Desktop QWERTY layout
const DESKTOP_ADJACENT: Record<string, string[]> = {
  's': ['q', 'w', 'e', 'a', 'd', 'z', 'x'], // Physical QWERTY neighbors
  'e': ['w', 'r', 's', 'd', 'f'],
  ' ': ['c', 'v', 'b', 'n', 'm'], // Spacebar bottom row
  // ... complete mapping
}

// Mobile touch layout  
const MOBILE_ADJACENT: Record<string, string[]> = {
  's': ['a', 'd', 'w', 'e', 'z', 'x'], // Touch-optimized mistakes
  'e': ['w', 'r', 'd', 's'], 
  ' ': ['c', 'v', 'b', 'n', 'm', 'x', 'z'], // Wider spacebar interference
  // ... complete mapping
}

// Legacy compatibility
const QWERTY_ADJACENT = DESKTOP_ADJACENT

getAdjacentKeys Helper

Get appropriate adjacent keys based on platform.

function getAdjacentKeys(keyboardMode: 'mobile' | 'desktop'): Record<string, string[]>

Usage Examples

import { getAdjacentKeys } from '@ertekinno/human-like'

// Get platform-specific adjacent keys
const mobileAdjacent = getAdjacentKeys('mobile')
const desktopAdjacent = getAdjacentKeys('desktop')

// Use in custom mistake logic
const customMistakeHandler = (char: string, keyboardMode: 'mobile' | 'desktop') => {
  const adjacentKeys = getAdjacentKeys(keyboardMode)
  const possibleMistakes = adjacentKeys[char] || []
  return possibleMistakes[Math.floor(Math.random() * possibleMistakes.length)]
}

Specialized Constants

COMMON_TYPOS

Real-world common typos for realistic mistake simulation.

const COMMON_TYPOS: Record<string, string> = {
  'the': 'teh',
  'and': 'adn', 
  'you': 'yuo',
  'that': 'taht',
  'this': 'tihs',
  'with': 'wiht',
  'have': 'ahve',
  'from': 'form',
  'because': 'becasue',
  'different': 'differnet',
  'important': 'importnat',
  'development': 'developement',
  // ... 50+ common typos
}

SPECIAL_CHARS & Character Sets

Character classification for enhanced timing behavior.

const SPECIAL_CHARS = new Set([
  '!', '@', '#', '$', '%', '^', '&', '*', '(', ')', 
  '-', '_', '+', '=', '[', ']', '{', '}', '\\', '|',
  ';', ':', "'", '"', ',', '.', '<', '>', '/', '?', 
  '`', '~'
])

const SHIFT_CHARS = new Set([
  'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M',
  'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
  '!', '@', '#', '$', '%', '^', '&', '*', '(', ')', '_', '+',
  // ... all shift-requiring characters
])

const NUMBER_CHARS = new Set(['0', '1', '2', '3', '4', '5', '6', '7', '8', '9'])

DEFAULT_CONFIG

Complete default configuration using constants.

const DEFAULT_CONFIG: HumanLikeConfig = {
  speed: TIMING_CONSTANTS.BASE_SPEED,
  speedVariation: TIMING_CONSTANTS.SPEED_VARIATION,
  mistakeFrequency: BEHAVIOR_RATES.MISTAKE_FREQUENCY,
  mistakeTypes: {
    adjacent: true,
    random: false,
    doubleChar: true,
    commonTypos: true,
  },
  fatigueEffect: true,
  concentrationLapses: true,
  overcorrection: true,
  sentencePause: TIMING_CONSTANTS.SENTENCE_PAUSE,
  wordPause: TIMING_CONSTANTS.WORD_SPACE,
  thinkingPause: TIMING_CONSTANTS.THINKING_PAUSE,
  // ... complete default configuration
}

Advanced Usage Patterns

Configuration Presets

Create reusable configuration presets using constants.

import { TIMING_CONSTANTS, BEHAVIOR_RATES, DEFAULT_CONFIG } from '@ertekinno/human-like'

// Speed-based presets
export const TYPING_PRESETS = {
  beginner: {
    ...DEFAULT_CONFIG,
    speed: TIMING_CONSTANTS.BASE_SPEED * 2,
    mistakeFrequency: BEHAVIOR_RATES.MISTAKE_FREQUENCY * 2,
    sentencePause: TIMING_CONSTANTS.SENTENCE_PAUSE * 1.5
  },
  
  professional: {
    ...DEFAULT_CONFIG,
    speed: TIMING_CONSTANTS.BASE_SPEED * 0.6,
    mistakeFrequency: BEHAVIOR_RATES.MISTAKE_FREQUENCY * 0.3,
    speedVariation: TIMING_CONSTANTS.SPEED_VARIATION * 0.5
  },
  
  expert: {
    ...DEFAULT_CONFIG,
    speed: TIMING_CONSTANTS.BASE_SPEED * 0.4,
    mistakeFrequency: BEHAVIOR_RATES.MISTAKE_FREQUENCY * 0.1,
    sentencePause: TIMING_CONSTANTS.SENTENCE_PAUSE * 0.6
  }
}

// Usage
<HumanLike text="Professional typing" config={TYPING_PRESETS.professional} />

Dynamic Configuration

Adjust constants based on content type.

const getConfigForContent = (contentType: 'code' | 'prose' | 'casual') => {
  const baseConfig = { ...DEFAULT_CONFIG }
  
  switch (contentType) {
    case 'code':
      return {
        ...baseConfig,
        speed: TIMING_CONSTANTS.BASE_SPEED * 1.2, // Slower for code
        mistakeFrequency: BEHAVIOR_RATES.MISTAKE_FREQUENCY * 0.5, // More careful
        thinkingPause: TIMING_CONSTANTS.THINKING_PAUSE * 2 // More thinking
      }
    
    case 'prose':
      return {
        ...baseConfig,
        speed: TIMING_CONSTANTS.BASE_SPEED * 0.8, // Faster for writing
        sentencePause: TIMING_CONSTANTS.SENTENCE_PAUSE * 1.5 // Longer pauses
      }
    
    case 'casual':
      return {
        ...baseConfig,
        mistakeFrequency: BEHAVIOR_RATES.MISTAKE_FREQUENCY * 1.5, // More mistakes
        speedVariation: TIMING_CONSTANTS.SPEED_VARIATION * 1.2 // More variation
      }
  }
}