Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion Three.js/js/KeyboardState.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand All @@ -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 =
Expand Down Expand Up @@ -109,4 +119,4 @@ KeyboardState.prototype.debug = function()
console.log(list);
}

///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////