An additional class for manage the key events in javascript
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 */
- events
| Info |
KeyDown | When a key is down. |
KeyUP | When a key is up. |
KeyPress | When a key is press. |
- methods
| Info |
addEvent(eventid,callback) : int | Bind an event to an action. |
removeEvent(eventid,int) : void | unBind an event. |
getLast() : {...data...} | Returns with the last event with some extra data. |
/* 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
}
*/