Skip to content

Instantly share code, notes, and snippets.

@kaievns
Forked from bebraw/keyboard.js
Created October 11, 2010 11:35
Show Gist options
  • Save kaievns/620392 to your computer and use it in GitHub Desktop.
Save kaievns/620392 to your computer and use it in GitHub Desktop.
var Keyboard = new Class({
prebind: 'handler',
initialize: function() {
$(document).on({
keypress: this.handler,
keyup: this.handler
});
},
handler: function(event, flag) {
(this._keys || (this._keys = {}))[
String.fromCharCode(event.keyCode)
] = event.type === 'keypress';
},
isPressed: function(key) {
return this._keys[key];
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment