key-events

0.1.1 • Public • Published

key-events

Provides keydown and keyup events using vkey to developers using Node.js to develop for browsers.

Usage

NPM

listener = keyevents([target], [events])

Examples

Basic Usage

const keyevents = require('key-events') // Also at window.keyevents.

// Default target is:  document.body
// Default events are: ['keyup', 'keydown']
var keys = keyevents() 

keys.on("keydown", function(key, event) {
    console.log(key)   // A vkey value based on the key pressed.
    console.log(event) // The original event received.
})    

keys.on("keyup", function(key, event) {
    console.log(key)   // A vkey value based on the key pressed.
    console.log(event) // The original event received.
})

Custom Target

var keys = window.keyevents(document) // Default target is `document.body`

Custom Event List

var keys = window.keyevents(['keypress']) // Default target is `document.body`

keys.on("keypress", function(key, event) {
    console.log(key)   // A vkey value based on the key pressed.
    console.log(event) // The original event received.
})

Custom Target & Event List

var keys = window.keyevents(document, ['keypress']) // Default target is `document.body`

keys.on("keypress", function(key, event) {
    console.log(key)   // A vkey value based on the key pressed.
    console.log(event) // The original event received.
})

Tests

  • Mocha
    • Test functionality in Node.js
  • Karma
    • Using browserify, test functionality in browsers
  • User Testing

Readme

Keywords

Package Sidebar

Install

npm i key-events

Weekly Downloads

12

Version

0.1.1

License

MIT

Unpacked Size

4.65 kB

Total Files

4

Last publish

Collaborators

  • apexearth