diff --git a/Three.js/js/KeyboardState.js b/Three.js/js/KeyboardState.js index 673af8f..cc3506d 100644 --- a/Three.js/js/KeyboardState.js +++ b/Three.js/js/KeyboardState.js @@ -10,6 +10,8 @@ * keyboard.down("A") -- true for one update cycle after key is pressed * keyboard.pressed("A") -- true as long as key is being pressed * keyboard.up("A") -- true for one update cycle after key is released + * (4) cleanup keyboard event listeners when you no longer need them + * keyboard.destroy(); * * See KeyboardState.k object data below for names of keys whose state can be polled */ @@ -22,6 +24,14 @@ KeyboardState = function() document.addEventListener("keyup", KeyboardState.onKeyUp, false); } +// cleanup - stop listening to key events +KeyboardState.prototype.destroy = function() +{ + // unbind keyEvents + document.removeEventListener("keydown", KeyboardState.onKeyDown, false); + document.removeEventListener("keyup", KeyboardState.onKeyUp, false); +} + /////////////////////////////////////////////////////////////////////////////// KeyboardState.k = @@ -109,4 +119,4 @@ KeyboardState.prototype.debug = function() console.log(list); } -/////////////////////////////////////////////////////////////////////////////// \ No newline at end of file +///////////////////////////////////////////////////////////////////////////////