-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInputHandler.js
More file actions
32 lines (25 loc) · 920 Bytes
/
InputHandler.js
File metadata and controls
32 lines (25 loc) · 920 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
var InputHandler = function() {
this.controllers = [];
}
InputHandler.prototype.keyDown = function(event) {
this.handleInput({type:'keydown','event':event});
}
InputHandler.prototype.keyUp = function(event) {
this.handleInput({type:'keyup','event':event});
}
InputHandler.prototype.mouseDown = function(event) {
this.handleInput({type:'mousedown','event':event});
}
InputHandler.prototype.mouseUp = function(event) {
this.handleInput({type:'mouseup','event':event});
}
InputHandler.prototype.mouseMove = function(event) {
this.handleInput({type:'mousemove','event':event});
}
InputHandler.prototype.handleInput = function(args) {
if(args.type === undefined || args.event === undefined) return;
for(var i=0; i<this.controllers.length; i++) this.controllers[i].handleEvent(args);
}
InputHandler.prototype.registerController = function(controller) {
this.controllers[this.controllers.length] = controller;
}