src/hft/scripts/misc/input.js
function(keyDownFn, keyUpFn) {
    var g_keyState = {};
    var g_oldKeyState = {};

    var updateKey = function(keyCode, state) {
      g_keyState[keyCode] = state;
      if (g_oldKeyState !== g_keyState) {
        g_oldKeyState = state;
        if (state) {
          keyDownFn(keyCode);
        } else {
          keyUpFn(keyCode);
        }
      }
    };

    var keyUp = function(event) {
      updateKey(event.keyCode, false);
    };

    var keyDown = function(event) {
      updateKey(event.keyCode, true);
    };

    window.addEventListener("keyup", keyUp, false);
    window.addEventListener("keydown", keyDown, false);
  }
function(keyDownFn, keyUpFn) {
    var g_keyState = {};
    var g_oldKeyState = {};

    var updateKey = function(keyCode, state) {
      g_keyState[keyCode] = state;
      if (g_oldKeyState !== g_keyState) {
        g_oldKeyState = state;
        if (state) {
          keyDownFn(keyCode);
        } else {
          keyUpFn(keyCode);
        }
      }
    };

    var keyUp = function(event) {
      updateKey(event.keyCode, false);
    };

    var keyDown = function(event) {
      updateKey(event.keyCode, true);
    };

    window.addEventListener("keyup", keyUp, false);
    window.addEventListener("keydown", keyDown, false);
  }
function ( keyDownFn , keyUpFn ) { var g_keyState = { } ; var g_oldKeyState = { } ; var updateKey = function ( keyCode , state ) { g_keyState [ keyCode ] = state ; if ( g_oldKeyState !== g_keyState ) { g_oldKeyState = state ; if ( state ) { keyDownFn ( keyCode ) ; } else { keyUpFn ( keyCode ) ; } } } ; var keyUp = function ( event ) { updateKey ( event . keyCode , false ) ; } ; var keyDown = function ( event ) { updateKey ( event . keyCode , true ) ; } ; window . addEventListener ( "keyup" , keyUp , false ) ; window . addEventListener ( "keydown" , keyDown , false ) ; }
Sets up controller key functions
@param {callback(code, down)} keyDownFn a function to be
called when a key is pressed. It's passed the keycode
and true.
@param {callback(code, down)} keyUpFn a function to be called
when a key is released. It's passed the keycode and
false.
@memberOf module:Input
Sets up controller key functions