Top down game. Facing direction problem.

Hi, I’m making a top-down 2d game and I’ve got a problem with player controller. Almost everything is working beside the part when the key is released then player returns to the first position. I don’t know how to store the value of the last key pressed so the player is facing the same direction as the last movement was made. So for example, if the player pressed “D” then it should be aimed in the right direction but instead it gets back to first position. My code so far for this part :

void PlayerInput () 
{ 
inputMovement = new Vector3(Input.GetAxis("Horizontal"),0,Input.GetAxis("Vertical")); tempVector = inputMovement; 
Debug.Log(tempVector);
inputRotation = tempVector ; 
}
void ProcessMovement() 
{ 
tempVector = rigidbody.GetPointVelocity(transform.position) * Time.deltaTime * 1000; rigidbody.AddForce (-tempVector.x, -tempVector.y, -tempVector.z);
rigidbody.AddForce (inputMovement.normalized * moveSpeed * Time.deltaTime); transform.rotation = Quaternion.LookRotation(inputRotation); 
transform.eulerAngles = new Vector3(0,transform.eulerAngles.y + 180,0); transform.position = new Vector3(transform.position.x,0,transform.position.z); 
}

Assuming you are using a charactercontroller, here is an exemplary piece of code:

var rotationToHold:Quaternion;

if(transform.parent.GetComponent(CharacterController).velocity.magnitude>0.0001){ //If the character is moving
//code that changes the character's rotation here
rotationToHold=transform.rotation; //store the last rotation into a variable

}
else{ //and if the character is not moving
transform.rotation=rotationToHold;  //make his rotation always be the last rotation
}