Skip to content

Instantly share code, notes, and snippets.

@HendrikRoth
Forked from barneycarroll/onkey.js
Last active August 29, 2015 14:20
Show Gist options
  • Save HendrikRoth/e22d89f06f4eee2a240c to your computer and use it in GitHub Desktop.
Save HendrikRoth/e22d89f06f4eee2a240c to your computer and use it in GitHub Desktop.
var onKey = (function(){
var keymap = {
'enter' : 13,
'space' : 31,
'tab' : 9,
'esc' : 27,
'left' : 37,
'up' : 38,
'right' : 39,
'down' : 40
};
return function bind( key, callback ){
if( key in keymap ){
key = keymap[ key ];
}
return function handler( e ){
if( e && key === e.keyCode || key === String.fromCharCode( e.keyCode ) ){
callback.call( this, e );
}
else {
m.redraw.strategy( 'none' );
}
};
};
}());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment