views:

940

answers:

6

I am able to find the cursor position. But I need to find out if the mouse is stable. If the mouse wasn't moved for more than 1 minute, then we have to alert the user.

How its possible, are there any special events for this? (Only for IE in javascript)

+1  A: 

Is there not a way to set a timer to start incrementing after every mouse movement event?

If it gets to a minute then pop up the message box, but every time the mouse moves the timer gets reset.

+1  A: 

Use a timer that resets its value on mousemove event. If timer reaches 1 minute --> Do something.

More info on timer here http://www.w3schools.com/js/js_timing.asp
And more info on catchin mouse events here http://www.quirksmode.org/js/events_mouse.html

Peter Gfader
A: 

You can use the onmousemove event. Inside it, clearTimeout(), and setTimeout(your_warning, 1 minute).

angus
A: 

You could use this script/snippet to detect the mouse pointer position and "remember" it. Then use a timer "setTimeout(...)" to check the position let's say every second and remember that time.

If more than one minute passed and the position hasn't changed, you could alert the user.

splattne
+8  A: 

Set a timeout when the mouse is moved one minute into the future, and if the mouse is moved, clear the timeout:

var timeout;
document.onmousemove = function(){
  clearTimout(timeout);
  timeout = setTimeout(function(){alert("move your mouse");}, 60000);
}
Marius
I see a potential problem: Every call to setTimeout returns a number for a counter. When will it wrap around and what happens then? I suggest a setInterval(update,1000) instead, where 'update' increments a variable that the onmousemove event resets. If the variable gets over 60 in update, alert user
some
+1  A: 

Yes, you have a onmousemove event in Javascript, so to achieve what you need you just have to do code something like this:

startTimer();
element.onmousemove = stopTimer(); //this stops and resets the timer

You can use it on the document body tag for instance.

UPDATE: @Marius has achieved a better example than this one.

rogeriopvl