1# @ohos.bluetooth.hid (Bluetooth hid Module) 2 3The **hid** module provides APIs for using the Bluetooth Human Interface Device Profile (HID). 4 5> **NOTE** 6> 7> The initial APIs of this module are supported since API version 10. Newly added APIs will be marked with a superscript to indicate their earliest API version. 8 9 10 11## Modules to Import 12 13```js 14import hid from '@ohos.bluetooth.hid'; 15import { BusinessError } from '@ohos.base'; 16``` 17 18 19## hid.createHidHostProfile<a name="createHidHostProfile"></a> 20 21createHidHostProfile(): HidHostProfile 22 23Creates a **HidHostProfile** instance. 24 25**System capability**: SystemCapability.Communication.Bluetooth.Core 26 27**Return value** 28 29| Type | Description | 30| ----------------------------- | ---------- | 31| HidHostProfile | **HidHostProfile** instance created.| 32 33**Example** 34 35```js 36try { 37 let hidHostProfile = hid.createHidHostProfile(); 38 console.info('hidHost success'); 39} catch (err) { 40 console.error('errCode: ' + (err as BusinessError).code + ', errMessage: ' + (err as BusinessError).message); 41} 42``` 43 44 45## HidHostProfile 46 47Before using any API of **HidHostProfile**, you need to create an instance of this class by using **createHidHostProfile()**. 48 49 50### connect<a name="HidHost-connect"></a> 51 52connect(deviceId: string): void 53 54Connects to the HidHost service of a device. 55 56**System API**: This is a system API. 57 58**Required permissions**: ohos.permission.ACCESS_BLUETOOTH and ohos.permission.MANAGE_BLUETOOTH 59 60**System capability**: SystemCapability.Communication.Bluetooth.Core 61 62**Parameters** 63 64| Name | Type | Mandatory | Description | 65| ------ | ------ | ---- | ------- | 66| deviceId | string | Yes | Address of the remote device.| 67 68**Error codes** 69 70For details about the error codes, see [Bluetooth Error Codes](../errorcodes/errorcode-bluetoothManager.md). 71 72| ID| Error Message| 73| -------- | ---------------------------- | 74|2900001 | Service stopped. | 75|2900003 | Bluetooth switch is off. | 76|2900004 | Profile is not supported. | 77|2900099 | Operation failed. | 78 79**Example** 80 81```js 82try { 83 let hidHostProfile = hid.createHidHostProfile(); 84 hidHostProfile.connect('XX:XX:XX:XX:XX:XX'); 85} catch (err) { 86 console.error('errCode: ' + (err as BusinessError).code + ', errMessage: ' + (err as BusinessError).message); 87} 88``` 89 90 91### disconnect<a name="HidHost-disconnect"></a> 92 93disconnect(deviceId: string): void 94 95Disconnects from the HidHost service of a device. 96 97**System API**: This is a system API. 98 99**Required permissions**: ohos.permission.ACCESS_BLUETOOTH and ohos.permission.MANAGE_BLUETOOTH 100 101**System capability**: SystemCapability.Communication.Bluetooth.Core 102 103**Parameters** 104 105| Name | Type | Mandatory | Description | 106| ------ | ------ | ---- | ------- | 107| deviceId | string | Yes | Address of the remote device.| 108 109**Error codes** 110 111For details about the error codes, see [Bluetooth Error Codes](../errorcodes/errorcode-bluetoothManager.md). 112 113| ID| Error Message| 114| -------- | ---------------------------- | 115|2900001 | Service stopped. | 116|2900003 | Bluetooth switch is off. | 117|2900004 | Profile is not supported. | 118|2900099 | Operation failed. | 119 120**Example** 121 122```js 123try { 124 let hidHostProfile = hid.createHidHostProfile(); 125 hidHostProfile.disconnect('XX:XX:XX:XX:XX:XX'); 126} catch (err) { 127 console.error('errCode: ' + (err as BusinessError).code + ', errMessage: ' + (err as BusinessError).message); 128} 129``` 130