How I built a keyboard/video/mouse switch for my two 4k monitors
In this technical retrospective (2020), @car shares practical architectural lessons learned from running, scaling, or migrating production software under lean constraints.
Core Principles for Independent Builders:
Defaulting to simpler architectures (such as monolithic frameworks, SQLite, or managed VPS) prevents early engineering bankruptcy.
Evaluating true compute and egress costs reveals that high cloud bills can often be slashed by 80%+ through judicious re-platforming.
Code you write at 2 AM as a solo engineer must be easy to debug six months later without complex microservice dependencies.
Community Debate Themes:
HN engineers debated the tradeoffs between cloud convenience and raw server economics, database indexing strategies, and resisting premature architectural complexity.
CATEGORY Frugal Engineering →
HISTORICAL ERA Pandemic Bubble (2020–2022)
COMMUNITY SCORE ★ 458 points
TOTAL DISCUSSIONS 228 comments
I hoped for the actual switch schematics :) .
Offtopic: I wanted to buy this USB switch, but it's hard to get on the current market in my country (or available for an absurd price). So I started trying to build my own... which was fun, but then I understood I need a some USB/MAX chips that are also hard to find, and started to cause me frustration instead of fun, because I'm not really that good with low-level electronics, university was a long time ago. And I was still without my switch/hub. So at the end I just chose a 3-pole double-throw toggle switch and a couple of USB connectors and wired them up. I only need to switch my keyboard, because my mouse is multi-device. If I need more, I'll just wire a hub to it. Work is in progress, but it can't get simpler than that.
If you're wondering what got complicated, well as far as I read and understood, actually breaking a USB connection with solid state logic is kind of a pain in the neck if you want to stay within the USB parameters, at least for an inexperienced designer like me. And you need to build the power supply for the circuit, and I didn't want to introduce an external power supply, I wanted to piggyback of the USB source. Something this ugreen product does not do. So I left this project for another time, when I freshen up on my perished knowledge. A mechanical switch just switches the lines and that's it.
Okay, let's talk about that USB switch [1], because I was looking for one a few days ago and discovered something ghastly about the majority of the ones available on Amazon:
Most of them use a USB Type-A to Type-A cable for the link between the switch and PC.
This cable violates the USB spec, and is the moral equivalent of an electrical cord with prongs on both ends. It should never, ever be made or used, because plugging one of the ends into the wrong receptacle can destroy both USB ports.
The correct cable to use here would be a standard Type-A to Type-B or Type-A to Micro-B cable, but for some reason a very small minority of these switches do that [2].
WTF is going on here?
[1] https://www.amazon.com/gp/product/B01N6GD9JO/
[2] https://www.amazon.com/gp/product/B083JKDNRJ/
While we're on the subject on KVMs, what do you guys do about audio?
Currently I have one computer connected to the AV receiver via TOSLINK (optical audio). The other computer is connected to the receiver via coaxial S/PDIF. When I switch computers I have to physically go to the receiver and switch between the two input channels. This presents two problems:
P1: Manual action required
P2: Only one computer can play sound at any given time
Ideally, I would want a S/PDIF mixer that can decode the two S/PDIF streams, add each constituent channel together, and then output that as a single S/PDIF stream to the receiver. But I can't seem to find this anywhere.
Most mixers I've found are:
1. Analog mixers
2. Pro audio mixing consoles that have a dozen input channels and 50 dials on it, with a price tag to match
Since working from home I've had the exact same use case. I thought a KVM would be perfect, but was really surprised that they are incredibly expensive and don't really seem very good anyway. It's odd because switching the keyboard/mouse seems easy, while switching the monitor inputs is something that is done by AVR receivers which can be found for less than a KVM.
I've resorted to having both machines plugged into my monitors and switching inputs using the monitor front panel. Not ideal. For the keyboard/mouse I currently just have two of each on my desk. Also not ideal, although I must admit it provides some semblance of work/life separation. I'm going to look into one of the software solutions for switching the keyboard/mouse.
I like it! Thank you for sharing the code!
By the way, I have that same USB switch. I have tried a number of them, and that is the fastest I've found. The only major flaw is the status lights -- they are too hard to see from far away.
To fix that issue, I drilled a hole in the top of the case, over the lights, about the same size as the adjacent power button. I put a small piece of foam inside to separate the two lights, and covered it with tape. It works perfectly now and it's so much easier to see the status from a typical usage angle.
The whole modification took maybe 15 minutes, and I didn't even bother disassembling it first.