context: //-----------------------------------------------------------------------------
  // Torque Game Engine
  // Copyright (C) GarageGames.com, Inc.
  //-----------------------------------------------------------------------------
  
  if ( isObject( moveMap ) )
     moveMap.delete();
  new ActionMap(moveMap);
  
  
  //------------------------------------------------------------------------------
  // Non-remapable binds
  //------------------------------------------------------------------------------
  
  function escapeFromGame()
  {
     if ( $Server::ServerType $= "SinglePlayer" )
        MessageBoxYesNoOld( "Quit Mission", "Exit from this Mission?", "disconnect();", "");
     else
        MessageBoxYesNoOld( "Disconnect", "Disconnect from the server?", "disconnect();", "");
  }
  
  //moveMap.bindCmd(keyboard, "escape", "", "escapeFromGame();");
  
  function showPlayerList(%val)
  {
     if (%val)
        PlayerListGui.toggle();
  }
  
  moveMap.bind( keyboard, F2, showPlayerList );
  moveMap.bind( keyboard, F5, toggleParticleEditor);
  
  
  //------------------------------------------------------------------------------
  // Movement Keys
  //------------------------------------------------------------------------------
  
  $movementSpeed = 1; // m/s
  
  function setSpeed(%speed)
  {
     if(%speed)
        $movementSpeed = %speed;
  }
  
  function moveleft(%val)
  {
     $mvLeftAction = %val * $movementSpeed;
  }
  
  function moveright(%val)
  {
     $mvRightAction = %val * $movementSpeed;
  }
  
  function moveforward(%val)
  {
     $mvForwardAction = %val * $movementSpeed;
  }
  
  function movebackward(%val)
  {
     $mvBackwardAction = %val * $movementSpeed;
  }
  
  function moveup(%val)
  {
     $mvUpAction = %val * $movementSpeed;
  }
  
  function movedown(%val)
  {
     $mvDownAction = %val * $movementSpeed;
  }
  
  function turnLeft( %val )
  {
     $mvYawRightSpeed = %val ? $Pref::Input::KeyboardTurnSpeed : 0;
  }
  
  function turnRight( %val )
  {
     $mvYawLeftSpeed = %val ? $Pref::Input::KeyboardTurnSpeed : 0;
  }
  
  function panUp( %val )
  {
     $mvPitchDownSpeed = %val ? $Pref::Input::KeyboardTurnSpeed : 0;
  }
  
  function panDown( %val )
  {
     $mvPitchUpSpeed = %val ? $Pref::Input::KeyboardTurnSpeed : 0;
  }
  
  function getMouseAdjustAmount(%val)
  {
     // based on a default camera fov of 90'
     return(%val * ($cameraFov / 90) * 0.01) * $pref::Input::LinkMouseSensitivity;
  }
  
  function yaw(%val)
  {
     $mvYaw += getMouseAdjustAmount(%val);
  }
  
  function pitch(%val)
  {
     $mvPitch += getMouseAdjustAmount(%val);
  }
  
  function jump(%val)
  {
     $mvTriggerCount2++;
  }
  
  function gamePadMoveX( %val )
  {
     $mvXAxis_L = %val;
  }
  
  function gamePadMoveY( %val )
  {
     $mvYAxis_L = %val;
  }
  
  function gamepadYaw(%val)
  {
     if( $pref::invertXCamera )
        %val *= -1.0;
        
     // if we get a non zero val, the user must have moved the stick, so switch 
     // out of keyboard/mouse mode
     if (%val != 0.0)
        $mvDeviceIsKeyboardMouse = false;
        
     // stick events come in even when the user isn't using the gamepad, so make 
     // sure we don't slam the move if we don't think the user is using the gamepad
     if (!$mvDeviceIsKeyboardMouse)
     {
        %scale = (ServerConnection.gameState $= "wait") ? -0.1 : 3.14;
        $mvYawRightSpeed = -(-0.1 * %val);
     }
  }
  
  function gamepadPitch(%val)
  {
     if( $pref::invertYCamera )
        %val *= -1.0;
  
     // if we get a non zero val, the user must have moved the stick, so switch 
     // out of keyboard/mouse mode
     if (%val != 0.0)
        $mvDeviceIsKeyboardMouse = false;
  
     // stick events come in even when the user isn't using the gamepad, so make 
     // sure we don't slam the move if we don't think the user is using the gamepad
     if (!$mvDeviceIsKeyboardMouse)
     {
        %scale = (ServerConnection.gameState $= "wait") ? -0.05 : 3.14;
        $mvPitchUpSpeed = -0.05 * %val;
     }
  }
  
  moveMap.bind( keyboard, a, moveleft );
  moveMap.bind( keyboard, d, moveright );
  moveMap.bind( keyboard, left, moveleft );
  moveMap.bind( keyboard, right, moveright );
  
  moveMap.bind( keyboard, w, moveforward );
  moveMap.bind( keyboard, s, movebackward );
  moveMap.bind( keyboard, up, moveforward );
  moveMap.bind( keyboard, down, movebackward );
  
  moveMap.bind( keyboard, space, jump );
  moveMap.bind( mouse, xaxis, yaw );
  moveMap.bind( mouse, yaxis, pitch );
  
  moveMap.bind( gamepad, rxaxis, "D", "-0.23 0.23", gamepadYaw );
  moveMap.bind( gamepad, ryaxis, "D", "-0.23 0.23", gamepadPitch );
  moveMap.bind( gamepad, xaxis, "D", "-0.23 0.23", gamePadMoveX );
  moveMap.bind( gamepad, yaxis, "D", "-0.23 0.23", gamePadMoveY );
  
  moveMap.bind( gamepad, btn_a, jump );
  moveMap.bindCmd( gamepad, btn_x, "disconnect();", "" );
  
  
  //------------------------------------------------------------------------------
  // Mouse Trigger
  //------------------------------------------------------------------------------
  
  function mouseFire(%val)
  {
     $mvTriggerCount0++;
  }
  
  function altTrigger(%val)
  {
     $mvTriggerCount1++;
  }
  
  moveMap.bind( mouse, button0, mouseFire );
  moveMap.bind( mouse, button1, altTrigger );
  
  
  //------------------------------------------------------------------------------
  // Zoom and FOV functions
  //------------------------------------------------------------------------------
  
  if($Pref::player::CurrentFOV $= "")
     $Pref::player::CurrentFOV = 45;
  
  function setZoomFOV(%val)
  {
     if(%val)
        toggleZoomFOV();
  }
        
  function toggleZoom( %val )
  {
     if ( %val )
     {
        $ZoomOn = true;
        setFov( $Pref::player::CurrentFOV );
     }
     else
     {
        $ZoomOn = false;
        setFov( $Pref::player::DefaultFov );
     }
  }
  
  moveMap.bind(keyboard, r, setZoomFOV);
  moveMap.bind(keyboard, e, toggleZoom);
  
  
  //------------------------------------------------------------------------------
  // Camera & View functions
  //------------------------------------------------------------------------------
  
  function toggleFreeLook( %val )
  {
     if ( %val )
        $mvFreeLook = true;
     else
        $mvFreeLook = false;
  }
  
  function toggleFirstPerson(%val)
  {
     if (%val)
     {
        ServerConnection.setFirstPerson(!ServerConnection.isFirstPerson());
     }
  }
  
  function toggleCamera(%val)
  {
     if (%val)
        commandToServer('ToggleCamera');
  }
  
  moveMap.bind( keyboard, z, toggleFreeLook );
  moveMap.bind(keyboard, tab, toggleFirstPerson );
  
gt: moveMap.bind(keyboard, "alt c", toggleCamera);