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 🙏

© 2024 – Pkg Stats / Ryan Hefner

@quickey/binder

v1.2.1

Published

Subscribe to keyboard key bindings

Downloads

81

Readme

@quickey/binder

Subscribe to keyboard key bindings

Intro

Quickey Binder will help you to craete keyboard key combination subscriptions. Want to know when a user presses Ctrl + H? or maybe you want to create an easteregg for your web app and want to know that a user entered a combination of keys? Quickey Binder is the tool you need.

Install

Quickey Binder can be installed via npm:

$ npm install --save @quickey/binder

Or via yarn:

$ yarn add @quickey/binder

Or using the CDN:

<script src="https://unpkg.com/@quickey/binder@latest/umd/quickey.binder.js"></script>

Or the minified version:

<script src="https://unpkg.com/@quickey/binder@latest/umd/quickey.binder.min.js"></script>

Usage

import { KeyBinder } from "@quickey/binder";

// Or when using the UMD module

const { KeyBinder } = Quickey.binder;

const keyBinder = new KeyBinder();

keyBinder.delegate = {
  didMatchFound: function(binder, matches, target) {
    console.log(binder, matches, target);
  }
}

keyBinder.bind({
  keys: "I > D > D > Q > D"
});

keyBinder.bind({
  keys: "Ctrl + H"
});

keyBinder.bind({
  keys: "J"
});

For your convenience, we created this Fiddle, so you can take Quickey Binder for a quick spin.

API

KeyBinder

KeyBinder([options])

Type: constructor

Creates a new KeyBinder.

options

Type: object - optional

bindings

Type: Array

A list of combinations to bind to. See keyBindingOptions for details.

disabled

Type: boolean

Should the key binder listen or halt key bindings.

target

Type: EventTarget

KeyBinder creates a Keyboard under the hood, this is the keyboard's EventTarget.

All options are optionals

.disable()

Disables the key binder.

.enable()

Enables the key binder.

.bind([keyBindingOptions])

Subscribe to key binding.

keyBindingOptions

Type: object

id

Type: string - optional

You can supply an id to the key binding so you can remove it later if you want to.

keys

Type: string

The combination of keys to bind to.
For Combination binding (hold them together to activate) create a list of keys separated with the + sign. For example:
Ctrl + H, Ctrl + Alt + Delete, Shift + R

For Stream binding (enter one after another to activate) create a list of keys separated with the > sign. For example:
I > D > D > Q > D, Ctrl > Ctrl, H > E > L > L > O

For Single binding (enter one key) supply the key you want to bind to. For example:
J, F, K

See this list for uniqe key options.

alias

Type: Array - optional

You can supply a list of keyBindingOptions to the alias option to create aliases with this binding.

delay

Type: number

The delay between key strokes when using Stream bindings.

strict

Type: boolean

In Combination bindings, strict mode will activate only if the binded keys are the only active keys in the keyboard.
In Stream bindings, each key must be released before the next one is active.
In Single bindings, only one key must to be active.

.unbind([keyBindingId])

Unsubscribe from key binding.

keyBindingId

Type: string

.removeAll()

Unsubscribe all key bindings.

.destroy()

Unsubscribe all key bindings and destroys the Keyboard.

.disabled

Type: boolean

Get the key binder disabled state.

.delegate

Type: object

Attach a delegate to KeyBinder instance.

didMatchFound([binder,matches,target])

This function gets called each time a subscribed key binding is detected.

Type: function

binder

Type: object

The key binder instance in which the detection occurred.

matches

Type: Array

A list of key binding matches.

target

Type: EventTarget

The key binder keyboard target.


← Go back to Quickey