Skip to content
Single handler for browser keyboard events.
JavaScript HTML
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
sandbox
.gitignore
.travis.yml
index.js
license
package-lock.json
package.json
readme.md
test.js

readme.md

keyboard-handler Build Status npm version Coverage Status

Single handler for all browser keyboard events.

Appends a single listener for keyboard events, using the document.addEventListener function. See the API section for available helper functions, when key(s) are pressed and released.

Install

$ npm install --save keyboard-handler

Usage

import * as keyboard from 'keyboard-handler'
keyboard.keyPressed(e => {
  console.log(e.which)
})
// => 27

API

keysAreDown(codes, cb)

Calls cb if all codes are held down.

codes

Type: array

cb

Type: function

keyIsDown(code, cb)

Calls cb when a certain key code is pressed.

code

Type: number

cb

Type: function

keyPressed(cb)

Calls cb when any key is pressed.

cb

Type: function

keyReleased(cb)

Calls cb when any key is released.

cb

Type: function

License

MIT © Emil Johansson

You can’t perform that action at this time.