/keyBoard

An additional class for manage the key events in javascript

Primary LanguageJavaScriptMIT LicenseMIT

keyBoard

An additional class for manage the key events in javascript

Fast example:

var keyboard = new keyBoard(/*undefined*/); /* Automatically binds to the document. */
console.log(keyboard); /* return with the keyboard object */
keyboard.addEvent(keyboard.events.KeyDown,function(){
	console.log(arguments); /* see the arguments */
});
console.log(keyboard.getLast()); /* get the last action with other stuff */

Methods & others

  1. events
Info
KeyDownWhen a key is down.
KeyUPWhen a key is up.
KeyPressWhen a key is press.
  1. methods
Info
addEvent(eventid,callback) : intBind an event to an action.
removeEvent(eventid,int) : voidunBind an event.
getLast() : {...data...}Returns with the last event with some extra data.

Examples

/* returns int like this
12445765678 it's a uniqe int for indetify the events
*/
console.log(keyboard.addEvent(keyboard.events.KeyDown,function(){});
/* remove the event with id */
console.log(keyboard.removeEvent(keyboard.events.KeyDown,12445765678));
/* returns an object like this:
{
  alt:false,
  ctrl:false,
  event:undefined,
  key:undefined,
  keyCode:undefined,
  lastEvent: undefined,
  shift: false,
}
*/
console.log(keyboard.getLast());
/* OR an other returns
{
  alt:false,
  ctrl:false,
  event:"KeyUp",
  key:"�",
  keyCode:16,
  lastEvent:keyup charCode=0, keyCode=16,
  shift:true
}
*/