General advise: don't use a while-loop for these things and don't use delay.
A simple solution might be to
- get rid of delay
- make the variable n a global variable and if another key is pressed, change n from 0 to 1 and test in algoritm.
To get rid of delay, you will have to implement algorithm as a finite state machine.
Your topic has been moved to a more suitable location on the forum. Installation and Troubleshooting is not for problems with (nor for advise on) your project
See About the IDE 1.x category.