How can I make it so that if a button is held down it sends a text depending on the time it is pressed, so when I release it I don't send any more messages

How can I make it so that if a button is held down it sends a text depending on the time it is pressed, so when I release it I don't send any more messages