# Has anyone used the mousewheel to select between shapes onscreen

**URL:** <https://discourse.processing.org/t/has-anyone-used-the-mousewheel-to-select-between-shapes-onscreen/6547>\
**Category:** Coding Questions\
**Created:** [December 12, 2018, 5:52pm UTC](https://discourse.processing.org/t/has-anyone-used-the-mousewheel-to-select-between-shapes-onscreen/6547 "2018-12-12T17:52:51Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![CalvinBreene](https://avatars.discourse-cdn.com/v4/letter/c/58956e/32.png) [@CalvinBreene](https://discourse.processing.org/u/CalvinBreene)\
**Post date:** [December 12, 2018, 5:52pm UTC](https://discourse.processing.org/t/has-anyone-used-the-mousewheel-to-select-between-shapes-onscreen/6547/1 "2018-12-12T17:52:51Z")

</div>

Hi Experts,

I have 3 rectangles onscreen and want to use the mouse wheel to highlight each one in turn. Has anyone done something similar? I would appreciate an example if possible.

Thank you.

KB

---

<div class="post-metadata">

**Author:** ![jb4x](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jb4x/32/789_2.png) [@jb4x](https://discourse.processing.org/u/jb4x)\
**Post date:** [December 12, 2018, 6:08pm UTC](https://discourse.processing.org/t/has-anyone-used-the-mousewheel-to-select-between-shapes-onscreen/6547/2 "2018-12-12T18:08:40Z")

</div>

Hi,

Here’s a quick and dirty example:

```auto
int selectedShape = 0;

void setup() {
  size(1280, 420);
  noStroke();
}

void draw() {
  background(20);
  
  fill(200);
  if (selectedShape == 0) {
    fill(200, 20, 20);
  }
  rect(20, 20, 1240, 80);
  
  fill(200);
  if (selectedShape == 1) {
    fill(200, 20, 20);
  }
  rect(20, 120, 1240, 80);
  
  fill(200);
  if (selectedShape == 2) {
    fill(200, 20, 20);
  }
  rect(20, 220, 1240, 80);
  
  fill(200);
  if (selectedShape == 3) {
    fill(200, 20, 20);
  }
  rect(20, 320, 1240, 80);
}

void mouseWheel(MouseEvent event) {
  float e = event.getCount();
  
  if (e > 0) {
    selectedShape++;
  } else {
    selectedShape--;
  }
  
  if (selectedShape > 3) {
    selectedShape = 0;
  }
  
  if (selectedShape < 0) {
    selectedShape = 3;
  }
}

```

---

<div class="post-metadata">

**Author:** ![CalvinBreene](https://avatars.discourse-cdn.com/v4/letter/c/58956e/32.png) [@CalvinBreene](https://discourse.processing.org/u/CalvinBreene)\
**Post date:** [December 12, 2018, 6:48pm UTC](https://discourse.processing.org/t/has-anyone-used-the-mousewheel-to-select-between-shapes-onscreen/6547/3 "2018-12-12T18:48:19Z")

</div>

Oh I see, very clean. Thank you, now I see. I was going down the road of Pshapes such that I had to name each shape. Yours is cleaner.

Thanks again.

KB

---

<div class="post-metadata">

**Author:** ![kll](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kll/32/964_2.png) [@kll](https://discourse.processing.org/u/kll)\
**Post date:** [December 13, 2018, 2:07am UTC](https://discourse.processing.org/t/has-anyone-used-the-mousewheel-to-select-between-shapes-onscreen/6547/4 "2018-12-13T02:07:17Z")

</div>

the mouse wheel can even be multiplexed for several jobs,  
by using add the keyboard:  
a full framework would be [this](http://kll.engineering-news.org/kllfusion01/articles.php?article_id=154#here13)

here the short example

```auto
int e_objectTyp = 0;

void draw() {
  switch(e_objectTyp) {
  case 0: 
    user_object();
    break;
//...
 }
}

void mouseWheel(MouseEvent event) {
  float e = event.getCount();
  if ( keyPressed && key == 'o' ) {    
    e_objectTyp += e;
    e_objectTyp = constrain(e_objectTyp, 0, 3); } // [o] object typ YOUR, circle, rect, triangle,
}

```

---

<div class="post-metadata">

**Author:** ![CalvinBreene](https://avatars.discourse-cdn.com/v4/letter/c/58956e/32.png) [@CalvinBreene](https://discourse.processing.org/u/CalvinBreene)\
**Post date:** [December 13, 2018, 4:28am UTC](https://discourse.processing.org/t/has-anyone-used-the-mousewheel-to-select-between-shapes-onscreen/6547/5 "2018-12-13T04:28:20Z")

</div>

Really interesting extension of the thought. Thank you for taking the time to reply.

Cheers,

KB
