Why does my character walk forward automatically?
I'm sure that I'm not alone. Sometimes when I go somewhere or build something, all of a sudden, the character keeps going forward just like the W is stuck. But it's not.
To recover from this I have to bash my ASWD keys on the keyboard (gently :P) and it's ok. What's causing this and how can I fix it?
This is a bug. It usually happens when I'm moving and clicking at the same time.
It has been reported on GetSatisfaction, and there is a known workaround: update lwjgl
library that is downloaded together with Minecraft.
This bug has been around for a lot of time, and it would be great if Mojang actually fixed it...
One cause of this is when you press two keys at almost the same time, one of which is a movement key and the other opens a GUI. A well-known "poor-man's autorun" in Minecraft is to press the "walk forward" and "inventory" keys at the same time. You will begin walking — with the inventory screen open — and will continue walking after closing your inventory again, even though no key is held down.
Other input "collisions" may cause this as well, but as badp points out, the only real after-the-fact solution is to press the "stuck" key again. There is no way to prevent this kind of key-sticking, either, other than avoiding the simultaneous inputs which cause it.
This probably means that Minecraft, for whatever reason, lost the "key W was released (thus the user wants to stop moving forwards)" event, and as a result you're still going forwards.
Try pressing W again.