You should search the web for mouse gesture recognition or detection. If you provide some code or even some pseudo-code, I am sure you will get come feed-back from people.