JSPM

meta-keys

1.1.0
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 5
  • Score
    100M100P100Q38358F
  • License MIT

Get the state of any pressed meta keys, differentiating between their left/right location on the keyboard

Package Exports

  • meta-keys

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (meta-keys) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

meta-keys

Get the state of any pressed meta keys, differentiating between their left/right location on the keyboard.

Usage

NPM

keys = MetaKeys([element], [capture])

Creates a new instance of meta-keys, listening to keyboard events fired on element. If element is not supplied, window will be used.

const keys = require('meta-keys')()

setInterval(function () {
  if (keys.shift[0]) {
    console.log('Left shift key is down')
  }
  if (keys.shift[1]) {
    console.log('Right shift key is down')
  }
}, 1000)

Optionally, you may pass capture as true to catch keyboard events before they're caught and disabled by any other scripts. For example, this is required in Atom:

const atomMeta = require('meta-keys')(null, true)

keys.shift

A [left, right] array of booleans, which are true when the Shift key is pressed.

keys.meta

A [left, right] array of booleans, which are true when the Meta key is pressed (either the Windows key on Windows or Command on OSX).

keys.ctrl

A [left, right] array of booleans, which are true when the Control key is pressed.

keys.alt

A [left, right] array of booleans, which are true when the Alt/Option key is pressed.

keys.dispose()

Removes all attached event listeners and sets all key states to false. To be used for cleaning up after yourself if required.

License

MIT. See LICENSE.md for details.