Files
hrynco-kswitcher/LAN-PREVIEW.md
T

16 KiB
Raw Blame History

LAN mouse, keyboard and clipboard — v0.6.58 (experimental)

KSwitcher discovers other enabled KSwitcher instances, pairs them with the same code on both computers, and shares mouse and keyboard through a screen edge. The module runs inside the resident process. Multiple paired computers can be arranged on a monitor grid. Mouse and keyboard follow neighboring cells, including A → B → C, without relaying input through B. New text and images are also shared with all online paired computers: history and the active clipboard.

Trusted LAN clients

Open Settings → Computers → Manage computers → Trusted clients and choose Add client…. Select the executable, confirm, and click Save in Settings. A newly approved or previously enrolled executable can list pairs, browse drives and download regular files. For each executable you can separately enable Allow write for creating, editing, renaming, and copying, and Allow delete for the recycle bin and permanent deletion. Move needs both permissions. The paired computer's Windows access and file-sharing settings still apply. KSwitcher retains the pairing credentials.

Select an executable and choose Remove, or turn off an individual grant, then click Save to revoke access. KSwitcher checks grants again during streaming and before publication or source removal. Add an updated executable again because approval covers its path and SHA-256 fingerprint.

Local trusted-client protocol

The Windows pipe is \\.\pipe\KSwitcher.LAN.Clients.v1.<session> and accepts one request per connection from the resident's user. Send a JSON object in an unsigned 32-bit little-endian length frame (maximum 16 KiB for the request). Replies have the same length prefix. After the last reply, send one raw acknowledgement byte and close. An error reply is a JSON object containing a string error. Existing peers, drives, list and download requests retain their original reply formats.

  • capabilities optionally takes a peer. It returns the broker protocol (2), hostRevision, and boolean write, delete, move, revisionRead, onHostTransfer, and localEndpoint fields. With no peer, the fields describe the local broker and its grants. With a peer, the flags also account for its supported protocol. A peer with revision 0 still supports legacy browsing and downloading.
  • stat takes peer and an absolute path. It returns Windows attributes, byte size and modified (Windows FILETIME). Preserve 64-bit integers without rounding. readFile takes the same arguments plus an optional expected object with size and modified. It returns metadata followed by raw frames up to 64 KiB and a zero-length frame. Require the declared byte count and the zero-length frame before accepting the download.
  • writeFile takes peer, path, and the incoming byte size. Omit expected for an exclusive create. Include the original size and modified in expected for an edit. After the ready JSON reply, send raw frames up to 64 KiB followed by a zero-length frame. The final reply contains the saved metadata or an error. The host stages bytes until the upload is complete and checks the revision when publishing an edit.
  • mkdir, rename, recycle, and delete take peer and path. Rename also takes a single new name and fails if the destination exists. Permanent deletion of nonempty directories requires recursive: true. The recycle bin is subject to Windows availability on the paired host.
  • transfer takes source and target objects with a peer and path each, optional move (default false), and a conflict policy of fail (default), skip, or replace. Replace merges directories and replaces regular files after validating the destination revision. The broker allows at most one local endpoint, represented by "peer": null. For a local endpoint the client must open the pipe with Windows impersonation enabled, and local files are accessed using the caller's token.
  • Transfer replies are JSON progress frames containing type: "progress", phase (copy or remove), source path, byte done and total for the current file, and completed and skipped item counts. Reply to each progress frame with a JSON frame containing continue: true or continue: false. The final frame has type: "complete" and counts, or an error. Transfers on one paired computer use its own file service even across drives. The local pipe exchanges only control and status for transfers.
  • For a move, the copy phase finishes before source deletion begins. Skipped items remain at the source. Cancellation or failure can leave previously completed destination items. Failure during source cleanup can leave a partially removed source tree. Unpublished file uploads are discarded. File-tree transfer does not follow junctions or symbolic links within the tree.

Remote files and diagnostic logs

Use KSwitcher Files → Change drive or Dirlume with a trusted-client entry to browse and copy remote files. Starting in v0.7.0, Manage computers focuses on pairing, shared input and diagnostic logs.

On the computer that owns the logs, enable Allow paired computers to download logs in Diagnostic logs (off by default). On the requesting computer, select the paired PC and choose Current log… or Previous log…. Diagnostic logs may contain text copied from applications.

MCP

In Settings → MCP, choose Copy configuration and paste the block into Codex's ~/.codex/config.toml. It starts the MCP server over stdio with the absolute path to KSwitcher.Config.exe and the --mcp argument. list_log_computers returns paired computer IDs and availability. read_diagnostic_log reads the latest 100 lines by default (1–500 with lines). Use offset to skip newer lines and page backward. Set previous to read the rotated log. Omit peer for the local log or pass a paired computer ID for a remote log. Remote reads need the local resident process running and log downloads enabled on the remote PC.

Set up multiple computers

  1. Install the v0.6.58 or newer on every participating PC. Input protocol v2 requires all participants to update; earlier one-pair builds cannot connect. Preserve local data; do not copy pairing identities between PCs.
  2. Open Settings → Computers → Manage computers and enable discovery on both PCs. Only running LAN-enabled KSwitcher instances appear, not generic network devices. In wide windows, the computer list and monitor layout grow side by side. In narrow windows, they stack above Diagnostic logs. The list identifies offline pairs, and Connection help appears below the input sharing controls.
  3. Match the computer name and instance-ID prefix displayed on the other PC. Enable discovery and click Save on each PC to make peers visible. Select each other, generate one code, and enter it on both. Click Pair, then Apply or Save on each PC within two minutes. Use Apply to keep the pairing status visible. Spaces, hyphens and uppercase hex are accepted.
  4. Pair each physical input source with every destination it must control. For unrestricted control from any PC, pair every pair of PCs. Drag monitors into neighboring grid cells and arrange the same physical layout relative to each local PC. For A → B → C, A sees B at (1,0), C at (2,0); B sees A at (-1,0), C at (1,0). Enable input sharing and click Save on all PCs to apply sharing and the monitor layout. The input sharing setting covers all pairs.
  5. Stop MWB or another mouse/keyboard router on both computers before trying KSwitcher input sharing, to avoid two tools forwarding the same events.
  6. Wait for the authenticated input connection. Move the cursor through the configured outer screen edge with no keys or buttons held. After the other computer acknowledges the handoff, both mouse and keyboard control that PC. Crossing another shared edge switches directly to that neighbor. Crossing back into the source computer restores its cursor at the corresponding edge. Empty cells, diagonal-only neighbors and offline PCs do not transfer control.

When input sharing is enabled, the tray icon shows a steady gray dot if all paired PCs are offline, a pulsing amber dot while a discovered PC is connecting, a green dot when all online paired PCs are connected, and a red dot if the LAN worker stops. Hover over the icon to see the connection status and the connected count when only some paired PCs are connected.

The source cursor is parked and hidden beneath a tiny no-activation window. A small banner identifies remote control; no full-screen layered bitmap is retained. The destination uses its own keyboard layout and runs its own hotkeys/snippets. The source suppresses forwarded events before its local hotkeys, snippets and other low-level hook consumers. Received input is marked so it is not forwarded again. Source recent-input tracking and shortcut latches reset when ownership changes.

Ctrl+Alt+Esc is emergency return, not the normal switching mechanism. Local physical input on a remotely controlled PC takes control back as well. Stop input sharing, disabling discovery, forgetting the currently controlled pair, suspension, secure desktop changes and connection loss cancel remote ownership. TCP heartbeat loss is detected after two seconds; a handoff request expires after one second. Held remote keys/buttons are released. Releases blocked by a secure desktop are retried when the ordinary desktop is available. Source key-ups for keys already sent remotely are consumed after return, avoiding stray local modifier events.

Layout and limitations

  • Positions are relative to this PC. All peers have independent authenticated connections; a failed peer does not disconnect the others. The physical source uses its own grid to choose every destination. Moving a monitor cancels current control safely and applies the updated layout without dropping all connections. Layouts are not synchronized automatically. One source controls a destination at a time. Each grid tile represents an entire PC, not an individual monitor.
  • Geometry uses the virtual desktop's outer bounding rectangle, including negative monitor coordinates. Internal monitor boundaries do not transfer control. Different resolutions map the entry position proportionally. Irregular layouts can have gaps on an outer edge; this is not a per-monitor arrangement editor.
  • Transferring while a key or mouse button is held is intentionally blocked. Dragging works within the controlled computer; dragging objects across PCs is not implemented. There is a short return cooldown to avoid bouncing.
  • Windows can block SendInput to elevated apps and secure desktops. Run both applications at suitable privilege levels for the target programs. The preview does not install a service, bypass UAC or implement remote Ctrl+Alt+Delete.
  • This is Windows input injection, not a virtual USB HID device. Raw-input games, exclusive full-screen applications and special device keys need separate testing.

Network, authentication and storage

Discovery broadcasts on private IPv4 and link-local interfaces using UDP 45883. Input uses TCP 45884. Allow KSwitcher on your private network when Windows asks; the preview does not change firewall rules. Broadcast-blocked networks, separate VLANs, public IPv4 and IPv6-only networks are not supported by discovery yet. A second LAN-enabled KSwitcher cannot use the same ports on one computer.

Input first tries TCP in the usual direction, then reverse TCP after 1.5 seconds. LAN discovery authenticates paired PCs before starting new input connections. Discovery remains active while all paired PCs are offline and wakes input sharing when one reappears. An authenticated input connection survives missed discovery announcements. Once discovery has expired and the channel closes, further input attempts wait for fresh discovery. After at least 5 seconds, the lower-ID peer starts encrypted UDP fallback on the discovery socket (UDP 45883) once its current TCP connection attempt has failed or reached its 10-second deadline. UDP uses fresh session challenges, authenticated encryption, ordered event numbers, acknowledgements and bounded retries; duplicated packets do not repeat key presses. Two seconds without authenticated traffic or acknowledgement progress closes the session and returns control locally. A working UDP session stays on UDP until disconnected; it does not oscillate between transports. Both PCs must run an updated build to use all fallback methods. Older peers can still use the original TCP protocol. No extra ports or external relay are used.

After 15 seconds without a connection, the UI points to Connection help. The help window can copy PowerShell commands for the actual resident EXE path, including a path containing apostrophes. Run each PC's own command in an administrator PowerShell on that PC. These commands permit inbound TCP 45884 and UDP 45883 only from the local subnet; the program does not execute them. Moving the EXE may require a new application firewall rule. A timeout alone does not establish that the firewall is the cause: check that input sharing is enabled on both PCs and that both are running the intended copy.

The instance ID belongs to a data directory, not a hostname/IP address. Discovered names and addresses are untrusted. Pairing uses a generated 128-bit code and mutual HMAC-SHA256 challenge proofs bound to both instance IDs. The code is never transmitted or logged. The pair key is separate from the setup code.

The input channel authenticates both peers with the saved pair key and fresh session challenges. Directional AES-256-GCM session keys bind the identities, nonces and the input protocol domain. Screen positions determine routing after authentication; they are no longer part of the pair channel key. Fixed-size authenticated frames use strict sequence numbers, so tampering, reflection and replay are rejected. Input is not dispatched until authentication succeeds. This PSK channel does not provide forward secrecy. Queues and frame sizes are bounded; overflow disconnects rather than dropping a key-up and leaving a key pressed. The input worker never injects Windows input; the resident's main thread owns the input state and hooks.

Identity, trust, enablement and screen position stay in DPAPI-protected data/lan-pairing.bin, outside settings export and OpenBao sync. Do not clone this file between installations. Forget a pair on both PCs for bilateral removal. Closing the settings window does not cancel pairing or disable sharing.

Disabled discovery has no socket or worker. Input sharing reuses the single LAN worker; there is no extra resident executable or service. The main input timer runs only while sharing is enabled. The existing configurator talks to the resident through local IPC.

Validation

Tests cover pairing, encrypted frames, replay/tamper rejection, actual loopback TCP authentication and bidirectional delivery, all four edges, ownership races, source suppression, scan codes, clicks/wheel, emergency return, held-key release, blocked injection, secure desktop recovery, exact one-pixel movement and timeout. Tests additionally exercise three actual TCP hubs, independent reconnect, A → B → C and back, vertical turns, unavailable neighbors, stale ownership, modifier delivery to only the active destination, and local shortcut recovery. UI tests drag three monitors and check persistence.

Three physical computers still need an end-to-end trial for their adapters, firewalls, displays and application privilege levels. The automated TCP tests use local sockets, and input-state tests use simulated desktop environments; they do not claim a completed three-machine hardware test.

v0.6.58 connection fixes

Saved trust keeps TCP listeners available even when discovery announcements are missed. Working authenticated input sessions no longer depend on discovery presence. Pair saved is distinct from input connected; the list refreshes every second. A changed instance ID requires a new pairing. Keep each PC's own data folder during upgrades. Connection state changes and listener Windows errors are written to the diagnostic log.