React hook written in TypeScript
npm install @react-typed-hooks/use-key-pressReact hook that returns true when the specified targetKey is pressed.
``bash`
npm install @react-typed-hooks/use-key-press
`tsx
import { useKeyPress } from "@react-typed-hooks/use-key-press";
const Demo = () => {
const isEscapePressed = useKeyPress({ targetKey: "Escape" });
return isEscapePressed ? "Yes" : "No";
};
`
`ts`
interface UseKeyPressOptions {
targetKey: KeyboardEvent["key"];
}
`ts`
function useKeyPress(options: UseKeyPressOptions): boolean;
targetKey: KeyboardEvent["key"]
A predefined key value (i.e, Escape, Enter, Backspace, etc) to watch the keydown and keyup` event on.