js-apis-inputdevice.md 30.5 KB
Newer Older
S
shawn_he 已提交
1
# @ohos.multimodalInput.inputDevice (Input Device)
Z
zengyawen 已提交
2 3


S
shawn_he 已提交
4 5 6 7 8
The **inputDevice** module allows you to listen for hot swap events of input devices and query information about input devices.


> **NOTE**
>
Z
zengyawen 已提交
9 10
> 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.

S
shawn_he 已提交
11

Z
zengyawen 已提交
12 13
## Modules to Import

S
shawn_he 已提交
14

S
shawn_he 已提交
15
```js
Z
zengyawen 已提交
16 17
import inputDevice from '@ohos.multimodalInput.inputDevice';
```
S
shawn_he 已提交
18

S
shawn_he 已提交
19 20 21 22 23 24 25 26 27 28
## inputDevice.getDeviceList<sup>9+</sup>

getDeviceList(callback: AsyncCallback&lt;Array&lt;number&gt;&gt;): void

Obtains the IDs of all input devices. This API uses an asynchronous callback to return the result.

**System capability**: SystemCapability.MultimodalInput.Input.InputDevice

**Parameters**

S
shawn_he 已提交
29 30
| Name    | Type                                    | Mandatory| Description                                    |
| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
S
shawn_he 已提交
31 32 33 34 35 36
| callback | AsyncCallback&lt;Array&lt;number&gt;&gt; | Yes  | Callback used to return the result.|

**Example**

```js
try {
S
shawn_he 已提交
37
  inputDevice.getDeviceList((error, ids) => {
S
shawn_he 已提交
38
    if (error) {
S
shawn_he 已提交
39
      console.log(`Failed to get device id list, error: ${JSON.stringify(error, [`code`, `message`])}`);
S
shawn_he 已提交
40 41
      return;
    }
S
shawn_he 已提交
42
    console.log(`Device id list: ${JSON.stringify(ids)}`);
S
shawn_he 已提交
43 44
  });
} catch (error) {
S
shawn_he 已提交
45
  console.log(`Failed to get device id list, error: ${JSON.stringify(error, [`code`, `message`])}`);
S
shawn_he 已提交
46 47 48 49 50 51 52 53 54 55 56 57 58
}
```

## inputDevice.getDeviceList<sup>9+</sup>

getDeviceList(): Promise&lt;Array&lt;number&gt;&gt;

Obtains the IDs of all input devices. This API uses a promise to return the result.

**System capability**: SystemCapability.MultimodalInput.Input.InputDevice

**Return value**

S
shawn_he 已提交
59 60
| Parameters                              | Description                                       |
| ---------------------------------- | ------------------------------------------- |
S
shawn_he 已提交
61 62 63 64 65 66
| Promise&lt;Array&lt;number&gt;&gt; | Promise used to return the result.|

**Example**

```js
try {
67
  inputDevice.getDeviceList().then((ids: Array<number>) => {
S
shawn_he 已提交
68
    console.log(`Device id list: ${JSON.stringify(ids)}`);
S
shawn_he 已提交
69 70
  });
} catch (error) {
S
shawn_he 已提交
71
  console.log(`Failed to get device id list, error: ${JSON.stringify(error, [`code`, `message`])}`);
S
shawn_he 已提交
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94
}
```

## inputDevice.getDeviceInfo<sup>9+</sup>

getDeviceInfo(deviceId: number, callback: AsyncCallback&lt;InputDeviceData&gt;): void

Obtains information about an input device. This API uses an asynchronous callback to return the result.

**System capability**: SystemCapability.MultimodalInput.Input.InputDevice

**Parameters**

| Name    | Type                                                    | Mandatory| Description                                   |
| -------- | -------------------------------------------------------- | ---- | --------------------------------------- |
| deviceId | number                                                   | Yes  | ID of the input device.                 |
| callback | AsyncCallback&lt;[InputDeviceData](#inputdevicedata)&gt; | Yes  | Callback used to return the result, which is an **InputDeviceData** object.|

**Example**

```js
// Obtain the name of the device whose ID is 1.
try {
S
shawn_he 已提交
95
  inputDevice.getDeviceInfo(1, (error, deviceData) => {
S
shawn_he 已提交
96
    if (error) {
S
shawn_he 已提交
97
      console.log(`Failed to get device info, error: ${JSON.stringify(error, [`code`, `message`])}`);
S
shawn_he 已提交
98 99
      return;
    }
S
shawn_he 已提交
100
    console.log(`Device info: ${JSON.stringify(deviceData)}`);
S
shawn_he 已提交
101 102
  });
} catch (error) {
S
shawn_he 已提交
103
  console.log(`Failed to get device info, error: ${JSON.stringify(error, [`code`, `message`])}`);
S
shawn_he 已提交
104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122
}
```

## inputDevice.getDeviceInfo<sup>9+</sup>

getDeviceInfo(deviceId: number): Promise&lt;InputDeviceData&gt;

Obtains information about an input device. This API uses a promise to return the result.

**System capability**: SystemCapability.MultimodalInput.Input.InputDevice

**Parameters**

| Name    | Type  | Mandatory| Description                  |
| -------- | ------ | ---- | ---------------------- |
| deviceId | number | Yes  | ID of the input device.|

**Return value**

S
shawn_he 已提交
123
| Parameters                                              | Description                           |
S
shawn_he 已提交
124 125 126 127 128 129 130 131
| -------------------------------------------------- | ------------------------------- |
| Promise&lt;[InputDeviceData](#inputdevicedata)&gt; | Promise used to return the result.|

**Example**

```js
// Obtain the name of the device whose ID is 1.
try {
S
shawn_he 已提交
132 133
  inputDevice.getDeviceInfo(1).then((deviceData) => {
    console.log(`Device info: ${JSON.stringify(deviceData)}`);
S
shawn_he 已提交
134 135
  });
} catch (error) {
S
shawn_he 已提交
136
  console.log(`Failed to get device info, error: ${JSON.stringify(error, [`code`, `message`])}`);
S
shawn_he 已提交
137 138 139
}
```

S
shawn_he 已提交
140 141 142 143
## inputDevice.on<sup>9+</sup>

on(type: "change", listener: Callback&lt;DeviceListener&gt;): void

S
shawn_he 已提交
144
Enables listening for device hot swap events.
S
shawn_he 已提交
145 146 147 148 149

**System capability**: SystemCapability.MultimodalInput.Input.InputDevice

**Parameters**

S
shawn_he 已提交
150 151 152
| Name      | Type                                      | Mandatory  | Description         |
| -------- | ---------------------------------------- | ---- | ----------- |
| type     | string                                   | Yes   | Event type of the input device. |
S
shawn_he 已提交
153
| listener | Callback&lt;[DeviceListener](#devicelistener9)&gt; | Yes   | Listener for events of the input device.|
S
shawn_he 已提交
154 155 156 157 158

**Example**

```js
let isPhysicalKeyboardExist = true;
S
shawn_he 已提交
159
try {
160
  inputDevice.on("change", (data: inputDevice.DeviceListener) => {
S
shawn_he 已提交
161
    console.log(`Device event info: ${JSON.stringify(data)}`);
162
    inputDevice.getKeyboardType(data.deviceId, (err: Error, type: inputDevice.KeyboardType) => {
S
shawn_he 已提交
163 164
      console.log("The keyboard type is: " + type);
      if (type == inputDevice.KeyboardType.ALPHABETIC_KEYBOARD && data.type == 'add') {
S
shawn_he 已提交
165 166
        // The physical keyboard is connected.
        isPhysicalKeyboardExist = true;
S
shawn_he 已提交
167
      } else if (type == inputDevice.KeyboardType.ALPHABETIC_KEYBOARD && data.type == 'remove') {
S
shawn_he 已提交
168 169 170
        // The physical keyboard is disconnected.
        isPhysicalKeyboardExist = false;
      }
S
shawn_he 已提交
171
    });
S
shawn_he 已提交
172 173 174
  });
  // Check whether the soft keyboard is open based on the value of isPhysicalKeyboardExist.
} catch (error) {
S
shawn_he 已提交
175
  console.log(`Get device info failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
S
shawn_he 已提交
176
}
S
shawn_he 已提交
177 178 179 180 181 182
```

## inputDevice.off<sup>9+</sup>

off(type: "change", listener?: Callback&lt;DeviceListener&gt;): void

S
shawn_he 已提交
183
Disables listening for device hot swap events. This API is called before the application exits.
S
shawn_he 已提交
184 185 186 187 188

**System capability**: SystemCapability.MultimodalInput.Input.InputDevice

**Parameters**

S
shawn_he 已提交
189 190 191
| Name      | Type                                      | Mandatory  | Description         |
| -------- | ---------------------------------------- | ---- | ----------- |
| type     | string                                   | Yes   | Event type of the input device. |
S
shawn_he 已提交
192
| listener | Callback&lt;[DeviceListener](#devicelistener9)&gt; | No   | Listener for events of the input device.|
S
shawn_he 已提交
193 194 195 196

**Example**

```js
S
shawn_he 已提交
197 198 199
function callback(data) {
  console.log(`Report device event info: ${JSON.stringify(data, [`type`, `deviceId`])}`);
};
S
shawn_he 已提交
200 201

try {
S
shawn_he 已提交
202
  inputDevice.on("change", callback);
S
shawn_he 已提交
203
} catch (error) {
S
shawn_he 已提交
204
  console.log(`Listen device event failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
S
shawn_he 已提交
205 206 207
}

// Disable this listener.
S
shawn_he 已提交
208
try {
S
shawn_he 已提交
209
  inputDevice.off("change", callback);
S
shawn_he 已提交
210
} catch (error) {
S
shawn_he 已提交
211
  console.log(`Cancel listening device event failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
S
shawn_he 已提交
212
}
S
shawn_he 已提交
213 214

// Disable all listeners.
S
shawn_he 已提交
215 216 217
try {
  inputDevice.off("change");
} catch (error) {
S
shawn_he 已提交
218
  console.log(`Cancel all listening device event failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
S
shawn_he 已提交
219
}
S
shawn_he 已提交
220
```
Z
zengyawen 已提交
221

S
shawn_he 已提交
222
## inputDevice.getDeviceIds<sup>(deprecated)</sup>
Z
zengyawen 已提交
223 224 225

getDeviceIds(callback: AsyncCallback&lt;Array&lt;number&gt;&gt;): void

E
ester.zhou 已提交
226
Obtains the IDs of all input devices. This API uses an asynchronous callback to return the result.
Z
zengyawen 已提交
227

S
shawn_he 已提交
228 229
This API is deprecated since API version 9. You are advised to use [inputDevice.getDeviceList](#inputdevicegetdevicelist9) instead.

Z
zengyawen 已提交
230 231
**System capability**: SystemCapability.MultimodalInput.Input.InputDevice

E
ester.zhou 已提交
232
**Parameters**
Z
zengyawen 已提交
233

S
shawn_he 已提交
234 235 236
| Name    | Type                                    | Mandatory| Description                                    |
| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
| callback | AsyncCallback&lt;Array&lt;number&gt;&gt; | Yes  | Callback used to return the result.|
E
ester.zhou 已提交
237 238 239

**Example**

S
shawn_he 已提交
240
```js
241
inputDevice.getDeviceIds((error: Error, ids: Array<number>) => {
S
shawn_he 已提交
242 243 244 245 246
  if (error) {
    console.log(`Failed to get device id list, error: ${JSON.stringify(error, [`code`, `message`])}`);
    return;
  }
  console.log(`Device id list: ${JSON.stringify(ids)}`);
S
shawn_he 已提交
247
});
E
ester.zhou 已提交
248 249
```

S
shawn_he 已提交
250
## inputDevice.getDeviceIds<sup>(deprecated)</sup>
E
ester.zhou 已提交
251

S
shawn_he 已提交
252
getDeviceIds(): Promise&lt;Array&lt;number&gt;&gt;
E
ester.zhou 已提交
253 254 255

Obtains the IDs of all input devices. This API uses a promise to return the result.

S
shawn_he 已提交
256 257
This API is deprecated since API version 9. You are advised to use [inputDevice.getDeviceList](#inputdevicegetdevicelist9) instead.

E
ester.zhou 已提交
258 259 260 261
**System capability**: SystemCapability.MultimodalInput.Input.InputDevice

**Return value**

S
shawn_he 已提交
262 263
| Parameters                              | Description                                       |
| ---------------------------------- | ------------------------------------------- |
S
shawn_he 已提交
264
| Promise&lt;Array&lt;number&gt;&gt; | Promise used to return the result.|
E
ester.zhou 已提交
265 266

**Example**
Z
zengyawen 已提交
267

S
shawn_he 已提交
268
```js
269
inputDevice.getDeviceIds().then((ids: Array<number>) => {
S
shawn_he 已提交
270
  console.log(`Device id list: ${JSON.stringify(ids)}`);
S
shawn_he 已提交
271
});
Z
zengyawen 已提交
272
```
E
ester.zhou 已提交
273

S
shawn_he 已提交
274
## inputDevice.getDevice<sup>(deprecated)</sup>
Z
zengyawen 已提交
275 276 277

getDevice(deviceId: number, callback: AsyncCallback&lt;InputDeviceData&gt;): void

S
shawn_he 已提交
278
Obtains information about an input device. This API uses an asynchronous callback to return the result.
Z
zengyawen 已提交
279

S
shawn_he 已提交
280 281
This API is deprecated since API version 9. You are advised to use [inputDevice.getDeviceInfo](#inputdevicegetdeviceinfo9) instead.

Z
zengyawen 已提交
282 283
**System capability**: SystemCapability.MultimodalInput.Input.InputDevice

E
ester.zhou 已提交
284 285
**Parameters**

S
shawn_he 已提交
286 287 288 289
| Name    | Type                                                    | Mandatory| Description                            |
| -------- | -------------------------------------------------------- | ---- | -------------------------------- |
| deviceId | number                                                   | Yes  | ID of the input device.                    |
| callback | AsyncCallback&lt;[InputDeviceData](#inputdevicedata)&gt; | Yes  | Callback used to return the result, which is an **InputDeviceData** object.|
Z
zengyawen 已提交
290

E
ester.zhou 已提交
291
**Example**
Z
zengyawen 已提交
292

S
shawn_he 已提交
293 294
```js
// Obtain the name of the device whose ID is 1.
S
shawn_he 已提交
295 296 297 298 299 300
inputDevice.getDevice(1, (error, deviceData) => {
  if (error) {
    console.log(`Failed to get device info, error: ${JSON.stringify(error, [`code`, `message`])}`);
    return;
  }
  console.log(`Device info: ${JSON.stringify(deviceData)}`);
S
shawn_he 已提交
301
});
Z
zengyawen 已提交
302 303
```

S
shawn_he 已提交
304
## inputDevice.getDevice<sup>(deprecated)</sup>
E
ester.zhou 已提交
305

S
shawn_he 已提交
306
getDevice(deviceId: number): Promise&lt;InputDeviceData&gt;
E
ester.zhou 已提交
307

S
shawn_he 已提交
308
Obtains information about an input device. This API uses a promise to return the result.
E
ester.zhou 已提交
309

S
shawn_he 已提交
310 311
This API is deprecated since API version 9. You are advised to use [inputDevice.getDeviceInfo](#inputdevicegetdeviceinfo9) instead.

E
ester.zhou 已提交
312 313
**System capability**: SystemCapability.MultimodalInput.Input.InputDevice

S
shawn_he 已提交
314 315
**Parameters**

S
shawn_he 已提交
316
| Name    | Type  | Mandatory| Description        |
S
shawn_he 已提交
317
| -------- | ------ | ---- | ------------ |
S
shawn_he 已提交
318
| deviceId | number | Yes  | ID of the input device.|
S
shawn_he 已提交
319

E
ester.zhou 已提交
320 321
**Return value**

S
shawn_he 已提交
322 323
| Parameters                                              | Description                               |
| -------------------------------------------------- | ----------------------------------- |
S
shawn_he 已提交
324
| Promise&lt;[InputDeviceData](#inputdevicedata)&gt; | Promise used to return the result.|
E
ester.zhou 已提交
325 326 327

**Example**

S
shawn_he 已提交
328 329
```js
// Obtain the name of the device whose ID is 1.
S
shawn_he 已提交
330 331
inputDevice.getDevice(1).then((deviceData) => {
  console.log(`Device info: ${JSON.stringify(deviceData)}`);
S
shawn_he 已提交
332
});
E
ester.zhou 已提交
333
```
S
shawn_he 已提交
334 335 336

## inputDevice.supportKeys<sup>9+</sup>

S
shawn_he 已提交
337
supportKeys(deviceId: number, keys: Array&lt;KeyCode&gt;, callback: AsyncCallback &lt;Array&lt;boolean&gt;&gt;): void
S
shawn_he 已提交
338

S
shawn_he 已提交
339
Obtains the key codes supported by the input device. This API uses an asynchronous callback to return the result.
S
shawn_he 已提交
340 341 342 343 344

**System capability**: SystemCapability.MultimodalInput.Input.InputDevice

**Parameters**

S
shawn_he 已提交
345 346 347 348 349
| Name    | Type                                     | Mandatory| Description                                                  |
| -------- | ----------------------------------------- | ---- | ------------------------------------------------------ |
| deviceId | number                                    | Yes  | Unique ID of the input device. If the same physical device is repeatedly inserted and removed, its ID changes.|
| keys     | Array&lt;KeyCode&gt;                      | Yes  | Key codes to be queried. A maximum of five key codes can be specified.               |
| callback | AsyncCallback&lt;Array&lt;boolean&gt;&gt; | Yes  | Callback used to return the result.                          |
S
shawn_he 已提交
350 351 352 353 354

**Example**

```js
// Check whether the input device whose ID is 1 supports key codes 17, 22, and 2055.
S
shawn_he 已提交
355
try {
356
  inputDevice.supportKeys(1, [17, 22, 2055], (error: Error, supportResult: Array<boolean>) => {
S
shawn_he 已提交
357
    console.log(`Query result: ${JSON.stringify(supportResult)}`);
S
shawn_he 已提交
358 359
  });
} catch (error) {
S
shawn_he 已提交
360
  console.log(`Query failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
S
shawn_he 已提交
361
}
S
shawn_he 已提交
362 363 364 365
```

## inputDevice.supportKeys<sup>9+</sup>

S
shawn_he 已提交
366
supportKeys(deviceId: number, keys: Array&lt;KeyCode&gt;): Promise&lt;Array&lt;boolean&gt;&gt;
S
shawn_he 已提交
367

S
shawn_he 已提交
368
Obtains the key codes supported by the input device. This API uses a promise to return the result.
S
shawn_he 已提交
369 370 371 372 373

**System capability**: SystemCapability.MultimodalInput.Input.InputDevice

**Parameters**

S
shawn_he 已提交
374 375 376 377
| Name    | Type                | Mandatory| Description                                                  |
| -------- | -------------------- | ---- | ------------------------------------------------------ |
| deviceId | number               | Yes  | Unique ID of the input device. If the same physical device is repeatedly inserted and removed, its ID changes.|
| keys     | Array&lt;KeyCode&gt; | Yes  | Key codes to be queried. A maximum of five key codes can be specified.               |
S
shawn_he 已提交
378 379 380

**Return value**

S
shawn_he 已提交
381 382
| Parameters                               | Description                           |
| ----------------------------------- | ------------------------------- |
S
shawn_he 已提交
383 384 385 386 387 388
| Promise&lt;Array&lt;boolean&gt;&gt; | Promise used to return the result.|

**Example**

```js
// Check whether the input device whose ID is 1 supports key codes 17, 22, and 2055.
S
shawn_he 已提交
389
try {
S
shawn_he 已提交
390 391
  inputDevice.supportKeys(1, [17, 22, 2055]).then((supportResult) => {
    console.log(`Query result: ${JSON.stringify(supportResult)}`);
S
shawn_he 已提交
392 393
  });
} catch (error) {
S
shawn_he 已提交
394
  console.log(`Query failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
S
shawn_he 已提交
395
}
S
shawn_he 已提交
396 397 398 399
```

## inputDevice.getKeyboardType<sup>9+</sup>

S
shawn_he 已提交
400
getKeyboardType(deviceId: number, callback: AsyncCallback&lt;KeyboardType&gt;): void
S
shawn_he 已提交
401 402 403 404 405 406 407

Obtains the keyboard type of an input device. This API uses an asynchronous callback to return the result.

**System capability**: SystemCapability.MultimodalInput.Input.InputDevice

**Parameters**

S
shawn_he 已提交
408 409 410 411
| Name    | Type                                               | Mandatory| Description                                                        |
| -------- | --------------------------------------------------- | ---- | ------------------------------------------------------------ |
| deviceId | number                                              | Yes  | Unique ID of the input device. If the same physical device is repeatedly inserted and removed, its ID changes.|
| callback | AsyncCallback&lt;[KeyboardType](#keyboardtype9)&gt; | Yes  | Callback used to return the result.                                |
S
shawn_he 已提交
412 413 414 415 416

**Example**

```js
// Query the keyboard type of the input device whose ID is 1.
S
shawn_he 已提交
417
try {
S
shawn_he 已提交
418
  inputDevice.getKeyboardType(1, (error, type) => {
S
shawn_he 已提交
419
    if (error) {
S
shawn_he 已提交
420
      console.log(`Failed to get keyboard type, error: ${JSON.stringify(error, [`code`, `message`])}`);
S
shawn_he 已提交
421 422
      return;
    }
S
shawn_he 已提交
423
    console.log(`Keyboard type: ${JSON.stringify(type)}`);
S
shawn_he 已提交
424 425
  });
} catch (error) {
S
shawn_he 已提交
426
  console.log(`Failed to get keyboard type, error: ${JSON.stringify(error, [`code`, `message`])}`);
S
shawn_he 已提交
427
}
E
ester.zhou 已提交
428 429
```

S
shawn_he 已提交
430
## inputDevice.getKeyboardType<sup>9+</sup>
E
ester.zhou 已提交
431

S
shawn_he 已提交
432
getKeyboardType(deviceId: number): Promise&lt;KeyboardType&gt;
S
shawn_he 已提交
433

S
shawn_he 已提交
434
Obtains the keyboard type of an input device. This API uses an asynchronous callback to return the result.
S
shawn_he 已提交
435 436 437

**System capability**: SystemCapability.MultimodalInput.Input.InputDevice

S
shawn_he 已提交
438 439 440 441 442 443
**Parameters**

| Name    | Type  | Mandatory| Description                                                        |
| -------- | ------ | ---- | ------------------------------------------------------------ |
| deviceId | number | Yes  | Unique ID of the input device. If the same physical device is repeatedly inserted and removed, its ID changes.|

S
shawn_he 已提交
444 445
**Return value**

S
shawn_he 已提交
446 447
| Parameters                                         | Description                           |
| --------------------------------------------- | ------------------------------- |
S
shawn_he 已提交
448
| Promise&lt;[KeyboardType](#keyboardtype9)&gt; | Promise used to return the result.|
S
shawn_he 已提交
449 450 451 452 453

**Example**

```js
// Query the keyboard type of the input device whose ID is 1.
S
shawn_he 已提交
454
try {
455
  inputDevice.getKeyboardType(1).then((type: number) => {
S
shawn_he 已提交
456 457 458 459 460 461 462 463 464 465 466 467 468 469 470
    console.log(`Keyboard type: ${JSON.stringify(type)}`);
  });
} catch (error) {
  console.log(`Failed to get keyboard type, error: ${JSON.stringify(error, [`code`, `message`])}`);
}
```

## inputDevice.setKeyboardRepeatDelay<sup>10+</sup>

setKeyboardRepeatDelay(delay: number, callback: AsyncCallback&lt;void&gt;): void

Sets the keyboard repeat delay. This API uses an asynchronous callback to return the result.

**System capability**: SystemCapability.MultimodalInput.Input.InputDevice

S
shawn_he 已提交
471 472
**System API**: This is a system API.

S
shawn_he 已提交
473 474 475 476
**Parameters**

| Name    | Type  | Mandatory| Description                                                        |
| -------- | ------ | ---- | ------------------------------------------------------------ |
S
shawn_he 已提交
477
| delay    | number                    | Yes   | Keyboard repeat delay, in ms. The value range is [300, 1000] and the default value is **500**.|
S
shawn_he 已提交
478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503
| callback | AsyncCallback&lt;void&gt; | Yes   | Callback used to return the result.|

**Example**

```js
try {
  inputDevice.setKeyboardRepeatDelay(350, (error) => {
    if (error) {
      console.log(`Set keyboard repeat delay failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
      return;
    }
    console.log(`Set keyboard repeat delay success`);
  });
} catch (error) {
  console.log(`Set keyboard repeat delay failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
}
```

## inputDevice.setKeyboardRepeatDelay<sup>10+</sup>

setKeyboardRepeatDelay(delay: number): Promise&lt;void&gt;

Sets the keyboard repeat delay. This API uses a promise to return the result.

**System capability**: SystemCapability.MultimodalInput.Input.InputDevice

S
shawn_he 已提交
504 505
**System API**: This is a system API.

S
shawn_he 已提交
506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529
**Parameters**

| Name   | Type    | Mandatory  | Description                                 |
| ----- | ------ | ---- | ----------------------------------- |
| delay | number | Yes   | Keyboard repeat delay, in ms. The value range is [300, 1000] and the default value is **500**.|

**Return value**

| Parameters                 | Description              |
| ------------------- | ---------------- |
| Promise&lt;void&gt; | Promise used to return the result.|

**Example**

```js
try {
  inputDevice.setKeyboardRepeatDelay(350).then(() => {
    console.log(`Set keyboard repeat delay success`);
  });
} catch (error) {
  console.log(`Set keyboard repeat delay failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
}
```

S
shawn_he 已提交
530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549
## inputDevice.getKeyboardRepeatDelay<sup>10+</sup>

getKeyboardRepeatDelay(callback: AsyncCallback&lt;number&gt;): void

Obtains the keyboard repeat delay. This API uses an asynchronous callback to return the result.

**System capability**: SystemCapability.MultimodalInput.Input.InputDevice

**System API**: This is a system API.

**Parameters**

| Name    | Type  | Mandatory| Description                                                        |
| -------- | ------ | ---- | ------------------------------------------------------------ |
| callback   | AsyncCallback&lt;number&gt;                    | Yes   | Callback used to return the result.|

**Example**

```js
try {
550
  inputDevice.getKeyboardRepeatDelay((error: Error, delay: number) => {
S
shawn_he 已提交
551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589
    if (error) {
      console.log(`Get keyboard repeat delay failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
      return;
    }
    console.log(`Get keyboard repeat delay success`);
  });
} catch (error) {
  console.log(`Get keyboard repeat delay failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
}
```

## inputDevice.getKeyboardRepeatDelay<sup>10+</sup>

getKeyboardRepeatDelay(): Promise&lt;number&gt;

Obtains the keyboard repeat delay. This API uses a promise to return the result.

**System capability**: SystemCapability.MultimodalInput.Input.InputDevice

**System API**: This is a system API.

**Return value**

| Parameters                   | Description                 |
| --------------------- | ------------------- |
| Promise&lt;number&gt; | Promise used to return the result.|

**Example**

```js
try {
  inputDevice.getKeyboardRepeatDelay().then(delay => {
    console.log(`Get keyboard repeat delay success`);
  });
} catch (error) {
  console.log(`Get keyboard repeat delay failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
}
```

S
shawn_he 已提交
590 591 592 593 594 595 596 597
## inputDevice.setKeyboardRepeatRate<sup>10+</sup>

setKeyboardRepeatRate(rate: number, callback: AsyncCallback&lt;void&gt;): void

Sets the keyboard repeat rate. This API uses an asynchronous callback to return the result.

**System capability**: SystemCapability.MultimodalInput.Input.InputDevice

S
shawn_he 已提交
598 599
**System API**: This is a system API.

S
shawn_he 已提交
600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630
**Parameters**

| Name    | Type  | Mandatory| Description                                                        |
| -------- | ------ | ---- | ------------------------------------------------------------ |
| rate    | number                    | Yes   | Keyboard repeat rate, in ms/time. The value range is [36, 100] and the default value is 50.|
| callback | AsyncCallback&lt;void&gt; | Yes   | Callback used to return the result.|

**Example**

```js
try {
  inputDevice.setKeyboardRepeatRate(60, (error) => {
    if (error) {
      console.log(`Set keyboard repeat rate failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
      return;
    }
    console.log(`Set keyboard repeat rate success`);
  });
} catch (error) {
  console.log(`Set keyboard repeat rate failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
}
```

## inputDevice.setKeyboardRepeatRate<sup>10+</sup>

setKeyboardRepeatRate(rate: number): Promise&lt;void&gt;

Sets the keyboard repeat rate. This API uses a promise to return the result.

**System capability**: SystemCapability.MultimodalInput.Input.InputDevice

S
shawn_he 已提交
631 632
**System API**: This is a system API.

S
shawn_he 已提交
633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650
**Parameters**

| Name   | Type    | Mandatory  | Description                                 |
| ----- | ------ | ---- | ----------------------------------- |
| rate | number | Yes   | Keyboard repeat rate, in ms/time. The value range is [36, 100] and the default value is 50.|

**Return value**

| Parameters                 | Description              |
| ------------------- | ---------------- |
| Promise&lt;void&gt; | Promise used to return the result.|

**Example**

```js
try {
  inputDevice.setKeyboardRepeatRate(60).then(() => {
    console.log(`Set keyboard repeat rate success`);
S
shawn_he 已提交
651 652
  });
} catch (error) {
S
shawn_he 已提交
653
  console.log(`Set keyboard repeat rate failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
S
shawn_he 已提交
654
}
S
shawn_he 已提交
655 656
```

S
shawn_he 已提交
657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716
## inputDevice.getKeyboardRepeatRate<sup>10+</sup>

getKeyboardRepeatRate(callback: AsyncCallback&lt;number&gt;): void

Obtains the keyboard repeat rate. This API uses an asynchronous callback to return the result.

**System capability**: SystemCapability.MultimodalInput.Input.InputDevice

**System API**: This is a system API.

**Parameters**

| Name      | Type                         | Mandatory  | Description            |
| -------- | --------------------------- | ---- | -------------- |
| callback | AsyncCallback&lt;number&gt; | Yes   | Callback used to return the result.|

**Example**

```js
try {
  inputDevice.getKeyboardRepeatRate((error, rate) => {
    if (error) {
      console.log(`Get keyboard repeat rate failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
      return;
    }
    console.log(`Get keyboard repeat rate success`);
  });
} catch (error) {
  console.log(`Get keyboard repeat rate failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
}
```

## inputDevice.getKeyboardRepeatRate<sup>10+</sup>

getKeyboardRepeatRate(): Promise&lt;number&gt;

Obtains the keyboard repeat rate. This API uses a promise to return the result.

**System capability**: SystemCapability.MultimodalInput.Input.InputDevice

**System API**: This is a system API.

**Return value**

| Parameters                   | Description                 |
| --------------------- | ------------------- |
| Promise&lt;number&gt; | Promise used to return the result.|

**Example**

```js
try {
  inputDevice.getKeyboardRepeatRate().then(rate => {
    console.log(`Get keyboard repeat rate success`);
  });
} catch (error) {
  console.log(`Get keyboard repeat rate failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
}
```

S
shawn_he 已提交
717 718
## DeviceListener<sup>9+</sup>

S
shawn_he 已提交
719
Defines the listener for hot swap events of an input device.
S
shawn_he 已提交
720 721 722

**System capability**: SystemCapability.MultimodalInput.Input.InputDevice

S
shawn_he 已提交
723 724 725 726
| Name       | Type  | Readable  | Writable  | Description     |
| --------- | ------ | ---- | ---- | ------- |
| type     | [ChangedType](#changedtype) | Yes| No| Device change type, which indicates whether an input device is inserted or removed.|
| deviceId | number                      | Yes| No| Unique ID of the input device. If the same physical device is repeatedly inserted and removed, its ID changes.|
Z
zengyawen 已提交
727 728 729 730 731

## InputDeviceData

Defines the information about an input device.

E
ester.zhou 已提交
732 733
**System capability**: SystemCapability.MultimodalInput.Input.InputDevice

S
shawn_he 已提交
734 735 736 737 738
| Name       | Type  | Readable  | Writable  | Description     |
| --------- | ------ | ---- | ---- | ------- |
| id                   | number                                 | Yes| No| Unique ID of the input device. If the same physical device is repeatedly inserted and removed, its ID changes.|
| name                 | string                                 | Yes| No| Name of the input device.                                            |
| sources              | Array&lt;[SourceType](#sourcetype)&gt; | 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.|
S
shawn_he 已提交
739
| axisRanges           | Array&lt;[AxisRange](#axisrange)&gt;  | Yes| No| Axis information of the input device.                                          |
S
shawn_he 已提交
740 741 742 743 744 745
| bus<sup>9+</sup>     | number                                 | Yes| No| Bus type of the input device.                                        |
| product<sup>9+</sup> | number                                 | Yes| No| Product information of the input device.                                        |
| vendor<sup>9+</sup>  | number                                 | Yes| No| Vendor information of the input device.                                        |
| version<sup>9+</sup> | number                                 | Yes| No| Version information of the input device.                                        |
| phys<sup>9+</sup>    | string                                 | Yes| No| Physical address of the input device.                                        |
| uniq<sup>9+</sup>    | string                                 | Yes| No| Unique ID of the input device.                                        |
E
ester.zhou 已提交
746

S
shawn_he 已提交
747
## AxisType<sup>9+</sup>
E
ester.zhou 已提交
748

S
shawn_he 已提交
749
Defines the axis type of an input device.
E
ester.zhou 已提交
750

S
shawn_he 已提交
751
**System capability**: SystemCapability.MultimodalInput.Input.InputDevice
E
ester.zhou 已提交
752

S
shawn_he 已提交
753 754
| Name       | Type  | Readable  | Writable  | Description     |
| --------- | ------ | ---- | ---- | ------- |
S
shawn_he 已提交
755 756 757 758
| touchmajor  | string | Yes| No| **touchmajor** axis. |
| touchminor  | string | Yes| No| **touchminor** axis. |
| toolminor   | string | Yes| No| **toolminor** axis.  |
| toolmajor   | string | Yes| No| **toolmajor** axis.  |
S
shawn_he 已提交
759 760 761 762
| orientation | string | Yes| No| Orientation axis.|
| pressure    | string | Yes| No| Pressure axis.   |
| x           | string | Yes| No| X axis.          |
| y           | string | Yes| No| Y axis.          |
S
shawn_he 已提交
763
| null        | string | Yes| No| None.             |
E
ester.zhou 已提交
764

S
shawn_he 已提交
765
## AxisRange
E
ester.zhou 已提交
766

S
shawn_he 已提交
767
Defines the axis range of an input device.
E
ester.zhou 已提交
768

S
shawn_he 已提交
769
**System capability**: SystemCapability.MultimodalInput.Input.InputDevice
Z
zengyawen 已提交
770

S
shawn_he 已提交
771 772 773 774 775 776 777 778 779
| Name       | Type  | Readable  | Writable  | Description     |
| --------- | ------ | ---- | ---- | ------- |
| source                  | [SourceType](#sourcetype) | Yes| No| Input source type of the axis.|
| axis                    | [AxisType](#axistype9)    | Yes| No| Axis type.   |
| max                     | number                    | Yes| No| Maximum value of the axis.  |
| min                     | number                    | Yes| No| Minimum value of the axis.  |
| fuzz<sup>9+</sup>       | number                    | Yes| No| Fuzzy value of the axis.  |
| flat<sup>9+</sup>       | number                    | Yes| No| Benchmark value of the axis.  |
| resolution<sup>9+</sup> | number                    | Yes| No| Resolution of the axis.  |
Z
zengyawen 已提交
780

S
shawn_he 已提交
781
## SourceType<sup>9+</sup>
Z
zengyawen 已提交
782

S
shawn_he 已提交
783
Input 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.
Z
zengyawen 已提交
784 785 786

**System capability**: SystemCapability.MultimodalInput.Input.InputDevice

S
shawn_he 已提交
787 788 789 790 791 792 793 794
| Name       | Type  | Readable  | Writable  | Description     |
| --------- | ------ | ---- | ---- | ------- |
| keyboard    | string | Yes| No| The input device is a keyboard. |
| touchscreen | string | Yes| No| The input device is a touchscreen.|
| mouse       | string | Yes| No| The input device is a mouse. |
| trackball   | string | Yes| No| The input device is a trackball.|
| touchpad    | string | Yes| No| The input device is a touchpad.|
| joystick    | string | Yes| No| The input device is a joystick.|
S
shawn_he 已提交
795

S
shawn_he 已提交
796
## ChangedType<sup>9+</sup>
S
shawn_he 已提交
797 798 799 800 801

Defines the change type for the hot swap event of an input device.

**System capability**: SystemCapability.MultimodalInput.Input.InputDevice

S
shawn_he 已提交
802 803 804 805
| Name       | Type  | Readable  | Writable  | Description     |
| --------- | ------ | ---- | ---- | ------- |
| add    | string | Yes| No| An input device is inserted.|
| remove | string | Yes| No| An input device is removed.|
S
shawn_he 已提交
806 807 808 809 810 811 812

## KeyboardType<sup>9+</sup>

Enumerates the keyboard types.

**System capability**: SystemCapability.MultimodalInput.Input.InputDevice

S
shawn_he 已提交
813 814 815 816 817 818 819 820
| Name                 | Value   | Description       |
| ------------------- | ---- | --------- |
| NONE                | 0    | Keyboard without keys. |
| UNKNOWN             | 1    | Keyboard with unknown keys.|
| ALPHABETIC_KEYBOARD | 2    | Full keyboard. |
| DIGITAL_KEYBOARD    | 3    | Keypad. |
| HANDWRITING_PEN     | 4    | Stylus. |
| REMOTE_CONTROL      | 5    | Remote control. |