A KVM switch switches a single setup of keyboard, video and mouse (or some other combination) between different host computers so that the same setup could be used to control either.
A KM switch is a simpler variant that connects only keyboard and mouse.
KVM switches are typically hardware boxes. Some KVM switches switch also audio. KM switches can also be implemented in software between networked computers.
USB ports and HID emulation
There are (in general) two different types of USB ports on KVM/KM switches. Different switches have only one of either type or ports of both types.
- "Hub port": The switch disconnects/connects ports when switching.
- Dedicated "mouse", "keyboard" or "HID port". The switch acts as USB host to keyboard and mouse, and as keyboards and mice to the host computers.
On many KVMs, dedicated HID/keyboard ports allow the KVM to switch hosts using a shortcut on the keyboard. In some cases these ports can help when there are problems in the communication in certain combinations of host and keyboard.
A switched USB port should work with more types of devices, but devices lose power when switching, and reconnect-events can cause annoying side-effects on the computers.
Some KM switches can switch by moving the mouse pointer over screen edges. This is more common on software KM switches.
Screen-edge switching is supported by a few hardware KVMs with emulated USB ports. These provide absolute coordinates to the host computers like a graphics tablet or touch screen. They require that the monitor setup and video resolutions be configured into the switch or else mouse precision could be inaccurate. Screen-edge switching does also not work with BIOS'es — because those require relative coordinates. Windows PCs that connect more than one monitor also require special mouse drivers. 
Software KM switch
Software KM switches are programs cooperating over a network. Typically, one set of keyboard and mouse are plugged into the "master" computer which controls the others. Networking and security options very between programs.
Unlike hardware KM switches's they often support copy/paste of text and images between computers. Some support even file transfer.
One popular software KM switch is Synergy, of which there are both proprietary and open source variants.
Logitech Flow is a hybrid software/wireless KM switch that works only with special wireless mice and keyboards from Logitech. The software is part of the driver package for Mac and PC. Rather than forwarding input from a master computer over the network, it switches which paired host that the Logitech peripherals should talk to over Bluetooth Low Energy or Unifying.
- KVM switch on Wikipedia (much more info than here)
- Belkin F1DN104K-3 F1DN108K-3 Custom Monitor Configuration Guide. Retrieved 2020-04-18
- Blackbox KV0004A Glide-and-Switch. (user manual) Retrieved 2020-04-18
- HowToGeek—How to Use Logitech Flow for Mice and Keyboards Across Multiple Computers. Dated 2017-08-01. Retrieved 2020-04-17