npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@nk11/keyboard-interactions

v3.0.1

Published

A wrapper for mousetrap and other human interface libraries with additional actions to be able to change hotkeys for actions via dialog.

Readme

| | | :----------------------------: | | keyboard-interactions | | Action-based hotkey management with swappable input adapters |

Overview

Bind keyboard (and other input) combos to named actions. Actions can be rebound at runtime via a built-in UI dialog. The library ships as three independent packages:

| Import | Contents | |---|---| | @nk11/keyboard-interactions | Core — action registry, mousetrap adapter | | @nk11/keyboard-interactions/react | React hooks — useHotkeys, useSvelteComponent | | @nk11/keyboard-interactions/ui | Svelte components — KeybindingsEditorDialog, KeyBindingsEditor, DebugLog | | @nk11/keyboard-interactions/adapters/humaninput | HumanInput adapter (gamepad, touch, speech, …) | | @nk11/keyboard-interactions/adapters/keypress | Keypress.js adapter |

Installation

npm install @nk11/keyboard-interactions

Basic usage

import { Hotkeys } from "@nk11/keyboard-interactions";

// 1. Register actions (once, at app init)
Hotkeys.register("save", "ctrl+s", { title: "Save", description: "Save the document" });
Hotkeys.register("undo", "ctrl+z", { title: "Undo" });

// 2. Bind handlers (scoped to window by default, or any DOM element)
const hk = Hotkeys(window);

hk.on("save", (e) => save());
hk.on("undo", (e) => undo());

// 3. Unbind
hk.off("save", handler);

Scope hotkeys to a specific element:

const hk = Hotkeys(document.querySelector("#my-panel"));
hk.on("move-up", () => moveUp());

Theming

import "@nk11/keyboard-interactions/ui/index.css";

// pick one:
import "@nk11/keyboard-interactions/ui/themes/dark.css";
import "@nk11/keyboard-interactions/ui/themes/light.css";

Or define your own CSS variables — see src/gui/themes/dark.css for the full list.

Pluggable adapters

Core ships with mousetrap as the default keyboard adapter. To use an alternative, import the adapter and register it:

import { Hotkeys } from "@nk11/keyboard-interactions";
import { getHumanInputInstance } from "@nk11/keyboard-interactions/adapters/humaninput";
import { getKJSInstance } from "@nk11/keyboard-interactions/adapters/keypress";

Hotkeys.registerInputType("humaninput", getHumanInputInstance);
Hotkeys.registerInputType("keypress", getKJSInstance);

// then use the type in your combo params:
Hotkeys.register("jump", [{ type: "humaninput", combo: "space" }], { title: "Jump" });

Adapters not imported are never bundled — fully tree-shakeable.

React

npm install @nk11/keyboard-interactions react

useHotkeys — fluent hotkey binding with automatic cleanup

import { useHotkeys, HotkeysDef } from "@nk11/keyboard-interactions/react";

const keys = {
  pause:   { keys: "p", title: "Pause",   description: "Pause / unpause" },
  restart: { keys: "r", title: "Restart", description: "Restart the game" },
} satisfies HotkeysDef;

function Game() {
  const canvasRef = useRef<HTMLCanvasElement>(null);

  useHotkeys(keys, canvasRef)       // scope to element, or omit for window
    .on("pause",   () => togglePause())
    .on("restart", () => restart());

  // held keys (keydown + keyup)
  useHotkeys({ thrust: { keys: "space", title: "Thrust" } }, canvasRef)
    .on("thrust", { keydown: () => startThrust(), keyup: () => stopThrust() });

  return <canvas ref={canvasRef} />;
}

useSvelteComponent — mount Svelte 5 components in React

Use this to render the built-in UI components (KeybindingsEditorDialog, KeyBindingsEditor, DebugLog) from React:

import { useSvelteComponent } from "@nk11/keyboard-interactions/react";
import { KeybindingsEditorDialog } from "@nk11/keyboard-interactions/ui";
import "@nk11/keyboard-interactions/ui/index.css";

function App() {
  const dialogRef = useSvelteComponent(KeybindingsEditorDialog, {
    persistenceKey: "my-app-keybindings",  // optional: saves/restores from localStorage
  });

  return <div ref={dialogRef} />;
}

Press H to open the dialog. Rebind any key — bindings are saved to localStorage automatically and restored on next load. A Reset all button appears in the editor header whenever any binding differs from its default.

API

Hotkeys.register(action, combo, options?)

| Param | Type | |---|---| | action | string — unique action name | | combo | string \| ComboParam \| (string \| ComboParam)[] | | options | Partial<ActionOptions> — title, description, category, preventDefault, stopPropagation, persistent |

Hotkeys(target?)

Returns a HotkeysInstance scoped to target (default: window).

  • .on(action, handler, extraHandler?) — bind keydown (+ optional keyup)
  • .off(action, handler) — unbind

Static methods

| Method | Description | |---|---| | Hotkeys.register(...) | Declare an action | | Hotkeys.clearRegistered() | Remove all non-persistent actions | | Hotkeys.registerInputType(type, factory) | Plug in a custom adapter | | Hotkeys.getRegistered() | Return all registered actions | | Hotkeys.onChange(handler) | Subscribe to registry changes | | Hotkeys.onAction(handler) | Subscribe to action triggers |

Utilities

  • rebind(action, comboIndex, newCombo) — remap a combo at runtime
  • resetActionCombosToDefault(action, comboIndex?) — restore defaults
  • addComboForAction(action) — append a new empty combo slot
  • getActionByName(action) — look up a registered action

Credits