Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Accessing right click with three.js

Been looking for how to do this everywhere and there is almost no documentation on three.js. Does anyone know how I can access a right click on the mouse? This is what I have now:

function onDocumentMouseDown(event) 
{
    mouseDown = true;
    event.preventDefault();

    mouseX = event.clientX - windowHalfX;
    mouseY = event.clientY - windowHalfY;

    document.addEventListener('mousemove', onDocumentMouseMove, false);
    document.addEventListener('mouseup', onDocumentMouseUp, false);
    document.addEventListener('mouseout', onDocumentMouseOut, false);
}

And this is working great for what I am using it for but this event is for left click, middle click and right click. How do I isolate a right click event so that left click and right click can have different effects?

like image 349
user2287949 Avatar asked Dec 08 '22 15:12

user2287949


1 Answers

The event has the property button. You can handle it like this:

switch ( event.button ) {
    case 0: // left 
        break;
    case 1: // middle
        break;
    case 2: // right
        break;
}
like image 119
mrdoob Avatar answered Dec 11 '22 11:12

mrdoob