I have this USB switch I use for exactly this case:
https://www.amazon.com/gp/product/B07FDNTS34/ref=ppx_yo_dt_b_asin_title_o00_s00?ie=UTF8&psc=1
I picked up this one because I wanted the wires to be hidden away under my desk and to be able to place the button to switch between devices near the front of my desk where I can reach it easily.
If you don't care about those things, here is a cheaper option that I've also used:
https://www.amazon.com/gp/product/B01N6GD9JO/ref=ppx_yo_dt_b_asin_title_o00_s00?ie=UTF8&psc=1
If using the first one on only 2 devices, you may find it helpful to connect 2 ports on it to each device, like this:
This way when you push the button to switch devices it'll always be 1 button press to get to the other device. Otherwise you'd have to press the button a few extra times to cycle through the unused ports. (and if it's hidden away, you can't see the lights to see which port is active)