# keyPressed to change image color, help!

**URL:** <https://discourse.processing.org/t/keypressed-to-change-image-color-help/24244>\
**Category:** Coding Questions\
**Created:** [September 30, 2020, 4:47pm UTC](https://discourse.processing.org/t/keypressed-to-change-image-color-help/24244 "2020-09-30T16:47:35Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![iwanttobelieve](https://avatars.discourse-cdn.com/v4/letter/i/e68b1a/32.png) [@iwanttobelieve](https://discourse.processing.org/u/iwanttobelieve)\
**Post date:** [September 30, 2020, 4:47pm UTC](https://discourse.processing.org/t/keypressed-to-change-image-color-help/24244/1 "2020-09-30T16:47:35Z")

</div>

Hey there! I was tasked to recreate the bouncing DVD logo screen - however I’m meant to make it so that when a key is pressed, the image changes a random color.

I’ve tried a bunch of different combinations, and can’t seem to make anything stick 😕

I’d be grateful for any advice. Thank you!

My p5 file:

> **[p5.js Web Editor](https://editor.p5js.org/shtweaver/sketches/wbMeH3hqD)**

---

<div class="post-metadata">

**Author:** ![GoToLoop](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gotoloop/32/86_2.png) [@GoToLoop](https://discourse.processing.org/u/GoToLoop)\
**Post date:** [September 30, 2020, 5:21pm UTC](https://discourse.processing.org/t/keypressed-to-change-image-color-help/24244/2 "2020-09-30T17:21:46Z")

</div>

> [@iwanttobelieve](#):
>
> , the image changes a random color.

You may try out method p5.Image::**tint()** or even p5.Image::**filter()**:

- [reference | p5.js](http://p5js.org/reference/#/p5/tint)
- [reference | p5.js](http://p5js.org/reference/#/p5/filter)

---

<div class="post-metadata">

**Author:** ![wyattsworlddd](https://avatars.discourse-cdn.com/v4/letter/w/9f8e36/32.png) [@wyattsworlddd](https://discourse.processing.org/u/wyattsworlddd)\
**Post date:** [October 1, 2020, 10:22pm UTC](https://discourse.processing.org/t/keypressed-to-change-image-color-help/24244/3 "2020-10-01T22:22:58Z")

</div>

if you’re confused about the activation and not the changing image color

> “when a key is pressed”

you want to look at the function

```auto
function keyPressed() {
// Code to activate here
}

```

you can then use a if statement to check which key was pressed:

```auto
function keyPressed() {
  if (keyCode === LEFT_ARROW) {
    // Do this
  } else if (keyCode === RIGHT_ARROW) {
    // Do that
  }
}

```

Here is also the reference link: [Key Pressed Ref](https://p5js.org/reference/#/p5/keyPressed)
