Keyboard write Issue

Your loop happens many times before you can release the button.
You need to check the state of the button and compare it to a previous state to differentiate between when the button just became pressed vs when it is being held down.