npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

kb-handler

v1.1.0

Published

Simplified keyboard event handler

Readme

Kb-handler

    var KbHandler = require('kb-handler')

Signature

The keyboard handler constructor needs one parameter which will be the event container. Meaning that all events that occur in this context will be catched. This container needs to have the prototype method addEventListener to be working.

Thus all these instanciations are valid:

    var kb = new KbHandler(document.body)
    var kb = new KbHandler(document.createComment('event container'))
    var kb = new KbHandler(window)

Keyboard handler instance

The KbHandler instance exposes a key property which contains all keys supported. This is needed for the on function which registers events on the specified key

    kb.on(kb.key.Enter)/* conditions and actions then */ 
List of supported keys

| Key name | Keypress support | Keydown support | Keyup support | |-------------------|:-----------------:|:-----------------:|:-----------------:| | Escape | × | ✔ | ✔ | | F1 | × | ✔ | ✔ | | F2 | × | ✔ | ✔ | | F3 | × | ✔ | ✔ | | F4 | × | ✔ | ✔ | | F5 | × | ✔ | ✔ | | F6 | × | ✔ | ✔ | | F7 | × | ✔ | ✔ | | F8 | × | ✔ | ✔ | | F9 | × | ✔ | ✔ | | F10 | × | ✔ | ✔ | | F11 | × | ✔ | ✔ | | F12 | × | ✔ | ✔ | | PrintScreen | × | × | ✔ | | Backquote | ✔ | ✔ | ✔ | | Digit0 | ✔ | ✔ | ✔ | | Digit1 | ✔ | ✔ | ✔ | | Digit2 | ✔ | ✔ | ✔ | | Digit3 | ✔ | ✔ | ✔ | | Digit4 | ✔ | ✔ | ✔ | | Digit5 | ✔ | ✔ | ✔ | | Digit6 | ✔ | ✔ | ✔ | | Digit7 | ✔ | ✔ | ✔ | | Digit8 | ✔ | ✔ | ✔ | | Digit9 | ✔ | ✔ | ✔ | | Backspace | × | ✔ | ✔ | | Space | ✔ | ✔ | ✔ | | Enter | ✔ | ✔ | ✔ | | Tab | × | ✔ | × | | CapsLock | × | ✔ | ✔ | | ShiftLeft | × | ✔ | ✔ | | ShiftRight | × | ✔ | ✔ | | ControlLeft | × | ✔ | ✔ | | ControlRight | × | ✔ | ✔ | | MetaLeft | × | ✔ | ✔ | | MetaRight | × | ✔ | ✔ | | AltLeft | × | ✔ | ✔ | | AltRight | × | ✔ | ✔ | | Insert | × | ✔ | ✔ | | Home | × | ✔ | ✔ | | Delete | × | ✔ | ✔ | | End | × | ✔ | ✔ | | PageUp | × | ✔ | ✔ | | PageDown | × | ✔ | ✔ | | ArrowLeft | × | ✔ | ✔ | | ArrowRight | × | ✔ | ✔ | | ArrowUp | × | ✔ | ✔ | | ArrowDown | × | ✔ | ✔ | | NumLock | × | × | ✔ | | NumpadDivide | ✔ | ✔ | ✔ | | NumpadMultiply | ✔ | ✔ | ✔ | | NumpadSubstract | ✔ | ✔ | ✔ | | NumpadAdd | ✔ | ✔ | ✔ | | NumpadEnter | ✔ | ✔ | ✔ | | NumpadDecimal | ✔ | ✔ | ✔ | | Numpad0 | ✔ | ✔ | ✔ | | Numpad1 | ✔ | ✔ | ✔ | | Numpad2 | ✔ | ✔ | ✔ | | Numpad3 | ✔ | ✔ | ✔ | | Numpad4 | ✔ | ✔ | ✔ | | Numpad5 | ✔ | ✔ | ✔ | | Numpad6 | ✔ | ✔ | ✔ | | Numpad7 | ✔ | ✔ | ✔ | | Numpad8 | ✔ | ✔ | ✔ | | Numpad9 | ✔ | ✔ | ✔ | | KeyA | ✔ | ✔ | ✔ | | KeyB | ✔ | ✔ | ✔ | | KeyC | ✔ | ✔ | ✔ | | KeyD | ✔ | ✔ | ✔ | | KeyE | ✔ | ✔ | ✔ | | KeyF | ✔ | ✔ | ✔ | | KeyG | ✔ | ✔ | ✔ | | KeyH | ✔ | ✔ | ✔ | | KeyI | ✔ | ✔ | ✔ | | KeyJ | ✔ | ✔ | ✔ | | KeyK | ✔ | ✔ | ✔ | | KeyL | ✔ | ✔ | ✔ | | KeyM | ✔ | ✔ | ✔ | | KeyN | ✔ | ✔ | ✔ | | KeyO | ✔ | ✔ | ✔ | | KeyP | ✔ | ✔ | ✔ | | KeyQ | ✔ | ✔ | ✔ | | KeyR | ✔ | ✔ | ✔ | | KeyS | ✔ | ✔ | ✔ | | KeyT | ✔ | ✔ | ✔ | | KeyU | ✔ | ✔ | ✔ | | KeyV | ✔ | ✔ | ✔ | | KeyW | ✔ | ✔ | ✔ | | KeyX | ✔ | ✔ | ✔ | | KeyY | ✔ | ✔ | ✔ | | KeyZ | ✔ | ✔ | ✔ | | BracketLeft | ✔ | ✔ | ✔ | | BracketRight | ✔ | ✔ | ✔ | | Quote | ✔ | ✔ | ✔ | | Backslash | ✔ | ✔ | ✔ | | Semicolon | ✔ | ✔ | ✔ | | Comma | ✔ | ✔ | ✔ | | Period | ✔ | ✔ | ✔ | | Slash | ✔ | ✔ | ✔ | | Any | ✔ | ✔ | ✔ |

Event methods

Once you register an event, some methods become available, providing you control about the event.

Example: This event will only trigger when the keyC will be pressed while holding Control key, will prevent the default behavior of the original event, will stop its propagation and will call the function pasteMyContent() before the function clearMyContentCopied().

So this example emulates the true Ctrl+C paste command.

    kb.on(kb.key.keyC).pressed().withCtrl().prevent().stop().do(pasteMyContent).do(clearMyContentCopied)

| Mehod Name | Parameters | Description | |---------------|:-------------:|-------------------------------------------------------------------------------------------| | pressed | No parameters | The event will only trigger if the origin event is a keyPress | | down | No parameters | The event will only trigger if the original event is a keyDown | | up | No parameters | The event will only trigger if the original event is a keyUp | | once | No parameters | The event will only trigger once | | withAlt | No parameters | The event will only trigger if the alt key is down | | withCtrl | No parameters | The event will only trigger if the ctrl key is down | | withShift | No parameters | The event will only trigger if the shift key is down | | withMeta | No parameters | The event will only trigger if the meta key is down | | prevent | No parameters | Prevents the default behavior of the original event | | stop | No parameters | Stops the propagation of the original event | | do | 0: Function | Applies a callback to the event (callbacks are called in order which they are assigned |