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

use-shortcut-recorder

v2.2.0

Published

A React hook for capturing keyboard shortcuts

Readme

useShortcutRecorder

A React hook for effortlessly capturing and validating keyboard shortcut keys.

  • Record keyboard shortcuts with modifier keys (Ctrl, Alt, Shift, Meta/Command)
  • Customizable validation rules:
    • Min/max number of modifier keys
    • Excluded keys and modifiers
    • Excluded shortcut combinations

Demo

https://stackblitz.com/edit/react-brtovrsp?file=Shortcut.jsx

Installation

npm install use-shortcut-recorder

Usage


import { useShortcutRecorder } from 'use-shortcut-recorder';


function ShortcutInput() {

  const {
    shortcut,
    savedShortcut,
    isRecording,
    error,
    startRecording,
    stopRecording,
    resetRecording,
    clearLastRecording,
  } = useShortcutRecorder({
    onChange: (newShortcut) => {
      console.log('Shortcut changed:', newShortcut);
    },
    excludedKeys: ['KeyA', 'KeyB'], 
    excludedShortcuts: [
        ['Alt', 'KeyM'],
        ['Meta', 'KeyZ']
    ],
    excludedModKeys: ['Control'],
    maxModKeys: 3,
    minModKeys: 1,
  } );

  return (
    <div>
      <label htmlFor="shortcut-input">Enter Shortcut:</label>

      <input
        id="shortcut-input"
        type="text"
        className='shortcut-input'
        placeholder={
          isRecording ? 'Key Recording Started..' : 'Click to Record Shortcut..'
        }
        onFocus={startRecording}
        onClick={startRecording}
        onBlur={() => stopRecording()}
        value={isRecording 
          ? shortcut.join(' + ') 
          : savedShortcut.join(' + ')}
        readOnly={true}
      />

      {error && <div>{error.message}</div>}

      {savedShortcut && (
        <div>
          Saved Shortcut: <strong>{savedShortcut.join(' + ')}</strong>
        </div>
      )}
       <button onClick={clearLastRecording}>Reset</button>
    </div>
  );
}

API Reference

Hook Options

The useShortcutRecorder hook accepts a configuration object with the following properties:

| Option | Type | Default | Description | |--------|------|---------|-------------| | onChange | (keys: string[]) => void | () => {} | Callback function called when a valid shortcut is recorded | | excludedShortcuts | string[][] | [[]] | Array of shortcut combinations to exclude | | excludedModKeys | string[] | [] | Array of modifier keys to exclude | | excludedKeys | string[] | [] | Array of non-modifier keys to exclude | | minModKeys | number | 0 | Minimum number of modifier keys required | | maxModKeys | number | 4 | Maximum number of modifier keys allowed |

Return Values

The hook returns an object with the following properties:

| Property | Type | Description | |----------|------|-------------| | shortcut | string[] | Current shortcut being recorded | | savedShortcut | string[] | Last successfully recorded shortcut | | isRecording | boolean | Whether the recorder is currently active | | error | ShortcutRecorderError | Current error state | | startRecording | () => void | Function to start recording | | stopRecording | () => void | Function to stop recording | | resetRecording | () => void | Function to reset current recording | | clearLastRecording | () => void | Function to clear saved shortcut |

Error Codes

The error object contains a code and message. Possible error codes:

| Error Code | Description | |------------|-------------| | NONE | No error | | MAX_MOD_KEYS_EXCEEDED | Too many modifier keys used | | MIN_MOD_KEYS_REQUIRED | Not enough modifier keys used | | MOD_KEY_NOT_ALLOWED | Modifier key is in the excluded list | | KEY_NOT_ALLOWED | Non-modifier key is in the excluded list | | SHORTCUT_NOT_ALLOWED | Shortcut combination is in the excluded list |

Keyboard Code Reference

This hook uses keyboard event codes for key identification. For consistency and cross-browser compatibility, all left/right variations of modifier keys (e.g., ShiftLeft/ShiftRight, ControlLeft/ControlRight) are normalized to their base name (e.g., Shift, Control). Specifically, both MetaLeft/MetaRight and the now-deprecated OSLeft/OSRight are mapped to Meta for the Windows/Command key.

License

MIT