how to detect right mouse button press/release while left mouse button is plessed in P3D mode?

edited March 2016 in Questions about Code

Hello! I want to use both mouse button, but in P3D mode, mouseButton only returns left button.

void setup() {
  size(100, 100);
  //size(100, 100, P3D);

  fill(255);
}

boolean LMB, RMB;

void draw() {
  if (LMB) {
    background(0);
    if (RMB) {
      rect(30, 30, 40, 40);
    }
  } else {
    background(255);
  }
}

void mousePressed() {
  if (mouseButton==LEFT) {
    LMB=true;
  } else {
    RMB=true;
  }
}

void mouseReleased() {
  if (mouseButton==LEFT) {
    LMB=false;
  } else {
    RMB=false;
    if (LMB) {
      println("success");
    }
  }
}

This works, but doesn't in P3D mode. Please help me.

Answers

  • edited March 2016 Answer ✓

    Indeed all renderers but JAVA2D is bugged for mouseButton under P3! :-O
    You should report it here: https://GitHub.com/processing/processing/issues
    Also mention your forum thread here there, so you don't need to explain from zero. O:-)

    This is the rest of the full report below: :-B

    /**
     * Mouse Button Check (v1.0)
     * GoToLoop (2016-Mar-17)
     *
     * forum.Processing.org/two/discussion/15531/
     * how-to-detect-right-mouse-button-press-release-
     * while-left-mouse-button-is-plessed-in-p3d-mode
     *
     * studio.ProcessingTogether.com/sp/pad/export/ro.9$uOULvJSGGfw
     */
    
    static final String RENDERER = P3D;
    //static final String RENDERER = P2D;
    //static final String RENDERER = FX2D;
    //static final String RENDERER = JAVA2D;
    
    boolean leftBtn, rightBtn, centerBtn;
    
    void setup() {
      size(400, 300, RENDERER);
      smooth(8);
      //noLoop();
      frameRate(20);
    
      fill(-1);
      stroke(0);
      strokeWeight(2.5);
      rectMode(CENTER);
    }
    
    void draw() {
      final String btnStats = "L: " + leftBtn +
        "    R: " + rightBtn + "    C: " + centerBtn;
    
      if (1/2 != 1/2.)  frame.setTitle(btnStats);
      else              println(btnStats);
    
      background(leftBtn? 0 : -1);
      if (leftBtn & rightBtn)
        rect(width>>1, height>>1, width>>1, height>>1);
    }
    
    void mousePressed() {
      updateButtons(mouseButton, true);
      redraw();
    }
    
    void mouseReleased() {
      updateButtons(mouseButton, false);
      redraw();
    }
    
    void updateButtons(int btn, boolean bool) {
      if      (btn == LEFT)   leftBtn   = bool;
      else if (btn == RIGHT)  rightBtn  = bool;
      else                    centerBtn = bool;
    }
    
  • I reported it and wait for this bug is fixed. Thank you!

Sign In or Register to comment.