I have two computers, a USB keyboard and a USB mouse. I want to build something that lets me switch the USB devices between the two computers. My approach would be to buy a new powered USB hub and plug the keyboard and the mouse into it. Then, I would use a microcontroller to control transistors for the DATA- and DATA+ lines to the two PCs (so four transistors total). I would just short all the GND wires (from the powered hub and the PCs) – that shouldn't do any harm, right? – and leave the +5V wires from the PCs unconnected. As far as I can see, that should work fine for switching.
However, how would the PCs (or the powered hub?) know when to do a new handshake and so on? Is it sufficient to have the +5V wire to the USB hub high by default and pull it to GND while switching? Would the USB hub initiate a handshake or something when its USB +5V wire goes up?
Also, how would the other PC find out that it has just lost the connection? By checking whether there's a voltage between Data+ and Data-?