in your original code, replace while(1) with if(key_space) and visa versa