You can have a variable hold the direction of the player (e.g. 0 means forward, 1 means moving right, 2 means moving backwards, 3 means moving to the left etc.), then have that direction change whenever you press a key (e.g. W for forward would set direction to 0 in this case). The variable that holds the direction doesn't even have to do anything, in fact, you can just have it hold information that will only be useful to you.
It's really up to you to define what counts as "moving forward".