[HN Gopher] How I built a keyboard/video/mouse switch for my two... ___________________________________________________________________ How I built a keyboard/video/mouse switch for my two 4k monitors Author : car Score : 165 points Date : 2020-09-02 19:56 UTC (3 hours ago) (HTM) web link (haim.dev) (TXT) w3m dump (haim.dev) | yfiapo wrote: | That's cool. As another alternative, this is the one I bought at | start of lockdown which does everything but the USB-C: | https://smile.amazon.com/gp/product/B0851CMHP2/ | | Not particularly cheap but at least no longer back-ordered. I've | been pretty happy with it switching 2x4K monitors, keyboard and | mouse between a Mac and a PC laptop. Both corporate laptops where | custom software is more difficult. | dkersten wrote: | Hah, I use a low tech solution: I have a HDMI extension cable | that reaches the front of the monitor that I just plug the device | I want active into (and a usb splitter similar to what he uses | for keyboard and mouse). It's not quite as seamless as the | solution described here but it took no time to set up. | evanweaver wrote: | You can get a physical HDMI button so you don't even have to | unplug anything: https://www.amazon.com/gp/product/B01L8LLP2G/ | pstrateman wrote: | "4Kx2K@30hz resolution" | | The issue is 4k@60. | dkersten wrote: | Yeah, I did use a switcher before I upgraded my resolution. | Yetanfou wrote: | I have another solution to the same problem using a monitor | which has both HDMI and DVI. The HDMI port is used for the | 'main' machine which the DVI is connected through a DVI-HDMI | connector to any secondary machine which I may want to connect. | Switching between the two is either automatic - when there is | no signal on the DVI input - or through the monitor source | selector. The monitor also has a few analog inputs which I have | used on occasion with older laptops, extending the scheme even | further. Of course this only switches the monitor, not the | keyboard so it is not a complete replacement for a KVM switch. | hinkley wrote: | If you get some short extension cables, then most of the wear | will be on the cable instead of your devices. | dkersten wrote: | That's basically what I have: extension cable from monitor to | front of monitor and HDMI cable from device to extension | cable. So worst case is I have to replace either the | extension cable or the HDMI cable. Either way, no biggy. I | guess I wasn't clear that when I said "I plug my devices in", | I meant a HDMI cable that then stretches to the actual | devices, so they don't need to be at the monitor (eg my PS4). | nkrisc wrote: | This is perfect. The software competent is exactly what I was | missing from my setup. I use a USB switch to switch my | peripherals but I've been manually changing the input on my | monitor like a caveman. | joshu wrote: | I use the IOGear switch between windows/pc and like 1/5 times it | doesn't switch correctly (it'll end up holding the option key | down or something.) | | are there any keyboard switches that emulate a keyboard correctly | instead of just unplugging and replugging the usb connection? | duskwuff wrote: | > are there any keyboard switches that emulate a keyboard | correctly instead of just unplugging and replugging the usb | connection? | | StarTech's KVMs have a rather robust USB stack which handles | this situation very well. | joshu wrote: | thank you! any particular products you have experience with? | zerkten wrote: | I've given up finding a KVM that has this support for | emulation. I've got a Kinesis Freestyle Edge RGB and even for | the better ConnectPRO KVMs, there are just too many USB | endpoints. | | I found that X-Keys make a range of keypads that are | specifically designed for KVMs. I have it setup for KVM | switching and the remaining keys have other macros. I'm glad I | got it, but it's expensive compared to DIY kits. | AntiRush wrote: | This is awesome! | | I've often dreamed about doing this with a keyboard shortcut ala | switching layouts in a tiling WM (or 'real' kvm switches from the | CRT + ps2 era). | | Is there a good usb hub that supports switching outputs via | software? | bertjk wrote: | Some of the IOGear KVMs do provide hotkey functionality. | TehCorwiz wrote: | This would probably work great for running VMs with a hardware | pass-through GPU. Can't wait to try this out. | aloer wrote: | I recently bought a Philips 346b1c (34" UWQHD with built-in USB C | hub + KVM) and the use of DDC/CI to tell the monitor what input | to switch to could come in super handy here. | | The display is very good at automatically switching KVM based on | the selected input, but the selection still has to be done with | the little buttons underneath the screen | dasloop wrote: | I have an MX Keys keyboard that can connect to up to three | devices (with three special keys). Unfortunately, the operating | system does not see the key pressed. But if it was, I could | activate the display input switching using your app (thanks!). I | have filled a support request at Logitech, maybe one day... | OJFord wrote: | Are other keys (e.g. Fn) mappable to the special keys? Maybe | you could work around it by setting e.g. F1-3 to F1-3 + | Special1-3, and then input switching on F1-3. | [deleted] | dugmartin wrote: | I use a combination of a cheap USB switch and the remote for my | 4K monitor (really a 43" TV) to switch inputs. Not as nice as one | button press but much cheaper than a high end KVM. | NKosmatos wrote: | Reminds me of a similar post in HN in order to switch inputs on a | single monitor, between mac and PC, via software only. Ideally a | shortcut on the mac desktop in order to switch to HDMI and | another shortcut on the PC desktop to switch to DisplayPort. For | sure I'm going to give a go at the code of this soft/hard KVM. | doctorhandshake wrote: | There was a comment here yesterday[1] about DDC/CI writes being | finite on some hardware -- is that a concern with this approach? | | [1] top comment - https://news.ycombinator.com/item?id=24344045 | justaguy88 wrote: | for those who have less time than money, | https://store.level1techs.com/?category=Hardware | D13Fd wrote: | Both of the KVMs meeting his criteria on that page are sold out | (and one is a pre-order as well as being sold out). | vaillancourtmax wrote: | Neat! | | I use a similar setup where I literally have a single USB cable | that gives me access to everything: monitor, keyboard, mouse, | lighting, camera, microphone. | | I just need to plug the cable in the computer I want to use. | However, I do need to change the input on the monitor as one of | the them is connected via HDMI. | harikb wrote: | You must in the USBC world! | D13Fd wrote: | 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. | haimgel wrote: | This is an interesting hack, thanks for sharing! I agree the | status lights are hard to see... | Bloggerzune wrote: | https://www.bloggerzune.com/2020/06/make-money-online-withou... | How to make money online without investment in home,earn Money on | blogging, earn Money on Fiverr,make money writing online,How can | I make money online fast and easy without investment,how to earn | money online without paying anything. | Havoc wrote: | > I wrote some software. | | And my heart sank. | | Zero chance of getting that past corporate laptops that are way | too locked down for actual code anything beyond VBA | smabie wrote: | Then just have corporate buy you a real KVM switch? | mercora wrote: | ive done the same on Linux using udev rules and a simple usb | switch. i use it for a VM with a physical GPU attached and it | worked great ever since. | zwayhowder wrote: | To paraphrase the internet. Sample configs or it didn't happen! | | Seriously, I'd love to see this. I have had mixed results with | udev and no idea where to start to send an input switch command | to my monitor. | Splendor wrote: | Very cool. Will this only work over HDMI? | moolcool wrote: | I imagine it will work on any input your display supports | salex89 wrote: | 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. | mandeepj wrote: | I was searching for it couple weeks ago. The cheapest KVM for two | monitors at ebay starts from $80. So, good job. | brian_herman wrote: | https://store.level1techs.com/products/kvm-switch-dual-monit... A | little more expensive. But gets the job done! | bijant wrote: | The Headline hit me right in the stomach because it was just | yesterday that I was pondering whether to build or to order a USB | Switch. With much to do currently, I wussed out and just ordered | it. I didnt pay 38$ though: | https://de.aliexpress.com/item/1005001274095928.html USB 2 is | more than enough for mouse and keyboard and it has the additional | advantage of having an extension button to switch. | mmsimanga wrote: | I have similar setup without the software to automatically switch | inputs. I use the physical buttons on the monitor to switch | input. Not efficient but I get a better resolution than pushing | display through a cheap KVM switch. Will be trying software in | article. Anyone know of software that runs on Linux to switch | display the input? OP lists Windows and Mac OS support. | pedrocr wrote: | In Linux you can probably do it with a script that calls | ddcutil: | | http://www.ddcutil.com/ | haram_masala wrote: | https://www.amazon.com/gp/aw/d/B0817YFJKW | | $60 shipped. | D13Fd wrote: | That's USB 2 and one monitor. He is looking for USB 3. | | Also, I can tell you it's harder than you'd think to find good | hardware in this area, so I don't think the software effort is | wasted. | hbcondo714 wrote: | Interesting image descriptions. The 6th one says "Suport | operate system" with a Windows 7, 8 and Vista icons. | vxNsr wrote: | that's one monitor | jen20 wrote: | This fails at two criteria presented in the second paragraph: | | - it only supports one 4K monitor, not two, | | - it doesn't support USB-C. | m0shen wrote: | This is great! I did something very similar using AutoHotKey and | Synergy : https://moshen.net/posts/virtual_kvm/ | D13Fd wrote: | That looks nice! But there are two downsides: | | - Your solution requires Synergy. In my experience, Synergy has | been buggy--or at least extremely finicky--every time I've | tried it since release circa 2001. When it comes to input | devices, I want things to be basically flawless. So I like this | very simple fix better. | | - The posted solution is cross-platform between Mac and | Windows, which is a common use case. Yours relies on | Autohotkey, which is awesome on Windows but, last I checked, | terrible on Mac OS. | kitsunesoba wrote: | The other thing about Synergy is that it's a bit of a | question mark in terms of security, even with encryption | enabled (at least that I've seen -- would be happy to be | corrected!) | m0shen wrote: | Yeah, fair points. Every now and then I have to stop/start | Synergy for it to work. Since my mouse/keyboard remain | connected to my Windows machine, it can act as the "server" | and issue the DCC to the monitor to switch when my key combo | is hit. So I only ever run it on the Windows box. | zachrose wrote: | Would somebody like to help me understand why KVM switches are so | sophisticated? A DisplayPort cable has 20 pins, so why can't it | just be a 20 pole switch? (Or 30 pole for two USBs and a | headphone jack, etc.) | formerly_proven wrote: | Using a literal switch or multiplexer would have the link | disappear, so switching causes ~5-10 seconds of delay, assuming | the machine doesn't crash or hang because somehow that's okay | behavior for computers in 2020...?! | | Additionally: The DisplayPort spec mandates that operating | systems have to throw a huge temper tantrum and garble your | desktop and windows when you disconnect or turn off a display. | (Yes, nVidia and Microsoft consistently deny implementing an | option to turn this utterly braindead behavior off, saying that | it's not a bug, but intended behavior because DisplayPort and | VESA say so). | | What KVMs instead contain is similar to the rescaler ASICs | found in a monitor, they receive multiple streams of display | data and mix/forward/scale one of these. But since they | constantly receive all of the streams, switching can be | instant, or at least as quick the monitor can modeswitch | (which, for some reason, takes screens at least a second). | JoshTriplett wrote: | Can you provide more information about the details of | DisplayPort you're referring to, and what actual spec- | required behavior you're referencing? | stonogo wrote: | In addition to the signal issues outlined in sibling comments, | a good KVM switch presents the HID devices full-time, so | instead of the computers seeing USB disconnect/reconnects, they | don't see any difference at all. This requires a complete USB | implementation including HID protocols and something to | translate real-keyboard and real-mouse signals into the virtual | USB devices. | | There are similar considerations regarding DDC passthrough on | monitors for resolution negotiation and so forth. | | A bad KVM presents to the computer as though the user is | disconnecting all the input devices and the monitors every time | you switch. These are indeed much simpler and cheaper devices | but they cause all kinds of quality-of-life issues when you use | them regularly. | comboy wrote: | I have one of those bad KVM switches. How do I know which one | to buy to have a good one? | formerly_proven wrote: | Level1 sells KVM switches that are said to be quite good | for their money. | zachrose wrote: | Definitely didn't imagine that KVM switches could actually be | that good when I asked the question. (I've obviously never | used one.) Thanks! | modeless wrote: | Why shouldn't a computer be able to handle reconnection of | peripherals without quality of life issues? It's pretty silly | if this pure software issue is the reason KVM hardware has to | be so complex and expensive. | qppo wrote: | To be honest it probably comes down to being a non trivial | problem to get it to be perceptually seamless and a rare | enough event that people don't have the incentive to fix | it. | | Most people aren't plugging/unplugging monitors often | stonogo wrote: | Some peripherals require configuration after connection. | Waiting for this can suck. I'm including monitors here -- a | bad implementation will present, as an example, monitors | out of order. Another problem you run into is inadvertently | cycling through connections too quickly, which can show as | devices being disconnected during initialization, causing | some systems to flag the device as malfunctioning and | refuse to initialize it next connection. | | Of course it's easy to say that these are silly problems | that should have pure software fixes, but Microsoft and | Apple don't exactly accept patches. Let's not pretend that | software is optimal. | aetch wrote: | You can see for yourself by disconnecting your monitor in a | multi monitor setup or opening your laptop lid if you use | the laptop on a dock. Computer windowing systems seem to | take a moment to reposition all the windows and might not | remember to redistribute your windows when the monitor | count changes. | formerly_proven wrote: | For many years I was happy with my multi-monitor setups. | I'd use multiple screens for work, and turn all off | except the center one for watching movies or playing | games (because the backlight bleeding of the other | screens was annoying, even with a 100 % black image). | | That's not possible any more. Microsoft, VESA, nVidia say | no. This mustn't be possible. (Actually it used to be | possible to add a registry key in Windows 7 that disabled | all of this bullshit, but Microsoft wisely decided in | Windows 10 to remove that. It must not be done.) | | Turning _compliant_ DisplayPort devices off while using a | _compliant_ operating system must always garble all | windows and shuffle desktop icons around. The spec says | so. So it must be. The will of the ancients. | | (nVidia will allow you to turn this off, _if_ you are | using a Quadro card - then you can use EDID emulation | even on display-ports, which causes the OS to think the | display is always connected - and more importantly - | _turned on_. One of these areas where Linux is ahead -- | although Linux is back to garbling windows like the rest | in case you do actually decide, as an individual with | agency, not a compliant operating system, to change the | arrangement of displays.) | zachrose wrote: | Thanks everyone! | bravo22 wrote: | Signal integrity. High speed signals degrade with even | slightest mismatch in trace length or stubs. For high-speed | signals you use a chip which is essentially an electrical | repeater to redirect the output to port A or B. | adrianpike wrote: | It can be, eBay has HDMI physical switches for like $8. Your | computers will see it as a monitor unplug, though, and do fun | things with adjusting windows/icons/resolutions, and then have | to re-handshake on every switch. Not a blocker, just a pain. | | I'm also not 100% sure if it'll freak HDCP out. | myself248 wrote: | At the multi-gigabit speeds of a modern video signal, the | components of a normal mechanical switch are antennas. | modeless wrote: | So are the pins in cable connectors, but cables are | (relatively) cheap and switching signals by replugging | connectors works just fine. | formerly_proven wrote: | In my experience displayport and DVI cables of all brands | and prices are incredibly fragile and definitely stop | working well soon if you plug/unplug them once too often. | | Too often is something like 20-30 times. | chrisseaton wrote: | I think KVMs provide the illusion of the monitor still being | there when you switch away from that machine? So it doesn't | think you just yanked the cable. | Ductapemaster wrote: | A lot of it has to do with the electrical properties of such a | switch. Even older versions of DisplayPort have _massive_ data | rates, meaning each electrical signal switches many millions of | times a second. Also, each signal may have to switch states | close to the same time as the other signals, meaning there | needs to be some sort of matching between the different signal | paths. | | Add in noise sources from the power supplies, your cell phone, | and other sources, and it becomes a challenging physics | problem. Not to mention, you don't want those signals leaking | _out_ either. At these data rates, wires are both transmitting | and receiving antennas. | | Switches are inherently very mechanical devices, so designing | one that can operate in these conditions reliably would be both | complex and expensive. Much easier to have some silicon do it | for you. | renewiltord wrote: | Haha, this is clever and I like it. You turned what is usually | solved on the physical layer to something solved on the logical | layer - which is almost always better because you can express | conceptual changes much better when you don't need hardware. | | It's a small taste of the stuff that software-defined networks | have added to networking. ___________________________________________________________________ (page generated 2020-09-02 23:00 UTC)