0.1.9 • Published 10 years ago

sc-keycodes v0.1.9

Weekly downloads
3
License
MIT
Repository
github
Last release
10 years ago

sc-keycodes

A simple package to make working with browser key events a little more convenient.

API

dispatch(evt, callbackTable)

A convenience API for mapping key combinations to callback functions. Takes an event object and a table of key combinations to callback functions.

const keycodes = require('sc-keycodes');

const MyReactComponent = React.createClass({
    render : function() {
        ...
    },
    _handleKeyPress: function (evt) {
        keycodes.dispatch(evt, {
            "SHIFT+UP":         this._moveUp(),
            "SHIFT+DOWN":       this._moveDown(),
            "CTRL+S":           this._saveData(),
            "TAB, SHIFT+RIGHT": this._indent(),
        });
    }
});

KeyCodes

A map of keys by string name to keyCode numeric values.

var keycodes = require('sc-keycodes');

$('#my_div').on('keydown', function (evt) {
    if (evt.keyCode === keycodes.KeyCodes["ENTER"]) {
        doSomething();
    }
});

This is just a simple associative array so key combinations are not supported.

0.1.9

10 years ago

0.1.8

10 years ago

0.1.7

10 years ago

0.1.6

10 years ago

0.1.4

10 years ago

0.1.3

10 years ago

0.1.2

10 years ago