Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function Input()
- {
- this.callbacks =
- {
- keyDown: [],
- keyUp: [],
- mouseDown: [],
- mouseUp: []
- }
- this.addCallbackOnKeyDown = function(code, cb)
- {
- if (this.callbacks.keyDown[code] === undefined)
- this.callbacks.keyDown[code] = [];
- this.callbacks.keyDown[code].push(cb);
- };
- this.addCallbackOnKeyUp = function(code, cb)
- {
- if (this.callbacks.keyUp[code] === undefined)
- this.callbacks.keyUp[code] = [];
- this.callbacks.keyUp[code].push(cb);
- };
- this.addCallbackOnMouseDown = function(code, cb)
- {
- if (this.callbacks.mouseDown[code] === undefined)
- this.callbacks.mouseDown[code] = [];
- this.callbacks.mouseDown[code].push(cb);
- };
- this.addCallbackOnMouseUp = function(code, cb)
- {
- if (this.callbacks.mouseUp[code] === undefined)
- this.callbacks.mouseUp[code] = [];
- this.callbacks.mouseUp[code].push(cb);
- };
- this.notifyKeyDown = function(code)
- {
- if (this.callbacks.keyDown[code] !== undefined)
- for (var i = 0; i < this.callbacks.keyDown[code].length; ++ i)
- this.callbacks.keyDown[code][i]();
- };
- this.notifyKeyUp = function(code)
- {
- if (this.callbacks.keyUp[code] !== undefined)
- for (var i = 0; i < this.callbacks.keyUp[code].length; ++ i)
- this.callbacks.keyUp[code][i]();
- };
- this.notifyMouseDown = function(code)
- {
- if (this.callbacks.mouseDown[code] !== undefined)
- for (var i = 0; i < this.callbacks.mouseDown[code].length; ++ i)
- this.callbacks.mouseDown[code][i]();
- };
- this.notifyMouseUp = function(code)
- {
- if (this.callbacks.mouseUp[code] !== undefined)
- for (var i = 0; i < this.callbacks.mouseUp[code].length; ++ i)
- this.callbacks.mouseUp[code][i]();
- };
- }
Add Comment
Please, Sign In to add comment