Maybe, you should store the lastpressed key before the if(key_any) wait(), and also compare if its still the same. Because otherwise, when another key is pressed during wait, the previous key got lost, which is probably why your strings are crippled.