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

hackedvoxels-kb-bindings

v0.0.1

Published

present a polling interface and events for keyboard state given a binding object

Downloads

16

Readme

kb-bindings

TODO: UPDATE PACKAGE and links TODO: Look into vkey

kb-bindings is now deprecated in favor of the following modules:

original readme below:

Expose a polling object and edge-triggered events for (game) keybindings using vkey definitions. Can be configured in a GUI using the kb-bindings-ui module.

Based on @chrisdickinson's kb-controls (should be mostly compatible)

var kb = require('./index')
  , raf = require('raf')

var ctl = kb({
  '<left>': 'strafe_left'
, '<right>': 'strafe_right'
, '<up>': 'forward'
, '<down>': 'backward'
, 'W': 'forward'
, 'A': 'strafe_left'
, 'S': 'backward'
, 'D': 'strafe_right'
, '<mouse 1>': 'fire'
, 'E': 'inventory'
})

raf(document.body).on('data', function(dt) {
  console.log(!!ctl.forward)
})

See the demo at http://deathcap.github.io/kb-bindings-ui/

Why both polling and events?

This module provides both a polling object and up/down events for each binding, so you can use which ever is most convenient for your application (level-triggered or edge-triggered), all with a unified shared set of bindings.

API

kb = require('kb-bindings')

return the kb function.

ctl = kb([DOMElement,] bindings[, augmentObject, opts])

Add event listeners to DOMElement or document.body if not provided.

Bindings is a map of vkey's to desired property names:

// bindings example
{ 'X': 'do_something'
, '<space>': 'jump'
, '<control>': 'sprint' }

// would yield the following ctl object (sans methods):
{ 'do_something': 0
, 'jump': 0
, 'sprint': 0 }

If augmentObject is passed, these property names will be attached to it instead of a new object.

If opts is passed, the following options are understood:

  • preventDefaults: if true (default), the default browser action for the DOM events will be prevented

ctl[yourPropertyName] -> Number

If the number is truthy, that means it's actively being pressed. Otherwise it's not. If it's greater than 1, then two different keys may have been bound to the action and are simultaneously being pressed.

ctl.enable()

Enables the keyup, keydown, mouseup, mousedown, and contextmenu listeners (and makes them preventDefault() if preventDefaults is set.)

ctl.enabled() -> boolean

Returns whether or not the ctl is enabled.

ctl.disable()

Disables the DOM listeners (without removing them). Keyboard and mouse events should work as normal while the ctl is disabled.

ctl.destroy()

Removes all DOM event listeners and renders the ctl inert.

ctl.down.on(binding, function(){})

Emits when the binding state changes to down. Note this event is only emitted when the state changes (unlike the DOM keydown event it does not continuously emit as the key is held down).

The event name is the binding name, for example:

ctl.down.on('inventory', function() { ... });

ctl.up.on(binding, function(){})

Emits when the binding state changes to up.

License

MIT