Human-Like
Usage

Hook

useHumanLike hook API

Full programmatic control over typing.

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

const {
  displayText, isTyping, isActive, isPaused, isCompleted,
  progress, currentWPM,
  start, stop, pause, resume, reset, skip, rewind,
} = useHumanLike({ text: 'Hello', speed: 80 })

Options

NameTypeDefaultDescription
textstringrequiredText to type
speednumber80Base speed (ms)
keyboardMode'mobile' | 'desktop''mobile'Platform behavior
autoStartbooleantrueStart on mount
configPartial\<HumanLikeConfig\>{}Advanced behavior
Callbackssee /docs/usage/events-onStart, onComplete, onChar, onMistake, onKey, ...

Returns

NameTypeDescription
displayTextstringCurrent output
isTypingbooleanActively typing or correcting
isActivebooleanAny activity: typing, paused, correcting, thinking
isPausedbooleanPaused state
isCompletedbooleanFinished state
currentState'idle' | 'typing' | 'paused' | 'correcting' | 'thinking' | 'completed'Internal state
progressnumber0–100
currentWPMnumberWords per minute
mistakeCountnumberTotal mistakes
totalDurationnumberms elapsed
start, stop, pause, resume, reset, skip, rewind() => voidControls
showCursor, cursorChar, cursorBlinkSpeedmixedCursor state
setCursorVisible, setCursorChar, setCursorBlinkSpeedfunctionsCursor control

Patterns

Basic Controls

Control typing flow with start, pause, resume, and reset methods.

const { 
  displayText, 
  isTyping, 
  isActive,
  start, 
  pause, 
  resume, 
  reset 
} = useHumanLike({ 
  text: 'Click buttons to control typing!',
  autoStart: false 
})

return (
  <div>
    <p>{displayText}</p>
    <div>Status: {isActive ? 'Active' : 'Idle'}</div>
    <div>Typing: {isTyping ? 'Yes' : 'No'}</div>
    <button onClick={start} disabled={isTyping}>Start</button>
    <button onClick={pause} disabled={!isTyping}>Pause</button>
    <button onClick={resume}>Resume</button>
    <button onClick={reset}>Reset</button>
  </div>
)

Dynamic Configuration

Update typing behavior in real-time by changing options.

const [speed, setSpeed] = useState(80)
const [mistakes, setMistakes] = useState(0.03)

const { displayText, reset } = useHumanLike({ 
  text: 'Adjust speed and mistakes dynamically',
  config: { 
    speed, 
    speedVariation: 30,
    mistakeFrequency: mistakes
  }
})

// Reset to apply new settings
useEffect(() => {
  reset()
}, [speed, mistakes, reset])

Event Handling & Progress

Monitor typing progress and respond to events.

const [progress, setProgress] = useState(0)
const [mistakes, setMistakeCount] = useState(0)

const { displayText, currentWPM } = useHumanLike({
  text: 'Track progress and performance metrics',
  onProgress: setProgress,
  onMistake: () => setMistakeCount(prev => prev + 1),
  onComplete: () => console.log('Typing finished!')
})

return (
  <div>
    <p>{displayText}</p>
    <div>Progress: {progress.toFixed(1)}%</div>
    <div>Speed: {currentWPM} WPM</div>
    <div>Mistakes: {mistakes}</div>
  </div>
)

Platform-Specific Behavior

Different keyboard behaviors for mobile vs desktop.

const { displayText } = useHumanLike({
  text: 'Mobile: @hello 123 vs Desktop: @Hello 123',
  keyboardMode: 'mobile', // or 'desktop'
  onKey: (keyInfo) => {
    console.log('Key pressed:', keyInfo.key)
    console.log('Platform:', keyInfo.platform)
  }
})