It's not that hard. I think. On top of my head:
Lets say your character moves with wasd keys. First you could setup a series of condition that detect these input.
Have the player object have lastx and last y instance variables.
Add a global variable named totaldistance.
Then, under every (direction input) condition call
totaldistance = totaldistance + distance(player.lastx, player.lasty,player.x,player.Y)
player.lastx = player.x
player.lasty = player.y
this means, every time you press w, a, s, d, system will check the distance of lastx, lasty position, add to totaldistance, and set new lastx and lasty positions. I hope I could explain it.