Buttonbox leonardo keyboard

Under what circumstances should the Arduino press the 'P'?

It should be pretty obvious what you need to change.