When you are close enough to your enemy you will automatically use a melee attack with your currently held weapon instead of firing it.