Repolode
jamiebuilds

jamiebuilds/tinykeys

A tiny keybinding library for browsers that maps keyboard shortcuts, including multi-key sequences, to handler functions.

Stars
4,105
Forks
89
Open issues
7
Last commit
last month

What is it?

tinykeys is a small JavaScript library for registering keyboard shortcuts in web applications. You pass it a target such as window and an object that maps key patterns like "Shift+D" or "$mod+b" to callback functions, and it listens for keyboard events and calls the matching handler. It also returns an unsubscribe function, which makes it easy to clean up bindings when a component unmounts.

The syntax covers modifiers, optional modifiers in brackets, a cross-platform $mod alias that maps to Meta on Mac and Control elsewhere, and regular-expression groups for matching sets of keys. Sequences such as "g i" are supported, with a configurable timeout between presses. Bindings match against KeyboardEvent.key or KeyboardEvent.code, and the library includes a parseKeybinding helper for rendering shortcuts in a UI.

The library can be installed from npm or loaded from a CDN, and it is written in TypeScript.

Key features

  • 01Binds single keys, modifier combinations, and multi-key sequences to handler functions.
  • 02Provides a $mod alias that resolves to Meta on Mac and Control on other platforms.
  • 03Supports regular-expression groups to match several keys with one binding.
  • 04Returns an unsubscribe function for cleaning up listeners.
  • 05Can match on key or code, and handles keyboard layout differences such as AltGraph.
  • 06Offers parseKeybinding for displaying shortcuts in a UI.

Use cases

  • Adding keyboard shortcuts such as Cmd+B for bold to a web text editor.
  • Implementing Gmail-style multi-key navigation sequences like "g i" in a web app.
  • Registering shortcuts inside React components with cleanup on unmount.

Quick start

  1. 1

    Install the package with npm

    npm install --save tinykeys
  2. 2

    Import tinykeys and bind shortcuts to window

In collections

Topics

FAQ

What is tinykeys?
A tiny keybinding library for browsers that maps keyboard shortcuts, including multi-key sequences, to handler functions. tinykeys is a small JavaScript library for registering keyboard shortcuts in web applications. You pass it a target such as window and an object that maps key patterns like "Shift+D" or "$mod+b" to callback functions, and it listens for keyboard events and calls the matching handler. It also returns an unsubscribe function, which makes it easy to clean up bindings when a component unmounts.
Is tinykeys free to use? What license does it have?
tinykeys is open source under the MIT license. Check the license terms before using it in commercial products.
Is tinykeys still maintained?
Updated within 6 months. The last commit to tinykeys was on Sep 25, 2026.
What can I use tinykeys for?
Adding keyboard shortcuts such as Cmd+B for bold to a web text editor. Implementing Gmail-style multi-key navigation sequences like "g i" in a web app. Registering shortcuts inside React components with cleanup on unmount.
How do I install tinykeys?
Install the package with npm: npm install --save tinykeys Import tinykeys and bind shortcuts to window
Where can I get tinykeys?
The source code and installation instructions are on GitHub: https://github.com/jamiebuilds/tinykeys

Summary generated by AI from the project's README. GitHub stats refresh daily.

Related projects