Hi, I’ve got the problem that I want to detect via a boolean when I press either my left or my right mouse bottom, however, it seems I can’t do it with keyCode.
It would really help a lot if someone could make a small program with a boolean that turns true when the right or left mouse bottom is pressed.
Thank you for the help!
1 Like
it has not to do with keys
please check here: mouseButton / Reference / Processing.org
or more general Reference / Processing.org [section Input | Mouse]
Example from the link
// Click within the image and press
// the left and right mouse buttons to
// change the value of the rectangle
void draw() {
if (mousePressed && (mouseButton == LEFT)) {
fill(0);
} else if (mousePressed && (mouseButton == RIGHT)) {
fill(255);
} else {
fill(126);
}
rect(25, 25, 50, 50);
}
Example with setting 2 boolean permanently
// Click within the image and press
// the left and right mouse buttons to
// change the value of the rectangle
boolean leftButton = false;
boolean rightButton = false;
void draw() {
background(255, 0, 0);
if (mousePressed && (mouseButton == LEFT)) {
fill(0);
leftButton = true;
} else if (mousePressed && (mouseButton == RIGHT)) {
fill(255);
rightButton = true;
} else {
fill(126);
}
rect(25, 25, 50, 50);
fill(255);
if (leftButton)
text("Left is on", 12, 12);
else text("Left is off", 12, 12);
}
Hello @jensemand,
Processing resources (tutorials, references, examples, etc.) are here:
Take a look at this tutorial:
:)
Thank you! I must have missed mouseButton part before
1 Like