is there a way to cancel an input with another input

for example if i press A to move left but then press D to go right as im still pressing A the new input will take priority.

A idea. Maybe it helps.

private string[] keys = new string[] {"A", "D"};
private Queue keyQueue;

void Awake() {
        keyQueue = new Queue();
    }

  void Update() {
        foreach (string key in keys) {
            if (Input.GetKeyDown(key)) {
                keyQueue.Enqueue(key);
            }
        }

// parse the input here, reading the queue
    }