[thelist] detect held-down mouse button

shortestpath shortestpath at yahoo.com
Tue Aug 19 06:58:18 CDT 2003


Thanks to everyone who gave their suggestions. 
I was trying to avoid setting a global variable.
For some reason I thought I could somehow get to a 
parent or ancestor event, kinda like how you can get 
to a parent or ancestor node. I was thinkng that a 
mouseup could not have occurred without a mousedown. 
So if there's a mousemove in between, then mousedown 
must be a parent of mousemove. I guess I'm realizing 
there's no such thing? 


--- RLivsey <R.Livsey at cache-22.co.uk> wrote:
shortestpath wrote:

> is there a way to detect a held-down button, -while-
> the mouse is moving?

> thanks in advance,
> -alex

Paste the following into a new html document.

// -------- Start ----------- //
<html>
<head>
<title>mouse test</title>
<script>
var isDown = false;
function mup()
{
	isDown = false;
	setText("mouse up");
}
function mdown()
{
	isDown = true;
	setText("mouse down");
}
function mmove()
{
	setText((isDown) ? "move while down" : "move while up");
}
function setText(txt)
{
	document.moveTestForm.status.value = txt;
}
</script>
</head>
<body onmouseup="mup()" onmousedown="mdown()" onmousemove="mmove()">
<form name="moveTestForm">
	<input type="test" name="status" />
</form>
</body>
</html>
// -------- End ----------- //

so basically on mouse down, set a variable (here called isDown) to 
true. 
On mouse up, set it to false.
When the mouse moves check this var and you can tell if the mouse is 
clicked while you are moving the mouse.

hth

-- 
R.Livsey
Incutio Web Developer
[ PHP | Perl | Java | C# ]
www.cache-22.co.uk
www.incutio.com

__________________________________
Do you Yahoo!?
Yahoo! SiteBuilder - Free, easy-to-use web site design software
http://sitebuilder.yahoo.com


More information about the thelist mailing list