# The sketch crashes when I press some other key that isn't a letter or a number

**URL:** <https://discourse.processing.org/t/the-sketch-crashes-when-i-press-some-other-key-that-isnt-a-letter-or-a-number/31960>\
**Category:** Beginners\
**Created:** [August 26, 2021, 9:21pm UTC](https://discourse.processing.org/t/the-sketch-crashes-when-i-press-some-other-key-that-isnt-a-letter-or-a-number/31960 "2021-08-26T21:21:34Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![vinijoncrafts](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/vinijoncrafts/32/14306_2.png) [@vinijoncrafts](https://discourse.processing.org/u/vinijoncrafts)\
**Post date:** [August 26, 2021, 9:21pm UTC](https://discourse.processing.org/t/the-sketch-crashes-when-i-press-some-other-key-that-isnt-a-letter-or-a-number/31960/1 "2021-08-26T21:21:34Z")

</div>

If I press a key like shift, alt, caps lock, etc. the sketch crashes. How do I make this stop happening? Thanks for reading this 🙂 here’s the code:

```auto
float v = 5;
int x = 1920/2;
int y = 1080/2;
boolean [] keys = new boolean[128];

import java.awt.Robot;

Robot robot;

void setup () {
  size(600, 600);
  try {
    robot = new Robot();
  } 
  catch (Throwable e) {
  }
}

void draw() {
  if (keyPressed) {
    if (keys['w']) {
      y -= v;
    }

    if (keys['a']) {
      x -= v;
    }

    if (keys['s']) {
      y += v;
    }

    if (keys['d']) {
      x += v;
    }  
  }
  robot.mouseMove(x, y);
}

void keyPressed() {
  keys[key] = true;
}

void keyReleased() {
  keys[key] = false;
}

```

---

<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:** [August 26, 2021, 9:31pm UTC](https://discourse.processing.org/t/the-sketch-crashes-when-i-press-some-other-key-that-isnt-a-letter-or-a-number/31960/2 "2021-08-26T21:31:13Z")

</div>

> [@vinijoncrafts](#):
>
> `boolean [] keys = new boolean[128];`

You could pick a higher value than `128`:  
[Studio.ProcessingTogether.com/sp/pad/export/ro.9cfU11egvzT6G](http://Studio.ProcessingTogether.com/sp/pad/export/ro.9cfU11egvzT6G)

---

<div class="post-metadata">

**Author:** ![glv](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/glv/32/18785_2.png) [@glv](https://discourse.processing.org/u/glv)\
**Post date:** [August 26, 2021, 9:41pm UTC](https://discourse.processing.org/t/the-sketch-crashes-when-i-press-some-other-key-that-isnt-a-letter-or-a-number/31960/3 "2021-08-26T21:41:15Z")

</div>

Hello,

Try this:

```auto
boolean [] keys = new boolean[128];

void setup() {
}

void draw() {
}

void keyPressed() {
  println(key, int(key));
  if(key<128)
    keys[key] = true;
}

void keyReleased() {
  println(key, int(key));
  if (key<128) 
    keys[key] = false;
}

```

I added some` println()` statements to help you understand what is happening

`:)`

---

<div class="post-metadata">

**Author:** ![vinijoncrafts](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/vinijoncrafts/32/14306_2.png) [@vinijoncrafts](https://discourse.processing.org/u/vinijoncrafts)\
**Post date:** [January 2, 2023, 11:12pm UTC](https://discourse.processing.org/t/the-sketch-crashes-when-i-press-some-other-key-that-isnt-a-letter-or-a-number/31960/4 "2023-01-02T23:12:23Z")

</div>

thanks that’s it! Sorry for late response, I just didn’t continue what I was doing, but now that I searched about the same problem I saw my question and then your awnser, and it also worked for that different situation! thanks!
