bind-mousetrap-global
v1.0.1
Published
A version of mousetrap-global-bind in an easy-to-use module
Downloads
468
Readme
🪤 bind-mousetrap-global
A mousetrap-global-bind module that doesn't assume the presence of a global object.
Perfect for use in a module environment like create-react-app as opposed to a <script />
tag approach.
npm i bind-mousetrap-global
Usage
Setup
import mousetrap from 'mousetrap'
import addGlobalBinds from 'bind-mousetrap-global'
addGlobalBinds(mousetrap)
Use
// This shortcut will fire even if the user has an input focused
mousetrap.bindGlobal('mod+s', saveDocument)
// This one won't
mousetrap.bind('n', newDocument)
License note
This is a rewrite inspired by similar packages from ccampbell and Elvynia. It does not contain any of their code.