Mousetrap

A simple, dependency-free JavaScript library for binding keyboard shortcuts

Library
npm
v1.6.5
11,777stars
Apache License 2.0

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum.How we score it →
47/100Fair
Development Activity0
Maintenance20
Community68
Maturity60
Momentum40

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation.How we score it →
68/100Good
Architecture62
Code Quality65
Innovation55
Learning Curve90

Mousetrap is a small, dependency-free JavaScript library for binding keyboard shortcuts in the browser — single keys, modifier combinations like command+shift+k, and Gmail-style key sequences like g i or the Konami code. At roughly 2KB minified and gzipped, it has no external dependencies and has historically supported browsers back to Internet Explorer 6.

The core library handles keypress, keydown, and keyup binding with a simple Mousetrap.bind(keys, callback, event) API, and its functionality is extended through a small set of official plugins (global binding outside focused inputs, pausing/unpausing all bindings, recording key sequences, and binding from a dictionary of named shortcuts) rather than baking every feature into the core.

What You Get

  • Mousetrap.bind(keys, callback, event) for registering single keys, modifier combinations, or multi-key sequences
  • Support for keypress, keydown, and keyup event types on the same binding API
  • Konami-code-style and Gmail-style sequence binding (e.g. g i, up up down down left right left right b a enter)
  • Official plugins for global binding (shortcuts that fire even while an input is focused), pausing/unpausing all bindings, recording key sequences, and binding from a name-to-shortcut dictionary
  • Zero external runtime dependencies and a small (~2KB gzipped) footprint

Common Use Cases

  • Adding power-user keyboard shortcuts to web applications (e.g. Gmail-style g i navigation shortcuts)
  • Implementing global application shortcuts that need to work even when a text input has focus, via the global-bind plugin
  • Building customizable keyboard-shortcut settings screens by combining the bind-dictionary and record plugins to capture and label user-defined shortcuts
  • Adding modal or context-specific keyboard shortcuts that can be paused/resumed via the pause plugin when a dialog opens

Under The Hood

Architecture The entire core library lives in a single ~1,058-line mousetrap.js file structured as a self-invoking function that returns a Mousetrap constructor/singleton. Internally it maintains a direct map from normalized key-combination strings to callback arrays, listens for keydown/keyup/keypress at the document level, and normalizes cross-browser key codes and modifier detection (handling historical quirks like differing keyCode values across browsers) before matching the pressed sequence against registered bindings, including multi-key sequence state tracking for combos like g i. Additional behavior — global binding, pause/resume, sequence recording, dictionary-based binding — is deliberately kept out of the core and shipped as separate plugin files under plugins/, each extending the core Mousetrap object rather than being conditionally compiled in.

Tech Stack Plain vanilla JavaScript (no TypeScript, no framework dependency), built and linted via Grunt (Gruntfile.js, including a complexity-analysis task), with mousetrap.min.js as the pre-built minified distributable checked into the repo alongside the source. Tests run via Mocha with Chai assertions and jsdom/jsdom-global to simulate a DOM environment without a real browser.

Code Quality The project has a dedicated tests/ suite run via npm test (mocha --reporter=nyan) and a Grunt complexity-analysis task, suggesting some attention to keeping the single large core file maintainable despite its age and broad legacy-browser support requirements. Being last released in 2020, the library is stable but not actively evolving; its cross-browser key-code normalization logic, while effective, reflects patterns from an era before the standardized KeyboardEvent.key API was universally available.

API Design The public API is a single global object with a small, memorable method set (bind, unbind, trigger, reset) and a string-based key-combination syntax ('command+shift+k', 'g i') that reads close to natural language, requiring no build step or configuration — just <script src="mousetrap.min.js"> or require('mousetrap') and a call to bind. This low-ceremony design is a major reason for its long-standing popularity, though the plugin-based extension model means some commonly wanted behavior (global shortcuts, pausing) requires pulling in additional files rather than being available out of the box.

Used by 13 apps in this directory

TypeScript
76%
AGPL 3.0

Abby

Developer Tools · Product Management

167

Statically typed feature flags, remote config, and A/B testing with framework-native SDKs for TypeScript teams.

View details
30
Repo Health
70
Technical
63
Dependency
Built with
TypeScript76%
MDX18%
Updated 1 years ago
Vue
46%
MIT

flatnotes

Note Taking · Knowledge Management

3,183

Self-hosted, database-free note-taking with plain Markdown files, full-text search, wikilinks, and zero proprietary lock-in.

View details
70
Repo Health
64
Technical
81
Dependency
Built with
Vue46%
Python32%
JavaScript13%
Updated 2 weeks ago
Ruby
67%
Other

GitLab

Devops · Developer Tools

24,533

The complete DevOps platform that unifies Git hosting, CI/CD, issue tracking, and security scanning into a single self-hostable application.

View details
87
Repo Health
86
Technical
70
Dependency
Built with
Ruby67%
JavaScript20%
Updated today
TypeScript
83%
Apache 2.0

Grist

Databases · No Code Platforms

11,469

A modern relational spreadsheet that combines Python-powered formulas, drag-and-drop dashboards, and granular access controls in a self-hostable, SQLite-backed data platform.

View details
91
Repo Health
93
Technical
68
Dependency
Built with
TypeScript83%
Python11%
Updated yesterday
PHP
79%
GPL 3.0

matomo

Analytics

21,786

Open-source, privacy-first web and app analytics that puts you in complete control of your data.

View details
95
Repo Health
82
Technical
62
Dependency
Built with
PHP79%
Updated today
PHP
82%
Other

Mautic

Automation · Marketing · Ecommerce

10,366

The world's largest open source marketing automation platform — own your data, run multi-channel campaigns, and escape vendor lock-in forever.

View details
98
Repo Health
76
Technical
64
Dependency
Built with
PHP82%
Updated yesterday
JavaScript
87%
GPL 3.0

NodeBB

Community

15,199

Modern Node.js forum software with real-time WebSockets, multi-database support, and a plugin ecosystem — the community platform built for the open web and the Fediverse.

View details
97
Repo Health
78
Technical
71
Dependency
Built with
JavaScript87%
Go Template12%
Updated today
Ruby
79%
GPL 3.0

OpenProject

Project Management · Productivity · Collaboration

15,881

The open source project management platform that unifies Gantt charts, agile boards, time tracking, and team collaboration under full self-hosted control.

View details
96
Repo Health
79
Technical
70
Dependency
Built with
Ruby79%
TypeScript13%
Updated today
TypeScript
84%
MIT

Plasmic

CMS · Low Code Platforms · No Code Platforms

6,961

The open-source visual builder that lets teams design React apps and websites with drag-and-drop while integrating seamlessly with your codebase.

View details
81
Repo Health
78
Technical
65
Dependency
Built with
TypeScript84%
Updated today

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers

Search