Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

add-keyup-events

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

add-keyup-events

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".

  • 0.0.2
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
5
increased by150%
Maintainers
1
Weekly downloads
 
Created
Source

add-keyup-events

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'}.

installing

npm install add-keyup-events

using

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


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

// pass it our input
addKeyupEvents(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);

credits

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

license

MIT

Keywords

FAQs

Package last updated on 19 Mar 2014

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc