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-hotkeys-ts

v1.1.4

Published

A typed React hook for handling hotkeys with TypeScript support.

Readme

use-hotkeys-ts

npm version TypeScript License Bundle Size codecov

A fully typed React hook for handling keyboard shortcuts and hotkeys with ease.

Key Sequences

You can now use key sequences - combinations of keys pressed one after another:

// Detecting "g" followed by "h"
useHotkeys('g h', () => {
  console.log('Redirecting to home page');
});

// With custom delay (default is 1000ms)
useHotkeys('g i t', () => {
  console.log('Git command');
}, 2000); // 2 second timeout

Improved Function Key Support

Function keys are now fully supported with better case handling:

useHotkeys('shift+f12', () => {
  console.log('Open developer tools');
});

Installation

npm install use-hotkeys-ts

or

yarn add use-hotkeys-ts

Quick Start

import { useHotkeys } from 'use-hotkeys-ts';

useHotkeys('ctrl+s', (e) => {
  e.preventDefault();
  console.log('Saving...');
});

Usage Examples

Multiple Key Combinations

Use an array to match several shortcuts. On macOS, cmd and meta are equivalent (e.g. cmd+s matches ⌘+S):

useHotkeys(['ctrl+s', 'cmd+s'], (e) => {
  e.preventDefault();
  console.log('Save triggered');
});

Special and Function Keys

useHotkeys('f5', () => {
  console.log('Page refresh');
});

useHotkeys('/', () => {
  console.log('Focus search');
});

Integration with react-hook-form

const { handleSubmit } = useForm();

useHotkeys('ctrl+enter', () => {
  handleSubmit(onSubmit)();
});

Callback return value

Return false from the callback to call event.preventDefault():

useHotkeys('ctrl+s', (e) => {
  console.log('Saving...');
  return false; // prevents default browser save
});

API

  • useHotkeys(keys, callback, delay?)
    • keys: string | string[] — key combo(s), e.g. 'ctrl+s', ['ctrl+s', 'cmd+s'], or a sequence like 'g h'.
    • callback: (e: KeyboardEvent) => void | boolean — called when the shortcut matches. Return false to call e.preventDefault().
    • delay: number (optional, default 1000) — timeout in ms for key sequences (e.g. 'g i').

Hotkeys are ignored when focus is inside <input>, <textarea>, <select>, or contenteditable (except types like button, submit, checkbox, radio).

Features

✅ Multiple key combinations

✅ Key sequences (e.g. g i then t)

✅ Full TypeScript support

✅ macOS / Windows: cmd and meta both work

✅ Ignores form elements and contenteditable

✅ Easy integration with forms and UI frameworks

Future Plans

  • Options: keydown/keyup, ignoreModifiers

  • Scope restriction via ref (limit hotkey to a DOM node)

  • Auto-detection of platform (ctrl vs cmd)

  • Global mode for background hotkeys

  • Dev/debug mode

  • Logging and telemetry support

  • Storybook demo support

Links