# How to stop the ball from moving when no key is beying pressed?

**URL:** <https://discourse.processing.org/t/how-to-stop-the-ball-from-moving-when-no-key-is-beying-pressed/32559>\
**Category:** Coding Questions\
**Created:** [October 2, 2021, 7:48am UTC](https://discourse.processing.org/t/how-to-stop-the-ball-from-moving-when-no-key-is-beying-pressed/32559 "2021-10-02T07:48:28Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![MoonAlien822](https://avatars.discourse-cdn.com/v4/letter/m/65b543/32.png) [@MoonAlien822](https://discourse.processing.org/u/MoonAlien822)\
**Post date:** [October 2, 2021, 7:48am UTC](https://discourse.processing.org/t/how-to-stop-the-ball-from-moving-when-no-key-is-beying-pressed/32559/1 "2021-10-02T07:48:28Z")

</div>

how to stop the ellipse from moving when no key is being pressed?

```auto
PImage shrek;
float charx=0;
float chary=0;
boolean invert= false;

void setup() {
  size(600, 500);
  shrek= loadImage("shrek.jpg");
  chary= height/2;
}
void draw() {
  background(0);
  color(255);

  ellipse(charx, chary, 50, 50);
  //invert colors
  if (invert==true) {
    filter(INVERT);
  }

  //move left with a
  if (key == 'a'&&invert==false) {
    charx=charx-10;
  } 

  //move right with d
  if (key == 'd'&&invert==false) {
    charx=charx+10;
  }

  //move right with a
  if (key == 'a'&&invert==true) {
    charx=charx+10;
  } 

  //move left with d
  if (key == 'd'&&invert==true) {
    charx=charx-10;
  }
}

```

---

<div class="post-metadata">

**Author:** ![jafal](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jafal/32/19112_2.png) [@jafal](https://discourse.processing.org/u/jafal)\
**Post date:** [October 2, 2021, 8:21am UTC](https://discourse.processing.org/t/how-to-stop-the-ball-from-moving-when-no-key-is-beying-pressed/32559/2 "2021-10-02T08:21:52Z")

</div>

Hi

For your previous code this example stop moving on one direction I am on Android I don’t have keyboard option

```auto

float charx=0;
float chary=0;

void setup() {
  size(600, 500);;
  chary= height/2;
}
void draw() {
  background(0);
  color(255);

  ellipse(charx, chary, 50, 50);
  
  filter(INVERT);
  
       //move left with a
     // if (key == 'a') {
       if (mousePressed == true) {
         
    charx=charx-0;
    
    //move right with d
   } else {
     
   
   
   charx=charx+10;
    }
}

```

Same idea you can use for other direction you need to make charx increase / decrease by zero when you press certain key to freeze the moving

---

<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:** [October 2, 2021, 8:36am UTC](https://discourse.processing.org/t/how-to-stop-the-ball-from-moving-when-no-key-is-beying-pressed/32559/3 "2021-10-02T08:36:38Z")

</div>

[studio.ProcessingTogether.com/sp/pad/export/ro.91tcpPtI9LrXp](http://studio.ProcessingTogether.com/sp/pad/export/ro.91tcpPtI9LrXp)

---

<div class="post-metadata">

**Author:** ![MoonAlien822](https://avatars.discourse-cdn.com/v4/letter/m/65b543/32.png) [@MoonAlien822](https://discourse.processing.org/u/MoonAlien822)\
**Post date:** [October 2, 2021, 11:49am UTC](https://discourse.processing.org/t/how-to-stop-the-ball-from-moving-when-no-key-is-beying-pressed/32559/5 "2021-10-02T11:49:03Z")

</div>

thank you, do you also happen to know how to turn of filters, is there maybe something like noFilter or filter(none)?

---

<div class="post-metadata">

**Author:** ![rapatski](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/rapatski/32/5164_2.png) [@rapatski](https://discourse.processing.org/u/rapatski)\
**Post date:** [October 3, 2021, 9:07pm UTC](https://discourse.processing.org/t/how-to-stop-the-ball-from-moving-when-no-key-is-beying-pressed/32559/6 "2021-10-03T21:07:24Z")

</div>

Umm… how about not calling filter()?

```auto
boolean doBlur = true;

void setup() {
  size(400, 400, P2D);
  frameRate(60);

  background(0);
}
void draw() {
  
  noStroke();
  
  fill(0, 5);
  rect(0, 0, width, height);
  
  fill(255, 0, 0);
  rect(mouseX, mouseY, width/4, height/4);
  
  if(doBlur)
    filter(BLUR);
}

void keyReleased()
{
  doBlur = !doBlur;
}

```
