Character's direction animation

Hello,
I was wondering if there’s a way to know if the character is moving left, right, left+forward or right+forward. I would need to get the rotation in order to rotate the character’s legs. If the player is pressing left (A) the animation should rotate the legs left, right (D) it should rotate them to right 90° angle, forward+right (W+D) will rotate the legs 45° angle.
Thank you in advance for your help.