# Make the last key pressed dominant

Making a snake addon (Minigame through HUD), right now movement goes like this:
[lua]local up, down, left, right = input.IsKeyDown(KEY_UP), input.IsKeyDown(KEY_DOWN), input.IsKeyDown(KEY_LEFT), input.IsKeyDown(KEY_RIGHT)

``````if (up and snake.diry ~= 1 ) then
snake.diry = -1
snake.dirx = 0
elseif ( down and snake.diry ~= -1 ) then
snake.diry = 1
snake.dirx = 0
elseif (left and snake.dirx ~= 1 ) then
snake.diry = 0
snake.dirx = -1
elseif ( right and snake.dirx ~= -1 ) then
snake.diry = 0
snake.dirx = 1
end[/lua]
``````

Afterwards the draw function moves the drawx/drawy position in the diry/dirx value.

The way this goes is if you’re going right or left, and you then (Still holding Left/Right arrow key), go up/down, your snake changes its movement. If you then let go of up/down, it keeps going in the original direction it went before (Left/Right). This way, up/down are the “dominant” keys, meaning the same thing won’t happen if you replace the direction I’m moving at, and the direction I want to move at (i.e. going up/down and hold left/right).
Sorry for poor explanation, I’ll see if I can make a representation of this

How would I go on making the last key the “dominant” key, regardless of up/down/left/right?

You can use KeyPressed instead of KeyDown, that way it will only have effect for one frame. However, that way you’ll lose the behavior where if you kept holding the first key when you let go of the second key it will go back in the first direction.