Let me try to describe the whole picture:
The input of MIDI track in Sonar can either be
ONE device or
ALL devices (Omni). But not some subset of them.
Input MIDI is transfered to VST in case "Input Echo" is set. By default, it is in "Automatic" mode, so Echo is active on focused track and deactivated on all other. But Echo can be switched to "Always active" easily.
If we have E-Drum and 2 keyboards and we want control Drum VST and E-Piano VST.
1) if we play/record only one of these VSTs per time, we can set all tracks input to Omni and leave Echo in automatic mode. The data from all 3 MIDI sources goes to focused track (the result is recorded into one clip, independent from the device). We change the VST we control by moving focus (as already mentioned by keyboard, but also by mouse or with Control Surface plug-in by any particular (MIDI) keyboard key, controller or drum pad).
2) if we want control Drum VST by E-Drum and E-Piano VST by 2 MIDI keyboards
simultaneously, we can not use Omni on
ANY track since this track will use ALL devices than. So we need 3 tracks, one with E-Drum (only!) as the input and 2 for each MIDI keyboards with related Inputs (note that Global Omni is not the same as Device Omni, the last just means all MIDI channels from one device while the first means all devices). We also should force "Input Echo" always active for all 3 tracks. We set output from the first stack to the Drum VST and outputs from the second and the third tracks to E-Piano VST.
When recording there will be 2 separate tracks for E-Piano. It is possible to see them both in the PRV or just merge them (by MIDI bouncing the track with all (also overlapped) MIDI clips).
Note: when using Omni inputs, check that your VSTs have no "MIDI Output" enabled. VST MIDI Outputs are valid MIDI track inputs, so they can "leak" into Omny tracks! Example: if E-Piano VST has "MIDI Output" active and we use approach 1 (with Omni inputs). Initially everything is fine. But once we have recorded E-Piano and have switched the focus to the Drum track, E-Piano MIDI track data can leak throw E-Piano VST to our Drum track.That does not happened all the time, since most VSTs are not sending MIDI on the output, even when it is enabled. But once you get the effect, it is confusing.