• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Input Device
2
3
4The input device management module is used to listen for the connection, disconnection, and updates of input devices and display information about input devices. For example, it can be used to listen for mouse insertion and removal and obtain information such as the ID, name, and pointer speed of the mouse.
5
6
7> **NOTE**<br>
8> 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.
9
10
11## Modules to Import
12
13
14```js
15import inputDevice from '@ohos.multimodalInput.inputDevice';
16```
17
18
19## inputDevice.getDeviceIds
20
21getDeviceIds(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
34**Example**
35
36```js
37inputDevice.getDeviceIds((ids)=>{
38    console.log("The device ID list is: " + ids);
39});
40```
41
42## inputDevice.getDeviceIds
43
44getDeviceIds(): Promise&lt;Array&lt;number&gt;&gt;
45
46Obtains the IDs of all input devices. This API uses a promise to return the result.
47
48**System capability**: SystemCapability.MultimodalInput.Input.InputDevice
49
50**Return value**
51
52| Parameter                    | Description                |
53| ---------------------- | ------------------ |
54| Promise&lt;Array&lt;number&gt;&gt; | Promise used to return the result.|
55
56**Example**
57
58```js
59inputDevice.getDeviceIds().then((ids)=>{
60    console.log("The device ID list is: " + ids);
61});
62```
63
64
65
66
67
68## inputDevice.getDevice
69
70getDevice(deviceId: number, callback: AsyncCallback&lt;InputDeviceData&gt;): void
71
72Obtains the information about an input device. This API uses an asynchronous callback to return the result.
73
74**System capability**: SystemCapability.MultimodalInput.Input.InputDevice
75
76**Parameters**
77
78| Name      | Type                                      | Mandatory  | Description                         |
79| -------- | ---------------------------------------- | ---- | --------------------------- |
80| deviceId | number                                   | Yes   | ID of the input device whose information is to be obtained.               |
81| callback | AsyncCallback&lt;[InputDeviceData](#inputdevicedata)&gt; | Yes   | Callback used to return the **InputDeviceData** object.|
82
83**Example**
84
85```js
86// This example obtains the information about the device whose ID is 1.
87inputDevice.getDevice(1, (inputDevice)=>{
88    console.log("The device name is: " + inputDevice.name);
89});
90```
91
92## inputDevice.getDevice
93
94getDevice(deviceId: number): Promise&lt;InputDeviceData&gt;
95
96Obtains the information about an input device. This API uses a promise to return the result.
97
98**System capability**: SystemCapability.MultimodalInput.Input.InputDevice
99
100**Parameters**
101
102| Name      | Type    | Mandatory  | Description           |
103| -------- | ------ | ---- | ------------ |
104| deviceId | number | Yes   | ID of the input device.|
105
106**Return value**
107
108| Parameter                      | Description                |
109| ------------------------ | ------------------ |
110| Promise&lt;[InputDeviceData](#inputdevicedata)&gt; | Promise used to return the result.|
111
112**Example**
113
114```js
115// This example obtains the information about the device whose ID is 1.
116inputDevice.getDevice(1).then((inputDevice)=>{
117    console.log("The device name is: " + inputDevice.name);
118});
119```
120
121
122
123## InputDeviceData
124
125Defines the information about an input device.
126
127**System capability**: SystemCapability.MultimodalInput.Input.InputDevice
128
129| Name      | Type                              | Description                                                        |
130| -------------------- | -------------------------------------- | ---------------------------------------- |
131| id                   | number                                 | Unique ID of the input device. If the same physical device is repeatedly inserted and removed, its ID changes.       |
132| name                 | string                                 | Name of the input device.                                |
133| sources              | Array&lt;[SourceType](#sourcetype)&gt; | 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.|
134| axisRanges           | Array&lt;[axisRanges](#axisrange)&gt;  | Axis information of the input device.                               |
135
136## AxisType<sup>9+</sup>
137
138Defines the axis type of an input device.
139
140## AxisRange
141
142Defines the axis information of an input device.
143
144**System capability**: SystemCapability.MultimodalInput.Input.InputDevice
145
146| Name    | Type                     | Description      |
147| ------ | ------------------------- | -------- |
148| source | [SourceType](#sourcetype) | Input source type of the axis.|
149| axis   | [AxisType](#axistype)      | Axis type.    |
150| max    | number                    | Maximum value reported by the axis. |
151| min    | number                    | Minimum value reported by the axis. |
152
153
154
155## SourceType
156
157Enumerates the input source types of the axis. For example, if a mouse reports an x-axis event, the source of the x-axis is the mouse.
158
159**System capability**: SystemCapability.MultimodalInput.Input.InputDevice
160
161| Name         | Type  | Description         |
162| ----------- | ------ | ----------- |
163| keyboard    | string | The input device is a keyboard. |
164| touchscreen | string | The input device is a touchscreen.|
165| mouse       | string | The input device is a mouse. |
166| trackball   | string | The input device is a trackball.|
167| touchpad    | string | The input device is a touchpad.|
168| joystick    | string | The input device is a joystick.|
169