This package has been deprecated

Author message:

Renamed to @waradu/keyboard

wrdu-keyboard
TypeScript icon, indicating that this package has built-in type declarations

4.0.1 • Public • Published

How to use it

import { useKeyboard, Key } from "wrdu-keyboard";

// Create keyboard
const keyboard = useKeyboard();

// Listen for "A".
keyboard.listen([Key.A], (e) => {
  console.log("A key pressed");
});

// Listen for "B" and call prevent default.
keyboard.listen(
  [Key.B],
  (e) => {
    console.log("B key pressed");
  },
  { prevent: true },
);

// Listen for "C" unless an editable element like input is focused.
keyboard.listen(
  [Key.C],
  (e) => {
    console.log("C key pressed");
  },
  { ignoreIfEditable: true },
);

// Listen for "D" but only 1 time.
const unlisten = keyboard.listen(
  [Key.Alt, Key.L],
  (e) => {
    console.log("D key pressed");
  },
  { once: true },
);

// Stop listening for "D" again.
unlisten();

// Listen for every key.
keyboard.listen([Key.All], (e) => {
  console.log("Anything pressed");
});

// Call this when "window" is available.
keyboard.init();

You can find the complete list of available keys in the src/keys.ts file.

Package Sidebar

Install

npm i wrdu-keyboard

Homepage

waradu.dev

Weekly Downloads

6

Version

4.0.1

License

MIT

Unpacked Size

10.5 kB

Total Files

7

Last publish

Collaborators

  • waradu