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