The secret is in the eyes of the fly. But how?
Our eyes send 70 still images to our brain every second then the brain combines them and shows us the moving world. But a fly's eye sends 250 flash / images to its brain every second. When the fly's brain makes them move, it actually sees everything much slower than we do, which we call slow motion.
When we go to kill a fly we attack the fly in less than a second. Now that we see 60 frames per second, our task seems much faster to us, but to the fly, our task seems much slower. So long before we hit the flies, they can fly away.
Mosquitoes do not have this special ability like flies that is why they cannot fly so easily, that is why it is easy to kill mosquitoes but it is so difficult to kill flies.