470,855 Members | 1,154 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,855 developers. It's quick & easy.

Get mousebuttonstate in NS

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
Jul 20 '05 #1
4 1241
Silvio Bierman wrote:
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?


By adding a listener for the mousedown event:
document.addEventListener("mousedown", showButtonFunction, false);
JW

Jul 20 '05 #2
DU
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">&nbsp;</span> mouse.</p>

Tested and working without a problem in Mozilla 1.6 beta, NS 7.1 and
K-meleon 0.8.2.

DU
Jul 20 '05 #3
OK guys,

That is what I thought. I have solved it that way but thought there might be
a more elegant way of querying the button states during any other event. I
now use a document level event that sets/clear global button-down flags for
use in other event handlers, not nice but it works.

Thanks,

Silvio Bierman
Jul 20 '05 #4
Silvio Bierman wrote:
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?


Use the "which" property instead and be sure to pass and use
a reference to the local event object ("event" in an intrinsic
HTML event handler attribute) in the case the IE-proprietary
global "event" object is undefined.
PointedEars
Jul 20 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

12 posts views Thread by Jarod_24 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.