PDA

View Full Version : Is there any way to know if left mouse button is staying pressed



frontline
12-07-2003, 09:34 AM
Hello
im trying to detect when the user is pressing on the left mouse button
that is keep pressing it not "onclick" it .
i have to know the time from when the user start the press until he relies the left mouse button.
thanks

x_goose_x
12-07-2003, 03:56 PM
Try adding the following to your body tag:


<body onLoad="isClicked=false;" onMouseDown="isClicked=true" onMouseUp="isClicked=false;">

Then in whatever script you're using, just use the boolean isClicked to see if it's clicked.




<script type="text/javascript" language="JavaScript">

function whatever()
{
if (isClicked)
{
alert("You are holding your mouse down.");
}
}

</script>

If you want something to happen while your mouse is down, you can enter your function directly into onLoad/onMouseDown/Up:


<body onLoad="window.status='not pressed...';" onMouseDown="window.status='pressed...';" onMouseUp="window.status='not pressed...';">

Note: You don'thave to use the body tag, if you only want it to work in a textarea, DIV, or whatever just put onLoad/onMouseDown/Up in the tag you want.