0

In a function to find mouse velocity we have to do distance/time every time mousemove is triggered.But if I stop mouse for 10 seconds and then I move it for 10 pixels in 1 millisecond,the velocity will be 1px/1s more or less.But in reality it isn't like this because I've moved the mouse in 1 millisecond for 10px so the velocity should be 10px/1ms...How this thing could be fixed?

Fistright
  • 175
  • 1
  • 11
  • [Debounce](http://stackoverflow.com/a/4298672/1169519). – Teemu Jun 07 '16 at 18:30
  • I don't understand how that question could help me – Fistright Jun 07 '16 at 18:33
  • I don't understand how that link could help me – Fistright Jun 07 '16 at 18:47
  • With a debouncer you can detect when the mouse stops. At a mouse stop you set the starting time variable used to calculate the time the mouse moves to zero. In another mousemove handler check if starting time is zero, if that's the case, assign a new starting time and calculate the speed. – Teemu Jun 07 '16 at 19:36
  • With the debouncer is not great for me because you have to set a time to see if mouse is stopped.If I move mouse before this time is passed? – Fistright Jun 07 '16 at 20:38
  • Debounce is worth of trying, a couple of milliseconds is a very short time to stop the mouse and get it moving again. I can't imagine any more accurate way to achieve what you need. – Teemu Jun 08 '16 at 06:46

0 Answers0