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

  • SEARCH
  • Home
  • 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 7717317
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T02:51:35+00:00 2026-06-01T02:51:35+00:00

I have a canvas which listens for mouse down event… but I wanted to

  • 0

I have a canvas which listens for mouse down event… but I wanted to make it more detailed by listening on the buttons and if they were double clicks or not.

I have this:

 canvas.addEventListener("mousedown", what_button, false);

Then a function named what_button:

 function what_button(e){
 //check which button on the mouse
 //was it a double click ?

 }

Is this possible in JavaScript?

  • 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-06-01T02:51:37+00:00Added an answer on June 1, 2026 at 2:51 am

    I don’t think that the 'mousedown' event is able to anticipate whether or not a second mouse click will occur. You’ll have to bind to both 'click' and 'dblclick' and then override the behavior if a double-click occurred…

    Inside the handler, the e.button property tells you which button was clicked:

    0 => left
    1 => middle
    2 => right
    

    This works for me:

    var dblclick;
    var timeout;
    
    $( document ).on( 'click', function ( e ) {
        if ( !timeout ) {
            timeout = setTimeout( function () {
                timeout = 0;           
                handler( dblclick ? 'dblclick' : 'click' );
                dblclick = false;
            }, 200 );
        }
    });
    
    $( document ).on( 'dblclick', function ( e ) {
        dblclick = true;
    });
    
    // this function receives either 'click' or 'dblclick'
    // and performs the corresponding action
    function handler ( type ) {
        alert( type );
    }
    

    Live demo: http://jsfiddle.net/f73tY/1/

    I use a delay value of 200. I have found that (at least on my machine) a value of 100 does not detect a double-click.

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

Sidebar

Related Questions

I'm trying to make a canvas which can be operated via the mouse (dragging,
I have a canvas element which I would like to make interactive by allowing
I have a canvas which user can interact to make changes to design. Now
I have a canvas on which on doubleclick event I create a box object.
I have a canvas which contains a single myComponentA. A myComponentA contains a MyComponentB.
I have a Canvas which has many components inside it and those again, have
My problem is: I have a Canvas which covers part of my Window. The
On my application, I have a canvas which CSS size (CSS, not html) updates
In my WPF application I have a Canvas in which I do some drawing.
I have a Canvas in a Flex application which has items inside it that

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.