A React implementation of the infamous Konami Code detector, ported from konami-lit. This project includes a custom React hook (useKonami) for detecting keyboard input sequences, along with a demo component.
- useKonami Hook: Detect the Konami Code or custom key sequences
- Configurable: Custom sequences, timeout duration, and event callbacks
- TypeScript: Full TypeScript support with type definitions
- Interactive Demo: Visual feedback with progress tracking and animations
npm installnpm run devnpm run buildimport { useKonami } from './hooks/useKonami';
function MyComponent() {
const konami = useKonami({
onActivated: () => {
console.log('Konami Code activated!');
}
});
return (
<div>
<p>Progress: {konami.progress} / {konami.total}</p>
<p>Next key: {konami.nextExpectedKey}</p>
</div>
);
}const konami = useKonami({
code: ['a', 'b', 'c'],
timeout: 3000,
onActivated: () => console.log('Custom sequence activated!'),
onProgress: (position, total) => console.log(`${position}/${total}`),
onReset: () => console.log('Sequence reset')
});function MyComponent() {
const [enabled, setEnabled] = useState(true);
const konami = useKonami({ enabled });
return (
<div>
<button onClick={() => setEnabled(!enabled)}>
{enabled ? 'Disable' : 'Enable'} Konami Code
</button>
{konami.activated && (
<div>
<p>Success!</p>
<button onClick={konami.reset}>Try Again</button>
</div>
)}
</div>
);
}code?: string[]- Custom key sequence (default: Konami Code)timeout?: number- Milliseconds between key presses before reset (default: 2000)enabled?: boolean- Whether the hook should listen for keyboard input (default: true)onActivated?: () => void- Callback when sequence is completedonProgress?: (position: number, total: number) => void- Callback on each correct keyonReset?: () => void- Callback when sequence is reset
progress: number- Current position in the sequencetotal: number- Total length of the sequencenextExpectedKey: string- The next key needed in the sequenceactivated: boolean- Whether the sequence was completedreset: () => void- Manually reset the sequence and activated state
↑ ↑ ↓ ↓ ← → ← → B A
(ArrowUp, ArrowUp, ArrowDown, ArrowDown, ArrowLeft, ArrowRight, ArrowLeft, ArrowRight, b, a)
MIT