present a polling interface for keyboard state given a binding object
expose a polling object for (game) keybindings using vkey definitions.
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'rafdocumentbodyon'data'console.log!!ctlforward
Events are great! I love them. But when you're writing game logic, oftentimes you want the frame event to drive the simulation -- and dealing with the keyboard as a separate evented interface can be troublesome in this regard.
Add event listeners to
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
augmentObject is passed, these property names will be attached to it instead
of a new object.
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.
Enables the keyup, keydown, mouseup, and mousedown listeners (and makes them
Returns whether or not the
ctl is enabled.
Disables the DOM listeners (without removing them). Keyboard and mouse events should work
as normal while the
ctl is disabled.
Removes all DOM event listeners and renders the