I use a software called Synergy.
https://symless.com/synergy
I have one keyboard and mouse connected to one "host" machine, and two machines connected as clients.
Sometimes if the host machine bogs a bit (like running a build or something) then the clients will have some latency but I've used this setup for gaming and work for two years and it's been pretty good.
My only complaint (about my personal setup, not the software) is that one machine has absolutely no peripherals attached to it aside from a monitor, so if I need to update the software, I need to connect a keyboard and mouse in order to do so.
Again, an issue with my setup and a caveat of using software as opposed to hardware.