• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# HID DDK
2
3
4## Overview
5
6Provides HID driver development kit (DDK) functions, including those for creating a device, sending events to a device, and destroying a device.
7
8**System capability**: SystemCapability.Driver.HID.Extension
9
10**Since**: 11
11
12
13## Summary
14
15
16### Files
17
18| Name| Description|
19| -------- | -------- |
20| [hid_ddk_api.h](hid__ddk__api_8h.md) | Declares the HID DDK functions for accessing an input device from the host.<br>File to include: &lt;hid/hid_ddk_api.h&gt;<br>Library: libhid.z.so|
21| [hid_ddk_types.h](hid__ddk__types_8h.md) | Defines the enum variables and structs used in the HID DDK.<br>File to include: &lt;hid/hid_ddk_types.h&gt;<br>Library: libhid.z.so|
22
23
24### Structs
25
26| Name| Description|
27| -------- | -------- |
28| struct&nbsp;&nbsp;[Hid_EmitItem](_hid___emit_item.md) | Defines event information.|
29| struct&nbsp;&nbsp;[Hid_Device](_hid___device.md) | Defines basic device information.|
30| struct&nbsp;&nbsp;[Hid_EventTypeArray](_hid___event_type_array.md) | Defines an array of event types.|
31| struct&nbsp;&nbsp;[Hid_KeyCodeArray](_hid___key_code_array.md) | Defines an array of key codes.|
32| struct&nbsp;&nbsp;[Hid_AbsAxesArray](_hid___abs_axes_array.md) | Defines an array of absolute coordinates.|
33| struct&nbsp;&nbsp;[Hid_RelAxesArray](_hid___rel_axes_array.md) | Defines an array of relative coordinates.|
34| struct&nbsp;&nbsp;[Hid_MscEventArray](_hid___msc_event_array.md) | Defines an array of miscellaneous events.|
35| struct&nbsp;&nbsp;[Hid_EventProperties](_hid___event_properties.md) | Defines the event properties of a device.|
36| struct&nbsp;&nbsp;[Hid_RawDevInfo](_hid___raw_dev_info.md) | Defines the raw device information.|
37
38
39### Macros
40
41| Name| Description|
42| -------- | -------- |
43| [HID_MAX_REPORT_BUFFER_SIZE](#hid_max_report_buffer_size)&nbsp;&nbsp;&nbsp;(16 \* 1024 - 1) | Defines the maximum size of the report buffer.|
44
45
46### Types
47
48| Name| Description|
49| -------- | -------- |
50| typedef struct [Hid_EmitItem](_hid___emit_item.md) [Hid_EmitItem](#hid_emititem) | Defines event information.|
51| typedef struct [Hid_Device](_hid___device.md) [Hid_Device](#hid_device) | Defines basic device information.|
52| typedef struct [Hid_EventTypeArray](_hid___event_type_array.md) [Hid_EventTypeArray](#hid_eventtypearray) | Defines an array of event types.|
53| typedef struct [Hid_KeyCodeArray](_hid___key_code_array.md) [Hid_KeyCodeArray](#hid_keycodearray) | Defines an array of key codes.|
54| typedef struct [Hid_AbsAxesArray](_hid___abs_axes_array.md) [Hid_AbsAxesArray](#hid_absaxesarray) | Defines an array of absolute coordinates.|
55| typedef struct [Hid_RelAxesArray](_hid___rel_axes_array.md) [Hid_RelAxesArray](#hid_relaxesarray) | Defines an array of relative coordinates.|
56| typedef struct [Hid_MscEventArray](_hid___msc_event_array.md) [Hid_MscEventArray](#hid_msceventarray) | Defines an array of miscellaneous events.|
57| typedef struct [Hid_EventProperties](_hid___event_properties.md) [Hid_EventProperties](#hid_eventproperties) | Defines the event properties of a device.|
58| typedef struct [Hid_DeviceHandle](#hid_devicehandle) [Hid_DeviceHandle](#hid_devicehandle) | Defines the opaque USB HID device structure.|
59| typedef struct [Hid_RawDevInfo](_hid___raw_dev_info.md) [Hid_RawDevInfo](#hid_rawdevinfo) | Defines the raw device information.|
60
61
62### Enums
63
64| Name| Description|
65| -------- | -------- |
66| [Hid_DeviceProp](#hid_deviceprop) {<br>HID_PROP_POINTER = 0x00, HID_PROP_DIRECT = 0x01, HID_PROP_BUTTON_PAD = 0x02, HID_PROP_SEMI_MT = 0x03, HID_PROP_TOP_BUTTON_PAD = 0x04, HID_PROP_POINTING_STICK = 0x05, HID_PROP_ACCELEROMETER = 0x06<br>} | Enumerates the properties of input devices.|
67| [Hid_EventType](#hid_eventtype) {<br>HID_EV_SYN = 0x00, HID_EV_KEY = 0x01, HID_EV_REL = 0x02, HID_EV_ABS = 0x03, HID_EV_MSC = 0x04<br>} | Enumerates the event types.|
68| [Hid_SynEvent](#hid_synevent) { HID_SYN_REPORT = 0, HID_SYN_CONFIG = 1, HID_SYN_MT_REPORT = 2, HID_SYN_DROPPED = 3 } | Enumerates sync events.|
69| [Hid_KeyCode](#hid_keycode) {<br>HID_KEY_A = 30, HID_KEY_B = 48, HID_KEY_C = 46, HID_KEY_D = 32, HID_KEY_E = 18, HID_KEY_F = 33, HID_KEY_G = 34, HID_KEY_H = 35, HID_KEY_I = 23, HID_KEY_J = 36, HID_KEY_K = 37, HID_KEY_L = 38, HID_KEY_M = 50, HID_KEY_N = 49, HID_KEY_O = 24, HID_KEY_P = 25, HID_KEY_Q = 16, HID_KEY_R = 19, HID_KEY_S = 31, HID_KEY_T = 20, HID_KEY_U = 22, HID_KEY_V = 47, HID_KEY_W = 17, HID_KEY_X = 45, HID_KEY_Y = 21, HID_KEY_Z = 44, HID_KEY_ESC = 1, HID_KEY_0 = 11, HID_KEY_1 = 2, HID_KEY_2 = 3, HID_KEY_3 = 4, HID_KEY_4 = 5, HID_KEY_5 = 6, HID_KEY_6 = 7, HID_KEY_7 = 8, HID_KEY_8 = 9, HID_KEY_9 = 10, HID_KEY_GRAVE = 41, HID_KEY_MINUS = 12, HID_KEY_EQUALS = 13, HID_KEY_BACKSPACE = 14, HID_KEY_LEFT_BRACKET = 26, HID_KEY_RIGHT_BRACKET = 27, HID_KEY_ENTER = 28, HID_KEY_LEFT_SHIFT = 42, HID_KEY_BACKSLASH = 43, HID_KEY_SEMICOLON = 39, HID_KEY_APOSTROPHE = 40, HID_KEY_SPACE = 57, HID_KEY_SLASH = 53, HID_KEY_COMMA = 51, HID_KEY_PERIOD = 52, HID_KEY_RIGHT_SHIFT = 54, HID_KEY_NUMPAD_0 = 82, HID_KEY_NUMPAD_1 = 79, HID_KEY_NUMPAD_2 = 80, HID_KEY_NUMPAD_3 = 81, HID_KEY_NUMPAD_4 = 75, HID_KEY_NUMPAD_5 = 76, HID_KEY_NUMPAD_6 = 77, HID_KEY_NUMPAD_7 = 71, HID_KEY_NUMPAD_8 = 72, HID_KEY_NUMPAD_9 = 73, HID_KEY_NUMPAD_DIVIDE = 70, HID_KEY_NUMPAD_MULTIPLY = 55, HID_KEY_NUMPAD_SUBTRACT = 74, HID_KEY_NUMPAD_ADD = 78, HID_KEY_NUMPAD_DOT = 83, HID_KEY_SYSRQ = 99, HID_KEY_DELETE = 111, HID_KEY_MUTE = 113, HID_KEY_VOLUME_DOWN = 114, HID_KEY_VOLUME_UP = 115, HID_KEY_BRIGHTNESS_DOWN = 224, HID_KEY_BRIGHTNESS_UP = 225, HID_BTN_0 = 0x100, HID_BTN_1 = 0x101, HID_BTN_2 = 0x102, HID_BTN_3 = 0x103, HID_BTN_4 = 0x104, HID_BTN_5 = 0x105, HID_BTN_6 = 0x106, HID_BTN_7 = 0x107, HID_BTN_8 = 0x108, HID_BTN_9 = 0x109, HID_BTN_LEFT = 0x110, HID_BTN_RIGHT = 0x111, HID_BTN_MIDDLE = 0x112, HID_BTN_SIDE = 0x113, HID_BTN_EXTRA = 0x114, HID_BTN_FORWARD = 0x115, HID_BTN_BACKWARD = 0x116, HID_BTN_TASK = 0x117, HID_BTN_TOOL_PEN = 0x140, HID_BTN_TOOL_RUBBER = 0x141, HID_BTN_TOOL_BRUSH = 0x142, HID_BTN_TOOL_PENCIL = 0x143, HID_BTN_TOOL_AIRBRUSH = 0x144, HID_BTN_TOOL_FINGER = 0x145, HID_BTN_TOOL_MOUSE = 0x146, HID_BTN_TOOL_LENS = 0x147, HID_BTN_TOOL_QUINT_TAP = 0x148, HID_BTN_STYLUS3 = 0x149, HID_BTN_TOUCH = 0x14a, HID_BTN_STYLUS = 0x14b, HID_BTN_STYLUS2 = 0x14c, HID_BTN_TOOL_DOUBLE_TAP = 0x14d, HID_BTN_TOOL_TRIPLE_TAP = 0x14e, HID_BTN_TOOL_QUAD_TAP = 0x14f, HID_BTN_WHEEL = 0x150<br>} | Enumerates the key codes.|
70| [Hid_AbsAxes](#hid_absaxes) {<br>HID_ABS_X = 0x00, HID_ABS_Y = 0x01, HID_ABS_Z = 0x02, HID_ABS_RX = 0x03, HID_ABS_RY = 0x04, HID_ABS_RZ = 0x05, HID_ABS_THROTTLE = 0x06, HID_ABS_RUDDER = 0x07, HID_ABS_WHEEL = 0x08, HID_ABS_GAS = 0x09, HID_ABS_BRAKE = 0x0a, HID_ABS_HAT0X = 0x10, HID_ABS_HAT0Y = 0x11, HID_ABS_HAT1X = 0x12, HID_ABS_HAT1Y = 0x13, HID_ABS_HAT2X = 0x14, HID_ABS_HAT2Y = 0x15, HID_ABS_HAT3X = 0x16, HID_ABS_HAT3Y = 0x17, HID_ABS_PRESSURE = 0x18, HID_ABS_DISTANCE = 0x19, HID_ABS_TILT_X = 0x1a, HID_ABS_TILT_Y = 0x1b, HID_ABS_TOOL_WIDTH = 0x1c, HID_ABS_VOLUME = 0x20, HID_ABS_MISC = 0x28<br>} | Enumerates the absolute coordinates.|
71| [Hid_RelAxes](#hid_relaxes) {<br>HID_REL_X = 0x00, HID_REL_Y = 0x01, HID_REL_Z = 0x02, HID_REL_RX = 0x03, HID_REL_RY = 0x04, HID_REL_RZ = 0x05, HID_REL_HWHEEL = 0x06, HID_REL_DIAL = 0x07, HID_REL_WHEEL = 0x08, HID_REL_MISC = 0x09, HID_REL_RESERVED = 0x0a, HID_REL_WHEEL_HI_RES = 0x0b, HID_REL_HWHEEL_HI_RES = 0x0c<br>} | Enumerates the relative coordinates.|
72| [Hid_MscEvent](#hid_mscevent) {<br>HID_MSC_SERIAL = 0x00, HID_MSC_PULSE_LED = 0x01, HID_MSC_GESTURE = 0x02, HID_MSC_RAW = 0x03, HID_MSC_SCAN = 0x04, HID_MSC_TIMESTAMP = 0x05<br>} | Enumerates miscellaneous input events.|
73| [Hid_DdkErrCode](#hid_ddkerrcode) {<br>HID_DDK_SUCCESS = 0, HID_DDK_NO_PERM = 201, HID_DDK_INVALID_PARAMETER = 401, HID_DDK_FAILURE = 27300001, HID_DDK_NULL_PTR = 27300002, HID_DDK_INVALID_OPERATION = 27300003, HID_DDK_TIMEOUT = 27300004, HID_DDK_INIT_ERROR = 27300005, HID_DDK_SERVICE_ERROR = 27300006, HID_DDK_MEMORY_ERROR = 27300007, HID_DDK_IO_ERROR = 27300008, HID_DDK_DEVICE_NOT_FOUND = 27300009<br>} | Enumerates the HID DDK error codes.|
74| [Hid_ReportType](#hid_reporttype) { HID_INPUT_REPORT = 0, HID_OUTPUT_REPORT = 1, HID_FEATURE_REPORT = 2 } | Defines the report (data packets exchanged between the HID device and the host) type.|
75
76
77### Functions
78
79| Name| Description|
80| -------- | -------- |
81| int32_t [OH_Hid_CreateDevice](#oh_hid_createdevice) ([Hid_Device](_hid___device.md) \*hidDevice, [Hid_EventProperties](_hid___event_properties.md) \*hidEventProperties) | Creates a device.|
82| int32_t [OH_Hid_EmitEvent](#oh_hid_emitevent) (int32_t deviceId, const [Hid_EmitItem](_hid___emit_item.md) items[], uint16_t length) | Sends an event list to a device.|
83| int32_t [OH_Hid_DestroyDevice](#oh_hid_destroydevice) (int32_t deviceId) | Destroys a device.|
84| int32_t [OH_Hid_Init](#oh_hid_init) (void) | Initializes an HID DDK.|
85| int32_t [OH_Hid_Release](#oh_hid_release) (void) | Releases an HID DDK.|
86| int32_t [OH_Hid_Open](#oh_hid_open) (uint64_t deviceId, uint8_t interfaceIndex, [Hid_DeviceHandle](#hid_devicehandle) \*\*dev) | Opens the device specified by **deviceId** and **interfaceIndex**.|
87| int32_t [OH_Hid_Close](#oh_hid_close) ([Hid_DeviceHandle](#hid_devicehandle) \*\*dev) | Closes an HID device.|
88| int32_t [OH_Hid_Write](#oh_hid_write) ([Hid_DeviceHandle](#hid_devicehandle) \*dev, uint8_t \*data, uint32_t length, uint32_t \*bytesWritten) | Writes reports to an HID device.|
89| int32_t [OH_Hid_ReadTimeout](#oh_hid_readtimeout) ([Hid_DeviceHandle](#hid_devicehandle) \*dev, uint8_t \*data, uint32_t bufSize, int timeout, uint32_t \*bytesRead) | Reads reports from the HID device within the specified timeout interval.|
90| int32_t [OH_Hid_Read](#oh_hid_read) ([Hid_DeviceHandle](#hid_devicehandle) \*dev, uint8_t \*data, uint32_t bufSize, uint32_t \*bytesRead) | Reads reports from the HID device. The blocking mode (that is, blocking remains active until data can be read) is used by default. You can call [OH_Hid_SetNonBlocking](#oh_hid_setnonblocking) to change the mode.|
91| int32_t [OH_Hid_SetNonBlocking](#oh_hid_setnonblocking) ([Hid_DeviceHandle](#hid_devicehandle) \*dev, int nonBlock) | Sets the device read mode to non-blocking mode.|
92| int32_t [OH_Hid_GetRawInfo](#oh_hid_getrawinfo) ([Hid_DeviceHandle](#hid_devicehandle) \*dev, [Hid_RawDevInfo](_hid___raw_dev_info.md) \*rawDevInfo) | Obtains the original device information.|
93| int32_t [OH_Hid_GetRawName](#oh_hid_getrawname) ([Hid_DeviceHandle](#hid_devicehandle) \*dev, char \*data, uint32_t bufSize) | Obtains the original device name.|
94| int32_t [OH_Hid_GetPhysicalAddress](#oh_hid_getphysicaladdress) ([Hid_DeviceHandle](#hid_devicehandle) \*dev, char \*data, uint32_t bufSize) | Obtains the physical address of the HID device.|
95| int32_t [OH_Hid_GetRawUniqueId](#oh_hid_getrawuniqueid) ([Hid_DeviceHandle](#hid_devicehandle) \*dev, uint8_t \*data, uint32_t bufSize) | Obtains the original unique identifier of a device.|
96| int32_t [OH_Hid_SendReport](#oh_hid_sendreport) ([Hid_DeviceHandle](#hid_devicehandle) \*dev, [Hid_ReportType](#hid_reporttype) reportType, const uint8_t \*data, uint32_t length) | Sends reports to the HID device.|
97| int32_t [OH_Hid_GetReport](#oh_hid_getreport) ([Hid_DeviceHandle](#hid_devicehandle) \*dev, [Hid_ReportType](#hid_reporttype) reportType, uint8_t \*data, uint32_t bufSize) | Obtains reports from the HID device.|
98| int32_t [OH_Hid_GetReportDescriptor](#oh_hid_getreportdescriptor) ([Hid_DeviceHandle](#hid_devicehandle) \*dev, uint8_t \*buf, uint32_t bufSize, uint32_t \*bytesRead) | Obtains the report descriptor of the HID device.|
99
100
101### Variables
102
103| Name| Description|
104| -------- | -------- |
105| uint16_t [Hid_EmitItem::type](#type) | Enumerates the event types.|
106| uint16_t [Hid_EmitItem::code](#code) | Event code.|
107| uint32_t [Hid_EmitItem::value](#value) | Event value.|
108| const char \* [Hid_Device::deviceName](#devicename) | Device name.|
109| uint16_t [Hid_Device::vendorId](#vendorid) | Vendor ID.|
110| uint16_t [Hid_Device::productId](#productid) | Product ID.|
111| uint16_t [Hid_Device::version](#version) | Version.|
112| uint16_t [Hid_Device::bustype](#bustype) | Bus type.|
113| [Hid_DeviceProp](#hid_deviceprop) \* [Hid_Device::properties](#properties) | Device properties.|
114| uint16_t [Hid_Device::propLength](#proplength) | Number of device properties.|
115| [Hid_EventType](#hid_eventtype) \* [Hid_EventTypeArray::hidEventType](#hideventtype) | Event type.|
116| uint16_t [Hid_EventTypeArray::length](#length-15) | Size of the array.|
117| [Hid_KeyCode](#hid_keycode) \* [Hid_KeyCodeArray::hidKeyCode](#hidkeycode) | Enumerates the key codes.|
118| uint16_t [Hid_KeyCodeArray::length](#length-25) | Size of the array.|
119| [Hid_AbsAxes](#hid_absaxes) \* [Hid_AbsAxesArray::hidAbsAxes](#hidabsaxes) | Array of absolute coordinates.|
120| uint16_t [Hid_AbsAxesArray::length](#length-35) | Size of the array.|
121| [Hid_RelAxes](#hid_relaxes) \* [Hid_RelAxesArray::hidRelAxes](#hidrelaxes) | Relative coordinate.|
122| uint16_t [Hid_RelAxesArray::length](#length-45) | Size of the array.|
123| [Hid_MscEvent](#hid_mscevent) \* [Hid_MscEventArray::hidMscEvent](#hidmscevent) | Miscellaneous event.|
124| uint16_t [Hid_MscEventArray::length](#length-55) | Size of the array.|
125| struct [Hid_EventTypeArray](_hid___event_type_array.md)[Hid_EventProperties::hidEventTypes](#hideventtypes) | Array of event types.|
126| struct [Hid_KeyCodeArray](_hid___key_code_array.md)[Hid_EventProperties::hidKeys](#hidkeys) | Array of key codes.|
127| struct [Hid_AbsAxesArray](_hid___abs_axes_array.md)[Hid_EventProperties::hidAbs](#hidabs) | Array of absolute coordinates.|
128| struct [Hid_RelAxesArray](_hid___rel_axes_array.md)[Hid_EventProperties::hidRelBits](#hidrelbits) | Array of relative coordinates.|
129| struct [Hid_MscEventArray](_hid___msc_event_array.md)[Hid_EventProperties::hidMiscellaneous](#hidmiscellaneous) | Array of miscellaneous events.|
130| int32_t [Hid_EventProperties::hidAbsMax](#hidabsmax) [64] | Maximum values of the absolute coordinates.|
131| int32_t [Hid_EventProperties::hidAbsMin](#hidabsmin) [64] | Minimum values of the absolute coordinates.|
132| int32_t [Hid_EventProperties::hidAbsFuzz](#hidabsfuzz) [64] | Fuzzy values of the absolute coordinates.|
133| int32_t [Hid_EventProperties::hidAbsFlat](#hidabsflat) [64] | Fixed values of the absolute coordinates.|
134| uint32_t [Hid_RawDevInfo::busType](#bustype) | Bus type.|
135| uint16_t [Hid_RawDevInfo::vendor](#vendor) | Provider ID.|
136| uint16_t [Hid_RawDevInfo::product](#product) | Product ID.|
137
138
139## Macro Description
140
141
142### HID_MAX_REPORT_BUFFER_SIZE
143
144```
145#define HID_MAX_REPORT_BUFFER_SIZE   (16 * 1024 - 1)
146```
147
148**Description**
149
150Defines the maximum size of the report buffer.
151
152**Since**: 18
153
154
155## Type Description
156
157
158### Hid_AbsAxesArray
159
160```
161typedef struct Hid_AbsAxesArray Hid_AbsAxesArray
162```
163
164**Description**
165
166Defines a struct for an array of absolute coordinates.
167
168**Since**: 11
169
170
171### Hid_Device
172
173```
174typedef struct Hid_Device Hid_Device
175```
176
177**Description**
178
179Defines a struct for basic device information.
180
181**Since**: 11
182
183
184### Hid_DeviceHandle
185
186```
187typedef struct Hid_DeviceHandle Hid_DeviceHandle
188```
189
190**Description**
191
192Defines the opaque USB HID device structure.
193
194**Since**: 18
195
196
197### Hid_EmitItem
198
199```
200typedef struct Hid_EmitItem Hid_EmitItem
201```
202
203**Description**
204
205Defines a struct for event information.
206
207**Since**: 11
208
209
210### Hid_EventProperties
211
212```
213typedef struct Hid_EventProperties Hid_EventProperties
214```
215
216**Description**
217
218Defines a struct for the event properties of a device.
219
220**Since**: 11
221
222
223### Hid_EventTypeArray
224
225```
226typedef struct Hid_EventTypeArray Hid_EventTypeArray
227```
228
229**Description**
230
231Defines a struct for an array of event types.
232
233**Since**: 11
234
235
236### Hid_KeyCodeArray
237
238```
239typedef struct Hid_KeyCodeArray Hid_KeyCodeArray
240```
241
242**Description**
243
244Defines a struct for an array of key codes.
245
246**Since**: 11
247
248
249### Hid_MscEventArray
250
251```
252typedef struct Hid_MscEventArray Hid_MscEventArray
253```
254
255**Description**
256
257Defines a struct for an array of miscellaneous events.
258
259**Since**: 11
260
261
262### Hid_RawDevInfo
263
264```
265typedef struct Hid_RawDevInfo Hid_RawDevInfo
266```
267
268**Description**
269
270Defines the raw device information.
271
272**Since**: 18
273
274
275### Hid_RelAxesArray
276
277```
278typedef struct Hid_RelAxesArray Hid_RelAxesArray
279```
280
281**Description**
282
283Defines a struct for an array of relative coordinates.
284
285**Since**: 11
286
287
288## Enum Description
289
290
291### Hid_AbsAxes
292
293```
294enum Hid_AbsAxes
295```
296
297**Description**
298
299Enumerates the absolute coordinates.
300
301**Since**: 11
302
303| Value| Description|
304| -------- | -------- |
305| HID_ABS_X | X axis.|
306| HID_ABS_Y | Y axis.|
307| HID_ABS_Z | Z axis.|
308| HID_ABS_RX | X axis of the right analog stick.|
309| HID_ABS_RY | Y axis of the right analog stick.|
310| HID_ABS_RZ | Z axis of the right analog stick.|
311| HID_ABS_THROTTLE | Throttle.|
312| HID_ABS_RUDDER | Rudder.|
313| HID_ABS_WHEEL | Scroll wheel.|
314| HID_ABS_GAS | Gas.|
315| HID_ABS_BRAKE | Brake.|
316| HID_ABS_HAT0X | HAT0X.|
317| HID_ABS_HAT0Y | HAT0Y.|
318| HID_ABS_HAT1X | HAT1X.|
319| HID_ABS_HAT1Y | HAT1Y.|
320| HID_ABS_HAT2X | HAT2X.|
321| HID_ABS_HAT2Y | HAT2Y.|
322| HID_ABS_HAT3X | HAT3X.|
323| HID_ABS_HAT3Y | HAT3Y.|
324| HID_ABS_PRESSURE | Pressure.|
325| HID_ABS_DISTANCE | Distance.|
326| HID_ABS_TILT_X | Tilt of X axis.|
327| HID_ABS_TILT_Y | Tilt of Y axis.|
328| HID_ABS_TOOL_WIDTH | Width of the touch tool.|
329| HID_ABS_VOLUME | Volume.|
330| HID_ABS_MISC | Others.|
331
332
333### Hid_DdkErrCode
334
335```
336enum Hid_DdkErrCode
337```
338
339**Description**
340
341Enumerates the HID DDK error codes.
342
343**Since**: 11
344
345| Value| Description|
346| -------- | -------- |
347| HID_DDK_SUCCESS | Operation succeeded.|
348| HID_DDK_NO_PERM | No permission. The value is changed from **-6** to **201** since API version 16.|
349| HID_DDK_INVALID_PARAMETER | Invalid parameter. The value is changed from **-2** to **401** since API version 16.|
350| HID_DDK_FAILURE | Operation failed. The value is changed from **-1** to **27300001** since API version 16.|
351| HID_DDK_NULL_PTR | Null pointer. The value is changed from **-4** to **27300002** since API version 16.|
352| HID_DDK_INVALID_OPERATION | Invalid operation. The value is changed from **-3** to **27300003** since API version 16.|
353| HID_DDK_TIMEOUT | Timeout. The value is changed from **-5** to **27300004** since API version 16.|
354| HID_DDK_INIT_ERROR | DDK initialization error. This enum is supported since API version 16.|
355| HID_DDK_SERVICE_ERROR | Service communication error. This enum is supported since API version 16.|
356| HID_DDK_MEMORY_ERROR | Memory-related errors, such as memory data copy failure and memory allocation failure. This enum is supported since API version 16.|
357| HID_DDK_IO_ERROR | I/O operation failure. This enum is supported since API version 16.|
358| HID_DDK_DEVICE_NOT_FOUND | Device not found. This enum is supported since API version 16.|
359
360
361### Hid_DeviceProp
362
363```
364enum Hid_DeviceProp
365```
366
367**Description**
368
369Enumerates the properties of input devices.
370
371**Since**: 11
372
373| Value| Description|
374| -------- | -------- |
375| HID_PROP_POINTER | Pointer device.|
376| HID_PROP_DIRECT | Direct input device.|
377| HID_PROP_BUTTON_PAD | Touch device with bottom keys.|
378| HID_PROP_SEMI_MT | Full multi-touch device.|
379| HID_PROP_TOP_BUTTON_PAD | Touch device with top soft keys.|
380| HID_PROP_POINTING_STICK | Pointing stick.|
381| HID_PROP_ACCELEROMETER | Accelerometer.|
382
383
384### Hid_EventType
385
386```
387enum Hid_EventType
388```
389
390**Description**
391
392Enumerates the event types.
393
394**Since**: 11
395
396| Value| Description|
397| -------- | -------- |
398| HID_EV_SYN | Sync event.|
399| HID_EV_KEY | Key event.|
400| HID_EV_REL | Relative coordinate event.|
401| HID_EV_ABS | Absolute coordinate event.|
402| HID_EV_MSC |  Miscellaneous event.|
403
404
405### Hid_KeyCode
406
407```
408enum Hid_KeyCode
409```
410
411**Description**
412
413Enumerates the key codes.
414
415**Since**: 11
416
417| Value| Description|
418| -------- | -------- |
419| HID_KEY_A | Key A|
420| HID_KEY_B | Key B|
421| HID_KEY_C | Key C|
422| HID_KEY_D | Key D|
423| HID_KEY_E | Key E|
424| HID_KEY_F | Key F|
425| HID_KEY_G | Key G|
426| HID_KEY_H | Key H|
427| HID_KEY_I | Key I|
428| HID_KEY_J | Key J|
429| HID_KEY_K | Key K|
430| HID_KEY_L | Key L|
431| HID_KEY_M | Key M|
432| HID_KEY_N | Key N|
433| HID_KEY_O | Key O|
434| HID_KEY_P | Key P|
435| HID_KEY_Q | Key Q|
436| HID_KEY_R | Key R|
437| HID_KEY_S | Key S|
438| HID_KEY_T | Key T|
439| HID_KEY_U | Key U|
440| HID_KEY_V | Key V|
441| HID_KEY_W | Key W|
442| HID_KEY_X | Key X|
443| HID_KEY_Y | Key Y|
444| HID_KEY_Z | Key Z|
445| HID_KEY_ESC | Key Esc|
446| HID_KEY_0 | Key 0|
447| HID_KEY_1 | Key 1|
448| HID_KEY_2 | Key 2|
449| HID_KEY_3 | Key 3|
450| HID_KEY_4 | Key 4|
451| HID_KEY_5 | Key 5|
452| HID_KEY_6 | Key 6|
453| HID_KEY_7 | Key 7|
454| HID_KEY_8 | Key 8|
455| HID_KEY_9 | Key 9|
456| HID_KEY_GRAVE | Key `|
457| HID_KEY_MINUS | Key -|
458| HID_KEY_EQUALS | Key =|
459| HID_KEY_BACKSPACE | key Backspace|
460| HID_KEY_LEFT_BRACKET | Key [|
461| HID_KEY_RIGHT_BRACKET | Key ]|
462| HID_KEY_ENTER | Key Enter|
463| HID_KEY_LEFT_SHIFT | Left Shift|
464| HID_KEY_BACKSLASH | Key \|
465| HID_KEY_SEMICOLON | Key ;|
466| HID_KEY_APOSTROPHE | Key '|
467| HID_KEY_SPACE | Key Space|
468| HID_KEY_SLASH | Key /|
469| HID_KEY_COMMA | Key ,|
470| HID_KEY_PERIOD | Key .|
471| HID_KEY_RIGHT_SHIFT | Right Shift|
472| HID_KEY_NUMPAD_0 | Numeral 0 on the numeric keypad|
473| HID_KEY_NUMPAD_1 | Numeral 1 on the numeric keypad|
474| HID_KEY_NUMPAD_2 | Numeral 2 on the numeric keypad|
475| HID_KEY_NUMPAD_3 | Numeral 3 on the numeric keypad|
476| HID_KEY_NUMPAD_4 | Numeral 4 on the numeric keypad|
477| HID_KEY_NUMPAD_5 | Numeral 5 on the numeric keypad|
478| HID_KEY_NUMPAD_6 | Numeral 6 on the numeric keypad|
479| HID_KEY_NUMPAD_7 | Numeral 7 on the numeric keypad|
480| HID_KEY_NUMPAD_8 | Numeral 8 on the numeric keypad|
481| HID_KEY_NUMPAD_9 | Numeral 9 on the numeric keypad|
482| HID_KEY_NUMPAD_DIVIDE | Key / on the numeric keypad|
483| HID_KEY_NUMPAD_MULTIPLY | Key * on the numeric keypad|
484| HID_KEY_NUMPAD_SUBTRACT | Key - on the numeric keypad|
485| HID_KEY_NUMPAD_ADD | Key + on the numeric keypad|
486| HID_KEY_NUMPAD_DOT | Key . on the numeric keypad|
487| HID_KEY_SYSRQ | SYSRQ key|
488| HID_KEY_DELETE | Delete key|
489| HID_KEY_MUTE | Mute key|
490| HID_KEY_VOLUME_DOWN | Volume Down key|
491| HID_KEY_VOLUME_UP | Volume Down key|
492| HID_KEY_BRIGHTNESS_DOWN | Brightness Down key|
493| HID_KEY_BRIGHTNESS_UP | Brightness Up key|
494| HID_BTN_0 | Button 0|
495| HID_BTN_1 | Button 1|
496| HID_BTN_2 | Button 2|
497| HID_BTN_3 | Button 3|
498| HID_BTN_4 | Button 4|
499| HID_BTN_5 | Button 5|
500| HID_BTN_6 | Button 6|
501| HID_BTN_7 | Button 7|
502| HID_BTN_8 | Button 8|
503| HID_BTN_9 | Button 9|
504| HID_BTN_LEFT | Left mouse button|
505| HID_BTN_RIGHT | Right mouse button|
506| HID_BTN_MIDDLE | Middle mouse button|
507| HID_BTN_SIDE | Side mouse button|
508| HID_BTN_EXTRA | Extra mouse button|
509| HID_BTN_FORWARD | Mouse forward button|
510| HID_BTN_BACKWARD | Mouse backward button|
511| HID_BTN_TASK | Mouse task button|
512| HID_BTN_TOOL_PEN | Pen|
513| HID_BTN_TOOL_RUBBER | Rubber|
514| HID_BTN_TOOL_BRUSH | Brush|
515| HID_BTN_TOOL_PENCIL | Pencil|
516| HID_BTN_TOOL_AIRBRUSH | Air brush|
517| HID_BTN_TOOL_FINGER | Finger|
518| HID_BTN_TOOL_MOUSE | Mouse|
519| HID_BTN_TOOL_LENS | Lens|
520| HID_BTN_TOOL_QUINT_TAP | Five-finger touch|
521| HID_BTN_STYLUS3 | Stylus 3|
522| HID_BTN_TOUCH | Touch|
523| HID_BTN_STYLUS | Stylus|
524| HID_BTN_STYLUS2 | Stylus 2|
525| HID_BTN_TOOL_DOUBLE_TAP | Two-finger touch|
526| HID_BTN_TOOL_TRIPLE_TAP | Three-finger touch|
527| HID_BTN_TOOL_QUAD_TAP | Four-finger touch|
528| HID_BTN_WHEEL | Scroll wheel|
529
530
531### Hid_MscEvent
532
533```
534enum Hid_MscEvent
535```
536
537**Description**
538
539Enumerates miscellaneous input events.
540
541**Since**: 11
542
543| Value| Description|
544| -------- | -------- |
545| HID_MSC_SERIAL | Serial number|
546| HID_MSC_PULSE_LED | Pulse|
547| HID_MSC_GESTURE | Gesture|
548| HID_MSC_RAW | Start event|
549| HID_MSC_SCAN | Scan|
550| HID_MSC_TIMESTAMP | Timestamp|
551
552
553### Hid_RelAxes
554
555```
556enum Hid_RelAxes
557```
558
559**Description**
560
561Enumerates the relative coordinates.
562
563**Since**: 11
564
565| Value| Description|
566| -------- | -------- |
567| HID_REL_X | X axis.|
568| HID_REL_Y | Y axis.|
569| HID_REL_Z | Z axis|
570| HID_REL_RX | X axis of the right analog stick|
571| HID_REL_RY | Y axis of the right analog stick|
572| HID_REL_RZ | Z axis of the right analog stick|
573| HID_REL_HWHEEL | Horizontal scroll wheel|
574| HID_REL_DIAL | Scale|
575| HID_REL_WHEEL | Scroll wheel|
576| HID_REL_MISC | Others|
577| HID_REL_RESERVED | Reserved|
578| HID_REL_WHEEL_HI_RES | High-resolution scroll wheel|
579| HID_REL_HWHEEL_HI_RES | High-resolution horizontal scroll wheel|
580
581
582### Hid_ReportType
583
584```
585enum Hid_ReportType
586```
587
588**Description**
589
590Defines the report (data packets exchanged between the HID device and the host) type.
591
592**Since**: 18
593
594| Value| Description|
595| -------- | -------- |
596| HID_INPUT_REPORT | Input report.|
597| HID_OUTPUT_REPORT | Output report.|
598| HID_FEATURE_REPORT | Feature report.|
599
600
601### Hid_SynEvent
602
603```
604enum Hid_SynEvent
605```
606
607**Description**
608
609Enumerates sync events.
610
611**Since**: 11
612
613| Value| Description|
614| -------- | -------- |
615| HID_SYN_REPORT | End of an event.|
616| HID_SYN_CONFIG | Configuration synchronization.|
617| HID_SYN_MT_REPORT | End of a multi-touch ABS data packet.|
618| HID_SYN_DROPPED | Event discarded.|
619
620
621## Function Description
622
623
624### OH_Hid_Close()
625
626```
627int32_t OH_Hid_Close (Hid_DeviceHandle ** dev)
628```
629
630**Description**
631
632Closes an HID device.
633
634**Since**: 18
635
636**Parameters**
637
638| Name| Description|
639| -------- | -------- |
640| dev | Device operation handle.|
641
642**Required Permissions**
643
644ohos.permission.ACCESS_DDK_HID
645
646**Returns**
647
648- HID_DDK_SUCCESS: Operation succeeded.
649
650- HID_DDK_NO_PERM: Permission verification failed.
651
652- HID_DDK_INIT_ERROR DDK: DDK initialization error.
653
654- HID_DDK_SERVICE_ERROR: DDK service communication error.
655
656- HID_DDK_IO_ERROR: I/O operation error.
657
658- HID_DDK_INVALID_PARAMETER: Empty **dev**.
659
660
661### OH_Hid_CreateDevice()
662
663```
664int32_t OH_Hid_CreateDevice (Hid_Device * hidDevice, Hid_EventProperties * hidEventProperties)
665```
666
667**Description**
668
669Creates a device.
670
671**Since**: 11
672
673**Parameters**
674
675| Name| Description|
676| -------- | -------- |
677| hidDevice | Pointer to the basic information about the device to create, including the device name, vendor ID, and product ID.|
678| hidEventProperties | Pointer to the event properties related to the device to create, including the event type, key event properties, absolute coordinate event properties, and relative coordinate event properties.|
679
680**Required Permissions**
681
682ohos.permission.ACCESS_DDK_HID
683
684**Returns**
685
686- deviceID (a non-negative number) if the API call is successful.
687
688- HID_DDK_NO_PERM: Permission verification failed.
689
690- HID_DDK_INVALID_OPERATION: hid_ddk service connection failed.
691
692- HID_DDK_INVALID_PARAMETER: Parameter verification failed. Possible causes: 1. The input **hidDevice** is a null pointer. 2. The input **hidEventProperties** is a null pointer. 3. The length of **properties** exceeds 7 characters. 4. The length of **hidEventTypes** exceeds 5 characters. 5. The length of **hidKeys** exceeds 100 characters. 6. The length of **hidAbs** exceeds 26 characters. 7. The length of **hidRelBits** exceeds 13 characters. 8. The length of **hidMiscellaneous** exceeds 6 characters.
693
694- HID_DDK_FAILURE: Number of devices exceeding the maximum value (200).
695
696
697### OH_Hid_DestroyDevice()
698
699```
700int32_t OH_Hid_DestroyDevice (int32_t deviceId)
701```
702
703**Description**
704
705Destroys a device.
706
707**Since**: 11
708
709**Parameters**
710
711| Name| Description|
712| -------- | -------- |
713| deviceId | Device ID.|
714
715**Required Permissions**
716
717ohos.permission.ACCESS_DDK_HID
718
719**Returns**
720
721- HID_DDK_SUCCESS: Operation succeeded.
722
723- HID_DDK_NO_PERM: Permission verification failed.
724
725- HID_DDK_INVALID_OPERATION: Invalid operation. The hid_ddk service connection fails or the caller is not the device creator.
726
727- HID_DDK_FAILURE: Device not exist.
728
729
730### OH_Hid_EmitEvent()
731
732```
733int32_t OH_Hid_EmitEvent (int32_t deviceId, const Hid_EmitItem items[], uint16_t length)
734```
735
736**Description**
737
738Sends an event list to a device.
739
740**Since**: 11
741
742**Parameters**
743
744| Name| Description|
745| -------- | -------- |
746| deviceId | Device ID.|
747| items | List of the events to send. The event information includes the event type (**Hid_EventType**), code (**Hid_SynEvent**, **Hid_KeyCode**, **HidBtnCode**, **Hid_AbsAxes**, **Hid_RelAxes**, or **Hid_MscEvent**), and value (depending on the actual device input).|
748| length | Length of the event list (number of events to be sent at a time).|
749
750**Required Permissions**
751
752ohos.permission.ACCESS_DDK_HID
753
754**Returns**
755
756- HID_DDK_SUCCESS: Operation succeeded.
757
758- HID_DDK_NO_PERM: Permission verification failed.
759
760- HID_DDK_INVALID_OPERATION: Invalid operation. The hid_ddk service connection fails or the caller is not the device creator.
761
762- HID_DDK_INVALID_PARAMETER: Parameter verification failed. Possible causes: 1. The device ID is smaller than 0. 2. The length of the input parameter exceeds 7 characters. 3. The input **items** is a null pointer.
763
764- HID_DDK_NULL_PTR: Null pointer. The input device is empty.
765
766- HID_DDK_FAILURE: Device not exist.
767
768
769### OH_Hid_GetPhysicalAddress()
770
771```
772int32_t OH_Hid_GetPhysicalAddress (Hid_DeviceHandle * dev, char * data, uint32_t bufSize)
773```
774
775**Description**
776
777Obtains the physical address of the HID device.
778
779**Since**: 18
780
781**Parameters**
782
783| Name| Description|
784| -------- | -------- |
785| dev | Device operation handle.|
786| data | Buffer for storing the read data.|
787| bufSize | Size of the buffer for storing read data. The value cannot exceed [HID_MAX_REPORT_BUFFER_SIZE](#hid_max_report_buffer_size).|
788
789**Required Permissions**
790
791ohos.permission.ACCESS_DDK_HID
792
793**Returns**
794
795- HID_DDK_SUCCESS: Operation succeeded.
796
797- HID_DDK_NO_PERM: Permission verification failed.
798
799- HID_DDK_INVALID_PARAMETER: Parameter verification failed. Possible causes: 1. **dev** is empty. 2. **data** is empty. 3. The value of **bufSize** is **0**. 4. The value of **bufSize** exceeds [HID_MAX_REPORT_BUFFER_SIZE](#hid_max_report_buffer_size). HID_DDK_INIT_ERROR DDK: DDK initialization error.
800
801- HID_DDK_SERVICE_ERROR: DDK service communication error.
802
803- HID_DDK_MEMORY_ERROR: Memory data copy error.
804
805- HID_DDK_IO_ERROR: I/O operation error.
806
807- HID_DDK_INVALID_OPERATION: Invalid operation.
808
809
810### OH_Hid_GetRawInfo()
811
812```
813int32_t OH_Hid_GetRawInfo (Hid_DeviceHandle * dev, Hid_RawDevInfo * rawDevInfo)
814```
815
816**Description**
817
818Obtains the original device information.
819
820**Since**: 18
821
822**Parameters**
823
824| Name| Description|
825| -------- | -------- |
826| dev | Device operation handle.|
827| rawDevInfo | Original device information, including the vendor ID, product ID, and bus type.|
828
829**Required Permissions**
830
831ohos.permission.ACCESS_DDK_HID
832
833**Returns**
834
835- HID_DDK_SUCCESS: Operation succeeded.
836
837- HID_DDK_NO_PERM: Permission verification failed.
838
839- HID_DDK_INVALID_PARAMETER: Parameter verification failed. Possible causes: 1. **dev** is empty. 2. **rawDevInfo** is empty.
840
841- HID_DDK_INIT_ERROR DDK: DDK initialization error.
842
843- HID_DDK_SERVICE_ERROR: DDK service communication error.
844
845- HID_DDK_IO_ERROR: I/O operation error.
846
847- HID_DDK_INVALID_OPERATION: Invalid operation.
848
849
850### OH_Hid_GetRawName()
851
852```
853int32_t OH_Hid_GetRawName (Hid_DeviceHandle * dev, char * data, uint32_t bufSize)
854```
855
856**Description**
857
858Obtains the original device name.
859
860**Since**: 18
861
862**Parameters**
863
864| Name| Description|
865| -------- | -------- |
866| dev | Device operation handle.|
867| data | Buffer for storing the read data.|
868| bufSize | Size of the buffer for storing read data. The value cannot exceed [HID_MAX_REPORT_BUFFER_SIZE](#hid_max_report_buffer_size).|
869
870**Required Permissions**
871
872ohos.permission.ACCESS_DDK_HID
873
874**Returns**
875
876- HID_DDK_SUCCESS: Operation succeeded.
877
878- HID_DDK_NO_PERM: Permission verification failed.
879
880- HID_DDK_INVALID_PARAMETER: Parameter verification failed. Possible causes: 1. **dev** is empty. 2. **data** is empty. 3. The value of **bufSize** is **0**. 4. The value of **bufSize** exceeds [HID_MAX_REPORT_BUFFER_SIZE](#hid_max_report_buffer_size). HID_DDK_INIT_ERROR DDK: DDK initialization error.
881
882- HID_DDK_SERVICE_ERROR: DDK service communication error.
883
884- HID_DDK_MEMORY_ERROR: Memory data copy error.
885
886- HID_DDK_IO_ERROR: I/O operation error.
887
888- HID_DDK_INVALID_OPERATION: Invalid operation.
889
890
891### OH_Hid_GetRawUniqueId()
892
893```
894int32_t OH_Hid_GetRawUniqueId (Hid_DeviceHandle * dev, uint8_t * data, uint32_t bufSize)
895```
896
897**Description**
898
899Obtains the original unique identifier of a device.
900
901**Since**: 18
902
903**Parameters**
904
905| Name| Description|
906| -------- | -------- |
907| dev | Device operation handle.|
908| data | Buffer for storing the read data.|
909| bufSize | Size of the buffer for storing read data. The value cannot exceed [HID_MAX_REPORT_BUFFER_SIZE](#hid_max_report_buffer_size).|
910
911**Required Permissions**
912
913ohos.permission.ACCESS_DDK_HID
914
915**Returns**
916
917- HID_DDK_SUCCESS: Operation succeeded.
918
919- HID_DDK_NO_PERM: Permission verification failed.
920
921- HID_DDK_INVALID_PARAMETER: Parameter verification failed. Possible causes: 1. **dev** is empty. 2. **data** is empty. 3. The value of **bufSize** is **0**. 4. The value of **bufSize** exceeds [HID_MAX_REPORT_BUFFER_SIZE](#hid_max_report_buffer_size). HID_DDK_INIT_ERROR DDK: DDK initialization error.
922
923- HID_DDK_SERVICE_ERROR: DDK service communication error.
924
925- HID_DDK_MEMORY_ERROR: Memory data copy error.
926
927- HID_DDK_IO_ERROR: I/O operation error.
928
929- HID_DDK_INVALID_OPERATION: Invalid operation.
930
931
932### OH_Hid_GetReport()
933
934```
935int32_t OH_Hid_GetReport (Hid_DeviceHandle * dev, Hid_ReportType reportType, uint8_t * data, uint32_t bufSize)
936```
937
938**Description**
939
940Obtains reports from the HID device.
941
942**Since**: 18
943
944**Parameters**
945
946| Name| Description|
947| -------- | -------- |
948| dev | Device operation handle.|
949| reportType | Report type.|
950| data | Buffer for storing the read data.|
951| bufSize | Size of the buffer for storing read data. The value cannot exceed [HID_MAX_REPORT_BUFFER_SIZE](#hid_max_report_buffer_size).|
952
953**Required Permissions**
954
955ohos.permission.ACCESS_DDK_HID
956
957**Returns**
958
959- HID_DDK_SUCCESS: Operation succeeded.
960
961- HID_DDK_NO_PERM: Permission verification failed.
962
963- HID_DDK_INVALID_PARAMETER: Parameter verification failed. Possible causes: 1. **dev** is empty. 2. **data** is empty. 3. The value of **bufSize** is **0**. 4. The value of **bufSize** exceeds [HID_MAX_REPORT_BUFFER_SIZE](#hid_max_report_buffer_size).
964
965- HID_DDK_INIT_ERROR DDK: DDK initialization error.
966
967- HID_DDK_SERVICE_ERROR: DDK service communication error.
968
969- HID_DDK_MEMORY_ERROR: Memory data copy error.
970
971- HID_DDK_IO_ERROR: I/O operation error.
972
973- HID_DDK_INVALID_OPERATION: Invalid operation.
974
975
976### OH_Hid_GetReportDescriptor()
977
978```
979int32_t OH_Hid_GetReportDescriptor (Hid_DeviceHandle * dev, uint8_t * buf, uint32_t bufSize, uint32_t * bytesRead)
980```
981
982**Description**
983
984Obtains the report descriptor of the HID device.
985
986**Since**: 18
987
988**Parameters**
989
990| Name| Description|
991| -------- | -------- |
992| dev | Device operation handle.|
993| buf | Buffer for storing descriptors.|
994| bufSize | Size of the buffer, in bytes. The value cannot exceed [HID_MAX_REPORT_BUFFER_SIZE](#hid_max_report_buffer_size).|
995| bytesRead | Number of bytes to read.|
996
997**Required Permissions**
998
999ohos.permission.ACCESS_DDK_HID
1000
1001**Returns**
1002
1003- HID_DDK_SUCCESS: Operation succeeded.
1004
1005- HID_DDK_NO_PERM: Permission verification failed.
1006
1007- HID_DDK_INVALID_PARAMETER: Parameter verification failed. Possible causes: 1. **dev** is empty. 2. **buf** is empty. 3. The value of **bufSize** is **0**. 4. The value of **bufSize** exceeds that of **[HID_MAX_REPORT_BUFFER_SIZE](#hid_max_report_buffer_size)**. 5. **bytesRead** is empty.
1008
1009- HID_DDK_INIT_ERROR DDK: DDK initialization error.
1010
1011- HID_DDK_SERVICE_ERROR: DDK service communication error.
1012
1013- HID_DDK_MEMORY_ERROR: Memory data copy error.
1014
1015- HID_DDK_IO_ERROR: I/O operation error.
1016
1017- HID_DDK_INVALID_OPERATION: Invalid operation.
1018
1019
1020### OH_Hid_Init()
1021
1022```
1023int32_t OH_Hid_Init (void)
1024```
1025
1026**Description**
1027
1028Initializes an HID DDK.
1029
1030**Since**: 18
1031
1032**Required Permissions**
1033
1034ohos.permission.ACCESS_DDK_HID
1035
1036**Returns**
1037
1038- HID_DDK_SUCCESS: Operation succeeded.
1039
1040- HID_DDK_NO_PERM: Permission verification failed.
1041
1042- HID_DDK_INIT_ERROR: DDK initialization error.
1043
1044- HID_DDK_SERVICE_ERROR: DDK service communication error.
1045
1046
1047### OH_Hid_Open()
1048
1049```
1050int32_t OH_Hid_Open (uint64_t deviceId, uint8_t interfaceIndex, Hid_DeviceHandle ** dev)
1051```
1052
1053**Description**
1054
1055Opens the device specified by **deviceId** and **interfaceIndex**.
1056
1057**Since**: 18
1058
1059**Parameters**
1060
1061| Name| Description|
1062| -------- | -------- |
1063| deviceId | Device ID.|
1064| interfaceIndex | Interface index for the API of the HID device.|
1065| dev | Device operation handle.|
1066
1067**Required Permissions**
1068
1069ohos.permission.ACCESS_DDK_HID
1070
1071**Returns**
1072
1073- HID_DDK_SUCCESS: Operation succeeded.
1074
1075- HID_DDK_NO_PERM: Permission verification failed.
1076
1077- HID_DDK_INIT_ERROR DDK: DDK initialization error.
1078
1079- HID_DDK_SERVICE_ERROR: DDK service communication error.
1080
1081- HID_DDK_MEMORY_ERROR: dev memory application error.
1082
1083- HID_DDK_IO_ERROR: I/O operation error.
1084
1085- HID_DDK_INVALID_PARAMETER: Empty **dev**.
1086
1087- HID_DDK_DEVICE_NOT_FOUND: Device not found based on the specified **deviceId** and **interfaceIndex**.
1088
1089
1090### OH_Hid_Read()
1091
1092```
1093int32_t OH_Hid_Read (Hid_DeviceHandle * dev, uint8_t * data, uint32_t bufSize, uint32_t * bytesRead)
1094```
1095
1096**Description**
1097
1098Reads reports from the HID device. The blocking mode (that is, blocking remains active until data can be read) is used by default. You can call [OH_Hid_SetNonBlocking](#oh_hid_setnonblocking) to change the mode.
1099
1100**Since**: 18
1101
1102**Parameters**
1103
1104| Name| Description|
1105| -------- | -------- |
1106| dev | Device operation handle.|
1107| data | Buffer for storing the read data.|
1108| bufSize | Size of the buffer for storing read data. The value cannot exceed [HID_MAX_REPORT_BUFFER_SIZE](#hid_max_report_buffer_size).|
1109| bytesRead | Number of bytes to read.|
1110
1111**Required Permissions**
1112
1113ohos.permission.ACCESS_DDK_HID
1114
1115**Returns**
1116
1117- HID_DDK_SUCCESS: Operation succeeded.
1118
1119- HID_DDK_NO_PERM: Permission verification failed.
1120
1121- HID_DDK_INVALID_PARAMETER: Parameter verification failed. Possible causes: 1. **dev** is empty. 2. **data** is empty. 3. The value of **bufSize** is **0**. 4. The value of **bufSize** exceeds that of **[HID_MAX_REPORT_BUFFER_SIZE](#hid_max_report_buffer_size)**. 5. **bytesRead** is empty.
1122
1123- HID_DDK_INIT_ERROR DDK: DDK initialization error.
1124
1125- HID_DDK_SERVICE_ERROR: DDK service communication error.
1126
1127- HID_DDK_MEMORY_ERROR: Memory data copy error.
1128
1129- HID_DDK_IO_ERROR: I/O operation error.
1130
1131- HID_DDK_TIMEOUT: Reading timed out.
1132
1133
1134### OH_Hid_ReadTimeout()
1135
1136```
1137int32_t OH_Hid_ReadTimeout (Hid_DeviceHandle * dev, uint8_t * data, uint32_t bufSize, int timeout, uint32_t * bytesRead)
1138```
1139
1140**Description**
1141
1142Reads reports from the HID device within the specified timeout interval.
1143
1144**Since**: 18
1145
1146**Parameters**
1147
1148| Name| Description|
1149| -------- | -------- |
1150| dev | Device operation handle.|
1151| data | Buffer for storing the read data.|
1152| bufSize | Size of the buffer for storing read data. The value cannot exceed [HID_MAX_REPORT_BUFFER_SIZE](#hid_max_report_buffer_size).|
1153| timeout | Timeout interval, in ms. The value **-1** indicates block waiting.|
1154| bytesRead | Number of bytes to read.|
1155
1156**Required Permissions**
1157
1158ohos.permission.ACCESS_DDK_HID
1159
1160**Returns**
1161
1162- HID_DDK_SUCCESS: Operation succeeded.
1163
1164- HID_DDK_NO_PERM: Permission verification failed.
1165
1166- HID_DDK_INVALID_PARAMETER: Parameter verification failed. Possible causes: 1. **dev** is empty. 2. **data** is empty. 3. The value of **bufSize** is **0**. 4. The value of **bufSize** exceeds that of **[HID_MAX_REPORT_BUFFER_SIZE](#hid_max_report_buffer_size)**. 5. **bytesRead** is empty.
1167
1168- HID_DDK_INIT_ERROR DDK: DDK initialization error.
1169
1170- HID_DDK_SERVICE_ERROR: DDK service communication error.
1171
1172- HID_DDK_MEMORY_ERROR: Memory data copy error.
1173
1174- HID_DDK_IO_ERROR: I/O operation error.
1175
1176- HID_DDK_TIMEOUT: Reading timed out.
1177
1178
1179### OH_Hid_Release()
1180
1181```
1182int32_t OH_Hid_Release (void)
1183```
1184
1185**Description**
1186
1187Releases an HID DDK.
1188
1189**Since**: 18
1190
1191**Required Permissions**
1192
1193ohos.permission.ACCESS_DDK_HID
1194
1195**Returns**
1196
1197- HID_DDK_SUCCESS: Operation succeeded.
1198
1199- HID_DDK_NO_PERM: Permission verification failed.
1200
1201- HID_DDK_INIT_ERROR DDK: DDK initialization error.
1202
1203- HID_DDK_SERVICE_ERROR: DDK service communication error.
1204
1205
1206### OH_Hid_SendReport()
1207
1208```
1209int32_t OH_Hid_SendReport (Hid_DeviceHandle * dev, Hid_ReportType reportType, const uint8_t * data, uint32_t length)
1210```
1211
1212**Description**
1213
1214Sends reports to the HID device.
1215
1216**Since**: 18
1217
1218**Parameters**
1219
1220| Name| Description|
1221| -------- | -------- |
1222| dev | Device operation handle.|
1223| reportType | Report type.|
1224| data | Data to be sent.|
1225| length | Length of the data to be sent, in bytes. The value cannot exceed [HID_MAX_REPORT_BUFFER_SIZE](#hid_max_report_buffer_size).|
1226
1227**Required Permissions**
1228
1229ohos.permission.ACCESS_DDK_HID
1230
1231**Returns**
1232
1233- HID_DDK_SUCCESS: Operation succeeded.
1234
1235- HID_DDK_NO_PERM: Permission verification failed.
1236
1237- HID_DDK_INVALID_PARAMETER: Parameter verification failed. Possible causes: 1. **dev** is empty. 2. **data** is empty. 3. The value of **length** is **0**; 4. The value of **length** exceeds [HID_MAX_REPORT_BUFFER_SIZE](#hid_max_report_buffer_size).
1238
1239- HID_DDK_INIT_ERROR DDK: DDK initialization error.
1240
1241- HID_DDK_SERVICE_ERROR: DDK service communication error.
1242
1243- HID_DDK_IO_ERROR: I/O operation error.
1244
1245- HID_DDK_INVALID_OPERATION: Invalid operation.
1246
1247
1248### OH_Hid_SetNonBlocking()
1249
1250```
1251int32_t OH_Hid_SetNonBlocking (Hid_DeviceHandle * dev, int nonBlock)
1252```
1253
1254**Description**
1255
1256Sets the device read mode to non-blocking mode.
1257
1258**Since**: 18
1259
1260**Parameters**
1261
1262| Name| Description|
1263| -------- | -------- |
1264| dev | Device operation handle.|
1265| nonBlock | Whether to enable the non-blocking mode for reading data.<br>- 1: The non-blocking mode is enabled. When [OH_Hid_Read](#oh_hid_read) is called, if the device has readable data, **HID_DDK_SUCCESS** is returned; if the device has no readable data, **HID_DDK_TIMEOUT** is returned.<br>- 0: The non-blocking mode is disabled.|
1266
1267**Required Permissions**
1268
1269ohos.permission.ACCESS_DDK_HID
1270
1271**Returns**
1272
1273- HID_DDK_SUCCESS: Operation succeeded.
1274
1275- HID_DDK_NO_PERM: Permission verification failed.
1276
1277- HID_DDK_INIT_ERROR DDK: DDK initialization error.
1278
1279- HID_DDK_INVALID_PARAMETER: Parameter verification failed. Possible causes: 1. **dev** is empty. 2. The value of **nonBlock** is not **1** or **0**.
1280
1281- HID_DDK_SERVICE_ERROR: DDK service communication error.
1282
1283
1284### OH_Hid_Write()
1285
1286```
1287int32_t OH_Hid_Write (Hid_DeviceHandle * dev, uint8_t * data, uint32_t length, uint32_t * bytesWritten)
1288```
1289
1290**Description**
1291
1292Writes reports to an HID device.
1293
1294**Since**: 18
1295
1296**Parameters**
1297
1298| Name| Description|
1299| -------- | -------- |
1300| dev | Device operation handle.|
1301| data | Data to be written.|
1302| length | Length of the data to be written, in bytes. The value cannot exceed [HID_MAX_REPORT_BUFFER_SIZE](#hid_max_report_buffer_size).|
1303| bytesWritten | Number of written bytes.|
1304
1305**Required Permissions**
1306
1307ohos.permission.ACCESS_DDK_HID
1308
1309**Returns**
1310
1311- HID_DDK_SUCCESS: Operation succeeded.
1312
1313- HID_DDK_NO_PERM: Permission verification failed.
1314
1315- HID_DDK_INVALID_PARAMETER: Parameter verification failed. Possible causes: 1. **dev** is empty. 2. **data** is empty. 3. The value of length is **0**; 4. The value of **length** exceeds [HID_MAX_REPORT_BUFFER_SIZE](#hid_max_report_buffer_size); 5. **bytesWritten** is empty.
1316
1317- HID_DDK_INIT_ERROR DDK: DDK initialization error.
1318
1319- HID_DDK_SERVICE_ERROR: DDK service communication error.
1320
1321- HID_DDK_IO_ERROR: I/O operation error.
1322
1323
1324## Variable Description
1325
1326
1327### bustype
1328
1329```
1330uint16_t Hid_Device::bustype
1331```
1332
1333**Description**
1334
1335Bus type.
1336
1337
1338### busType
1339
1340```
1341uint32_t Hid_RawDevInfo::busType
1342```
1343
1344**Description**
1345
1346Bus type.
1347
1348
1349### code
1350
1351```
1352uint16_t Hid_EmitItem::code
1353```
1354
1355**Description**
1356
1357Event code.
1358
1359
1360### deviceName
1361
1362```
1363const char* Hid_Device::deviceName
1364```
1365
1366**Description**
1367
1368Device name.
1369
1370
1371### hidAbs
1372
1373```
1374struct Hid_AbsAxesArray Hid_EventProperties::hidAbs
1375```
1376
1377**Description**
1378
1379Array of absolute coordinates.
1380
1381
1382### hidAbsAxes
1383
1384```
1385Hid_AbsAxes* Hid_AbsAxesArray::hidAbsAxes
1386```
1387
1388**Description**
1389
1390Array of absolute coordinates.
1391
1392
1393### hidAbsFlat
1394
1395```
1396int32_t Hid_EventProperties::hidAbsFlat[64]
1397```
1398
1399**Description**
1400
1401Fixed values of the absolute coordinates.
1402
1403
1404### hidAbsFuzz
1405
1406```
1407int32_t Hid_EventProperties::hidAbsFuzz[64]
1408```
1409
1410**Description**
1411
1412Fuzzy values of the absolute coordinates.
1413
1414
1415### hidAbsMax
1416
1417```
1418int32_t Hid_EventProperties::hidAbsMax[64]
1419```
1420
1421**Description**
1422
1423Maximum values of the absolute coordinates.
1424
1425
1426### hidAbsMin
1427
1428```
1429int32_t Hid_EventProperties::hidAbsMin[64]
1430```
1431
1432**Description**
1433
1434Minimum values of the absolute coordinates.
1435
1436
1437### hidEventType
1438
1439```
1440Hid_EventType* Hid_EventTypeArray::hidEventType
1441```
1442
1443**Description**
1444
1445Event type.
1446
1447
1448### hidEventTypes
1449
1450```
1451struct Hid_EventTypeArray Hid_EventProperties::hidEventTypes
1452```
1453
1454**Description**
1455
1456Array of event types.
1457
1458
1459### hidKeyCode
1460
1461```
1462Hid_KeyCode* Hid_KeyCodeArray::hidKeyCode
1463```
1464
1465**Description**
1466
1467Enumerates the key codes.
1468
1469
1470### hidKeys
1471
1472```
1473struct Hid_KeyCodeArray Hid_EventProperties::hidKeys
1474```
1475
1476**Description**
1477
1478Array of key codes.
1479
1480
1481### hidMiscellaneous
1482
1483```
1484struct Hid_MscEventArray Hid_EventProperties::hidMiscellaneous
1485```
1486
1487**Description**
1488
1489Array of miscellaneous events.
1490
1491
1492### hidMscEvent
1493
1494```
1495Hid_MscEvent* Hid_MscEventArray::hidMscEvent
1496```
1497
1498**Description**
1499
1500Miscellaneous event.
1501
1502
1503### hidRelAxes
1504
1505```
1506Hid_RelAxes* Hid_RelAxesArray::hidRelAxes
1507```
1508
1509**Description**
1510
1511Relative coordinate.
1512
1513
1514### hidRelBits
1515
1516```
1517struct Hid_RelAxesArray Hid_EventProperties::hidRelBits
1518```
1519
1520**Description**
1521
1522Array of relative coordinates.
1523
1524
1525### length [1/5]
1526
1527```
1528uint16_t Hid_EventTypeArray::length
1529```
1530
1531**Description**
1532
1533Size of the array.
1534
1535
1536### length [2/5]
1537
1538```
1539uint16_t Hid_KeyCodeArray::length
1540```
1541
1542**Description**
1543
1544Size of the array.
1545
1546
1547### length [3/5]
1548
1549```
1550uint16_t Hid_AbsAxesArray::length
1551```
1552
1553**Description**
1554
1555Size of the array.
1556
1557
1558### length [4/5]
1559
1560```
1561uint16_t Hid_RelAxesArray::length
1562```
1563
1564**Description**
1565
1566Size of the array.
1567
1568
1569### length [5/5]
1570
1571```
1572uint16_t Hid_MscEventArray::length
1573```
1574
1575**Description**
1576
1577Size of the array.
1578
1579
1580### product
1581
1582```
1583uint16_t Hid_RawDevInfo::product
1584```
1585
1586**Description**
1587
1588Product ID.
1589
1590
1591### productId
1592
1593```
1594uint16_t Hid_Device::productId
1595```
1596
1597**Description**
1598
1599Product ID.
1600
1601
1602### properties
1603
1604```
1605Hid_DeviceProp* Hid_Device::properties
1606```
1607
1608**Description**
1609
1610Device properties.
1611
1612
1613### propLength
1614
1615```
1616uint16_t Hid_Device::propLength
1617```
1618
1619**Description**
1620
1621Number of device properties.
1622
1623
1624### type
1625
1626```
1627uint16_t Hid_EmitItem::type
1628```
1629
1630**Description**
1631
1632Enumerates the event types.
1633
1634
1635### value
1636
1637```
1638uint32_t Hid_EmitItem::value
1639```
1640
1641**Description**
1642
1643Event value.
1644
1645
1646### vendor
1647
1648```
1649uint16_t Hid_RawDevInfo::vendor
1650```
1651
1652**Description**
1653
1654Provider ID.
1655
1656
1657### vendorId
1658
1659```
1660uint16_t Hid_Device::vendorId
1661```
1662
1663**Description**
1664
1665Vendor ID.
1666
1667
1668### version
1669
1670```
1671uint16_t Hid_Device::version
1672```
1673
1674**Description**
1675
1676Version.
1677