how to add debounce code to pushingbox code

You change your code in setup() to

pinMode(KEY, INPUT);  
digitalWrite(KEY, HIGH);

this initializes the pin as an input with a 20k ohm internal pullup resistor. This holds the pin HIGH unless something acts upon it.
You connect the button from the pin to ground.

Thus, the pin is held HIGH until the button is pressed -- then it goes LOW.

I didn't read your code but find where you are reading the pin (be sure to check for LOW now, instead of HIGH) with the digitalRead() and then add delay(100) to wait 1/10th of a second and then check that it is still HIGH. That will usually be enough.