User-space HID Device (UHID) Control
Control Human Interface Devices (HID) on the device. UHID stands for "User-space I/O driver support for HID subsystem", which enables software-emulation of HID devices.
UHID Create
Added in Scrcpy v2.4
Create a new virtual HID device on the device. The device is identified by an ID and configured with a HID descriptor that defines its capabilities. The create message format gains fields in later server versions:
-
name: The device name.(since v2.7) -
vendorIdandproductId: USB vendor and product identifiers.(since v3.1)
Options
interface ScrcpyUHidCreateControlMessage {
id: number;
name: string;
vendorId: number;
productId: number;
data: Uint8Array;
}
id: Identifier for the HID device. When using the low-level writer, choose an ID that isn't already in use.name: Human-readable name for the device (since Scrcpy v2.7).vendorIdandproductId: USB identifiers (since Scrcpy v3.1).data: The HID report descriptor as a byte array defining the device capabilities. The descriptor follows the USB HID specification and defines input/output/feature reports that the device supports.
Usage
- JavaScript
- TypeScript
// Using `ScrcpyControlMessageSerializer`
const message = serializer.uHidCreate({
id: 1,
name: "Example HID",
vendorId: 0x1234,
productId: 0x5678,
data: new Uint8Array([
// ...
]),
});
// Using `ScrcpyControlMessageWriter`
await writer.uHidCreate({
id: 1,
name: "Example HID",
vendorId: 0x1234,
productId: 0x5678,
data: new Uint8Array([/* HID descriptor bytes */]),
});
// Using `AdbScrcpyClient`
await client.controller.uHidCreate({
id: 1,
name: "Example HID",
vendorId: 0x1234,
productId: 0x5678,
data: new Uint8Array([/* HID descriptor bytes */]),
});
// Using `ScrcpyControlMessageSerializer`
const message: Uint8Array = serializer.uHidCreate({
id: 1,
name: "Example HID",
vendorId: 0x1234,
productId: 0x5678,
data: new Uint8Array([
// ...
]),
});
// Using `ScrcpyControlMessageWriter`
await writer.uHidCreate({
id: 1,
name: "Example HID",
vendorId: 0x1234,
productId: 0x5678,
data: new Uint8Array([/* HID descriptor bytes */]),
});
// Using `AdbScrcpyClient`
await client.controller!.uHidCreate({
id: 1,
name: "Example HID",
vendorId: 0x1234,
productId: 0x5678,
data: new Uint8Array([/* HID descriptor bytes */]),
});
UHID Input
Added in Scrcpy v2.4
Send input events to a previously created HID device. This allows simulating physical input from the emulated device.
Options
interface ScrcpyUHidInputControlMessage {
id: number;
data: Uint8Array;
}
id: The identifier of the UHID device to send input to.data: The HID input report containing the input data, formatted according to the device's HID descriptor.
Usage
- JavaScript
- TypeScript
// Using `ScrcpyControlMessageSerializer`
const message = serializer.uHidInput({
id: 1,
// Send a key press event (e.g., press 'A' key)
data: new Uint8Array([
0x00,
0x00,
0x04,
0x00,
0x00,
0x00,
0x00,
0x00, // Report with modifier + key code
]),
});
// Using `ScrcpyControlMessageWriter`
await writer.uHidInput({
id: 1,
data: new Uint8Array([/* HID report bytes */]),
});
// Using `AdbScrcpyClient`
await client.controller.uHidInput({
id: 1,
data: new Uint8Array([/* HID report bytes */]),
});
// Using `ScrcpyControlMessageSerializer`
const message: Uint8Array = serializer.uHidInput({
id: 1,
// Send a key press event (e.g., press 'A' key)
data: new Uint8Array([
0x00,
0x00,
0x04,
0x00,
0x00,
0x00,
0x00,
0x00, // Report with modifier + key code
]),
});
// Using `ScrcpyControlMessageWriter`
await writer.uHidInput({
id: 1,
data: new Uint8Array([/* HID report bytes */]),
});
// Using `AdbScrcpyClient`
await client.controller!.uHidInput({
id: 1,
data: new Uint8Array([/* HID report bytes */]),
});
UHID Destroy
Added in Scrcpy v2.7
Remove a previously created HID device. Closing the file descriptor automatically unregisters and destroys the device internally.
Options
interface ScrcpyUHidDestroyControlMessage {
id: number;
}
id: The identifier of the UHID device to destroy.
Usage
- JavaScript
- TypeScript
// Using `ScrcpyControlMessageSerializer`
const message = serializer.uHidDestroy(1);
// Using `ScrcpyControlMessageWriter`
await writer.uHidDestroy(1);
// Using `AdbScrcpyClient`
await client.controller.uHidDestroy(1);
// Using `ScrcpyControlMessageSerializer`
const message: Uint8Array = serializer.uHidDestroy(1);
// Using `ScrcpyControlMessageWriter`
await writer.uHidDestroy(1);
// Using `AdbScrcpyClient`
await client.controller!.uHidDestroy(1);
See the UHID manager to create and manage virtual devices, and UHID output stream to read their output reports.