Silvio Bierman wrote:
Hello,
In an event handler for onmousemove I want to know if a mousebutton is
currently prtessed. In IE "event.button == 1" works fine for me. In NS I
always get event.button == 0 in onmousemove event if the mousebutton is
pressed.
How do I get the mousebutton state?
TIA
Silvio Bierman
You must query the button property of the created event object once
you've created an event listener in Mozilla-based browsers.
"0" is the left button, "1" is the middle button and "2" is the right
button.
E.g.:
function init()
{
document.addEventListener("mousedown", showButtonFunction, false);
}
function showButtonFunction(evt)
{
document.getElementById("idParg").style.visibility = "visible";
var txtMouseButton = evt.button == "0" ? "left" : evt.button == "1" ?
"middle" : "right";
document.getElementById("idMouseButton").firstChil d.nodeValue =
txtMouseButton;
}
// this code could be further improved and made more robust
</script>
</head>
<body onload="init();">
<p id="idParg" style="visibility:hidden;">You just have clicked the
button of your <span id="idMouseButton"> </span> mouse.</p>
Tested and working without a problem in Mozilla 1.6 beta, NS 7.1 and
K-meleon 0.8.2.
DU