Create a variable which you can change depending on what key you press, this isn't actual code but you get the idea:
if Up is pressed then DIR = "up"
if Left is pressed then DIR = "Left"
...
...
Then, when idle check the DIR variable
if DIR = "up" then idle anim = upidleanim
if DIR = "left" then idle anim = leftidleanim
...
...