If that happens again, right-click somewhere as soon as you notice - it will cancel the movement and save you whatever AP haven't been used.