1.0.2 • Published 2 years ago

use-keyboard v1.0.2

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

useKeyboard

An react hook for handling keyboard input.

This package is under development and is not production-ready.

Install

npm i use-keyboard

or

yarn add use-keyboard

Basic usage

const { pressed } = useKeyboard();
const spacePressed = pressed("Space");

Axis abstraction

  const { axis } = useKeyboard();
  const horizontal = axis("LeftArrow", "RightArrow");
};

Key handlers

const _keyboard = useKeyboard({
  down: {
    Space: () => console.log("Spacebar pressed"),
  },
  up: {
    Space: () => console.log("Spacebar released"),
  },
});