That question has a very long, complicated answer! The short, non technical version is that it takes numerous inputs from lots of different sensors, and makes calculations based on these (either mechanically or electrically) to meter the correct amount of fuel for the desired power setting.
However, you really need to get a few technical books on the subject, as it covers chapters just looking at fuel control