Skip to main content
Version: next

UHID Output Stream

info

Added in Scrcpy v2.4

Each UHID device has an output stream that receives reports sent by the virtual device, such as keyboard LED state changes. The UHID manager routes reports to the corresponding device, so applications do not need to filter a shared stream by device ID.

Output message​

// import type { ScrcpyUHidOutputDeviceMessage } from "@yume-chan/scrcpy";
interface ScrcpyUHidOutputDeviceMessage {
id: number;
data: Uint8Array;
}
  • id: ID of the UHID device that produced the report.
  • data: Output report bytes, formatted according to the device's HID descriptor.

Reading reports​

ScrcpyUHidDevice.output is a ReadableStream<ScrcpyUHidOutputDeviceMessage>. Read it while the device is active:

import type {
ScrcpyUHidDevice,
ScrcpyUHidOutputDeviceMessage,
} from "@yume-chan/scrcpy";

declare const device: ScrcpyUHidDevice;

const reader: ReadableStreamDefaultReader<ScrcpyUHidOutputDeviceMessage> =
device.output.getReader();
const result: ReadableStreamReadResult<ScrcpyUHidOutputDeviceMessage> =
await reader.read();
if (!result.done) {
console.log("UHID output report:", result.value.data);
}

The stream closes when the device is destroyed or the connection closes. If parsing the device message stream fails, the output stream errors with the same failure.

note

See UHID manager to create devices, or UHID control messages for the low-level protocol.