Skip to content
master
Switch branches/tags
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

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

About

Single handler for browser keyboard events.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published