# Problem with backspace key

**URL:** <https://discourse.processing.org/t/problem-with-backspace-key/29393>\
**Category:** Processing for Android\
**Created:** [April 15, 2021, 9:11pm UTC](https://discourse.processing.org/t/problem-with-backspace-key/29393 "2021-04-15T21:11:20Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![dinoelectro](https://avatars.discourse-cdn.com/v4/letter/d/97f17d/32.png) [@dinoelectro](https://discourse.processing.org/u/dinoelectro)\
**Post date:** [April 15, 2021, 9:11pm UTC](https://discourse.processing.org/t/problem-with-backspace-key/29393/1 "2021-04-15T21:11:20Z")

</div>

hello, i need your help!

I was experimenting with the code, but found a problem

for example if I type 5 letters, I need to press the backspace key six times to just delete a character

for example if I type 10 letters, I need to press the backspace key eleven times to just delete a character

and so on etc

```auto
String t = "abcde";

void setup() {
  textSize(60);
  textAlign (CENTER);
  fill (0);
}

void draw () {
  background (255);
  text (t, width/2, height/2);
}

void keyPressed() {
  if (keyCode == 67) { //backspace
    if (t.length() > 0) t = t.substring(0, max(0, t.length()-1));
  } else {
    if (key > 31 && key < 127 && t.length() < 10) {  
      t += key;
    }
  }
}

void mousePressed () {
  openKeyboard ();
}

```

in java mode the code works fine, but in android mode the problem appears

---

<div class="post-metadata">

**Author:** ![MPROCD](https://avatars.discourse-cdn.com/v4/letter/m/51bf81/32.png) [@MPROCD](https://discourse.processing.org/u/MPROCD)\
**Post date:** [April 20, 2021, 10:12am UTC](https://discourse.processing.org/t/problem-with-backspace-key/29393/2 "2021-04-20T10:12:32Z")

</div>

Your sketch works fine in Android. Just be aware it will not work in JAVA, where the key Code for Backspace is 8 instead of 67.

---

<div class="post-metadata">

**Author:** ![dinoelectro](https://avatars.discourse-cdn.com/v4/letter/d/97f17d/32.png) [@dinoelectro](https://discourse.processing.org/u/dinoelectro)\
**Post date:** [April 29, 2021, 12:33pm UTC](https://discourse.processing.org/t/problem-with-backspace-key/29393/3 "2021-04-29T12:33:00Z")

</div>

hello, friend thanks for your help, I made the following change in my code, instead of writing  
keyCode == 67  
wrote:  
keyCode == BACKSPACE  
but the problem persists

```auto
String t = "abcde";

void setup() {
  textSize(60);
  textAlign (CENTER);
  fill (0);
}

void draw () {
  background (255);
  text (t, width/2, height/2);
}

void keyPressed() {
  if (keyCode == BACKSPACE) { //backspace
    if (t.length() > 0) t = t.substring(0, max(0, t.length()-1));
  } else {
    if (key > 31 && key < 127 && t.length() < 10) {  
      t += key;
    }
  }
}

void mousePressed () {
  openKeyboard ();
}

```

---

<div class="post-metadata">

**Author:** ![dinoelectro](https://avatars.discourse-cdn.com/v4/letter/d/97f17d/32.png) [@dinoelectro](https://discourse.processing.org/u/dinoelectro)\
**Post date:** [April 29, 2021, 1:03pm UTC](https://discourse.processing.org/t/problem-with-backspace-key/29393/4 "2021-04-29T13:03:21Z")

</div>

apparently this problem occurs in huawei devices but in sansung it works fine, Thanks to Noel, he gave me the solution, install Hacker’s keyboard from google play. but I would like to find a more elegant solution.

---

<div class="post-metadata">

**Author:** ![paulgoux](https://avatars.discourse-cdn.com/v4/letter/p/b9bd4f/32.png) [@paulgoux](https://discourse.processing.org/u/paulgoux)\
**Post date:** [April 29, 2021, 2:02pm UTC](https://discourse.processing.org/t/problem-with-backspace-key/29393/5 "2021-04-29T14:02:05Z")

</div>

Have you checked to see the value of the keycode? It might be that it doesnt match the sketch variables.

---

<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:** [April 29, 2021, 3:45pm UTC](https://discourse.processing.org/t/problem-with-backspace-key/29393/6 "2021-04-29T15:45:30Z")

</div>

> [@paulgoux](#):
>
> Have you checked to see the value of the keycode? It might be that it doesnt match the sketch variables.

yes maybe because there is a multi choices for keyboard
