# How can i move the right rectangle using the up and down keys

**URL:** https://discourse.processing.org/t/how-can-i-move-the-right-rectangle-using-the-up-and-down-keys/12201
**Category:** Coding Questions
**Created:** [June 20, 2019, 11:58am UTC](https://discourse.processing.org/t/how-can-i-move-the-right-rectangle-using-the-up-and-down-keys/12201 "2019-06-20T11:58:49Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![joey\_2002](https://avatars.discourse-cdn.com/v4/letter/j/43a26b/32.png) [@joey\_2002](https://discourse.processing.org/u/joey_2002)
#### Post date: [June 20, 2019, 11:58am UTC](https://discourse.processing.org/t/how-can-i-move-the-right-rectangle-using-the-up-and-down-keys/12201/1 "2019-06-20T11:58:49Z")

</div>

i’ve started like two days ago and i cant figure out how top move things using the keys.  
this is what i got so far a bit messy but it works.

```auto
 int x = 320;
 int y = 240;
 int dx = +10;
 int dy = -5;
 int rx = 600;
 int ry = 160;
 int lx = 40;

 
 
void setup(){
  size(640, 480);
}
void draw(){
background(0, 0, 0);
  ellipse(x, y, 50, 50);
  x = x + dx;
  y = y + dy;
  if(x +25 > width || x -25 < 0) {
     dx *= -1;
  }
  if(y +25 > height || y -25 < 0) {
    dy *= -1;
  }
  rect(rx, ry, 20, 160);
  rect(lx, y - 80, 20, 160);
}

```

---

<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: [June 20, 2019, 12:12pm UTC](https://discourse.processing.org/t/how-can-i-move-the-right-rectangle-using-the-up-and-down-keys/12201/2 "2019-06-20T12:12:37Z")

</div>

look at this example

[https://www.processing.org/reference/keyCode.html](https://www.processing.org/reference/keyCode.html)

and change your ly accordingly
