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

react-simple-keys

v1.0.0

Published

A React Hook to handle shortcuts in your WebApp

Readme

react-simple-keys

A React Hook to easily create shortcuts with a hook:

import useKeys from "react-simple-keys";

useKeys({
  "cmd+k": (event) => {
    console.log("Open search panel");
  },
  esc: (event) => {
    console.log("Close search panel");
  },
  down: (event) => {
    console.log("Highlight next item");
  },
  up: (event) => {
    console.log("Highlight prev item");
  },
  enter: (event) => {
    if (event.metaKey) {
      console.log("Special open highlighted item");
    } else {
      console.log("Normal open highlighted item");
    }
  },
});

If the shortcut is matched, then the prevent default for that shortcut will be triggered.

useKeys({
  "k",   // Listening for simple "k" presses (excludes inputs/textareas/etc)
  "cmd+k",     // Listening when the modifier "cmd" is pressed
  "!cmd+k",     // Listening when "k" is pressed AND the modifier "cmd" is NOT pressed
  "input:k" ,    // Listening for "k" pressed only while an input is focused
});

Shortcuts examples

A shortcut is defined with the key, and then the action to be taken is defined with the value as as function. The key can have multiple parts:

  • A plain key, like a for the keyboard key a, "t" for the keyboard key t, etc.
  • A modifier cmd+[...], shift+[...], etc. They are normally special keys with a plain key: cmd+a, shift+k, etc.
  • A negative modifier !cmd+[...]: to force an alternative case, you can do k: e => e.metaKey ? X() : Y(), or alternatively you can specify two different modifiers, one negated: "cmd+k": X + "!cmd+k": Y.
  • A namespace namespace:[...]; this is so that global shortcuts do not activate while typing in an inbox, so we assume any shortcut without namespace is on "window" (nothing is focused) one (so that window:cmd+a, body:cmd+a or cmd+a are all equivalent). If you want to listen only in inputs then you should do input:cmd+a; this is a valid CSS selector, could alternatively use textarea:cmd+a, etc. For listening on both unfocused and focused elements, use the "*" namespace *:cmd+a.