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
}
}