Fighting Game

Hi. I want to know how to make a character punch when you press a ceratin key and if it is in range, take damage from another characters health bar. What I really need help with is the logic/code behind the attacking.