3.0.7 • Published 3 years ago

keyboard-handler v3.0.7

Weekly downloads
3
License
MIT
Repository
github
Last release
3 years ago

keyboard-handler npm version

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

or

$ pnpm add keyboard-handler

Usage

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

API

keysAreDown(keys, cb)

Calls cb if all keys are held down.

keys

Type: array

cb

Type: function

keyIsDown(key, cb)

Calls cb when a certain key key is pressed.

key

Type: string

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

3.0.4

3 years ago

3.0.3

3 years ago

3.0.2

3 years ago

3.0.1

3 years ago

3.0.7

3 years ago

3.0.6

3 years ago

3.0.5

3 years ago

3.0.0

3 years ago

3.0.0-next.0

3 years ago

2.0.0

7 years ago

1.1.3

7 years ago

1.1.2

8 years ago

1.1.1

9 years ago

1.1.0

9 years ago

1.0.0

9 years ago

0.0.1

9 years ago