Fixing 2D sprite moving direction

I currently have the set up below so I can move the sprite up/down or left/right by pressing WSAD keys .However ,when I pressed the W key and the D key together, it moved front right.Similar situation happened when I tried to press 2 keys together.
Is there any way to control the direction so the sprite can actually only move up /down and left/right?