key-events
v0.1.1
Published
Keyboard listener for browsers, using vkey.
Downloads
55
Readme
key-events
Provides keydown and keyup events using vkey to developers using Node.js to develop for browsers.
Usage
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
- grunt user-test is set to build, serve, and open test/index.html