Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 604673
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T17:03:49+00:00 2026-05-13T17:03:49+00:00

On mouse-down (and up) I need to check which mouse button has changed its

  • 0

On mouse-down (and up) I need to check which mouse button has changed its state. This is pretty easy with the W3C model and even the old netscape way (event.which) but IE gives me a headache. I know that event.button in IE is a bitmask but the problem is that I can’t find out which button was pressed from this bitmask. If IE gives me event.button == 3 then I can’t tell if the user pressed the left button while the right button was already down or if the user pressed the right button while the left button was already down.

To solve this problem once and for all I’m searching for a nice generic solution to convert the broken IE event into a W3C compatible event. Maybe someone already did that and wants to share?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T17:03:49+00:00Added an answer on May 13, 2026 at 5:03 pm

    IMO (and quirksmode’s), IE’s bitmasking is better than the W3C version because you can detect combo clicks, like left+right or middle+left. It offers a bit more flexibility. Both (total buttons pressed and newest button pressed) would be even better.

    I don’t know of a library or script that already does what you’re trying to do, I think most devs would just ignore combo clicks unless they wanted to apply a specific action to a combo click. Also, it’s rather tricky, you’d have to detect both onmousedown and onmouseup for the entire document and record the state of the mouse buttons. Then on the element you want to work your magic on, subtract the previous mouse state from the new one. Something like (tested):

    if (document.attachEvent)
    {
        (function ()
        {
            var mState = 0;
            document.documentElement.attachEvent("onmousedown", function () 
            {
                mState += event.button;
            });
            document.documentElement.attachEvent("onmouseup", function () 
            {
                mState -= event.button;
            });
            document.getElementById("jim").attachEvent("onmousedown", function ()
            {
                var realButton = event.button - mState;
    
                alert(realButton); 
                // Your code here
            });
        })();
    }
    

    Of course, there are only about a million things that could go wrong with this script. For instance, in my example there I have an alert window that pops up with the real button state. If you release the button whilst that alert dialog is up, the document won’t detect the mouseup and it will throw everything out of whack. Likewise, any mouseup or mousedown events on other elements that stop propagation up to the documentElement’s event handler would cause it to break.

    If you want my advice, display a message on a combo mouse click, guess at the "correct" mouse button or ignore them all together. Any one of those options is better than a hacky approach.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 335k
  • Answers 335k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Try var t=setInterval(function(){GetUpdates(5,ajaxResult);},300); You are including a double quote inside… May 14, 2026 at 3:39 am
  • Editorial Team
    Editorial Team added an answer Maybe you'll find that the Drupal documentation has the features… May 14, 2026 at 3:39 am
  • Editorial Team
    Editorial Team added an answer No, you can't add components at a specific cell. What… May 14, 2026 at 3:39 am

Related Questions

I wrote a program to click on an application automatically at scheduled time using
Ok, so I'll try to be as descriptive as possible. I'm working on a
I'm a total newbie when it comes to CSS so I've pretty much given
My 7 year old would like to learn, how to program? (his idea not
Sure I've seen this done before but off-hand I can't find any examples. I've

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.