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'; 15``` 16 17 18## hid.createHidHostProfile 19 20createHidHostProfile(): HidHostProfile 21 22Creates a **HidHostProfile** instance. 23 24**System capability**: SystemCapability.Communication.Bluetooth.Core 25 26**Return value** 27 28| Type | Description | 29| ----------------------------- | ---------- | 30| HidHostProfile | **HidHostProfile** instance created.| 31 32**Example** 33 34```js 35import { BusinessError } from '@ohos.base'; 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 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 82import { BusinessError } from '@ohos.base'; 83try { 84 let hidHostProfile = hid.createHidHostProfile(); 85 hidHostProfile.connect('XX:XX:XX:XX:XX:XX'); 86} catch (err) { 87 console.error('errCode: ' + (err as BusinessError).code + ', errMessage: ' + (err as BusinessError).message); 88} 89``` 90 91 92### disconnect 93 94disconnect(deviceId: string): void 95 96Disconnects from the HidHost service of a device. 97 98**System API**: This is a system API. 99 100**Required permissions**: ohos.permission.ACCESS_BLUETOOTH and ohos.permission.MANAGE_BLUETOOTH 101 102**System capability**: SystemCapability.Communication.Bluetooth.Core 103 104**Parameters** 105 106| Name | Type | Mandatory | Description | 107| ------ | ------ | ---- | ------- | 108| deviceId | string | Yes | Address of the remote device.| 109 110**Error codes** 111 112For details about the error codes, see [Bluetooth Error Codes](../errorcodes/errorcode-bluetoothManager.md). 113 114| ID| Error Message| 115| -------- | ---------------------------- | 116|2900001 | Service stopped. | 117|2900003 | Bluetooth switch is off. | 118|2900004 | Profile is not supported. | 119|2900099 | Operation failed. | 120 121**Example** 122 123```js 124import { BusinessError } from '@ohos.base'; 125try { 126 let hidHostProfile = hid.createHidHostProfile(); 127 hidHostProfile.disconnect('XX:XX:XX:XX:XX:XX'); 128} catch (err) { 129 console.error('errCode: ' + (err as BusinessError).code + ', errMessage: ' + (err as BusinessError).message); 130} 131``` 132