# How to press space key to toggle doubling the size of the rectangle?

**URL:** <https://discourse.processing.org/t/how-to-press-space-key-to-toggle-doubling-the-size-of-the-rectangle/7746>\
**Category:** Coding Questions\
**Created:** [January 22, 2019, 6:26pm UTC](https://discourse.processing.org/t/how-to-press-space-key-to-toggle-doubling-the-size-of-the-rectangle/7746 "2019-01-22T18:26:33Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![dxh188](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/dxh188/32/3365_2.png) [@dxh188](https://discourse.processing.org/u/dxh188)\
**Post date:** [January 22, 2019, 6:26pm UTC](https://discourse.processing.org/t/how-to-press-space-key-to-toggle-doubling-the-size-of-the-rectangle/7746/1 "2019-01-22T18:26:33Z")

</div>

```
        float x = 400, y=100;
      int a=20,b=10;
      void setup() { size(800, 200); }
      void draw() {
      rect(x-10, y-5, a, b);
      }
      void keyPressed() {
        int k=' ';
      if (keyCode == RIGHT) {
      x++;
      } else if (keyCode == LEFT) {
      x--;
      } else if (keyCode == UP){
        y--;
      } else if (keyCode == DOWN){
        y++;
      }else if(key=' '){
       a=a*2;
       b=b*2;
        }
      }

```

* * *

* * *

Can you teach for me how to press space key you toggle by doubling the size of the rectangle, 1 time, 2 times, 1 time?

---

<div class="post-metadata">

**Author:** ![Kevin](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kevin/32/2297_2.png) [@Kevin](https://discourse.processing.org/u/Kevin)\
**Post date:** [January 22, 2019, 6:38pm UTC](https://discourse.processing.org/t/how-to-press-space-key-to-toggle-doubling-the-size-of-the-rectangle/7746/2 "2019-01-22T18:38:23Z")

</div>

If you post your question to multiple sites, please link between those posts so we know what help you’ve already received.

This question has already been asked (and answered) here:

> <https://stackoverflow.com/questions/54310184/how-to-press-space-key-to-toggle-doubling-the-size-of-the-rectangle>
