Emit custom events from an input so you can do stuff like listening for "enter" and "esc" events the same way as you would "keyup".
Last updated 7 years ago by henrikjoreteg .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install add-keyup-events 
SYNC missed versions from official npm registry.


Takes an element, usually an <input> or <textarea> and registers a keyup handler on it that emits named events for special keys. It does enter and esc events by default.

You can override the events by passing an optional second argument that follows the format: {keyvalue: 'customEventName'}.


npm install add-keyup-events


var addKeyupEvents = require('add-keyup-events');

// some input
var input = document.create('input');

// pass it our input

// Now we can listen for "enter" and "esc" events using the
// normal `addEventListener` the browser gives us.
input.addEventListener('enter', doSomething, false);

You can also override the events to listen for whatever you want.

// some input
var input = document.create('input');

// create a custom hash of keycode to event name mappings:
var customEvents = {
    65: 'a',
    12: 'enter'

// pass it our input, and our custom events
addKeyupEvents(input, customEvents);

// now we can listen for 'a' events and 'enter' events
input.addEventListener('a', doSomething, false);


If you like this, follow @HenrikJoreteg on twitter and check out my book: Human JavaScript.



Current Tags

  • 0.0.2                                ...           latest (7 years ago)

2 Versions

  • 0.0.2                                ...           7 years ago
  • 0.0.1                                ...           7 years ago
Maintainers (1)
Today 0
This Week 0
This Month 1
Last Day 0
Last Week 1
Last Month 1
Dependencies (0)
Dev Dependencies (0)
Dependents (0)

Copyright 2014 - 2016 © |