Controlling an animated character?

I have a character with an animation that I control with the arrow keys on a keyboard. But even when I am not pressing the arrow keys, the players animation keeps playing on the spot. How can I fix that?

when pushing button animate character.
else - don’t animate character.

Convert this to code and it should work like you want it to.