Not so sure this would help. First of all, guns would have to be in a lock box, probably also having a trigger lock.
Then the ammunition would have to be stored separately, in another lock box. It would require TWO pilots to turn their lockbox keys at exactly the right moment to open.
Then they would have to check the manual, explaining the correct procedure for loading and firing the weapon.
No offence to pilots, these would be FAA regulations.
Look up TSA holster. They forced the pilots to secure the gun with a padlock, thru the trigger guard whil not in the locked cockpit, and wondered why they had holes in the side of planes.