1# @ohos.multimodalInput.inputDevice (Input Device) 2 3 4The **inputDevice** module allows you to listen for hot swap events of input devices and query information about input devices. 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 12## Modules to Import 13 14 15```js 16import inputDevice from '@ohos.multimodalInput.inputDevice'; 17``` 18 19## inputDevice.getDeviceList<sup>9+</sup> 20 21getDeviceList(callback: AsyncCallback<Array<number>>): void 22 23Obtains the IDs of all input devices. This API uses an asynchronous callback to return the result. 24 25**System capability**: SystemCapability.MultimodalInput.Input.InputDevice 26 27**Parameters** 28 29| Name | Type | Mandatory| Description | 30| -------- | ---------------------------------------- | ---- | ---------------------------------------- | 31| callback | AsyncCallback<Array<number>> | Yes | Callback used to return the result.| 32 33**Example** 34 35```js 36try { 37 inputDevice.getDeviceList((error: Error, ids: Array<Number>) => { 38 if (error) { 39 console.log(`Failed to get device id list, error: ${JSON.stringify(error, [`code`, `message`])}`); 40 return; 41 } 42 console.log(`Device id list: ${JSON.stringify(ids)}`); 43 }); 44} catch (error) { 45 console.log(`Failed to get device id list, error: ${JSON.stringify(error, [`code`, `message`])}`); 46} 47``` 48 49## inputDevice.getDeviceList<sup>9+</sup> 50 51getDeviceList(): Promise<Array<number>> 52 53Obtains the IDs of all input devices. This API uses a promise to return the result. 54 55**System capability**: SystemCapability.MultimodalInput.Input.InputDevice 56 57**Return value** 58 59| Parameters | Description | 60| ---------------------------------- | ------------------------------------------- | 61| Promise<Array<number>> | Promise used to return the result.| 62 63**Example** 64 65```js 66try { 67 inputDevice.getDeviceList().then((ids: Array<Number>) => { 68 console.log(`Device id list: ${JSON.stringify(ids)}`); 69 }); 70} catch (error) { 71 console.log(`Failed to get device id list, error: ${JSON.stringify(error, [`code`, `message`])}`); 72} 73``` 74 75## inputDevice.getDeviceInfo<sup>9+</sup> 76 77getDeviceInfo(deviceId: number, callback: AsyncCallback<InputDeviceData>): void 78 79Obtains information about an input device. This API uses an asynchronous callback to return the result. 80 81**System capability**: SystemCapability.MultimodalInput.Input.InputDevice 82 83**Parameters** 84 85| Name | Type | Mandatory| Description | 86| -------- | -------------------------------------------------------- | ---- | --------------------------------------- | 87| deviceId | number | Yes | ID of the input device. | 88| callback | AsyncCallback<[InputDeviceData](#inputdevicedata)> | Yes | Callback used to return the result, which is an **InputDeviceData** object.| 89 90**Example** 91 92```js 93// Obtain the name of the device whose ID is 1. 94try { 95 inputDevice.getDeviceInfo(1, (error: Error, deviceData: inputDevice.InputDeviceData) => { 96 if (error) { 97 console.log(`Failed to get device info, error: ${JSON.stringify(error, [`code`, `message`])}`); 98 return; 99 } 100 console.log(`Device info: ${JSON.stringify(deviceData)}`); 101 }); 102} catch (error) { 103 console.log(`Failed to get device info, error: ${JSON.stringify(error, [`code`, `message`])}`); 104} 105``` 106 107## inputDevice.getDeviceInfo<sup>9+</sup> 108 109getDeviceInfo(deviceId: number): Promise<InputDeviceData> 110 111Obtains information about an input device. This API uses a promise to return the result. 112 113**System capability**: SystemCapability.MultimodalInput.Input.InputDevice 114 115**Parameters** 116 117| Name | Type | Mandatory| Description | 118| -------- | ------ | ---- | ---------------------- | 119| deviceId | number | Yes | ID of the input device.| 120 121**Return value** 122 123| Parameters | Description | 124| -------------------------------------------------- | ------------------------------- | 125| Promise<[InputDeviceData](#inputdevicedata)> | Promise used to return the result.| 126 127**Example** 128 129```js 130// Obtain the name of the device whose ID is 1. 131try { 132 inputDevice.getDeviceInfo(1).then((deviceData: inputDevice.InputDeviceData) => { 133 console.log(`Device info: ${JSON.stringify(deviceData)}`); 134 }); 135} catch (error) { 136 console.log(`Failed to get device info, error: ${JSON.stringify(error, [`code`, `message`])}`); 137} 138``` 139 140## inputDevice.getDeviceInfoSync<sup>10+</sup> 141 142getDeviceInfoSync(deviceId: number): InputDeviceData 143 144Obtains information about the specified input device. 145 146**System capability**: SystemCapability.MultimodalInput.Input.InputDevice 147 148**Parameters** 149 150| Name | Type | Mandatory| Description | 151| -------- | ------ | ---- | ---------------------- | 152| deviceId | number | Yes | ID of the input device.| 153 154**Return value** 155 156| Parameters | Description | 157| -------------------------------------------------- | ------------------------------- | 158| [InputDeviceData](#inputdevicedata) | Information about the input device.| 159 160**Example** 161 162```js 163// Obtain the name of the device whose ID is 1. 164try { 165 let deviceData: inputDevice.InputDeviceData = inputDevice.getDeviceInfoSync(1) 166 console.log(`Device info: ${JSON.stringify(deviceData)}`) 167} catch (error) { 168 console.log(`Failed to get device info, error: ${JSON.stringify(error, [`code`, `message`])}`) 169} 170``` 171 172## inputDevice.on<sup>9+</sup> 173 174on(type: "change", listener: Callback<DeviceListener>): void 175 176Enables listening for device hot swap events. 177 178**System capability**: SystemCapability.MultimodalInput.Input.InputDevice 179 180**Parameters** 181 182| Name | Type | Mandatory | Description | 183| -------- | ---------------------------------------- | ---- | ----------- | 184| type | string | Yes | Event type of the input device. | 185| listener | Callback<[DeviceListener](#devicelistener9)> | Yes | Listener for events of the input device.| 186 187**Example** 188 189```js 190let isPhysicalKeyboardExist = true; 191try { 192 inputDevice.on("change", (data: inputDevice.DeviceListener) => { 193 console.log(`Device event info: ${JSON.stringify(data)}`); 194 inputDevice.getKeyboardType(data.deviceId, (err: Error, type: inputDevice.KeyboardType) => { 195 console.log("The keyboard type is: " + type); 196 if (type == inputDevice.KeyboardType.ALPHABETIC_KEYBOARD && data.type == 'add') { 197 // The physical keyboard is connected. 198 isPhysicalKeyboardExist = true; 199 } else if (type == inputDevice.KeyboardType.ALPHABETIC_KEYBOARD && data.type == 'remove') { 200 // The physical keyboard is disconnected. 201 isPhysicalKeyboardExist = false; 202 } 203 }); 204 }); 205 // Check whether the soft keyboard is open based on the value of isPhysicalKeyboardExist. 206} catch (error) { 207 console.log(`Get device info failed, error: ${JSON.stringify(error, [`code`, `message`])}`); 208} 209``` 210 211## inputDevice.off<sup>9+</sup> 212 213off(type: "change", listener?: Callback<DeviceListener>): void 214 215Disables listening for device hot swap events. This API is called before the application exits. 216 217**System capability**: SystemCapability.MultimodalInput.Input.InputDevice 218 219**Parameters** 220 221| Name | Type | Mandatory | Description | 222| -------- | ---------------------------------------- | ---- | ----------- | 223| type | string | Yes | Event type of the input device. | 224| listener | Callback<[DeviceListener](#devicelistener9)> | No | Listener for events of the input device.| 225 226**Example** 227 228```js 229function callback(data: inputDevice.DeviceListener) { 230 console.log(`Report device event info: ${JSON.stringify(data, [`type`, `deviceId`])}`); 231}; 232 233try { 234 inputDevice.on("change", callback); 235} catch (error) { 236 console.log(`Listen device event failed, error: ${JSON.stringify(error, [`code`, `message`])}`); 237} 238 239// Disable this listener. 240try { 241 inputDevice.off("change", callback); 242} catch (error) { 243 console.log(`Cancel listening device event failed, error: ${JSON.stringify(error, [`code`, `message`])}`); 244} 245 246// Disable all listeners. 247try { 248 inputDevice.off("change"); 249} catch (error) { 250 console.log(`Cancel all listening device event failed, error: ${JSON.stringify(error, [`code`, `message`])}`); 251} 252``` 253 254## inputDevice.getDeviceIds<sup>(deprecated)</sup> 255 256getDeviceIds(callback: AsyncCallback<Array<number>>): void 257 258Obtains the IDs of all input devices. This API uses an asynchronous callback to return the result. 259 260This API is deprecated since API version 9. You are advised to use [inputDevice.getDeviceList](#inputdevicegetdevicelist9) instead. 261 262**System capability**: SystemCapability.MultimodalInput.Input.InputDevice 263 264**Parameters** 265 266| Name | Type | Mandatory| Description | 267| -------- | ---------------------------------------- | ---- | ---------------------------------------- | 268| callback | AsyncCallback<Array<number>> | Yes | Callback used to return the result.| 269 270**Example** 271 272```js 273inputDevice.getDeviceIds((error: Error, ids: Array<Number>) => { 274 if (error) { 275 console.log(`Failed to get device id list, error: ${JSON.stringify(error, [`code`, `message`])}`); 276 return; 277 } 278 console.log(`Device id list: ${JSON.stringify(ids)}`); 279}); 280``` 281 282## inputDevice.getDeviceIds<sup>(deprecated)</sup> 283 284getDeviceIds(): Promise<Array<number>> 285 286Obtains the IDs of all input devices. This API uses a promise to return the result. 287 288This API is deprecated since API version 9. You are advised to use [inputDevice.getDeviceList](#inputdevicegetdevicelist9) instead. 289 290**System capability**: SystemCapability.MultimodalInput.Input.InputDevice 291 292**Return value** 293 294| Parameters | Description | 295| ---------------------------------- | ------------------------------------------- | 296| Promise<Array<number>> | Promise used to return the result.| 297 298**Example** 299 300```js 301inputDevice.getDeviceIds().then((ids: Array<Number>) => { 302 console.log(`Device id list: ${JSON.stringify(ids)}`); 303}); 304``` 305 306## inputDevice.getDevice<sup>(deprecated)</sup> 307 308getDevice(deviceId: number, callback: AsyncCallback<InputDeviceData>): void 309 310Obtains information about an input device. This API uses an asynchronous callback to return the result. 311 312This API is deprecated since API version 9. You are advised to use [inputDevice.getDeviceInfo](#inputdevicegetdeviceinfo9) instead. 313 314**System capability**: SystemCapability.MultimodalInput.Input.InputDevice 315 316**Parameters** 317 318| Name | Type | Mandatory| Description | 319| -------- | -------------------------------------------------------- | ---- | -------------------------------- | 320| deviceId | number | Yes | ID of the input device. | 321| callback | AsyncCallback<[InputDeviceData](#inputdevicedata)> | Yes | Callback used to return the result, which is an **InputDeviceData** object.| 322 323**Example** 324 325```js 326// Obtain the name of the device whose ID is 1. 327inputDevice.getDevice(1, (error: Error, deviceData: inputDevice.InputDeviceData) => { 328 if (error) { 329 console.log(`Failed to get device info, error: ${JSON.stringify(error, [`code`, `message`])}`); 330 return; 331 } 332 console.log(`Device info: ${JSON.stringify(deviceData)}`); 333}); 334``` 335 336## inputDevice.getDevice<sup>(deprecated)</sup> 337 338getDevice(deviceId: number): Promise<InputDeviceData> 339 340Obtains information about an input device. This API uses a promise to return the result. 341 342This API is deprecated since API version 9. You are advised to use [inputDevice.getDeviceInfo](#inputdevicegetdeviceinfo9) instead. 343 344**System capability**: SystemCapability.MultimodalInput.Input.InputDevice 345 346**Parameters** 347 348| Name | Type | Mandatory| Description | 349| -------- | ------ | ---- | ------------ | 350| deviceId | number | Yes | ID of the input device.| 351 352**Return value** 353 354| Parameters | Description | 355| -------------------------------------------------- | ----------------------------------- | 356| Promise<[InputDeviceData](#inputdevicedata)> | Promise used to return the result.| 357 358**Example** 359 360```js 361// Obtain the name of the device whose ID is 1. 362inputDevice.getDevice(1).then((deviceData: inputDevice.InputDeviceData) => { 363 console.log(`Device info: ${JSON.stringify(deviceData)}`); 364}); 365``` 366 367## inputDevice.supportKeys<sup>9+</sup> 368 369supportKeys(deviceId: number, keys: Array<KeyCode>, callback: AsyncCallback <Array<boolean>>): void 370 371Obtains the key codes supported by the input device. This API uses an asynchronous callback to return the result. 372 373**System capability**: SystemCapability.MultimodalInput.Input.InputDevice 374 375**Parameters** 376 377| Name | Type | Mandatory| Description | 378| -------- | ----------------------------------------- | ---- | ------------------------------------------------------ | 379| deviceId | number | Yes | Unique ID of the input device. If the same physical device is repeatedly inserted and removed, its ID changes.| 380| keys | Array<KeyCode> | Yes | Key codes to be queried. A maximum of five key codes can be specified. | 381| callback | AsyncCallback<Array<boolean>> | Yes | Callback used to return the result. | 382 383**Example** 384 385```js 386// Check whether the input device whose ID is 1 supports key codes 17, 22, and 2055. 387try { 388 inputDevice.supportKeys(1, [17, 22, 2055], (error: Error, supportResult: Array<Boolean>) => { 389 console.log(`Query result: ${JSON.stringify(supportResult)}`); 390 }); 391} catch (error) { 392 console.log(`Query failed, error: ${JSON.stringify(error, [`code`, `message`])}`); 393} 394``` 395 396## inputDevice.supportKeys<sup>9+</sup> 397 398supportKeys(deviceId: number, keys: Array<KeyCode>): Promise<Array<boolean>> 399 400Obtains the key codes supported by the input device. This API uses a promise to return the result. 401 402**System capability**: SystemCapability.MultimodalInput.Input.InputDevice 403 404**Parameters** 405 406| Name | Type | Mandatory| Description | 407| -------- | -------------------- | ---- | ------------------------------------------------------ | 408| deviceId | number | Yes | Unique ID of the input device. If the same physical device is repeatedly inserted and removed, its ID changes.| 409| keys | Array<KeyCode> | Yes | Key codes to be queried. A maximum of five key codes can be specified. | 410 411**Return value** 412 413| Parameters | Description | 414| ----------------------------------- | ------------------------------- | 415| Promise<Array<boolean>> | Promise used to return the result.| 416 417**Example** 418 419```js 420// Check whether the input device whose ID is 1 supports key codes 17, 22, and 2055. 421try { 422 inputDevice.supportKeys(1, [17, 22, 2055]).then((supportResult: Array<Boolean>) => { 423 console.log(`Query result: ${JSON.stringify(supportResult)}`); 424 }); 425} catch (error) { 426 console.log(`Query failed, error: ${JSON.stringify(error, [`code`, `message`])}`); 427} 428``` 429 430## inputDevice.supportKeysSync<sup>10+</sup> 431 432supportKeysSync(deviceId: number, keys: Array<KeyCode>): Array<boolean> 433 434Checks whether the input device supports the specified keycode value. 435 436**System capability**: SystemCapability.MultimodalInput.Input.InputDevice 437 438**Parameters** 439 440| Name | Type | Mandatory| Description | 441| -------- | -------------------- | ---- | ------------------------------------------------------ | 442| deviceId | number | Yes | Unique ID of the input device. If the same physical device is repeatedly inserted and removed, its ID changes.| 443| keys | Array<KeyCode> | Yes | Key codes to be queried. A maximum of five key codes can be specified. | 444 445**Return value** 446 447| Parameters | Description | 448| ----------------------------------- | ------------------------------- | 449| Array<boolean> | Result indicating whether the input device supports the keycode value. The value **true** indicates yes, and the value **false** indicates no.| 450 451**Example** 452 453```js 454// Check whether the input device whose ID is 1 supports key codes 17, 22, and 2055. 455try { 456 let supportResult: Array<Boolean> = inputDevice.supportKeysSync(1, [17, 22, 2055]) 457 console.log(`Query result: ${JSON.stringify(supportResult)}`) 458} catch (error) { 459 console.log(`Query failed, error: ${JSON.stringify(error, [`code`, `message`])}`) 460} 461``` 462 463## inputDevice.getKeyboardType<sup>9+</sup> 464 465getKeyboardType(deviceId: number, callback: AsyncCallback<KeyboardType>): void 466 467Obtains the keyboard type of an input device. This API uses an asynchronous callback to return the result. 468 469**System capability**: SystemCapability.MultimodalInput.Input.InputDevice 470 471**Parameters** 472 473| Name | Type | Mandatory| Description | 474| -------- | --------------------------------------------------- | ---- | ------------------------------------------------------------ | 475| deviceId | number | Yes | Unique ID of the input device. If the same physical device is repeatedly inserted and removed, its ID changes.| 476| callback | AsyncCallback<[KeyboardType](#keyboardtype9)> | Yes | Callback used to return the result. | 477 478**Example** 479 480```js 481// Query the keyboard type of the input device whose ID is 1. 482try { 483 inputDevice.getKeyboardType(1, (error: Error, type: Number) => { 484 if (error) { 485 console.log(`Failed to get keyboard type, error: ${JSON.stringify(error, [`code`, `message`])}`); 486 return; 487 } 488 console.log(`Keyboard type: ${JSON.stringify(type)}`); 489 }); 490} catch (error) { 491 console.log(`Failed to get keyboard type, error: ${JSON.stringify(error, [`code`, `message`])}`); 492} 493``` 494 495## inputDevice.getKeyboardType<sup>9+</sup> 496 497getKeyboardType(deviceId: number): Promise<KeyboardType> 498 499Obtains the keyboard type of an input device. This API uses an asynchronous callback to return the result. 500 501**System capability**: SystemCapability.MultimodalInput.Input.InputDevice 502 503**Parameters** 504 505| Name | Type | Mandatory| Description | 506| -------- | ------ | ---- | ------------------------------------------------------------ | 507| deviceId | number | Yes | Unique ID of the input device. If the same physical device is repeatedly inserted and removed, its ID changes.| 508 509**Return value** 510 511| Parameters | Description | 512| --------------------------------------------- | ------------------------------- | 513| Promise<[KeyboardType](#keyboardtype9)> | Promise used to return the result.| 514 515**Example** 516 517```js 518// Query the keyboard type of the input device whose ID is 1. 519try { 520 inputDevice.getKeyboardType(1).then((type: Number) => { 521 console.log(`Keyboard type: ${JSON.stringify(type)}`); 522 }); 523} catch (error) { 524 console.log(`Failed to get keyboard type, error: ${JSON.stringify(error, [`code`, `message`])}`); 525} 526``` 527 528## inputDevice.getKeyboardTypeSync<sup>10+</sup> 529 530getKeyboardTypeSync(deviceId: number): KeyboardType 531 532Obtains the keyboard type of the input device. 533 534**System capability**: SystemCapability.MultimodalInput.Input.InputDevice 535 536**Parameters** 537 538| Name | Type | Mandatory| Description | 539| -------- | ------ | ---- | ------------------------------------------------------------ | 540| deviceId | number | Yes | Unique ID of the input device. If the same physical device is repeatedly inserted and removed, its ID changes.| 541 542**Return value** 543 544| Parameters | Description | 545| --------------------------------------------- | ------------------------------- | 546| [KeyboardType](#keyboardtype9) | Keyboard type.| 547 548**Example** 549 550```js 551// Query the keyboard type of the input device whose ID is 1. 552try { 553 let type: number = inputDevice.getKeyboardTypeSync(1) 554 console.log(`Keyboard type: ${JSON.stringify(type)}`) 555} catch (error) { 556 console.log(`Failed to get keyboard type, error: ${JSON.stringify(error, [`code`, `message`])}`) 557} 558``` 559 560## inputDevice.setKeyboardRepeatDelay<sup>10+</sup> 561 562setKeyboardRepeatDelay(delay: number, callback: AsyncCallback<void>): void 563 564Sets the keyboard repeat delay. This API uses an asynchronous callback to return the result. 565 566**System capability**: SystemCapability.MultimodalInput.Input.InputDevice 567 568**System API**: This is a system API. 569 570**Parameters** 571 572| Name | Type | Mandatory| Description | 573| -------- | ------ | ---- | ------------------------------------------------------------ | 574| delay | number | Yes | Keyboard repeat delay, in ms. The value range is [300, 1000] and the default value is **500**.| 575| callback | AsyncCallback<void> | Yes | Callback used to return the result.| 576 577**Example** 578 579```js 580try { 581 inputDevice.setKeyboardRepeatDelay(350, (error: Error) => { 582 if (error) { 583 console.log(`Set keyboard repeat delay failed, error: ${JSON.stringify(error, [`code`, `message`])}`); 584 return; 585 } 586 console.log(`Set keyboard repeat delay success`); 587 }); 588} catch (error) { 589 console.log(`Set keyboard repeat delay failed, error: ${JSON.stringify(error, [`code`, `message`])}`); 590} 591``` 592 593## inputDevice.setKeyboardRepeatDelay<sup>10+</sup> 594 595setKeyboardRepeatDelay(delay: number): Promise<void> 596 597Sets the keyboard repeat delay. This API uses a promise to return the result. 598 599**System capability**: SystemCapability.MultimodalInput.Input.InputDevice 600 601**System API**: This is a system API. 602 603**Parameters** 604 605| Name | Type | Mandatory | Description | 606| ----- | ------ | ---- | ----------------------------------- | 607| delay | number | Yes | Keyboard repeat delay, in ms. The value range is [300, 1000] and the default value is **500**.| 608 609**Return value** 610 611| Parameters | Description | 612| ------------------- | ---------------- | 613| Promise<void> | Promise used to return the result.| 614 615**Example** 616 617```js 618try { 619 inputDevice.setKeyboardRepeatDelay(350).then(() => { 620 console.log(`Set keyboard repeat delay success`); 621 }); 622} catch (error) { 623 console.log(`Set keyboard repeat delay failed, error: ${JSON.stringify(error, [`code`, `message`])}`); 624} 625``` 626 627## inputDevice.getKeyboardRepeatDelay<sup>10+</sup> 628 629getKeyboardRepeatDelay(callback: AsyncCallback<number>): void 630 631Obtains the keyboard repeat delay. This API uses an asynchronous callback to return the result. 632 633**System capability**: SystemCapability.MultimodalInput.Input.InputDevice 634 635**System API**: This is a system API. 636 637**Parameters** 638 639| Name | Type | Mandatory| Description | 640| -------- | ------ | ---- | ------------------------------------------------------------ | 641| callback | AsyncCallback<number> | Yes | Callback used to return the result.| 642 643**Example** 644 645```js 646try { 647 inputDevice.getKeyboardRepeatDelay((error: Error, delay: Number) => { 648 if (error) { 649 console.log(`Get keyboard repeat delay failed, error: ${JSON.stringify(error, [`code`, `message`])}`); 650 return; 651 } 652 console.log(`Get keyboard repeat delay success`); 653 }); 654} catch (error) { 655 console.log(`Get keyboard repeat delay failed, error: ${JSON.stringify(error, [`code`, `message`])}`); 656} 657``` 658 659## inputDevice.getKeyboardRepeatDelay<sup>10+</sup> 660 661getKeyboardRepeatDelay(): Promise<number> 662 663Obtains the keyboard repeat delay. This API uses a promise to return the result. 664 665**System capability**: SystemCapability.MultimodalInput.Input.InputDevice 666 667**System API**: This is a system API. 668 669**Return value** 670 671| Parameters | Description | 672| --------------------- | ------------------- | 673| Promise<number> | Promise used to return the result.| 674 675**Example** 676 677```js 678try { 679 inputDevice.getKeyboardRepeatDelay().then((delay: Number) => { 680 console.log(`Get keyboard repeat delay success`); 681 }); 682} catch (error) { 683 console.log(`Get keyboard repeat delay failed, error: ${JSON.stringify(error, [`code`, `message`])}`); 684} 685``` 686 687## inputDevice.setKeyboardRepeatRate<sup>10+</sup> 688 689setKeyboardRepeatRate(rate: number, callback: AsyncCallback<void>): void 690 691Sets the keyboard repeat rate. This API uses an asynchronous callback to return the result. 692 693**System capability**: SystemCapability.MultimodalInput.Input.InputDevice 694 695**System API**: This is a system API. 696 697**Parameters** 698 699| Name | Type | Mandatory| Description | 700| -------- | ------ | ---- | ------------------------------------------------------------ | 701| rate | number | Yes | Keyboard repeat rate, in ms/time. The value range is [36, 100] and the default value is 50.| 702| callback | AsyncCallback<void> | Yes | Callback used to return the result.| 703 704**Example** 705 706```js 707try { 708 inputDevice.setKeyboardRepeatRate(60, (error: Error) => { 709 if (error) { 710 console.log(`Set keyboard repeat rate failed, error: ${JSON.stringify(error, [`code`, `message`])}`); 711 return; 712 } 713 console.log(`Set keyboard repeat rate success`); 714 }); 715} catch (error) { 716 console.log(`Set keyboard repeat rate failed, error: ${JSON.stringify(error, [`code`, `message`])}`); 717} 718``` 719 720## inputDevice.setKeyboardRepeatRate<sup>10+</sup> 721 722setKeyboardRepeatRate(rate: number): Promise<void> 723 724Sets the keyboard repeat rate. This API uses a promise to return the result. 725 726**System capability**: SystemCapability.MultimodalInput.Input.InputDevice 727 728**System API**: This is a system API. 729 730**Parameters** 731 732| Name | Type | Mandatory | Description | 733| ----- | ------ | ---- | ----------------------------------- | 734| rate | number | Yes | Keyboard repeat rate, in ms/time. The value range is [36, 100] and the default value is 50.| 735 736**Return value** 737 738| Parameters | Description | 739| ------------------- | ---------------- | 740| Promise<void> | Promise used to return the result.| 741 742**Example** 743 744```js 745try { 746 inputDevice.setKeyboardRepeatRate(60).then(() => { 747 console.log(`Set keyboard repeat rate success`); 748 }); 749} catch (error) { 750 console.log(`Set keyboard repeat rate failed, error: ${JSON.stringify(error, [`code`, `message`])}`); 751} 752``` 753 754## inputDevice.getKeyboardRepeatRate<sup>10+</sup> 755 756getKeyboardRepeatRate(callback: AsyncCallback<number>): void 757 758Obtains the keyboard repeat rate. This API uses an asynchronous callback to return the result. 759 760**System capability**: SystemCapability.MultimodalInput.Input.InputDevice 761 762**System API**: This is a system API. 763 764**Parameters** 765 766| Name | Type | Mandatory | Description | 767| -------- | --------------------------- | ---- | -------------- | 768| callback | AsyncCallback<number> | Yes | Callback used to return the result.| 769 770**Example** 771 772```js 773try { 774 inputDevice.getKeyboardRepeatRate((error: Error, rate: Number) => { 775 if (error) { 776 console.log(`Get keyboard repeat rate failed, error: ${JSON.stringify(error, [`code`, `message`])}`); 777 return; 778 } 779 console.log(`Get keyboard repeat rate success`); 780 }); 781} catch (error) { 782 console.log(`Get keyboard repeat rate failed, error: ${JSON.stringify(error, [`code`, `message`])}`); 783} 784``` 785 786## inputDevice.getKeyboardRepeatRate<sup>10+</sup> 787 788getKeyboardRepeatRate(): Promise<number> 789 790Obtains the keyboard repeat rate. This API uses a promise to return the result. 791 792**System capability**: SystemCapability.MultimodalInput.Input.InputDevice 793 794**System API**: This is a system API. 795 796**Return value** 797 798| Parameters | Description | 799| --------------------- | ------------------- | 800| Promise<number> | Promise used to return the result.| 801 802**Example** 803 804```js 805try { 806 inputDevice.getKeyboardRepeatRate().then((rate: Number) => { 807 console.log(`Get keyboard repeat rate success`); 808 }); 809} catch (error) { 810 console.log(`Get keyboard repeat rate failed, error: ${JSON.stringify(error, [`code`, `message`])}`); 811} 812``` 813 814## DeviceListener<sup>9+</sup> 815 816Defines the listener for hot swap events of an input device. 817 818**System capability**: SystemCapability.MultimodalInput.Input.InputDevice 819 820| Name | Type | Readable | Writable | Description | 821| --------- | ------ | ---- | ---- | ------- | 822| type | [ChangedType](#changedtype) | Yes| No| Device change type, which indicates whether an input device is inserted or removed.| 823| deviceId | number | Yes| No| Unique ID of the input device. If the same physical device is repeatedly inserted and removed, its ID changes.| 824 825## InputDeviceData 826 827Defines the information about an input device. 828 829**System capability**: SystemCapability.MultimodalInput.Input.InputDevice 830 831| Name | Type | Readable | Writable | Description | 832| --------- | ------ | ---- | ---- | ------- | 833| id | number | Yes| No| Unique ID of the input device. If the same physical device is repeatedly inserted and removed, its ID changes.| 834| name | string | Yes| No| Name of the input device. | 835| sources | Array<[SourceType](#sourcetype)> | Yes| No| Source type of the input device. For example, if a keyboard is attached with a touchpad, the device has two input sources: keyboard and touchpad.| 836| axisRanges | Array<[AxisRange](#axisrange)> | Yes| No| Axis information of the input device. | 837| bus<sup>9+</sup> | number | Yes| No| Bus type of the input device. | 838| product<sup>9+</sup> | number | Yes| No| Product information of the input device. | 839| vendor<sup>9+</sup> | number | Yes| No| Vendor information of the input device. | 840| version<sup>9+</sup> | number | Yes| No| Version information of the input device. | 841| phys<sup>9+</sup> | string | Yes| No| Physical address of the input device. | 842| uniq<sup>9+</sup> | string | Yes| No| Unique ID of the input device. | 843 844## AxisType<sup>9+</sup> 845 846Defines the axis type of an input device. 847 848**System capability**: SystemCapability.MultimodalInput.Input.InputDevice 849 850| Name | Type | Readable | Writable | Description | 851| --------- | ------ | ---- | ---- | ------- | 852| touchmajor | string | Yes| No| **touchmajor** axis. | 853| touchminor | string | Yes| No| **touchminor** axis. | 854| toolminor | string | Yes| No| **toolminor** axis. | 855| toolmajor | string | Yes| No| **toolmajor** axis. | 856| orientation | string | Yes| No| Orientation axis.| 857| pressure | string | Yes| No| Pressure axis. | 858| x | string | Yes| No| X axis. | 859| y | string | Yes| No| Y axis. | 860| null | string | Yes| No| None. | 861 862## AxisRange 863 864Defines the axis range of an input device. 865 866**System capability**: SystemCapability.MultimodalInput.Input.InputDevice 867 868| Name | Type | Readable | Writable | Description | 869| --------- | ------ | ---- | ---- | ------- | 870| source | [SourceType](#sourcetype) | Yes| No| Input source type of the axis.| 871| axis | [AxisType](#axistype9) | Yes| No| Axis type. | 872| max | number | Yes| No| Maximum value of the axis. | 873| min | number | Yes| No| Minimum value of the axis. | 874| fuzz<sup>9+</sup> | number | Yes| No| Fuzzy value of the axis. | 875| flat<sup>9+</sup> | number | Yes| No| Benchmark value of the axis. | 876| resolution<sup>9+</sup> | number | Yes| No| Resolution of the axis. | 877 878## SourceType<sup>9+</sup> 879 880Input source type of the axis. For example, if a mouse reports an x-axis event, the input source of the x-axis is the mouse. 881 882**System capability**: SystemCapability.MultimodalInput.Input.InputDevice 883 884| Name | Type | Readable | Writable | Description | 885| --------- | ------ | ---- | ---- | ------- | 886| keyboard | string | Yes| No| The input device is a keyboard. | 887| touchscreen | string | Yes| No| The input device is a touchscreen.| 888| mouse | string | Yes| No| The input device is a mouse. | 889| trackball | string | Yes| No| The input device is a trackball.| 890| touchpad | string | Yes| No| The input device is a touchpad.| 891| joystick | string | Yes| No| The input device is a joystick.| 892 893## ChangedType<sup>9+</sup> 894 895Defines the change type for the hot swap event of an input device. 896 897**System capability**: SystemCapability.MultimodalInput.Input.InputDevice 898 899| Name | Type | Readable | Writable | Description | 900| --------- | ------ | ---- | ---- | ------- | 901| add | string | Yes| No| An input device is inserted.| 902| remove | string | Yes| No| An input device is removed.| 903 904## KeyboardType<sup>9+</sup> 905 906Enumerates the keyboard types. 907 908**System capability**: SystemCapability.MultimodalInput.Input.InputDevice 909 910| Name | Value | Description | 911| ------------------- | ---- | --------- | 912| NONE | 0 | Keyboard without keys. | 913| UNKNOWN | 1 | Keyboard with unknown keys.| 914| ALPHABETIC_KEYBOARD | 2 | Full keyboard. | 915| DIGITAL_KEYBOARD | 3 | Keypad. | 916| HANDWRITING_PEN | 4 | Stylus. | 917| REMOTE_CONTROL | 5 | Remote control. | 918