skip to content
mpkcn

~/components/konami

Konami

A useKonami hook and an easter-egg component that fires a callback and plays matrix rain when someone types the Konami code.

type it anywhere on this page

↑↑↓↓←→←→BA

locked

Installation

terminal
npx mpkcn add konami
deps:none beyond react· tested with react@19.3.0

Usage

Drop the component anywhere. Typing ↑ ↑ ↓ ↓ ← → ← → B A on the page plays a few seconds of matrix rain.

tsx
import { Konami } from "@/components/mpkcn/konami";

export default function Layout({ children }: { children: React.ReactNode }) {
  return (
    <>
      {children}
      <Konami onActivate={() => console.log("cheat unlocked")} />
    </>
  );
}

A click or any key ends the rain early. Keys typed into fields are ignored.

Examples

Just the hook

useKonami calls your function on a match and returns how many keys are matched so far, so you can show progress or trigger anything else.

tsx
"use client";

import { useState } from "react";
import { useKonami } from "@/components/mpkcn/konami";

export function Secret() {
  const [unlocked, setUnlocked] = useState(false);
  const matched = useKonami(() => setUnlocked(true));
  return <p>{unlocked ? "+30 lives" : `${matched}/10`}</p>;
}

Your own sequence

sequence takes KeyboardEvent.key values, letters in lower case.

tsx
<Konami sequence={["m", "p", "k"]} rain={false} onActivate={() => setTheme("light")} />

Props

PropTypeDefaultDescription
onActivate() => void—Called each time the code is entered.
sequencestring[]KONAMI_CODEKeys to match, as KeyboardEvent.key values.
enabledbooleantrueListen at all.
rainbooleantruePlay matrix rain on a match.
durationnumber6000How long the rain lasts, in milliseconds.
fullscreenbooleantrueRain over the viewport. false fills the nearest positioned parent.
ignoreReducedMotionbooleanfalseRain even under reduced motion. Only use it behind an explicit action.
onProgress(matched: number) => void—Number of keys matched so far.

useKonami(onMatch, { sequence?, enabled?, ignoreInputs? }) returns the matched count. KONAMI_CODE is exported too.

Accessibility

  • Under prefers-reduced-motion: reduce there is no rain, but onActivate still fires.
  • The rain is decorative: aria-hidden, never focusable, and gone after duration or on the first click or key.
  • Keys typed into inputs, textareas, selects and editable content never count, so the code cannot fire while someone types.