# Making shape change color with keys

**URL:** https://discourse.processing.org/t/making-shape-change-color-with-keys/24584
**Category:** Coding Questions
**Tags:** homework
**Created:** [October 14, 2020, 12:35am UTC](https://discourse.processing.org/t/making-shape-change-color-with-keys/24584 "2020-10-14T00:35:54Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![karbon](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/karbon/32/10892_2.png) [@karbon](https://discourse.processing.org/u/karbon)
#### Post date: [October 14, 2020, 12:35am UTC](https://discourse.processing.org/t/making-shape-change-color-with-keys/24584/1 "2020-10-14T00:35:54Z")

</div>

I am coding for an assignment and I am having a hard time. I want to make a shape, then particles, change between red. yellow and blue by hitting keys. I can’t tell what I’m doing wrong. Please help!

float offset =180;  
boolean isKeyPressedLeft = false;  
boolean isKeyPressedDown= false;  
boolean isKeyPressedRight= false;

float centerX;  
float centerY;

void setup()  
{  
size(200, 200);  
centerX= width / 2.0f;  
centerY = height /2.0f;  
}

void draw ()  
{  
background (63);  
circle (100, 100, 100);  
noStroke();

if (isKeyPressedLeft)  
fill ( 228, 46,46);

if (isKeyPressedDown)  
fill ( 237, 201,41);

if (isKeyPressedRight)  
fill( 56, 76, 228);  
}

void keyPressed()  
{  
updateKeyboard(true);  
}

void keyReleased()  
{  
updateKeyboard(false);  
}

void updateKeyboard(boolean state)  
{  
if (keyCode ==LEFT)  
isKeyPressedLeft = state;  
if (keyCode ==DOWN)  
isKeyPressedLeft = state;  
if(keyCode == RIGHT)  
isKeyPressedLeft = state;  
}

---

<div class="post-metadata">

### Author: ![noel](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/noel/32/213_2.png) [@noel](https://discourse.processing.org/u/noel)
#### Post date: [October 14, 2020, 7:12am UTC](https://discourse.processing.org/t/making-shape-change-color-with-keys/24584/2 "2020-10-14T07:12:27Z")

</div>

Hi @karbon Welcome to the forum.  
In the updateKeyboard() function you are using the same boolean for all keyCodes  
Change them like:

```auto
if (keyCode == LEFT) isKeyPressedLeft = state;
if (keyCode == DOWN) isKeyPressedDown = state;
if (keyCode == RIGHT) isKeyPressedRight = state;

```
