i don't know, where your problem is, but you should try this:
while(key_any) wait(1); //Wait until no key is pressed
while(!key_any) wait(1); //Wait until a key is pressed
If you write it like this, you can step through your code, but if you forget the first line, you get a break at the first line, but if you press any key, the code will run till its end