KeyboardEvent
Keyboard Event triggered by Crafty Core
Events
- KeyDown
- is triggered for each entity when the DOM 'keydown' event is triggered.
- KeyUp
- is triggered for each entity when the DOM 'keyup' event is triggered.
Example
Crafty.e("2D, DOM, Color")
.attr({x: 100, y: 100, w: 50, h: 50})
.color("red")
.bind('KeyDown', function(e) {
if(e.key == Crafty.keys['LEFT_ARROW']) {
this.x=this.x-1;
} else if (e.key == Crafty.keys['RIGHT_ARROW']) {
this.x=this.x+1;
} else if (e.key == Crafty.keys['UP_ARROW']) {
this.y=this.y-1;
} else if (e.key == Crafty.keys['DOWN_ARROW']) {
this.y=this.y+1;
}
});

@craftyjs
#crafty@freenode.net
google groups
louis@craftyjs.com
github