@132ikl's answer works in general, but there is a flaw to the design: stat.walkOneCm
does not increase while you are in mid-air. We can fix this by assuming every player that is in mid-air is moving.
Create the scoreboard:
/scoreboard objectives add Moving stat.walkOneCm
Create a 20Hz clock or use repeat/chain command blocks and run the following two commands:
/scoreboard players remove @a[score_Moving_min=1] Moving 1 {OnGround:1b}
/scoreboard players set @a[score_Moving_min=1] Moving 1
The first command will reduce the Moving
score by one for every player on the ground, if it is at least 1 (I.e. the score will not go below 0).
The second command limits the Moving
score to at most 1 by setting it to one if it is greater.
Moving
will be 1 for people that are moving, or were moving prior to jumping (jumping in place does not work), and 0 otherwise.