# How to setup a timer to calculate the speed of mouse rotation movements on screen? [Answered]RSS

## 3 replies

Last post Jun 15, 2017 01:51 AM by Cathy Zou

• Paramu

Member

33 Points

38 Posts

### How to setup a timer to calculate the speed of mouse rotation movements on screen?

Jun 13, 2017 10:39 PM|Paramu|LINK

Hi,

After a long gap I am writing small project, WebForms to calculate the mouse rotation movement speed. Also the timer has to analyse, the clock wise direction speed only. Suppose if there is any Anti-Clock wise direction mouse movements, then the timer no need to calculate the speed. Therefore the speed calculation is required for clock wise directions only.

As a initial start-up, I draw a circle to centre of screen. And also I detect the direction of mouse rotation movements. ok. But I don't know how to setup the timer & measure it's speed. Any guidance & helps will be great.

Thanks

My Codes:-

``` <div id="Divn1" onmousemove="MyNewFunction(event)" onmouseout="ClearCoor()" style="width:99%; height:99%; border:solid;background-color:white; ;">
<p id="Demo1"></p>
<div id="Divn2" style="width:50px;height:50px;border-radius:50%;background-color:brown; ; top:45%; margin-left:47%;">

</div>

</div>
<script>
function MyNewFunction(e)
{
var oldx = 0;
var oldy = 0;
if (e.movementX < oldx) {
XDirection = "left"
} else if (e.movementX > oldx) {
XDirection = "right"
}

oldx = e.pageX;
oldY = e.pageY;
document.getElementById("Demo1").innerHTML = XDirection;
}
function ClearCoor()
{
document.getElementById("Demo1").innerHTML = "";
}
```

Note : Above code will show a circle on center of page & will show the mouse rotation direction. But need to analyse the speed by timer...

Thanks for the helps again.

`   </script>`

• Cathy Zou

Star

8410 Points

2862 Posts

### Re: How to setup a timer to calculate the speed of mouse rotation movements on screen?

Jun 14, 2017 07:44 AM|Cathy Zou|LINK

Hi Paramu,

Sparklines has a nifty example of tracking mouse movement and graphing it. Their code is available in the source of their site starting at line 315.
Simple and effective.

Here is the code:

``` var mrefreshinterval = 500; // update display every 500ms
var lastmousex=-1;
var lastmousey=-1;
var lastmousetime;
var mousetravel = 0;
\$('html').mousemove(function(e) {
var mousex = e.pageX;
var mousey = e.pageY;
if (lastmousex > -1)
mousetravel += Math.max( Math.abs(mousex-lastmousex), Math.abs(mousey-lastmousey) );
lastmousex = mousex;
lastmousey = mousey;
});```

Best regards

Cathy

MSDN Community Support
Please remember to click "Mark as Answer" the responses that resolved your issue.
If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.
• Paramu

Member

33 Points

38 Posts

### Re: How to setup a timer to calculate the speed of mouse rotation movements on screen?

Jun 15, 2017 12:44 AM|Paramu|LINK

Thanks Cathy.

But I have to include any Sparklines Java Script?

Thanks Again

• Cathy Zou

Star

8410 Points

2862 Posts

### Re: How to setup a timer to calculate the speed of mouse rotation movements on screen?

Jun 15, 2017 01:51 AM|Cathy Zou|LINK

Hi Paramu

jquery.sparkline.js is a plugin for jQuery

So, You need to include both on your page to generate sparkline.

You could get full understanding and download it through referring to the following link:

http://omnipotent.net/jquery.sparkline/#s-download

Following is a simple web page that will display some sparklines:

http://omnipotent.net/jquery.sparkline/#mouseover

Disclaimer: This response contains a reference to a third party World Wide Web site. Microsoft is providing this information as a convenience to you. Microsoft does not control these sites and has not tested any software or information found on these sites; therefore, Microsoft cannot make any representations regarding the quality, safety, or suitability of any software or information found there. There are inherent dangers in the use of any software found on the Internet, and Microsoft cautions you to make sure that you completely understand the risk before retrieving any software from the Internet.

Best regard

Cathy

MSDN Community Support
Please remember to click "Mark as Answer" the responses that resolved your issue.
If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.