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

keyboard-shortcuts-system

v1.0.0

Published

A user-friendly keyboard shortcuts system for React applications

Readme

Keyboard Shortcuts System

A complete, user-friendly keyboard shortcuts system for React applications. This system allows users to:

  1. Use predefined navigation shortcuts
  2. Create custom shortcuts for any button in the application
  3. Manage shortcuts through an elegant UI
  4. Trigger button clicks via keyboard combinations

Features

  • Keyboard Shortcut Recording: Users can record keyboard shortcuts by pressing the actual key combinations instead of typing them
  • Function Key Support: Support for function keys (F1-F12) that work even when typing in form fields
  • Enhanced Visual Button Selection: The modal temporarily closes during button selection for an unobstructed view
  • Interactive Selection Experience: Buttons are highlighted when hovered over during selection mode
  • Seamless Workflow: The modal automatically reopens after button selection with all form data preserved
  • Persistent Storage: Shortcuts are saved to localStorage and persist across page refreshes
  • Customizable: Easily integrate with any React application
  • User-Friendly: Intuitive UI with clear visual feedback at every step
  • Flexible: Works with any button in your application
  • Guided Experience: Clear instructions and notifications guide users through the process

Installation

NPM Package

  1. Install the package:
npm install keyboard-shortcuts-system
# or
yarn add keyboard-shortcuts-system
  1. Install peer dependencies:
npm install antd @ant-design/icons
# or
yarn add antd @ant-design/icons

CDN Usage

You can use the F8 key handler directly from a CDN without installing the npm package:

Standalone F8 Handler

<!-- Using unpkg -->
<script src="https://unpkg.com/keyboard-shortcuts-system/dist/f8-handler.min.js"></script>

<!-- OR using jsDelivr -->
<script src="https://cdn.jsdelivr.net/npm/keyboard-shortcuts-system/dist/f8-handler.min.js"></script>

When using the CDN version, the F8 handler is available under the global F8Handler object:

<script>
  // Initialize the F8 handler with default options
  const cleanup = F8Handler.default();
  
  // Or with custom options
  const cleanupCustom = F8Handler.default({
    debug: true,                                // Enable console logging
    buttonSelector: '#my-submit-button',        // Custom button selector
    preventDefault: true                        // Prevent default F8 behavior
  });
  
  // Later, if you want to remove the handler
  cleanup();
</script>

Full React Component Library (requires React and Ant Design)

For the complete React component library, you need to include React and Ant Design first:

<!-- React dependencies -->
<script src="https://unpkg.com/react@17/umd/react.production.min.js"></script>
<script src="https://unpkg.com/react-dom@17/umd/react-dom.production.min.js"></script>
<script src="https://unpkg.com/antd/dist/antd.min.js"></script>
<link rel="stylesheet" href="https://unpkg.com/antd/dist/antd.min.css">

<!-- Then load the keyboard shortcuts library -->
<script src="https://unpkg.com/keyboard-shortcuts-system/dist/keyboard-shortcuts.min.js"></script>

Example: Using the F8 Handler in a Plain HTML Page

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>F8 Handler Demo</title>
    <style>
        button { padding: 10px 20px; background: #4CAF50; color: white; border: none; }
    </style>
</head>
<body>
    <h1>Press F8 to Submit</h1>
    <form>
        <input type="text" placeholder="Type something...">
        <button type="submit" id="submit-button">Submit</button>
    </form>
    
    <!-- Load the F8 handler from CDN -->
    <script src="https://unpkg.com/keyboard-shortcuts-system/dist/f8-handler.min.js"></script>
    <script>
        // Initialize the F8 handler
        const cleanup = F8Handler.default({
            debug: true,
            buttonSelector: '#submit-button'
        });
        
        // Log when the form is submitted
        document.querySelector('form').addEventListener('submit', function(e) {
            e.preventDefault();
            console.log('Form submitted!');
            alert('Form submitted!');
        });
    </script>
</body>
</html>

Usage

1. Wrap your application with the provider

import { KeyboardShortcutsProvider } from './keyboard-shortcuts-system/src';
import ShortcutHelpModal from './keyboard-shortcuts-system/src/components/ShortcutHelpModal';

// Define default keyboard shortcuts
const defaultShortcuts = [
  { 
    id: 'dashboard', 
    keys: 'Alt+D', 
    description: 'Go to Dashboard',
    action: { type: 'route', path: '/dashboard' }, 
    category: 'Navigation'
  },
  { 
    id: 'profile', 
    keys: 'Alt+P', 
    description: 'Go to Profile',
    action: { type: 'route', path: '/profile' }, 
    category: 'Navigation'
  },
  { 
    id: 'help', 
    keys: 'Alt+/', 
    description: 'Show Keyboard Shortcuts Help',
    action: { type: 'function', handler: () => {} }, 
    category: 'Help'
  }
];

function App() {
  return (
    <KeyboardShortcutsProvider globalShortcuts={defaultShortcuts}>
      <YourApp />
      <ShortcutHelpModal />
    </KeyboardShortcutsProvider>
  );
}

2. Add the ShortcutManager component to your UI

import { ShortcutManager } from './keyboard-shortcuts-system/src';

function Header() {
  return (
    <header>
      <h1>My App</h1>
      <ShortcutManager buttonText="Keyboard Shortcuts" />
    </header>
  );
}

3. Use the useKeyboardShortcuts hook in your components

import { useKeyboardShortcuts } from './keyboard-shortcuts-system/src';

function MyComponent() {
  const { registerShortcut, unregisterShortcut } = useKeyboardShortcuts();
  
  useEffect(() => {
    // Register a shortcut for a button
    registerShortcut(
      'save_form',
      'Alt+S',
      { 
        type: 'element', 
        selector: '#save-button', 
        event: 'click' 
      },
      { 
        description: 'Save Form',
        category: 'Forms'
      }
    );
    
    // Clean up when component unmounts
    return () => {
      unregisterShortcut('save_form');
    };
  }, [registerShortcut, unregisterShortcut]);
  
  return (
    <div>
      <button id="save-button" onClick={handleSave}>Save</button>
    </div>
  );
}

4. Add the ShortcutDemo component to demonstrate usage

import { ShortcutDemo } from './keyboard-shortcuts-system/src';

function Routes() {
  return (
    <Switch>
      <Route path="/shortcut-demo" component={ShortcutDemo} />
      {/* Other routes */}
    </Switch>
  );
}

API Reference

KeyboardShortcutsProvider

Props:

  • children: React nodes
  • globalShortcuts: Array of default shortcuts

useKeyboardShortcuts

Returns:

  • shortcuts: Array of all registered shortcuts
  • registerShortcut(id, keys, action, options): Function to register a new shortcut
  • unregisterShortcut(id): Function to remove a shortcut
  • showHelpModal: Boolean state of the help modal
  • setShowHelpModal: Function to show/hide the help modal

ShortcutManager

Props:

  • buttonText: Text to display on the button (default: "Keyboard Shortcuts")
  • buttonStyle: Custom styles for the button
  • buttonType: Button type (default, primary, etc.)
  • showIcon: Whether to show the keyboard icon

ShortcutHelpModal

No props required. This component uses the context internally.

Shortcut Object Structure

interface Shortcut {
  id: string;              // Unique identifier
  keys: string;            // Key combination (e.g., "Alt+S")
  description: string;     // Human-readable description
  action: ShortcutAction;  // What happens when triggered
  category: string;        // Grouping category
  disabled?: boolean;      // Whether the shortcut is active
}

type ShortcutAction = 
  | { type: 'route'; path: string }                        // Navigate to a route
  | { type: 'element'; selector: string; event?: string }  // Trigger an element event
  | { type: 'function'; handler: () => void };             // Execute a function

License

MIT