I use barrier on my raspberry pi, and have a keyboard shortcut to pick wich machine receives the keystrokes and mouse movement.
Additionally to this keyboard shortcut, I also need to click a button on my monitor since it can receive hdmi from multiple machines.
It works great, If I could get it done with only a keyboard shortcut, I would only pick this solution if it does not induce additional lag.