Dual purpose guns will always automatically cause their damage to in range airtargets as long as you do not have AA turned off, they cause their damage even if you are using the guns on a surface target at the same time.
All your guns could be pointed north and firing at a surface target and an air target approaching from the south would still take the appropriate damage when in range assuming again that you have not used the P key to turn the AA off.