Keyboard shortcuts, in context.

A tiny, dependency-free library for shortcuts in the browser. Group them into contexts, react to every phase of a key press, and use them from any framework.

pnpm add shortcutter
Press any key
Shortcut
–
Context
default
  1. down
  2. press
  3. up

    Try it on this page

    Shortcuts that document themselves

    Give each shortcut a description when you register it. shortcuts() gathers them, with the keys resolved for the platform (⌘ on macOS, Ctrl elsewhere), so a keyboard help screen is one loop and never goes out of date.

    ? works too, as in Gmail, on US-style keyboard layouts. Why other layouts differ

    shortcutter.listen('ControlOrMeta+Slash', openHelp, {
    description: 'Show all keyboard shortcuts',
    });
    const help = shortcutter.shortcuts({ active: true });
    // [{ keys: ['meta', 'slash'],
    // description: 'Show all keyboard shortcuts', … }]
    help.forEach(({ keys, description }) => addRow(keys, description));

    Features

    Contexts

    Scope shortcuts to a modal, an editor or a page, and activate several at once.

    Phases

    Handle the press, the key repeat and the release: hold-to-peek and push-to-talk become one line.

    Tiny & SSR-safe

    No dependencies, under 3 kB gzipped, and safe to import on the server.

    Every framework

    Plain TypeScript, plus adapters for React, Vue, Svelte and Solid that clean up after themselves.

    One API, your framework

    The same counter, live. Press J and K; hold ⇧ to count in tens (Shift+K is a shortcut of its own). Switch frameworks with 1–5 (a single Digit* wildcard shortcut), or with ← → in the tabs.

    import { createShortcutter } from 'shortcutter';
    const shortcutter = createShortcutter();
    let count = 0;
    shortcutter.listen('K', () => render((count += 1)));
    shortcutter.listen('J', () => render((count -= 1)));
    shortcutter.listen('Shift+K', () => render((count += 10)));
    shortcutter.listen('Shift+J', () => render((count -= 10)));
    0

    Plain TypeScript

    ↑ ↓ move · Enter run ·Esc close

    Keyboard shortcuts

    Generated from shortcutter.shortcuts() · Esc close