Building A Better Keyboard And Mouse Switch

An exploded view render of a red 3D printed case with a green PCB is inside with visible USB-A connectors with a mouse and keyboard graphic above each and "A" and "B" labels above USB-C connectors on the other side.

Switching inputs between desktops seems like something that should be simple but can prove to be a pain in reality. [Hrvoje Cavrak] decided to take matters into his own hands and build a better keyboard and mouse switch.

DeskHop is built from two Raspberry Pi Pico boards connected via UART and separated by an Analog Devices ADuM1201 dual-channel digital isolator. Through the magic of Pico-PIO-USB these RP2040s can be both host and device. To keep things simple, the PCB is single-sided, and the BOM only has five distinct components.

Once hooked up to your Windows, Mac, or Linux device, your mouse pointer “magically” goes from one screen to the other when dragged across the screen edge. Keyboard LEDs can be reprogrammed to indicate which device is active, and the real beauty of the device is that since it’s a hardware solution, you don’t have to install any software on a computer you might not have admin access to.

If you want to see some more ideas for keyboard and mouse switching, check out this Pi KVM with ATX signaling, this USB triplexer, or this Pi KVM on a PCIe card.

38 thoughts on “Building A Better Keyboard And Mouse Switch

  1. > …your mouse pointer “magically” goes from one screen to the other when dragged across the screen edge.

    I don’t want to detract from the builder’s accomplishment, but in case folks do not know…

    x2x and cross-platform work-alikes do this with just software. x2x is reliable, and been around for decades. Can’t speak to the stuff that interops with win/mac.

    1. Yes, but that sort of thing requires network connectivity, has a latency penalty as a result, and doesn’t tend to work cross-platform very well (the software of this type that supports Linux rarely works on Wayland, for example), much less when you’re in, say, the BIOS trying to troubleshoot a device. Hardware solutions to this problem are attractive for a reason.

      1. Software-free is still sometimes useful like you said, but when you can get away with software it can be pretty nice. I seem to remember using a program called Synergy which worked fine cross-platform, though it may have been pre-wayland because it looks like it’s paid software now and it wasn’t when I got it. I didn’t have any reason to test VPN’ing into the lan from an outside connection but it generally didn’t have latency issues over basic wifi.

        1. Barrier is a fork of Synergy that works just fine with Wayland. I’m currently running it between my Arch setup and my Windows 10 work laptop with no issues – even copy/paste works.

    2. “and the real beauty of the device is that since it’s a hardware solution, you don’t have to install any software on a computer you might not have admin access to.”
      Think of your business laptop in your homeoffice where you dont have permission to install software like Barrier, x2x etc.

        1. That is so unbelievably more difficult, especially to do seamlessly. Check out Level1Techs to get a little taste of what it is. They make their own KVM and its a lot harder than it would appear.

          Ideally you would could do it in the actual monitor that supported picture in picture and kept both inputs live so they could merely swap the framebuffer. But there is so much lag with monitor switching it is ridiculous. I got an ultrawide LG one time that supposedly could do split screen from different outputs. But even for that they wanted some crappy LG software (if you’ve ever tried LG stuff you may have noticed they go “ooh shiny”, get something running as a mostly stable beta, and immediately drop all support)

        2. I bought some Extron usb and hdmi switches cheap on eBay to roll my own 4×4 (four monitors x four PCs). They have RS-232 control. You could combine this project with some more of those to get what you want.

        3. I use Barrier across a Linux, Mac and Windows computers. All three computers are connected to different inputs on the same physical display. I’ve patched the Barrier server (running on the Linux host) to call a script when the cursor jumps across hosts, and the script sends Display Data Channel messages to switch the display to the correct input. Practically the script maps each Barrier client to a display input and uses ‘ddcutil’ to switch inputs accordingly. If the server is running on a Mac, you can use ‘ddcctl’ instead.

          Another benefit of software KVM over hardware KVM is that the mouse acceleration is identical across all hosts, using settings from the host onto which the mouse is physically connected. You also get clipboard sharing across the hosts, which I find immensely useful.

      1. and also the worst thing is it is a hardware solution you have to buy and prepare the environment before of using it. with software only solution you can just install and be happy.

        1. And you get to pay a license for each device too! One piece of hardware that works regardless of which OS you’re using, where you don’t have to worry about newer versions, upgrade fees, etc. is really just a better way in the long term.

    3. … and they also have serious and fundamental bugs that haven’t been been fixed for decades (for example, I’m still not able to type @ and other symbols on the client), require SW to be installed as root/admin. I recently seriously pondered doing a project like this because some of these bugs made it impossible to use on my home setup (and yes, I’ve tried them “all”, they all have different quirks/bugs/limitations). TLDR; Hacking a keyboard/mouse emulation on top of an undocumented Win32 stack that has decades of cruft shoved in is not trivial (Linux, *BSD and mac usually don’t have any issues).

      1. You’re correct about it being non-trivial, but at least in Barrier I’ve found it can be solved by adding “meta = altgr” and “altgr = shift” configs for the Windows client. Those made “@” work fine for me in the Windows client, though there may be a few applications which still wouldn’t receive them correctly. I think PuTTY might have been one where “@” just wouldn’t work despite the config change, but since I’ve switched out the terminal emulator, I’d forgotten about this problem entirely as it Just Works for me now.

        1. I’m one of those “absurd” users who use English language in Windows (old habits and decades of horribly bad Norwegian translations), while having a Norwegian keyboard and locale. None of the SW based solutions handles this well, and even with a few quirks (like the one you mention), I still can’t use some shortcuts, others trigger Windows builtin features, it heavily depends on who is the client and who is the server, and it’s also unstable (I’ve more than once been unable to use it after a Windows update until the SW gets an update). And lest not forget how this quickly teaches you how “interactive” WLAN can be, just now struggling with me Windows box downloading updates and making the SW based keyboard nearly unusable.

          So having a HW solution is a bit of a must, and I don’t mind even if I have to manually switch (it would in fact be a benefit in some cases).

    4. There’s also the issue of software capturing the mouse, where continuous sideways movement is required, like a game. You don’t want to lose mouse and keyboard control because your turned around too much, or moved an object in your cad software too far.

    1. It does have the absolute coordinates – it is a slightly different HID device that reports absolute coordinates to the computer, while receiving relative movements from the mouse. It keeps the cursor position internally and reports that to the computer. When it figures out you hit the border, it replaces the left border X coordinate with the right border coordinate and switches screens, yet Y remains the same. That’s why the pointer kind of resumes on the other screen at the same height and position. Now I only need to figure out how to simply hide the pointer on the first screen :-)

      1. Does this work with multi monitor setups?

        I’ve used Synergy with two computers that each had 2+ monitors and it was a big pain in the butt. It would be awesome if this could handle that scenario more gracefully.

        Even better if this could handle two computers each with multiple displays in a non square/rectangle arrangements (example: one machine has three monitors in an L shape and the other has two screens).

    2. From their Github:
      “To get the mouse cursor to magically jump across, the mouse hid report descriptor was changed to use absolute coordinates and then the mouse reports (that still come in relative movements) accumulate internally, keeping the accurate tally on the position.

      When you try to leave the monitor area in the direction of the other monitor, it keeps the Y coordinate and swaps the maximum X for a minimum X, then flips the outputs. This ensures that the cursor seamlessly appears at the same height on the other monitor, enhancing the perception of a smooth transition.”

    3. “To get the mouse cursor to magically jump across, the mouse hid report descriptor was changed to use absolute coordinates and then the mouse reports (that still come in relative movements) accumulate internally, keeping the accurate tally on the position.”

      Normal mice report relative motion, but things like touchscreens report absolute position. I guess most applications can handle either these days. I would expect things like FPS video games to behave weirdly / not work at all with this solution though.

  2. I will second the pain of software based solutions. The problem is I can’t find a good/non buggy one that is not only cross platform but that also fully supports older platforms with the same version/protocol as the newer platforms *and* be bug free. When a bug causes you to pull a USB keyboard out of a drawn and climb under your desk it quickly defeats the point of software based solutions.

    I am a Mac user that does 99% of business on my main computer but I also have my older computer under my desk that can triple boot between macOS High Sierra, Windows and linux. I might do this for games, backups, testing, and oddball windows only software etc.

  3. Amazing project. I too am leery of the mouse tracked auto switching. Merely because modern OS have a lot of accel ramp curves and ‘pointer precision enhancement’ already, not sure how that might play out. Could bind it to an extra mouse button? I rarely use the forward/back or side to side scroll button.

    Now to expand to 3-4 PCs?

    I assume this would work fine on a $2 clone Pico? And by extension could we make a bare board with multiple RP2040 on it and skip the Pico altogether? If being really lazy would it be possible to make a copy of the Pico circuit on the current boards so you have the choice of populating it or just soldering a Pico down?

    I might try to merge some of this project with the https://github.com/jfedor2/hid-remapper/tree/master

    1. When I was trying it with relative movements, it was not great due to “mouse speed” and pointer acceleration problems. Even after turning it off, accumulated position did not match what OS was claiming and it did not work precisely (it either jumped 50 px ahead of the border or you needed to push it past). After switching to absolute coords and reporting that, it works surprisingly well – since we are reporting exact coordinates, tracking is precise and feels like it’s a single computer and not two different computers.

  4. I have used 5 different commercial keyboard mouse switches, and all leave a lot to be desired. I am so glad a project like this came along, built on sekigon-gonnoc’s PIO work, and made it possible for a very low cost.

  5. What i would like to find is bluetooth keyboard and mouse able to be switched between several computers. I have a Logitech K760 keyboard that is able to be switched between 3 computers, and it seems that the M720 Triathlon mouse is able to do the same. But i don’t know if there are other similar products on the market, and if any can go other the 3 devices limit?

  6. I think that this is exactly what I need. I have a home device and a work device on the same desk and I’m constantly flipping between keyboard/mouse and often forget which device I’m typing on. The work device is locked down and I don’t want to install anything that’s not from my employer on it so a hardware solution is absolutely perfect.
    My only comment is that the article and the developer website are a little confusing because it talks about connecting to your “computer” which without an “s” makes it singular.
    My understanding is that it is to control two computers (plural) from one keyboard and mouse but the article isn’t that clear until people read more.

Leave a Reply

Please be kind and respectful to help make the comments section excellent. (Comment Policy)

This site uses Akismet to reduce spam. Learn how your comment data is processed.