Virtual keyboard problem

google translate…
hi, I have a strange problem with entering characters with the virtual keyboard,
when I use uppercase, before the desired character an unknown character is inserted, square with an X inside
I tried everything, I changed tablet, updated sdk, updated android, updated processing but the problem remained.
Thanks for your help

String msg="";
boolean keyboard = false;
void setup() {
  fullScreen();
  textFont(createFont("SansSerif", 40 * displayDensity));
  fill(0);
}    
void draw() {
  background(255);
  text(msg,20, height/2);
}
void keyPressed() {
  background(200, 50, 30);  
msg+=key;
}
void mousePressed() {
  if (!keyboard) {
    openKeyboard();
    keyboard = true;
  } else {
    closeKeyboard();
    keyboard = false;
  }
}

only play on PC / win 10 / processing 3.5.4.

String msg="";

void setup() {
  size(200, 200);
  fill(0);
}    

void draw() {
  background(255);
  text(msg, 20, height/2);
}

void keyPressed() {
  if ( key == CODED ) {
    //println(key, keyCode);
  } else {
    msg+=key;
  }
}

Hi @camperos, welcome to the forum.
It’s obviously a bug.
My workaround is

If (key != '') msg += key;

What are you planning. If it is an edit box you are better of with an android java edit box. For instance If you want to use a back space you can do so by keeping track of the textWidth of each character and blank it out with a rect. There are other problems making it difficult. If you want a code for an android java edit box I can post it. Just let me know.

Edit: In code above the “notdef” character is not printed.

1 Like

thanks to all but it didn’t work, there are always “notdef” characters, i don’t want them

I typed:
asdQWERTY

Might be you need to use getchar() instead I remember getting a similar problem when coding a basic textbox.

Are you sure you put this “notdef” character between the single quotes in my code above? It solves the problem on all my devices. What android version are you using, and on what device.?

Image 1

the “notdef” (unwanted) is this how can I insert it?
ï¿¿

android 6.0.1

but with a notepad with different android version same problem

Edited
A “notdef” character is a square with a x in it.
Now I see that you have other characters.
What language is your device(keyboard)?
Try:

 if(key != "ï¿¿") msg += key;

Could you elaborate?
Something like

String   str = getChar(keyCode);

is undefined.

my bad, just use str(key)

It’s also in processing when you don’t check against CODED

It’s the shift key

@Chrisir, @camperos , Yes, it s the shitft key, but with android it is not coded as ==SHIFT; it is coded with= 59 and i think , like noel, that you have to create an edit text (android snippet) and add some keyEyEventListener(); i would try that ASAP, and tell you.

Or check against CODED ? Or against keyCode==59 ?

with your suggestions I think I have solved it, now I have to try sending the text to arduino

//String notDef="ï¿¿";
String msg="";
String msg1="";
boolean keyboard = false;
void setup() {
  fullScreen();
  textFont(createFont("SansSerif", 40 * displayDensity));
  fill(0);
}    
void draw() {
  background(255);
  text(msg, 20, height/2);
}
void keyPressed() {
  background(200, 50, 30);  
// msg+=str(key);
if (keyCode==SHIFT)
  {
    msg1+=key;
  } else {
    msg+=key;
  }
    println(msg);
}
void mousePressed() {
  if (!keyboard) {
    openKeyboard();
    keyboard = true;
  } else {
    closeKeyboard();
    keyboard = false;
  }
}

I did it … but it is not clear to me why if in the IF I put msg1, it becomes correct msg.
thank you all :grin:

1 Like

@camperos ===
you dont need your mess1, which stores the shift modifier event, which is useless;
As for your question that is easy to understand: Shift is a key event that you can capture but it s not a char and if you ask to draw it you get what you have said…I would add that the problem (and the result) is the same for keyEvents of the same kind, like “delete”

So in a more simple way:

void keyPressed() {
  background(200, 50, 30); 
  if(keyCode!=SHIFT){
msg+=key;
  }
}
1 Like

perfect thanks.
to complete, even if I don’t currently need it, the “backspace” button also has problems,
I forgot to mention that my sketch is based on an official example.
https://android.processing.org/reference/keyboard/virtual.html