By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,959 Members | 2,432 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,959 IT Pros & Developers. It's quick & easy.

Simultaneous pressing of left and right mouse buttons

P: n/a
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

Oct 27 '07 #1
Share this Question
Share on Google+
18 Replies


P: n/a
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.

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Oct 27 '07 #2

P: n/a
Shocky wrote:
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
--
"Use any version of Microsoft Frontpage to create your site. (This won't
prevent people from viewing your source, but no one will want to steal it.)"
-- from <http://www.vortex-webdesign.com/help/hidesource.htm>
Oct 27 '07 #3

P: n/a
In article <Xn********************@194.109.133.242>, "Evertjan." <ex**************@interxnl.netwrote:
>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.

--
Regards,
Doug Miller (alphageek at milmac dot com)

It's time to throw all their damned tea in the harbor again.
Oct 27 '07 #4

P: n/a
On Oct 27, 3:12 pm, spamb...@milmac.com (Doug Miller) wrote:
In article <Xns99D6B6F447586eej...@194.109.133.242>, "Evertjan." <exjxw.hannivo...@interxnl.netwrote:
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.)

Oct 27 '07 #5

P: n/a
David Mark wrote on 27 okt 2007 in comp.lang.javascript:
On Oct 27, 3:12 pm, spamb...@milmac.com (Doug Miller) wrote:
>In article <Xns99D6B6F447586eej...@194.109.133.242>, "Evertjan."
<exjxw.hannivo...@interxnl.netwrote:
>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.
--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Oct 27 '07 #6

P: n/a
Doug Miller wrote:
[...] 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
--
"Use any version of Microsoft Frontpage to create your site. (This won't
prevent people from viewing your source, but no one will want to steal it.)"
-- from <http://www.vortex-webdesign.com/help/hidesource.htm>
Oct 27 '07 #7

P: n/a
On Oct 27, 3:37 pm, "Evertjan." <exjxw.hannivo...@interxnl.netwrote:
David Mark wrote on 27 okt 2007 in comp.lang.javascript:


On Oct 27, 3:12 pm, spamb...@milmac.com (Doug Miller) wrote:
In article <Xns99D6B6F447586eej...@194.109.133.242>, "Evertjan."
<exjxw.hannivo...@interxnl.netwrote:
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.
Oct 27 '07 #8

P: n/a
On Oct 27, 3:37 pm, Thomas 'PointedEars' Lahn <PointedE...@web.de>
wrote:
Doug Miller wrote:
[...] 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.

Oct 27 '07 #9

P: n/a
David Mark wrote on 27 okt 2007 in comp.lang.javascript:
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.
<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?

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Oct 27 '07 #10

P: n/a
On Oct 27, 4:35 pm, "Evertjan." <exjxw.hannivo...@interxnl.netwrote:
David Mark wrote on 27 okt 2007 in comp.lang.javascript:
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.

<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.

Oct 27 '07 #11

P: n/a
In article <11**********************@y42g2000hsy.googlegroups .com>, David Mark <dm***********@gmail.comwrote:
>On Oct 27, 3:12 pm, spamb...@milmac.com (Doug Miller) wrote:
>In article <Xns99D6B6F447586eej...@194.109.133.242>, "Evertjan."
<exjxw.hannivo...@interxnl.netwrote:
>>
>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.

--
Regards,
Doug Miller (alphageek at milmac dot com)

It's time to throw all their damned tea in the harbor again.
Oct 27 '07 #12

P: n/a
SAM
David Mark a écrit :
On Oct 27, 3:37 pm, "Evertjan." <exjxw.hannivo...@interxnl.netwrote:
>David Mark wrote on 27 okt 2007 in comp.lang.javascript:
>>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.
Absolutely not ... I get "2" ... and ... the popup menu !
(Firefox on Mac)
Oct 28 '07 #13

P: n/a
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

--
sm
Oct 28 '07 #14

P: n/a
SAM wrote on 28 okt 2007 in comp.lang.javascript:
David Mark a écrit :
>On Oct 27, 3:37 pm, "Evertjan." <exjxw.hannivo...@interxnl.netwrote:
>>David Mark wrote on 27 okt 2007 in comp.lang.javascript:

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.

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??????????

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Oct 28 '07 #15

P: n/a
On Oct 27, 8:40 pm, SAM <stephanemoriaux.NoAd...@wanadoo.fr.invalid>
wrote:
David Mark a écrit :
On Oct 27, 3:37 pm, "Evertjan." <exjxw.hannivo...@interxnl.netwrote:
David Mark wrote on 27 okt 2007 in comp.lang.javascript:
>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.

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.

Oct 28 '07 #16

P: n/a
On Oct 27, 8:57 pm, SAM <stephanemoriaux.NoAd...@wanadoo.fr.invalid>
wrote:
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)
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.

Oct 28 '07 #17

P: n/a
On Oct 28, 4:59 am, "Evertjan." <exjxw.hannivo...@interxnl.netwrote:
SAM wrote on 28 okt 2007 in comp.lang.javascript:


David Mark a écrit :
On Oct 27, 3:37 pm, "Evertjan." <exjxw.hannivo...@interxnl.netwrote:
David Mark wrote on 27 okt 2007 in comp.lang.javascript:
>>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.
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??????????
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.

Oct 28 '07 #18

P: n/a
SAM
Evertjan. a écrit :
SAM wrote on 28 okt 2007 in comp.lang.javascript:
>><div onmousedown="window.status = event.button"></div>
(...)
>Absolutely not ... I get "2" ... and ... the popup menu !
(Firefox on Mac)

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)

--
sm
Oct 28 '07 #19

This discussion thread is closed

Replies have been disabled for this discussion.