It's not a secret anymore!*
The moose likes HTML, CSS and JavaScript and the fly likes How can I capture MOUSE MOVE and call a function? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "How can I capture MOUSE MOVE and call a function?" Watch "How can I capture MOUSE MOVE and call a function?" New topic
Author

How can I capture MOUSE MOVE and call a function?

Ken Shamrock
Ranch Hand

Joined: Jan 23, 2002
Posts: 139
For example, if my mouse is moved on screen, a function will be called, if it stop, nothing will be done. I've a simple script as follows:
<heaD>
<script>
function Key_Up(e) {
alert("message");
}
document.captureEvents(Event.MOUSEMOVE);
document.onmousemove = Key_Up;
</script>
</head>
<body>1</body>

However, it doesn't do what i suppose i want to do, if my mouse move, the alert message will LOOP forever, but my basic idea is when my mouse move, alert appear, press OK using keyboard, alert message disappear (<---but now the alert appear again). Please would anyone suggest a solution?Thanks


Thanks everyone who helped me
Ken Shamrock
Ranch Hand

Joined: Jan 23, 2002
Posts: 139
Forget to say that my script aims on running at Netscape 4.xx, not works for IE
Yuriy Fuksenko
Ranch Hand

Joined: Feb 02, 2001
Posts: 413
You should have a flag on yout page - if mouse move, and flag is set, than show dialog( alert).
If user hit OK on alert - reset a flag, so alert will not appear.
You might need to replace standart alert function with some thing else - either layer or another browser window (by the way, showModalDialog from for IE is exactly what you need).
By the way, for IE you need not to call captureEvent function, so put
if (!document.all) window.captureEvent(...)
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How can I capture MOUSE MOVE and call a function?