@devcrush/hotkey

1.3.0 • Public • Published

Hotkey

A small library to help creating hotkeys by listening to key-combos.

Install

$ npm install @devcrush/hotkey

Usage

Example hotkeys:

  • "Ctrl+p" (same as "Control+p")
  • "Ctrl+Click"
  • "Ctrl+Up"
  • "Cmd+Click" (same as "Meta+Click")
  • "Left+Down" (same as "ArrowLeft+ArrowDown")
import { hotkey } from "lib/hotkey";

// Subscribing
// ----------------------------------------
// Important!
// Always make sure you pass in function instances instead of anonymous functions,
// as like that it can create multiple subscriptions.

// Good
const callback = () => console.log("Hiya!");
hotkey.on("Cmd+p", callback);

// Bad
hotkey.on("Cmd+p", () => console.log("Hiya!"));

// Unsubscribing
// ----------------------------------------

// Good
const callback = () => console.log("Hiya!");
hotkey.off("Cmd+p", callback);

// Bad
// (this won't do anything)
hotkey.off("Cmd+p", () => console.log("Hiya!"));

Readme

Keywords

none

Package Sidebar

Install

npm i @devcrush/hotkey

Weekly Downloads

1

Version

1.3.0

License

MIT

Unpacked Size

7.05 kB

Total Files

6

Last publish

Collaborators

  • devcrush