Camera scrolls all the way in a direction when pressing WASD keys

I have a strange bug: During gameplay, sometimes while pressing the WASD keys, the camera will ‘‘lock’’ in a direction for a few seconds until i use the mouse and it ‘‘resets’’ to normal. Does somebody knows of to fix this?