Problem with backspace key

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

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

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.

1 Like

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

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 ();
}

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.

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

2 Likes

yes maybe because there is a multi choices for keyboard

1 Like