Dev.to WebDev πŸ›  Dev πŸ‘ 0 πŸ“– 3 min read

How I Built a Zero-App Local Wi-Fi PC Trackpad & 120 FPS Screen Mirror in Python

Most remote mouse and screen-mirror tools make a surprisingly simple task painful: they ask you to install a bloated mobile companion app, sit through banner ads, sign into a cloud relay account, or tolerate choppy VNC p

Most remote mouse and screen-mirror tools make a surprisingly simple task painful: they ask you to install a bloated mobile companion app, sit through banner ads, sign into a cloud relay account, or tolerate choppy VNC polling over your own home Wi-Fi.

While building PCDeck, I wanted the opposite workflow: launch one lightweight desktop host on Windows or Linux, scan a QR code from Safari or Chrome on any phone or tablet, and immediately get a zero-app trackpad, keyboard, 60/120 FPS screen mirror, audio stream, and camera bridge over local LAN.

Here is a breakdown of the architecture and the five engineering tricks that keep latency sub-frame over ordinary Wi-Fi.

Why Browser-First QR Pairing Over Local Wi-Fi

Instead of shipping separate iOS and Android binaries, PCDeck runs a local Python server powered by FastAPI and Uvicorn right on your PC. Scanning the LAN QR code opens a mobile-tuned web client directly in the phone's browserβ€”no App Store download, no cloud account, and no external relay server touching your input or pixels.

Once connected, dedicated WebSocket channels isolate traffic by latency profile:

  • /ws for pointer deltas, multi-touch gestures, keyboard events, and media shortcuts
  • /ws/screen for paced screen frames and resolution/FPS feedback
  • /ws/audio for low-latency PCM audio streaming
  • /ws/cam for using a mobile camera as a phone webcam for Windows with zero watermarks

Because the UI is pure HTML5/Canvas/WebSockets, the exact same host also works as a browser PC remote from another laptop or tablet on the same network.

5 Engineering Tricks for Sub-Frame Latency

1. Fast Win32 GDI Capture + Stride-Based Dirty-Frame Skipping

High-level Python screenshot wrappers allocate too many intermediate objects for 60–120 FPS streaming. On Windows, PCDeck captures directly via Win32 GDI BitBlt (with CAPTUREBLT so layered windows and cursors are preserved) and GetDIBits, keeping raw capture overhead around ~1.4 ms.

Before touching an encoder, we inspect a strided NumPy slice of the frame buffer:

sample = raw_np[::8, ::8, 0]

Comparing this sub-sampled plane against the previous frame catches static desktops in microseconds. When nothing on screen changes, encoding and network transmission are skipped completely, dropping idle CPU usage below 0.5%.

2. Adaptive Dual-Chroma JPEG Encoding

Text editors, terminals, and IDE windows look blurry under standard 4:2:0 chroma subsampling, especially on colored syntax highlighting. At the same time, 4:4:4 encoding wastes bandwidth during fast video playback or window dragging.

PCDeck dynamically switches chroma subsampling per frame based on the current adaptive quality target:

  • Quality >= 88: 4:4:4 chroma subsampling for razor-sharp code and UI text
  • Fast motion / lower quality: 4:2:0 chroma subsampling for smaller payloads and sustained frame rates

3. Client-Paced In-Flight ACK (Queue Depth = 1)

Pushing frames from the server as fast as a loop can encode them is the fastest way to cause Wi-Fi bufferbloat: TCP queues build up, and suddenly your trackpad or screen mirror lags half a second behind reality.

PCDeck enforces strict client pacing. The browser sends a tiny a (ACK) message over /ws/screen as soon as a frame finishes decoding/rendering, keeping the server's in-flight queue depth capped at 1 frame. If Wi-Fi momentarily slows down, old frames are dropped at the source instead of piling up in socket buffers.

4. WebAudio AudioWorklet Phase-Locked Loop (PLL)

Streaming Windows loopback audio to a mobile browser without crackles or drift requires handling clock skew between the PC sound card and the phone's DAC.

Instead of naive AudioBufferSourceNode scheduling, PCDeck streams PCM chunks into a custom WebAudio AudioWorklet ring buffer governed by a gentle Phase-Locked Loop:

  • TARGET_BUFFER_MS = 100 keeps latency tight while absorbing Wi-Fi jitter
  • Above 135 ms buffer fill, playback rate gently nudges up to 1.012x to drain excess latency smoothly without audible pitch pops or glitches

5. Sub-Tick Win32 SendInput Scrolling & Kinetic Momentum

Standard Windows mouse wheels fire coarse WHEEL_DELTA = 120 notches, which makes phone trackpad scrolling feel jerky. PCDeck feeds fractional wheel increments directly into Win32 SendInput using SMOOTH_WHEEL_STEP = 24 (1/5th of a legacy notch), paired with client-side kinetic touch momentum so two-finger trackpad flicks feel native.

Try It Out

PCDeck's core local trackpad, keyboard, media remote, browser file transfer, and standard screen/webcam tools are free, with an optional $3.99 one-time Pro upgrade unlocking 60/120 FPS mirroring and custom HUD layouts.

πŸ“° Read the original article on Dev.to WebDev

Originally published by Dev.to WebDev. Aggregated on AIWithGhost for educational purposes β€” full credit and traffic to the original publisher.