# Problem with keypressed

**URL:** <https://discourse.processing.org/t/problem-with-keypressed/9225>\
**Category:** Coding Questions\
**Created:** [March 12, 2019, 10:10am UTC](https://discourse.processing.org/t/problem-with-keypressed/9225 "2019-03-12T10:10:46Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![yonjukyu](https://avatars.discourse-cdn.com/v4/letter/y/9de0a6/32.png) [@yonjukyu](https://discourse.processing.org/u/yonjukyu)\
**Post date:** [March 12, 2019, 10:10am UTC](https://discourse.processing.org/t/problem-with-keypressed/9225/1 "2019-03-12T10:10:46Z")

</div>

hello i want to make my “rect” moove when i press “LEFT” but with this code the rect is mooving even if nothin is pressed.  
(i used keyreleased because i want to press many keys at the same time)  
what’s wrong??:

```auto
int x =100;
int y =100;
int x2 = 1000;
int y2 =50;
boolean[] keys;

void setup() {
  size (1200, 600);
  background(245, 72, 72);
  keys=new boolean[1];
  keys[0]=true;
}

void draw() {  
  background(245, 72, 72); 
  Player player1 = new Player(x, y);
  Player player2 = new Player(x2, y2);
  if (keys[0]=true) {
    x=x+1;
  }
  text(player1.x, 50, 50);
}

void keyPressed() {

  if (key==CODED) {
    if (keyCode==LEFT)
      keys[0]=false ;
  }
}

void keyReleased() {

  if (key==CODED) {
    if (keyCode==LEFT)
      keys[0]=false;
  }
}

public class Player {
  int x;
  int y;
  public Player(int px, int py) {
    rect (px, py, 50, 100);              
    x = px;
    y = py;
  }
}

```

---

<div class="post-metadata">

**Author:** ![TfGuy44](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/tfguy44/32/41_2.png) [@TfGuy44](https://discourse.processing.org/u/TfGuy44)\
**Post date:** [March 12, 2019, 10:19am UTC](https://discourse.processing.org/t/problem-with-keypressed/9225/2 "2019-03-12T10:19:46Z")

</div>

Two problems:

1. Both your keyPressed and keyReleased functions are setting keys[0] to false. One of them should set it to true!

2. Your conditional check, `if (keys[0]=true) {` is an assignment, not a comparison! Try `if (keys[0] == true) {`, or even just `if ( keys[0] ) {`

---

<div class="post-metadata">

**Author:** ![yonjukyu](https://avatars.discourse-cdn.com/v4/letter/y/9de0a6/32.png) [@yonjukyu](https://discourse.processing.org/u/yonjukyu)\
**Post date:** [March 12, 2019, 4:10pm UTC](https://discourse.processing.org/t/problem-with-keypressed/9225/3 "2019-03-12T16:10:02Z")

</div>

Oh thanks a lot x)  
I think i just have eyes problems xD
