Here is an old type KVM switch, PS/2 & VGA interface.
Top removed from the main body, the cables coming in from the bottom connect to the VGA, keyboard & mouse ports on the slave computers, the connectors at the top connect to the single monitor, keyboard & mouse.
PCB removed from the body. This is driven by a PIC16C57C-04 microcontroller.
The pair of LEDs indicate which computer is using the peripherals at any one time.
Top removed from the mouse, the ball fits in the gap in the centre. The slotted discs are visible which contact the ball & move relative to the surface the mouse is on.
PCB removed from the shell. Pairs of IR LEDs & Phototransistors make rotary encoders with the slotted discs. The microswitches read the mouse buttons & wheel.
IC in the centre interfaces with the PC over a PS/2 connection.