Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/hughsk/meta-keys
Get the state of any pressed meta keys, differentiating between their left/right location on the keyboard
https://github.com/hughsk/meta-keys
Last synced: 8 days ago
JSON representation
Get the state of any pressed meta keys, differentiating between their left/right location on the keyboard
- Host: GitHub
- URL: https://github.com/hughsk/meta-keys
- Owner: hughsk
- License: other
- Created: 2015-08-15T21:02:18.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2015-09-01T18:17:24.000Z (about 9 years ago)
- Last Synced: 2024-10-17T16:41:14.789Z (22 days ago)
- Language: JavaScript
- Size: 125 KB
- Stars: 2
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# meta-keys
![](http://img.shields.io/badge/stability-stable-orange.svg?style=flat)
![](http://img.shields.io/npm/v/meta-keys.svg?style=flat)
![](http://img.shields.io/npm/dm/meta-keys.svg?style=flat)
![](http://img.shields.io/npm/l/meta-keys.svg?style=flat)Get the state of any pressed meta keys, differentiating between their left/right location on the keyboard.
## Usage
[![NPM](https://nodei.co/npm/meta-keys.png)](https://nodei.co/npm/meta-keys/)
### `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.
``` javascript
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](http://atom.io/):``` javascript
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](http://github.com/hughsk/meta-keys/blob/master/LICENSE.md) for details.