How to control Audacity from external application?

I would like to write a program (in C++) that starts record in Audacity. The idea is to set up the (digital controllable) analog source and start both at the same time, so the timing is right (I don’t mind a few ms, but pressing a hardware button and a software one simultaneously is annoying).
All I want is to start record in the current state of Audacity, nothing else. What is the best way to achieve that? Does any plug-in infrastructure provide that function?
Best regards

The “best” way is probably to use a different program for recording. For example, SoX

That is not a good solution, I need a software with GUI so the user sees what is going on. All I want is to send a signal to Audacity as if the record button was clicked.

Audacity is very much a GUI application. Interacting with it from another application is not simple.

One way that can work is to use a third party app such as AutoHotKey or AutoKey to emulate key/mouse actions.

The other method is to build Audacity from the source code and build the optional mod-script-pipe. See:

So I need an external tool to simulate a key press. It seems that xdotool / libxdo is the easiest. Only problem is to find out the ID of the window. Audacity seems to have 8 windows, and only one is the correct one…