# Move with keyboard arrows

**URL:** https://discourse.processing.org/t/move-with-keyboard-arrows/21637
**Category:** Coding Questions
**Created:** [June 7, 2020, 2:01am UTC](https://discourse.processing.org/t/move-with-keyboard-arrows/21637 "2020-06-07T02:01:50Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![bismarck](https://avatars.discourse-cdn.com/v4/letter/b/c67d28/32.png) [@bismarck](https://discourse.processing.org/u/bismarck)
#### Post date: [June 7, 2020, 2:01am UTC](https://discourse.processing.org/t/move-with-keyboard-arrows/21637/1 "2020-06-07T02:01:50Z")

</div>

hello i am new here,i need help with this code because the thing that i try to move don’t do that, but if i leave one of the if/else statement the code run without problems.  
can you help me?  
(sorry for the bad english)

```auto
if (key == CODED) {
if (keyCode == UP) {
location.y--;
}else if (keyCode == DOWN) {
location.y++;
}else if (keyCode == RIGHT) {
location.x++;
}else{
location.x--;
}
}

```

---

<div class="post-metadata">

### Author: ![josephh](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/josephh/32/210_2.png) [@josephh](https://discourse.processing.org/u/josephh)
#### Post date: [June 7, 2020, 8:11am UTC](https://discourse.processing.org/t/move-with-keyboard-arrows/21637/2 "2020-06-07T08:11:32Z")

</div>

Hi,

Welcome to the community! 🙂

Remember that you can press `Ctrl+T` in the Processing IDE to format your code (correct indentation).

I just tested your code and it seems to work fine, I didn’t understand your problem :

```auto
// The location of the player
PVector location;

// The speed of the player
int speed = 5;

void setup() {
  size(500, 500);
  
  // Initialize the location in the middle of the window
  location = new PVector(width/2, height/2);
}

void draw() {
  background(255);
  
  // Fill red
  fill(255, 0, 0);
  
  // Draw the ellipse at that location
  ellipse(location.x, location.y, 50, 50);
}

void keyPressed() {
  // Handle arrow keys
  if (key == CODED) {
    if (keyCode == UP) {
      location.y -= speed;
    } else if (keyCode == DOWN) {
      location.y += speed;
    } else if (keyCode == RIGHT) {
      location.x += speed;
    } else if (keyCode == LEFT) {
      location.x -= speed;
    }
  }
}

```

![arrow_ball](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/1/1d00b328232c2faf83158d5f77798a1ff0e44a90.gif)

---

<div class="post-metadata">

### Author: ![bismarck](https://avatars.discourse-cdn.com/v4/letter/b/c67d28/32.png) [@bismarck](https://discourse.processing.org/u/bismarck)
#### Post date: [June 7, 2020, 12:37pm UTC](https://discourse.processing.org/t/move-with-keyboard-arrows/21637/3 "2020-06-07T12:37:46Z")

</div>

thank you for the help, i have found the problem is that i have forget to add a variable speed
