1.3.0 • Published 5 years ago

@devcrush/hotkey v1.3.0

Weekly downloads
5
License
MIT
Repository
-
Last release
5 years ago

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!"));
1.3.0

5 years ago

1.0.5

6 years ago

1.0.4

6 years ago

1.0.3

6 years ago