Guest User

Input.js

a guest
Dec 9th, 2016
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function Input()
  2. {
  3.     this.callbacks =
  4.     {
  5.         keyDown:   [],
  6.         keyUp:     [],
  7.         mouseDown: [],
  8.         mouseUp:   []
  9.     }
  10.    
  11.     this.addCallbackOnKeyDown = function(code, cb)
  12.     {
  13.         if (this.callbacks.keyDown[code] === undefined)
  14.             this.callbacks.keyDown[code] = [];
  15.        
  16.         this.callbacks.keyDown[code].push(cb);
  17.     };
  18.    
  19.     this.addCallbackOnKeyUp = function(code, cb)
  20.     {
  21.         if (this.callbacks.keyUp[code] === undefined)
  22.             this.callbacks.keyUp[code] = [];
  23.        
  24.         this.callbacks.keyUp[code].push(cb);
  25.     };
  26.    
  27.     this.addCallbackOnMouseDown = function(code, cb)
  28.     {
  29.         if (this.callbacks.mouseDown[code] === undefined)
  30.             this.callbacks.mouseDown[code] = [];
  31.        
  32.         this.callbacks.mouseDown[code].push(cb);
  33.     };
  34.    
  35.     this.addCallbackOnMouseUp = function(code, cb)
  36.     {
  37.         if (this.callbacks.mouseUp[code] === undefined)
  38.             this.callbacks.mouseUp[code] = [];
  39.        
  40.         this.callbacks.mouseUp[code].push(cb);
  41.     };
  42.    
  43.     this.notifyKeyDown = function(code)
  44.     {
  45.         if (this.callbacks.keyDown[code] !== undefined)
  46.             for (var i = 0; i < this.callbacks.keyDown[code].length; ++ i)
  47.                 this.callbacks.keyDown[code][i]();
  48.     };
  49.    
  50.     this.notifyKeyUp = function(code)
  51.     {
  52.         if (this.callbacks.keyUp[code] !== undefined)
  53.             for (var i = 0; i < this.callbacks.keyUp[code].length; ++ i)
  54.                 this.callbacks.keyUp[code][i]();
  55.     };
  56.    
  57.     this.notifyMouseDown = function(code)
  58.     {
  59.         if (this.callbacks.mouseDown[code] !== undefined)
  60.             for (var i = 0; i < this.callbacks.mouseDown[code].length; ++ i)
  61.                 this.callbacks.mouseDown[code][i]();
  62.     };
  63.    
  64.     this.notifyMouseUp = function(code)
  65.     {
  66.         if (this.callbacks.mouseUp[code] !== undefined)
  67.             for (var i = 0; i < this.callbacks.mouseUp[code].length; ++ i)
  68.                 this.callbacks.mouseUp[code][i]();
  69.     };
  70. }
Add Comment
Please, Sign In to add comment