It is possible that some monitors may implement HDMI control of which input is selected and that could be triggered from software via the CEC, part of the HDMI standard, command set - often called something different in each vendors documentation - this does have a couple of issues:
- Not all vendors implement it all properly
- Once you switch to VGA your monitor(s) may not listen to the HDMI port for some or any commands.
- The level of support for it in graphics cards is variable to poor so depending on your graphics card you may need a USB to CEC adapter, they do exist, that allow a computer to control CEC-enabled devices.
There are some libraries that allow you to send CEC commands, once you have some appropriate hardware, such as the dual licensed libCEC. This comes with C++, C and .NET interfaces, and a CLI utility called cec-client.
Disclaimer: I have nothing to do with any of the vendors, or suppliers, mentioned and have not tested to see if your specific use case is fully/partly/un-supported.