You should have a variable that keeps track of how many times the button has been pressed. Increase this variable every time the button is pressed. You can tell when the button is pressed with a signal.
Edit: wait you were looking for a key and not a button node. Okay in that case the concept is the same, just use an input()
function