arecordmidi
First I got vmpk working with fluidsynth on the CLI or qsynth through ALSA as shown at: Virtual MIDI Piano Keyboard setup
Now, after doing that setup to hear the keyboard presses, I also run the following on another terminal:
arecordmidi --port 129:0 out.mid
where 129:0
is the vmpk output port found with aconnect -l
just as was used for the fluidsynth setup on the other linked answer.
Once arecordmidi
starts running, it immediately starts recording vmpk MIDI input to out.mid, until I do Ctrl+C to kill it. I can still hear the sounds at the same time from fluidsynth as before to know what I'm playing.
LMMS
LMMS was so incredibly easy to use for this purpose! After one hour of playing with I was able to record VMPK input through any of the synthesizer plugins it has (including e.g. ZynAddSubFX), and it can also record live while looping the other instruments!
All you have to to is launch vmpk, then on an instrument track (ZynAddSubFX in my case) I go:
- gear symbol
- MIDI
- input
- VMPK
This is also shown at: https://www.youtube.com/watch?v=NpeP2th08ak
Now I can already hear the Zyn sound coming from VMPK.
Then to record, there are two cryptic looking record buttons next to play on the corresponding Piano-Roll view:

The right one allows you to hear other instruments at the same time as you record your track.
Then there is a File > Export MIDI menu if you really want the MIDI.
But then I made the incredible discovery that LMMS also has its own virtual MIDI keyboard, with the default traditional ZSXDC bindings, so there isn't much point in using VMPK with it I think. When you click on the instrument, a keyboard for that instrument opens up, and then ZSXDC now play that instrument:

The only thing I could not find was how to change octaves with a keyboard shortcut as I can in VMPK, I could only move it by changing that small white square on top of the keyboard (the "base note"?) with my mouse: https://www.lmms.io/forum/viewtopic.php?p=63072
Ardour 5
This is another method I almost got working. And it is likely to be a much more realistic use case, as it allows you to play back the backing track while recording, and see live where your MIDI notes are landing.
First you have to get VMPK to feed into Ardour 5. As mentioned at: https://discourse.ardour.org/t/vmpk-not-showing-in-midi-routing-grid/103387 Ardour 6 will have its own built-in keyboard so that won't be needed anymore. But on 5 you need to do the following.
Set MIDI System to "ALSA sequencer" instead of the default "ALSA Raw devices". This can be done on a running project under:
or when starting to run a new session.
"Audio System" should also be set to ALSA of course as that is what we are using.

Once that is done:
- create a new MIDI track in ardour
- start running vmpk
and then go under:
you will see something like:

The key thing is that there is a "Hardware" tab. This is vmpk!
So now, you just have to click on the area where there is a green dot on the screenshot to create that connection (the dot is not present when you first open the window).
Once that is done, I can now hear and see soundwaves moving on Ardour when I touch vmpk keys!
So then just start recording in Ardour as you would for any other audio:
- hit record symbol on the MIDI track we created and where we will record to
- hit round red recording symbol on top (shift + r)
- start playing (space)
and as it plays, it will record vmpk keys and show them live in ardour, something like this:

so you se that my random notes were registered!
Now the only thing I haven't managed is to export the MIDI track! Not that it matters much I guess, since once inside Ardour, we generally have more desirable output options like .ogg, but still.
Tested on Ubuntu 20.04, I can't believe I'm wasting my life doing this stuff! :-)