4

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?

4

2 回答 2

14

event有财产button。_ 你可以这样处理:

switch ( event.button ) {
    case 0: // left 
        break;
    case 1: // middle
        break;
    case 2: // right
        break;
}
于 2013-04-25T17:39:06.613 回答
0

从 r120 开始,OrbitControls 使用指针事件。尝试下指针:

document.onpointerdown = function(event) {
    switch ( event.button ) {
        case 0: console.log("Left Button is down."); 
            break;
        case 1: console.log("Middle Button is down."); 
        //Beware this work not on mac with magic mouse!
            break;
        case 2: console.log("Right Button is down.");
            break;
    }
}

干杯

于 2021-07-12T13:21:03.417 回答