onmousemove continually fires, indefinitely

by timvasil 11/12/2007 12:14:00 AM

I recently decided to hook document.onmousemove and document.onkeypress for idle detection on a web page.  Kind of the right idea, but surprising results. 

Did you know that, at least with IE 7, the onmousemove event continues to fire a couple times per second even when the mouse is not moving?  and even when the browser window doesn't have the focus, so long as the mouse is over the document?  Bizarre. 

There's an easy enough way around this issue:

document.onmousemove = observeMoveActivity;
var g_iOldX;
var g_iOldY;
function observeMoveActivity()
{
    if (event && (event.screenX != g_iOldX || event.screenY != g_iOldY))
    {
        g_iOldX = event.screenX;
        g_iOldY = event.screenY;
        observeActivity();  // do actual work here
    }
}

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags:

JavaScript

Related posts

Comments are closed

 

About the author

Tim Vasil Tim Vasil
I'm a software engineer living in Cambridge, MA.

E-mail me Send mail

Search

Calendar

<<  September 2010  >>
MoTuWeThFrSaSu
303112345
6789101112
13141516171819
20212223242526
27282930123
45678910

View posts in large calendar

Recent comments