How to make character move in a direction if a key is held after it's opposite(s)

I’ve got a basic character controller that can move up (backwards), down (forwards), left and right using WASD. However, I think because of the order of my GetKey statements, if I hold S after W or D after A, the character will start moving down while already moving up, or right while already moving left- however, if I hold W after S or A after D, the opposite won’t occur. It’s a little detail but it is annoying me, so I was wondering if there was any way to stop it? Strangely enough, as shown in the video console logs, the code acknowledges that A is being held, it just won’t turn the character and make it move.

For more info, I don’t want the movement to stop if I press two keys, I just want the character to keep moving in the direction of whichever key was pressed last, like what happens when S is pressed after W or D after A. (The other forums I looked at all wanted the character to stop, so people just offered entirely alternate code, hence why I’m asking my own question)

using UnityEngine;
using static UnityEngine.GraphicsBuffer;

public class player : MonoBehaviour
{
    [SerializeField] private float moveSpeed = 4f;
    Quaternion leftAngle = Quaternion.Euler(0, -180, 0);
    Quaternion rightAngle = Quaternion.Euler(0, 0, 0);
    [SerializeField] private bool flipped = false;
    [SerializeField] private float turnSpeed = 12f;

    private void Update() {
        Vector2 inputVector = new Vector2(0, 0);

        if (Input.GetKey(KeyCode.W)) {
            inputVector.y = +1;
            Debug.Log("Pressing W");
        }
        if (Input.GetKey(KeyCode.S)) {
            inputVector.y = -1;
            Debug.Log("Pressing S");
        }
        if (Input.GetKey(KeyCode.A)) {
            inputVector.x = -1;
            Debug.Log("Pressing A");
        }
        if (Input.GetKey(KeyCode.D)) {
            inputVector.x = +1;
            Debug.Log("Pressing D");
        }

        inputVector = inputVector.normalized;

        Vector3 moveDirection = new Vector3(inputVector.x, 0f, inputVector.y);
        transform.position += moveDirection * moveSpeed * Time.deltaTime;

        if (!flipped && inputVector.x < 0) {
            flipped = true;
        }
        if (flipped && inputVector.x > 0) {
            flipped = false;
        }

        if (flipped) transform.rotation = Quaternion.Lerp(transform.rotation, leftAngle, turnSpeed * Time.deltaTime);
        if (!flipped) transform.rotation = Quaternion.Lerp(transform.rotation, rightAngle, turnSpeed * Time.deltaTime);
    }
}

You need to detect when a key is pressed and assign a value to a variable based on which key was pressed during that frame (rather than checking whether the key is being held down).

Next you need an additional check: if one key is released while its opposite key is still being held, assign the variable the value corresponding to the opposite key.

Finally, you need to detect when the keys are released and then reset the variable.

In code, it would look something like this:

// check if any of the keys responible for the Y movement was pressed this frame.
// If you press first W and then while holding the W you press the S the value will be -1
// If you press first S and then while holding the S you press  the W the value will be +1
if (Input.GetKeyDown(KeyCode.W))
     currentY = 1f;
else if (Input.GetKeyDown(KeyCode.S))
     currentY = -1f;

// We check if when we release on of the keys the other is being held
// and we add the appropriate value to the variable
if (Input.GetKeyUp(KeyCode.W) && Input.GetKey(KeyCode.S))
     currentY = -1f;
if (Input.GetKeyUp(KeyCode.S) && Input.GetKey(KeyCode.W))
     currentY = 1f;

// We check if neither key is pressed and we make the variable zero
if (!Input.GetKey(KeyCode.W) && !Input.GetKey(KeyCode.S))
     currentY = 0f;

Then you do the same for the other axis and then you create the input vector:

inputVector = new Vector2(currentX, currentY).normalized;

So instead of checking every frame which key is being pressed, we change the state when a key was pressed the first time and then we check which key was released each frame to update the state of the input vector again.