Set 5 variables, oldx, newx, oldy, newy and mouse_direction.
Every tick set oldx to newx, and set newx to mouse.x. Do the same for the y values.
Compare 2 values, newx > than oldx set mouse_direction to "right".
newx < than oldx set mouse_direction to "left".
Do the same for the y values.