Virtual keyboard 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;