npm.io
1.0.1 • Published 5 years ago

bind-mousetrap-global

Licence
0BSD
Version
1.0.1
Deps
0
Size
3 kB
Vulns
0
Weekly
0

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.