The right tool for the job can often make things very much easier. A KVM switch is ideal for switching quickly between two or more computers whilst using the same peripheral devices.
But also consider whether you otherwise need a multiviewer instead. A multiviewer is used more when you want to display maybe some extra external video on your screen in a split view or picture-in-picture mode. An example is you maybe want to always keep an eye on your security camera. It really allows additional HDMI video signals on one display.
See https://www.xda-developers.com/kvm-switch-must-for-dual-pc-setups/