A hook that listens for a key press and calls a function when the key is pressed.

Installation

pnpm dlx shadcn@latest add https://mhl5.vercel.app/r/useKey.json

Usage

import { useKey } from "@/hooks/useKey";

useKey({
  key: "Escape",
  eventName: "keydown",
  handler: () => {
    console.log("Escape key pressed!");
  },
});