# Issue With Lists and Keycodes

I’m trying to queue up pressed buttons in a list, for example if you press W, A, D they should be in the list. I got this working but that is not the issue.

``````    List<KeyCode> queuedMovement = new List<KeyCode>(4);

void Update()
{
if (Input.GetKeyDown(KeyCode.W))
{
}
if (Input.GetKeyDown(KeyCode.D))
{
}
if (Input.GetKeyDown(KeyCode.S))
{
}
if (Input.GetKeyDown(KeyCode.A))
{
}
}
``````

As you can see this queues up to 4 keys. The game is a simple 2D game and when you press for example “S” you add a downward force to the Player and you can’t move until the player has hit something. Instead of checking if the Player has hit something I check the velocity of the Player.

``````            if (rb.velocity.x == 0 && rb.velocity.y == 0 && queuedMovement.Count != 0)
``````

After that I add the force to the corresponding button pressed and remove the pressed key from the list.

``````            if (rb.velocity.x == 0 && rb.velocity.y == 0 && queuedMovement.Count != 0)
{
switch (queuedMovement[0])
{
case KeyCode.W:
break;
case KeyCode.D:
break;
case KeyCode.S:
break;
case KeyCode.A:
break;
}
queuedMovement.RemoveAt(0);
}
``````

This all works perfectly but sometimes the player moves diagonal, meaning that 2 forces get added together and it results in that. I’ve tried to find a work-around this for couple of hours and I can’t. I know this sounds very vague but if you need more details about anything I will provide it.
Thanks.

Let me just point out that the value you pass to the constructor of a `List<T>` is only the initial capacity; it can and will go beyond it if you try to add more values to a list that is at full capacity.

``````capacity
Type: System.Int32
The number of elements that the new list can initially store.
``````

Code wise — I see nothing wrong. Perhaps the only concerning part is `x == 0 && y == 0`. You could instead try RigidBody.IsSleeping.