I have something similar set up with a Logitech MX keyboard and mouse. I have the added constraint that one laptop is locked to a VPN and thus inaccessible on the local network.
* Using the keyboard's switch-device button moves the keyboard to the other laptop.
* Logitech's Options+ app automatically switches the mouse to the same device in response.
* Claude vibe-coded me a native app that runs on both laptops and sends a DDC command to the monitor to switch inputs any time it detects keyboard and mouse both going away in quick succession: https://github.com/jawj/mxswitch
Made something very similar recently, minus the monitor input switching:
https://news.ycombinator.com/item?id=49823733
In this case the key thing was to make this work with an old MX Master, which isn’t properly supported for one-button multi-device easy switching.