# Detect Right and left mouse click

**URL:** <https://discourse.processing.org/t/detect-right-and-left-mouse-click/38239>\
**Category:** Beginners\
**Created:** [August 5, 2022, 4:11pm UTC](https://discourse.processing.org/t/detect-right-and-left-mouse-click/38239 "2022-08-05T16:11:50Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![jensemand](https://avatars.discourse-cdn.com/v4/letter/j/b38774/32.png) [@jensemand](https://discourse.processing.org/u/jensemand)\
**Post date:** [August 5, 2022, 4:11pm UTC](https://discourse.processing.org/t/detect-right-and-left-mouse-click/38239/1 "2022-08-05T16:11:51Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [August 5, 2022, 4:27pm UTC](https://discourse.processing.org/t/detect-right-and-left-mouse-click/38239/2 "2022-08-05T16:27:05Z")

</div>

it has not to do with keys

please check here: [mouseButton / Reference / Processing.org](https://processing.org/reference/mouseButton.html)

or more general [Reference / Processing.org](https://processing.org/reference/#input) [section Input | Mouse]

**Example from the link**

```auto

// 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**

```auto

// 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);
}

```

---

<div class="post-metadata">

**Author:** ![glv](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/glv/32/18785_2.png) [@glv](https://discourse.processing.org/u/glv)\
**Post date:** [August 5, 2022, 5:10pm UTC](https://discourse.processing.org/t/detect-right-and-left-mouse-click/38239/3 "2022-08-05T17:10:18Z")

</div>

Hello @jensemand,

Processing resources (tutorials, references, examples, etc.) are here:

> **[Welcome to Processing!](https://processing.org/)**
>
> Processing is a flexible software sketchbook and a language for learning how to code. Since 2001, Processing has promoted software literacy within the visual arts and visual literacy within technology…

Take a look at this tutorial:

> **[Interactivity](https://processing.org/tutorials/interactivity/)**
>
> Introduction to interactivity with the mouse and keyboard.

`:)`

---

<div class="post-metadata">

**Author:** ![jensemand](https://avatars.discourse-cdn.com/v4/letter/j/b38774/32.png) [@jensemand](https://discourse.processing.org/u/jensemand)\
**Post date:** [August 5, 2022, 6:12pm UTC](https://discourse.processing.org/t/detect-right-and-left-mouse-click/38239/4 "2022-08-05T18:12:12Z")

</div>

Thank you! I must have missed mouseButton part before
