473,513 Members | 2,552 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Simultaneous pressing of left and right mouse buttons

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
18 3924
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
1920
by: Trikki | last post by:
Hi, Im very new to Javascript and i'm in the very early learning stages. My question is: I have a web page with 8 links on, i want to disable the left mouse click on 6 of these links but still be able to use right click to "save target as" I still want 2 of the links to operate normally with left click.
5
7936
by: gsb | last post by:
I track the mouse location like this code: function mousePos(e) { var p = new Object(); if(e) { p.x = e.pageX; p.y = e.pageY; } else { p.x = event.x; p.y = event.y; } ... (show) } document.onmousemove=mousePos; Seems to do fine on many browsers.
3
3592
by: mitsura | last post by:
Hi, I have included a small listing. The test program opens a panel and show a bitmap. What I want is to when the mouse is over the bitmap panel, I want to trap the left mouse click. The purpose is to get the position of the mouse pointer on the bitmap. However, for some reason, the left (I also tried right) mouse clicks are not...
12
18276
by: mdb | last post by:
My app has a notify icon in the systray. I want the left mouse click to initiate a menu, and a right-mouse click to do something else. Normally, for a button, I would listen to MouseDown and if I need to display the menu, I would contextMenu.Show(buttonCtrl, new Point(0)). But I can't do this for a notifyIcon because notifyIcons aren't...
3
7401
by: SteveMac | last post by:
I am using VS2003 VC++ .NET. I want to make a tray icon with a popup menu (like a context menu) that pops up for a left click. I can make the notifyicon with a context menu and that works fine, but I really want it to show the menu for a left click, exactly as it would for a right click. SteveMac
8
4600
by: Chaitanya | last post by:
Hello, In my Application i want to know when user clicks both the "Left" and "Right" buttons of the Mouse. I am getting a number like this "3145728". But the MouseButtons Enum contains only Left, Right, Middle, None, XButton1 and XButton2. I am using .NET 1.1 version. How can i convert "3145728" to MouseButtons Enum? why Mouse Left+Right...
4
7606
by: nkoier | last post by:
Hi, I've been going crazy trying to figure out what's wrong with our Asp.Net 2.0 intranet site. At the very top of our main page I provide a TextBox and a Button for submitting Google searches. Recently somebody pointed out to me that you can't just press ENTER anymore after typing in the TextBox but that you HAVE to click on the submit...
18
4582
by: Zytan | last post by:
I want the same function to be run whether you press Enter or double click the listbox. It seems really verbose to write both handlers to both events everytime, even if they both call the same function, or one calls the other. Isn't there an event for 'ListBox selection selected' that is automatically called by ALL the standard GUI ways of...
6
9701
by: marss | last post by:
Hi, How can I define in Firefox whether the left mouse button is pressed when I move mouse over a html element? The documentation says that "e.button == 0 for standard 'click', usually left button" http://developer.mozilla.org/en/docs/DOM:event.button Tracing of mouse clicks or mousedown/mouseup events looks not reliable, because mouse can...
0
7270
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7178
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7397
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7565
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
5704
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5103
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
4759
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3242
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
817
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.