Skip to content

Instantly share code, notes, and snippets.

@bebraw
Created October 11, 2010 11:18
Show Gist options
  • Save bebraw/620380 to your computer and use it in GitHub Desktop.
Save bebraw/620380 to your computer and use it in GitHub Desktop.
var Keyboard = new Class({
initialize: function() {
var scope = this;
this._keys = {};
var handler = function(e, flag) {
scope._keys[String.fromCharCode(e.which)] = flag;
}
$(document).on('keypress', handler, true).on('keyup', handler, false);
},
isPressed: function(key) {
if (key in this._keys) {
return this._keys[key];
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment