React hook that tracks whether one or more specific keyboard keys are currently pressed.
A single key (e.g. "Enter") or an array of keys to listen for.
true if any of the specified keys are currently pressed, otherwise false.
true
false
const isEnterPressed = useKeyPress("Enter");const isMovementKeyPressed = useKeyPress(["ArrowUp", "w"]); Copy
const isEnterPressed = useKeyPress("Enter");const isMovementKeyPressed = useKeyPress(["ArrowUp", "w"]);
React hook that tracks whether one or more specific keyboard keys are currently pressed.