npm.io
0.4.3 • Published 7 years ago

user-input-keyboard

Licence
MIT
Version
0.4.3
Deps
1
Size
5 kB
Vulns
0
Weekly
0

user-input-keyboard

Keyboard input tracking as 0 or 1.

Useful for applications which require tracking of key states.

Usage

NPM

Example

var keyboard = window.keyboardInput(document)

When the user presses "A", keyboard will contain the following.

{
    "A": 1
}

When the user releases "A", and then presses "F", keyboard will contain the following.

{
    "A": 0,
    "F": 1
}
Intercepting Events

Events can be intercepted using the afterEvent option.

var keyboard = window.keyboardInput(document, {
    afterEvent: (key, event) => {
        // key   === vkey string of key pressed
        // event === original keyboard event
    }
})

Tests

  • Mocha
    • Test functionality in Node.js
    • npm test
  • User Test
    • Test functionality in browser.
    • npm user-test

Keywords