Simultaneous pressing of left and right mouse buttons

S

Shocky

Hi there,

I am trying to detect whether my IE6 users have pressed both right and
left mouse buttons simultaneously in my Javascript code, by using:

if(event.button==3) {alert("Both right and left mouse buttons
pressed");}

I am calling the above code on mousedown or mouseup events.

But it does not seem to work. :,(

The if condition is not satisfied even on pressing the left and right
buttons simultaneously.

Is there something that I am missing?

Best,
Shocky
 
E

Evertjan.

Shocky wrote on 27 okt 2007 in comp.lang.javascript:
I am trying to detect whether my IE6 users have pressed both right and
left mouse buttons simultaneously in my Javascript code, by using:

if(event.button==3) {alert("Both right and left mouse buttons
pressed");}

I am calling the above code on mousedown or mouseup events.

But it does not seem to work. :,(

The if condition is not satisfied even on pressing the left and right
buttons simultaneously.

Is there something that I am missing?

Yes.

Try it out:

<button onmousedown='alert(event.button)'>
Test down</button>
<br><br>
<button onmouseup='alert(event.button);return false;'>
Test up</button>

You see, you won't be able to press them simulaniously.
 
T

Thomas 'PointedEars' Lahn

Shocky said:
I am trying to detect whether my IE6 users have pressed both right and
left mouse buttons simultaneously in my Javascript code, by using:

if(event.button==3) {alert("Both right and left mouse buttons
pressed");}

I am calling the above code on mousedown or mouseup events.

But it does not seem to work. :,(

The if condition is not satisfied even on pressing the left and right
buttons simultaneously.

Is there something that I am missing?

My tests indicate that event.button == 3 requires the event type to be
`mousemove'.

http://msdn2.microsoft.com/en-us/library/ms533544.aspx


PointedEars
 
D

Doug Miller

Shocky wrote on 27 okt 2007 in comp.lang.javascript:
I am trying to detect whether my IE6 users have pressed both right and
left mouse buttons simultaneously in my Javascript code, by using:
[snip]

You see, you won't be able to press them simulaniously.

Yes and no. While it's nearly impossible to press the two buttons exactly
simultaneously, it's certainly possible to press one, then the other, without
releasing the first. Seems to me that the OP needs to look for two consecutive
mousedown events, on opposite buttons, without an intervening mouseup event.
 
D

David Mark

Shocky wrote on 27 okt 2007 in comp.lang.javascript:
I am trying to detect whether my IE6 users have pressed both right and
left mouse buttons simultaneously in my Javascript code, by using:
[snip]

You see, you won't be able to press them simulaniously.

Yes and no. While it's nearly impossible to press the two buttons exactly
simultaneously, it's certainly possible to press one, then the other, without
releasing the first. Seems to me that the OP needs to look for two consecutive
mousedown events, on opposite buttons, without an intervening mouseup event.

The mouseup event doesn't enter into it. The second mousedown event
will indicate that both buttons are pressed (event.button == 3.)
 
E

Evertjan.

David Mark wrote on 27 okt 2007 in comp.lang.javascript:
"Evertjan." said:
Shocky wrote on 27 okt 2007 in comp.lang.javascript:
I am trying to detect whether my IE6 users have pressed both right
and left mouse buttons simultaneously in my Javascript code, by
using: [snip]

You see, you won't be able to press them simulaniously.

Yes and no. While it's nearly impossible to press the two buttons
exactly simultaneously, it's certainly possible to press one, then
the other, without releasing the first. Seems to me that the OP needs
to look for two consecutive mousedown events, on opposite buttons,
without an intervening mouseup event.

The mouseup event doesn't enter into it. The second mousedown event
will indicate that both buttons are pressed (event.button == 3.)

show us a test code, please.
 
T

Thomas 'PointedEars' Lahn

Doug said:
[...] While it's nearly impossible to press the two buttons exactly
simultaneously, it's certainly possible to press one, then the other, without
releasing the first. Seems to me that the OP needs to look for two consecutive
mousedown events, on opposite buttons, without an intervening mouseup event.

Ahh, you are right :)


PointedEars
 
D

David Mark

David Mark wrote on 27 okt 2007 in comp.lang.javascript:




Shocky wrote on 27 okt 2007 in comp.lang.javascript:
I am trying to detect whether my IE6 users have pressed both right
and left mouse buttons simultaneously in my Javascript code, by
using:
[snip]
You see, you won't be able to press them simulaniously.
Yes and no. While it's nearly impossible to press the two buttons
exactly simultaneously, it's certainly possible to press one, then
the other, without releasing the first. Seems to me that the OP needs
to look for two consecutive mousedown events, on opposite buttons,
without an intervening mouseup event.
The mouseup event doesn't enter into it. The second mousedown event
will indicate that both buttons are pressed (event.button == 3.)

show us a test code, please.

Okay.

<div onmousedown="window.status = event.button"></div>

To test it, press the primary button and hold. Note that the status
reads "1." Now press the context button without releasing the
primary. Status changes to "3" as expected.
 
D

David Mark

Doug said:
[...] While it's nearly impossible to press the two buttons exactly
simultaneously, it's certainly possible to press one, then the other, without
releasing the first. Seems to me that the OP needs to look for two consecutive
mousedown events, on opposite buttons, without an intervening mouseup event.

Ahh, you are right :)

No, he is wrong. See my reply.
 
E

Evertjan.

David Mark wrote on 27 okt 2007 in comp.lang.javascript:
Okay.

<div onmousedown="window.status = event.button"></div>

To test it, press the primary button and hold. Note that the status
reads "1." Now press the context button without releasing the
primary. Status changes to "3" as expected.

<button onmousedown="if (event.button==3)alert('Yes')">
click me with both mouse buttons</button>

YES!

However I don't seem to be able
to cancel the single rightclick menu
[necessary imho]
with a return false:

<button onmousedown="if (event.button==3)alert('Yes')">
click me both mouse buttons</button>

and have to use:

<button
onmousedown="if (event.button==3)alert('Yes');"
oncontextmenu="return false;">
click me both mouse buttons</button>

The response seems to be bitwize:
the rightmost bit being the left button,
the second bit being the right button.

Is the third button the third bit [with value 4],
if not derouted by a Os or intellimouse routine?
 
D

David Mark

David Mark wrote on 27 okt 2007 in comp.lang.javascript:
<div onmousedown="window.status = event.button"></div>
To test it, press the primary button and hold. Note that the status
reads "1." Now press the context button without releasing the
primary. Status changes to "3" as expected.

<button onmousedown="if (event.button==3)alert('Yes')">
click me with both mouse buttons</button>

YES!

However I don't seem to be able
to cancel the single rightclick menu
[necessary imho]
with a return false:

<button onmousedown="if (event.button==3)alert('Yes')">
click me both mouse buttons</button>
Right.


and have to use:

<button
onmousedown="if (event.button==3)alert('Yes');"
oncontextmenu="return false;">
click me both mouse buttons</button>
Right.


The response seems to be bitwize:
the rightmost bit being the left button,

The primary button, which is often the left button.
the second bit being the right button.

The context button, which is often the right button.
Is the third button the third bit [with value 4],
if not derouted by a Os or intellimouse routine?

Yes.
 
D

Doug Miller

Shocky wrote on 27 okt 2007 in comp.lang.javascript:
I am trying to detect whether my IE6 users have pressed both right and
left mouse buttons simultaneously in my Javascript code, by using: [snip]

You see, you won't be able to press them simulaniously.

Yes and no. While it's nearly impossible to press the two buttons exactly
simultaneously, it's certainly possible to press one, then the other, without
releasing the first. Seems to me that the OP needs to look for two consecutive
mousedown events, on opposite buttons, without an intervening mouseup event.

The mouseup event doesn't enter into it. The second mousedown event
will indicate that both buttons are pressed (event.button == 3.)

I guess partly this depends on how you look at things. Certainly if there *is*
a mouseup event intervening, the second mousedown event will not return 3.
 
S

SAM

David Mark a écrit :
Okay.

<div onmousedown="window.status = event.button"></div>

To test it, press the primary button and hold. Note that the status
reads "1." Now press the context button without releasing the
primary. Status changes to "3" as expected.

Absolutely not ... I get "2" ... and ... the popup menu !
(Firefox on Mac)
 
S

SAM

Evertjan. a écrit :
<button
onmousedown="if (event.button==3)alert('Yes');"
oncontextmenu="return false;">
click me both mouse buttons</button>

That doesn't fire (because I cant get more than 2)
left click = 0 (Fx) 1 (Safari)
middle button (wheel) = 1 (Fx) 1 (Safari)
right click = 2 (Fx) popup menu or nothing (Safari)

With Firefox, 2 buttons pressed = 1 or 2
(depends if it is left + middle
left or middle + right
left + middle + right)
Is the third button the third bit [with value 4],
if not derouted by a Os or intellimouse routine?

I got 1
 
E

Evertjan.

SAM wrote on 28 okt 2007 in comp.lang.javascript:
David Mark a écrit :

Absolutely not ... I get "2" ... and ... the popup menu !
(Firefox on Mac)

Please see the thread's OQ, this was about IE6 only.

Does mac have a second mousebutton??????????
 
D

David Mark

David Mark a écrit :



Absolutely not ... I get "2" ... and ... the popup menu !
(Firefox on Mac)

This discussion is about IE. Here is a cross-platform version:

function mouseButtons(e) {
var b = {};
if (typeof(e.which) != 'undefined') {
b.left = (e.which == 1);
b.middle = (e.which == 2);
b.right = (e.which == 3);
}
else {
b.left = (e.button & 1);
b.middle = (e.button & 4);
b.right = (e.button & 2);
}
return b;
}

Pass it a normalized event (e || window.event) of course. You will
notice that only IE combines buttons.
 
D

David Mark

Evertjan. a écrit :




That doesn't fire (because I cant get more than 2)
left click = 0 (Fx) 1 (Safari)
middle button (wheel) = 1 (Fx) 1 (Safari)
right click = 2 (Fx) popup menu or nothing (Safari)

I assume you are not talking about click events.
With Firefox, 2 buttons pressed = 1 or 2
(depends if it is left + middle
left or middle + right
left + middle + right)
Is the third button the third bit [with value 4],
if not derouted by a Os or intellimouse routine?

I got 1

That's why you use the which property when it exists. There is no
telling what non-IE browsers will put in the button property.
 
D

David Mark

SAM wrote on 28 okt 2007 in comp.lang.javascript:







Please see the thread's OQ, this was about IE6 only.

Does mac have a second mousebutton??????????

I believe the context action on single button mice is physically
invoked by holding down the primary button. So with these there would
be no way to combine buttons.
 
T

Thomas 'PointedEars' Lahn

Doug said:
I guess partly this depends on how you look at things. Certainly if there *is*
a mouseup event intervening, the second mousedown event will not return 3.

Why, there could have been 3 buttons be pressed before.


PointedEars
 
S

SAM

Evertjan. a écrit :
SAM wrote on 28 okt 2007 in comp.lang.javascript:

Please see the thread's OQ, this was about IE6 only.

Oh ! on ne me dit jamais rien à moi !
Oh! Never anybody says to me nothing :)
(original post is a little far from here)
Does mac have a second mousebutton??????????

The last Apple's mouse : yes (and a ball to wheel up/down right/left)

any optical mouse bought anywhere has more than one button and works
without specific driver.
(my apple's mouse still lays in its box)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Staff online

Members online

Forum statistics

Threads
473,767
Messages
2,569,571
Members
45,045
Latest member
DRCM

Latest Threads

Top