Input Data Channels
CloudGaming uses dedicated WebRTC data channels to transmit user input from the client to the host with minimal latency. Each input type uses an optimized channel configuration based on its reliability requirements.Channel Configuration
keyPressChannel (Keyboard Input)
The keyboard channel uses ordered, reliable delivery to ensure no key events are lost or received out of order.Client/html-server/index.html:1369
Why ordered and reliable?
- Key sequences must be preserved (e.g., Ctrl+C)
- Missing key events cause stuck keys
- Order matters for text input and shortcuts
mouseChannel (Mouse Input)
The mouse channel uses unordered, unreliable delivery with no retransmissions for lowest possible latency.Client/html-server/index.html:1370
Why unordered and unreliable?
- Mouse movements are rapidly superseded by newer positions
- Retransmitting old mouse positions causes lag
- Missing one mouse event is imperceptible
- Immediate delivery is more important than reliability
Message Schemas
Keyboard Events
All keyboard messages include these fields:Host/InputSchema.h:5-22):
Example: Keydown Event
Client/html-server/index.html:1527):
Example: Keyup Event
Client/html-server/index.html:1536):
Mouse Events
All mouse messages include these fields:Host/InputSchema.h:11-21):
Example: Mouse Move
Client/html-server/index.html:1031-1046):
Example: Mouse Button Events
Client/html-server/index.html:1545-1578):
Host-Side Processing
Keyboard Processing
The host receives keyboard events through a blocking queue for deterministic processing (Host/KeyInputHandler.cpp:518-686):
Mouse Processing
The mouse handler processes events with priority elevation for low latency (Host/MouseInputHandler.cpp:440-716):
Input Injection
Windows SendInput API
Both keyboard and mouse events are injected using the WindowsSendInput API for system-level control (Host/KeyInputHandler.cpp:407-516, Host/MouseInputHandler.cpp:204-438):
Performance Optimizations
Mouse Move Coalescing
The host coalesces rapid mouse move events to reduce processing overhead (Host/MouseInputHandler.cpp:27-75):
Thread Priority Elevation
The mouse processing thread runs at elevated priority to minimize input latency (Host/MouseInputHandler.cpp:443-449):
State Management
Key State Tracking
Both client and host maintain key state to prevent duplicate events: Client (Client/html-server/index.html:715-717):
Host/KeyInputHandler.cpp:44-48):
Cleanup on Disconnect
When the connection closes, all held keys/buttons are automatically released (Host/KeyInputHandler.cpp:689-714, Host/MouseInputHandler.cpp:695-716):
Best Practices
Client-Side
-
Always check channel state before sending:
-
Throttle mouse moves to reasonable rate (8ms = 125Hz):
-
Prevent default events to avoid browser interference:
-
Track state locally to filter duplicates:
Host-Side
- Use blocking queues for deterministic event ordering
- Validate all input before injection
- Clamp coordinates to screen bounds
- Release all input on cleanup
- Use scancode injection for layout independence
- Elevate thread priority for time-sensitive input
Related Documentation
- Feedback Channels - Video stats and latency measurement
- Configuration Reference - Input injection configuration options
- Performance Tuning - Optimizing input latency