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.