1# @ohos.multimodalInput.inputDevice (Input Device) (System API) 2 3 4The **inputDevice** module implements input device management functions such as querying input device information. 5 6 7> **NOTE** 8> 9> The initial APIs of this module are supported since API version 8. Newly added APIs will be marked with a superscript to indicate their earliest API version. 10> 11> This topic describes only system APIs provided by the module. For details about its public APIs, see [@ohos.multimodalInput.inputDevice (Input Device)](js-apis-inputdevice.md). 12 13 14## Modules to Import 15 16```js 17import { inputDevice } from '@kit.InputKit'; 18``` 19 20## inputDevice.setKeyboardRepeatDelay<sup>10+</sup> 21 22setKeyboardRepeatDelay(delay: number, callback: AsyncCallback<void>): void 23 24Sets the keyboard repeat delay. This API uses an asynchronous callback to return the result. 25 26**System capability**: SystemCapability.MultimodalInput.Input.InputDevice 27 28**System API**: This is a system API. 29 30**Parameters** 31 32| Name | Type | Mandatory| Description | 33| -------- | ------ | ---- | ------------------------------------------------------------ | 34| delay | number | Yes | Keyboard repeat delay, in ms. The value range is [300, 1000] and the default value is **500**.| 35| callback | AsyncCallback<void> | Yes | Callback used to return the result.| 36 37**Error codes** 38 39For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 40 41| ID | Error Message | 42| ---- | --------------------- | 43| 202 | SystemAPI permission error. | 44| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;2. Incorrect parameter types; 3. Parameter verification failed. | 45 46**Example** 47 48```js 49try { 50 inputDevice.setKeyboardRepeatDelay(350, (error: Error) => { 51 if (error) { 52 console.error(`Set keyboard repeat delay failed, error: ${JSON.stringify(error, [`code`, `message`])}`); 53 return; 54 } 55 console.log(`Set keyboard repeat delay success`); 56 }); 57} catch (error) { 58 console.error(`Set keyboard repeat delay failed, error: ${JSON.stringify(error, [`code`, `message`])}`); 59} 60``` 61 62## inputDevice.setKeyboardRepeatDelay<sup>10+</sup> 63 64setKeyboardRepeatDelay(delay: number): Promise<void> 65 66Sets the keyboard repeat delay. This API uses a promise to return the result. 67 68**System capability**: SystemCapability.MultimodalInput.Input.InputDevice 69 70**System API**: This is a system API. 71 72**Parameters** 73 74| Name | Type | Mandatory | Description | 75| ----- | ------ | ---- | ----------------------------------- | 76| delay | number | Yes | Keyboard repeat delay, in ms. The value range is [300, 1000] and the default value is **500**.| 77 78**Return value** 79 80| Type | Description | 81| ------------------- | ---------------- | 82| Promise<void> | A promise that returns no value.| 83 84**Error codes** 85 86For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 87 88| ID | Error Message | 89| ---- | --------------------- | 90| 202 | SystemAPI permission error. | 91| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;2. Incorrect parameter types; 3. Parameter verification failed. | 92 93**Example** 94 95```js 96try { 97 inputDevice.setKeyboardRepeatDelay(350).then(() => { 98 console.log(`Set keyboard repeat delay success`); 99 }); 100} catch (error) { 101 console.error(`Set keyboard repeat delay failed, error: ${JSON.stringify(error, [`code`, `message`])}`); 102} 103``` 104 105## inputDevice.getKeyboardRepeatDelay<sup>10+</sup> 106 107getKeyboardRepeatDelay(callback: AsyncCallback<number>): void 108 109Obtains the keyboard repeat delay. This API uses an asynchronous callback to return the result. 110 111**System capability**: SystemCapability.MultimodalInput.Input.InputDevice 112 113**System API**: This is a system API. 114 115**Parameters** 116 117| Name | Type | Mandatory| Description | 118| -------- | ------ | ---- | ------------------------------------------------------------ | 119| callback | AsyncCallback<number> | Yes | Callback used to return the keyboard repeat delay.| 120 121**Error codes** 122 123For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 124 125| ID | Error Message | 126| ---- | --------------------- | 127| 202 | SystemAPI permission error. | 128| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;2. Incorrect parameter types; 3. Parameter verification failed. | 129 130**Example** 131 132```js 133try { 134 inputDevice.getKeyboardRepeatDelay((error: Error, delay: Number) => { 135 if (error) { 136 console.error(`Get keyboard repeat delay failed, error: ${JSON.stringify(error, [`code`, `message`])}`); 137 return; 138 } 139 console.log(`Get keyboard repeat delay success`); 140 }); 141} catch (error) { 142 console.error(`Get keyboard repeat delay failed, error: ${JSON.stringify(error, [`code`, `message`])}`); 143} 144``` 145 146## inputDevice.getKeyboardRepeatDelay<sup>10+</sup> 147 148getKeyboardRepeatDelay(): Promise<number> 149 150Obtains the keyboard repeat delay. This API uses a promise to return the result. 151 152**System capability**: SystemCapability.MultimodalInput.Input.InputDevice 153 154**System API**: This is a system API. 155 156**Return value** 157 158| Type | Description | 159| --------------------- | ------------------- | 160| Promise<number> | Promise used to return the keyboard repeat delay.| 161 162**Error codes** 163 164For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 165 166| ID | Error Message | 167| ---- | --------------------- | 168| 202 | SystemAPI permission error. | 169| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;2. Incorrect parameter types; 3. Parameter verification failed. | 170 171**Example** 172 173```js 174try { 175 inputDevice.getKeyboardRepeatDelay().then((delay: Number) => { 176 console.log(`Get keyboard repeat delay success`); 177 }); 178} catch (error) { 179 console.error(`Get keyboard repeat delay failed, error: ${JSON.stringify(error, [`code`, `message`])}`); 180} 181``` 182 183## inputDevice.setKeyboardRepeatRate<sup>10+</sup> 184 185setKeyboardRepeatRate(rate: number, callback: AsyncCallback<void>): void 186 187Sets the keyboard repeat rate. This API uses an asynchronous callback to return the result. 188 189**System capability**: SystemCapability.MultimodalInput.Input.InputDevice 190 191**System API**: This is a system API. 192 193**Parameters** 194 195| Name | Type | Mandatory| Description | 196| -------- | ------ | ---- | ------------------------------------------------------------ | 197| rate | number | Yes | Keyboard repeat rate, in ms/time. The value range is [36, 100] and the default value is 50.| 198| callback | AsyncCallback<void> | Yes | Callback used to return the result.| 199 200**Error codes** 201 202For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 203 204| ID | Error Message | 205| ---- | --------------------- | 206| 202 | SystemAPI permission error. | 207| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;2. Incorrect parameter types; 3. Parameter verification failed. | 208 209**Example** 210 211```js 212try { 213 inputDevice.setKeyboardRepeatRate(60, (error: Error) => { 214 if (error) { 215 console.error(`Set keyboard repeat rate failed, error: ${JSON.stringify(error, [`code`, `message`])}`); 216 return; 217 } 218 console.log(`Set keyboard repeat rate success`); 219 }); 220} catch (error) { 221 console.error(`Set keyboard repeat rate failed, error: ${JSON.stringify(error, [`code`, `message`])}`); 222} 223``` 224 225## inputDevice.setKeyboardRepeatRate<sup>10+</sup> 226 227setKeyboardRepeatRate(rate: number): Promise<void> 228 229Sets the keyboard repeat rate. This API uses a promise to return the result. 230 231**System capability**: SystemCapability.MultimodalInput.Input.InputDevice 232 233**System API**: This is a system API. 234 235**Parameters** 236 237| Name | Type | Mandatory | Description | 238| ----- | ------ | ---- | ----------------------------------- | 239| rate | number | Yes | Keyboard repeat rate, in ms/time. The value range is [36, 100] and the default value is 50.| 240 241**Return value** 242 243| Type | Description | 244| ------------------- | ---------------- | 245| Promise<void> | A promise that returns no value.| 246 247**Error codes** 248 249For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 250 251| ID | Error Message | 252| ---- | --------------------- | 253| 202 | SystemAPI permission error. | 254| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;2. Incorrect parameter types; 3. Parameter verification failed. | 255 256**Example** 257 258```js 259try { 260 inputDevice.setKeyboardRepeatRate(60).then(() => { 261 console.log(`Set keyboard repeat rate success`); 262 }); 263} catch (error) { 264 console.error(`Set keyboard repeat rate failed, error: ${JSON.stringify(error, [`code`, `message`])}`); 265} 266``` 267 268## inputDevice.getKeyboardRepeatRate<sup>10+</sup> 269 270getKeyboardRepeatRate(callback: AsyncCallback<number>): void 271 272Obtains the keyboard repeat rate. This API uses an asynchronous callback to return the result. 273 274**System capability**: SystemCapability.MultimodalInput.Input.InputDevice 275 276**System API**: This is a system API. 277 278**Parameters** 279 280| Name | Type | Mandatory | Description | 281| -------- | --------------------------- | ---- | -------------- | 282| callback | AsyncCallback<number> | Yes | Callback used to return the keyboard repeat rate.| 283 284**Error codes** 285 286For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 287 288| ID | Error Message | 289| ---- | --------------------- | 290| 202 | SystemAPI permission error. | 291| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;2. Incorrect parameter types; 3. Parameter verification failed. | 292 293**Example** 294 295```js 296try { 297 inputDevice.getKeyboardRepeatRate((error: Error, rate: Number) => { 298 if (error) { 299 console.error(`Get keyboard repeat rate failed, error: ${JSON.stringify(error, [`code`, `message`])}`); 300 return; 301 } 302 console.log(`Get keyboard repeat rate success`); 303 }); 304} catch (error) { 305 console.error(`Get keyboard repeat rate failed, error: ${JSON.stringify(error, [`code`, `message`])}`); 306} 307``` 308 309## inputDevice.getKeyboardRepeatRate<sup>10+</sup> 310 311getKeyboardRepeatRate(): Promise<number> 312 313Obtains the keyboard repeat rate. This API uses a promise to return the result. 314 315**System capability**: SystemCapability.MultimodalInput.Input.InputDevice 316 317**System API**: This is a system API. 318 319**Return value** 320 321| Type | Description | 322| --------------------- | ------------------- | 323| Promise<number> | Promise used to return the keyboard repeat rate.| 324 325**Error codes** 326 327For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 328 329| ID | Error Message | 330| ---- | --------------------- | 331| 202 | SystemAPI permission error. | 332| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;2. Incorrect parameter types; 3. Parameter verification failed. | 333 334**Example** 335 336```js 337try { 338 inputDevice.getKeyboardRepeatRate().then((rate: Number) => { 339 console.log(`Get keyboard repeat rate success`); 340 }); 341} catch (error) { 342 console.error(`Get keyboard repeat rate failed, error: ${JSON.stringify(error, [`code`, `message`])}`); 343} 344``` 345 346## inputDevice.setInputDeviceEnabled<sup>18+</sup> 347 348setInputDeviceEnabled(deviceId: number, enabled: boolean): Promise<void> 349 350Sets the input switch status of an input device. Take the touchscreen as an example. If the input switch is off, the touchscreen does not respond when being touched. If the input switch is on, the touchscreen wakes up when being touched. 351 352**Required permissions**: ohos.permission.INPUT_DEVICE_CONTROLLER 353 354**System capability**: SystemCapability.MultimodalInput.Input.InputDevice 355 356**System API**: This is a system API. 357 358**Parameters** 359 360| Name | Type | Mandatory| Description | 361| -------- | ------- | ---- | ------------------------- | 362| deviceId | number | Yes | Device ID. | 363| enabled | boolean | Yes | Switch status of the input device. The value **true** indicates that the input device is enabled, and the value **false** indicates the opposite.| 364 365**Error codes** 366 367For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Input Device Error Codes](errorcode-inputdevice.md). 368 369 370| ID| Error Message | 371| -------- | ------------------------------------------------------------ | 372| 201 | Permission denied. | 373| 202 | Not system application. | 374| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;2. Incorrect parameter types; 3. Parameter verification failed. | 375| 3900001 | The specified device does not exist. | 376 377**Example** 378 379```js 380try { 381 inputDevice.setInputDeviceEnabled(0, true).then(() => { 382 console.info(`Set input device enable success`); 383 }); 384} catch (error) { 385 console.error(`Set input device enable error`); 386} 387``` 388