A micro library for querying modifier keys at any time.
JavaScript
Latest commit 3ef6ee9 Nov 9, 2015 @fabienbrooke Update package.json
Permalink
Failed to load latest commit information.
bower.json
modifiers.js
modifiers.min.js
modifiers.min.map
package.json
readme.md

readme.md

Modifier key queries

Inspired by keymaster. This is a small subset of the functionality in that library.

Using this library you can query the modifiers object at any time to see if a modifier key is held down.

Default supported keys are: shift, alt, option (same as alt), control, command

if (modifiers.command || modifiers.control) {
  // do something special
}

// ..inside your click handler
if (modifiers.shift) {
  ...
}

You can also add your own to the defaults:

modifiers.add({
  leftArrow: 37,
  upArrow: 38,
  rightArrow: 39,
  downArrow: 40,
  w: 87,
  a: 65,
  s: 83,
  d: 68
});

Building

To create the minified and compressed version with source mapping, run:

npm run minify

The code uses addEventListener so if you need to support IE8 you'll want to change the code to use something like what's described here.

License

MIT