提交 178c5c49 编写于 作者: S shawn_he

update doc

Signed-off-by: Nshawn_he <shawn.he@huawei.com>
上级 6b682d4f
# @ohos.multimodalInput.inputDevice (Input Device) # @ohos.multimodalInput.inputDevice (Input Device)
The **inputDevice** module implements listening for connection, disconnection, and update events of input devices and displays 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. The **inputDevice** module allows you to listen for hot swap events of input devices and query information about input devices.
> **NOTE**<br> > **NOTE**
>
> 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. > 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.
## Modules to Import ## Modules to Import
...@@ -10,6 +11,7 @@ The **inputDevice** module implements listening for connection, disconnection, a ...@@ -10,6 +11,7 @@ The **inputDevice** module implements listening for connection, disconnection, a
```js ```js
import inputDevice from '@ohos.multimodalInput.inputDevice'; import inputDevice from '@ohos.multimodalInput.inputDevice';
``` ```
## inputDevice.getDeviceList<sup>9+</sup> ## inputDevice.getDeviceList<sup>9+</sup>
getDeviceList(callback: AsyncCallback&lt;Array&lt;number&gt;&gt;): void getDeviceList(callback: AsyncCallback&lt;Array&lt;number&gt;&gt;): void
...@@ -20,25 +22,23 @@ Obtains the IDs of all input devices. This API uses an asynchronous callback to ...@@ -20,25 +22,23 @@ Obtains the IDs of all input devices. This API uses an asynchronous callback to
**Parameters** **Parameters**
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| -------- | ---------------------------------------- | ---- | ---------- | | -------- | ---------------------------------------- | ---- | ---------------------------------------- |
| callback | AsyncCallback&lt;Array&lt;number&gt;&gt; | Yes | Callback used to return the result.| | callback | AsyncCallback&lt;Array&lt;number&gt;&gt; | Yes | Callback used to return the result.|
**Example** **Example**
```js ```js
try { try {
inputDevice.getDeviceIds((error, ids) => { inputDevice.getDeviceList((error, ids) => {
if (error) { if (error) {
console.log(`Failed to get device list. console.log(`Failed to get device id list, error: ${JSON.stringify(error, [`code`, `message`])}`);
error code=${err.code} msg=${err.message}`);
return; return;
} }
this.data = ids; console.log(`Device id list: ${JSON.stringify(ids)}`);
console.log("The device ID list is: " + ids);
}); });
} catch (error) { } catch (error) {
console.info("getDeviceList " + error.code + " " + error.message); console.log(`Failed to get device id list, error: ${JSON.stringify(error, [`code`, `message`])}`);
} }
``` ```
...@@ -52,19 +52,19 @@ Obtains the IDs of all input devices. This API uses a promise to return the resu ...@@ -52,19 +52,19 @@ Obtains the IDs of all input devices. This API uses a promise to return the resu
**Return value** **Return value**
| Name | Description | | Parameters | Description |
| ---------------------------------- | ------------------------------- | | ---------------------------------- | ------------------------------------------- |
| Promise&lt;Array&lt;number&gt;&gt; | Promise used to return the result.| | Promise&lt;Array&lt;number&gt;&gt; | Promise used to return the result.|
**Example** **Example**
```js ```js
try { try {
inputDevice.getDeviceIds().then((ids) => { inputDevice.getDeviceList().then((ids) => {
console.log("The device ID list is: " + ids); console.log(`Device id list: ${JSON.stringify(ids)}`);
}); });
} catch (error) { } catch (error) {
console.info("getDeviceList " + error.code + " " + error.message); console.log(`Failed to get device id list, error: ${JSON.stringify(error, [`code`, `message`])}`);
} }
``` ```
...@@ -88,16 +88,15 @@ Obtains information about an input device. This API uses an asynchronous callbac ...@@ -88,16 +88,15 @@ Obtains information about an input device. This API uses an asynchronous callbac
```js ```js
// Obtain the name of the device whose ID is 1. // Obtain the name of the device whose ID is 1.
try { try {
inputDevice.getDeviceInfo(1, (error, inputDevice) => { inputDevice.getDeviceInfo(1, (error, deviceData) => {
if (error) { if (error) {
console.log(`Failed to get device information. console.log(`Failed to get device info, error: ${JSON.stringify(error, [`code`, `message`])}`);
error code=${err.code} msg=${err.message}`);
return; return;
} }
console.log("The device name is: " + inputDevice.name); console.log(`Device info: ${JSON.stringify(deviceData)}`);
}); });
} catch (error) { } catch (error) {
console.info("getDeviceInfo " + error.code + " " + error.message); console.log(`Failed to get device info, error: ${JSON.stringify(error, [`code`, `message`])}`);
} }
``` ```
...@@ -117,7 +116,7 @@ Obtains information about an input device. This API uses a promise to return the ...@@ -117,7 +116,7 @@ Obtains information about an input device. This API uses a promise to return the
**Return value** **Return value**
| Name | Description | | Parameters | Description |
| -------------------------------------------------- | ------------------------------- | | -------------------------------------------------- | ------------------------------- |
| Promise&lt;[InputDeviceData](#inputdevicedata)&gt; | Promise used to return the result.| | Promise&lt;[InputDeviceData](#inputdevicedata)&gt; | Promise used to return the result.|
...@@ -126,20 +125,19 @@ Obtains information about an input device. This API uses a promise to return the ...@@ -126,20 +125,19 @@ Obtains information about an input device. This API uses a promise to return the
```js ```js
// Obtain the name of the device whose ID is 1. // Obtain the name of the device whose ID is 1.
try { try {
inputDevice.getDeviceInfo(id).then((inputDevice) => { inputDevice.getDeviceInfo(1).then((deviceData) => {
console.log("The device name is: " + inputDevice.name); console.log(`Device info: ${JSON.stringify(deviceData)}`);
}); });
} catch (error) { } catch (error) {
console.info("getDeviceInfo " + error.code + " " + error.message); console.log(`Failed to get device info, error: ${JSON.stringify(error, [`code`, `message`])}`);
} }
``` ```
## inputDevice.on<sup>9+</sup> ## inputDevice.on<sup>9+</sup>
on(type: "change", listener: Callback&lt;DeviceListener&gt;): void on(type: "change", listener: Callback&lt;DeviceListener&gt;): void
Enables listening for hot swap events of an input device. Enables listening for device hot swap events.
**System capability**: SystemCapability.MultimodalInput.Input.InputDevice **System capability**: SystemCapability.MultimodalInput.Input.InputDevice
...@@ -156,13 +154,13 @@ Enables listening for hot swap events of an input device. ...@@ -156,13 +154,13 @@ Enables listening for hot swap events of an input device.
let isPhysicalKeyboardExist = true; let isPhysicalKeyboardExist = true;
try { try {
inputDevice.on("change", (data) => { inputDevice.on("change", (data) => {
console.log("type: " + data.type + ", deviceId: " + data.deviceId); console.log(`Device event info: ${JSON.stringify(data)}`);
inputDevice.getKeyboardType(data.deviceId, (err, ret) => { inputDevice.getKeyboardType(data.deviceId, (err, type) => {
console.log("The keyboard type of the device is: " + ret); console.log("The keyboard type is: " + type);
if (ret == inputDevice.KeyboardType.ALPHABETIC_KEYBOARD && data.type == 'add') { if (type == inputDevice.KeyboardType.ALPHABETIC_KEYBOARD && data.type == 'add') {
// The physical keyboard is connected. // The physical keyboard is connected.
isPhysicalKeyboardExist = true; isPhysicalKeyboardExist = true;
} else if (ret == inputDevice.KeyboardType.ALPHABETIC_KEYBOARD && data.type == 'remove') { } else if (type == inputDevice.KeyboardType.ALPHABETIC_KEYBOARD && data.type == 'remove') {
// The physical keyboard is disconnected. // The physical keyboard is disconnected.
isPhysicalKeyboardExist = false; isPhysicalKeyboardExist = false;
} }
...@@ -170,7 +168,7 @@ try { ...@@ -170,7 +168,7 @@ try {
}); });
// Check whether the soft keyboard is open based on the value of isPhysicalKeyboardExist. // Check whether the soft keyboard is open based on the value of isPhysicalKeyboardExist.
} catch (error) { } catch (error) {
console.info("oninputdevcie " + error.code + " " + error.message); console.log(`Get device info failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
} }
``` ```
...@@ -178,7 +176,7 @@ try { ...@@ -178,7 +176,7 @@ try {
off(type: "change", listener?: Callback&lt;DeviceListener&gt;): void off(type: "change", listener?: Callback&lt;DeviceListener&gt;): void
Disables listening for hot swap events of an input device. Disables listening for device hot swap events. This API is called before the application exits.
**System capability**: SystemCapability.MultimodalInput.Input.InputDevice **System capability**: SystemCapability.MultimodalInput.Input.InputDevice
...@@ -192,33 +190,29 @@ Disables listening for hot swap events of an input device. ...@@ -192,33 +190,29 @@ Disables listening for hot swap events of an input device.
**Example** **Example**
```js ```js
callback: function(data) { function callback(data) {
console.log("type: " + data.type + ", deviceId: " + data.deviceId); console.log(`Report device event info: ${JSON.stringify(data, [`type`, `deviceId`])}`);
} };
try { try {
inputDevice.on("change", this.callback); inputDevice.on("change", callback);
} catch (error) { } catch (error) {
console.info("oninputdevcie " + error.code + " " + error.message) console.log(`Listen device event failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
} }
// Enable listening for hot swap events of an input device.
inputDevice.on("change", listener);
// Disable this listener. // Disable this listener.
try { try {
inputDevice.off("change", this.callback); inputDevice.off("change", callback);
} catch (error) { } catch (error) {
console.info("offinputdevcie " + error.code + " " + error.message) console.log(`Cancel listening device event failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
} }
// Disable all listeners. // Disable all listeners.
try { try {
inputDevice.off("change"); inputDevice.off("change");
} catch (error) { } catch (error) {
console.info("offinputdevcie " + error.code + " " + error.message); console.log(`Cancel all listening device event failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
} }
// By default, the soft keyboard is closed when listening is disabled.
``` ```
## inputDevice.getDeviceIds<sup>(deprecated)</sup> ## inputDevice.getDeviceIds<sup>(deprecated)</sup>
...@@ -233,9 +227,9 @@ This API is deprecated since API version 9. You are advised to use [inputDevice. ...@@ -233,9 +227,9 @@ This API is deprecated since API version 9. You are advised to use [inputDevice.
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
| -------- | ---------------------------------------- | ---- | ----- | | -------- | ---------------------------------------- | ---- | ---------------------------------------- |
| callback | AsyncCallback&lt;Array&lt;number&gt;&gt; | Yes | Callback used to return the result.| | callback | AsyncCallback&lt;Array&lt;number&gt;&gt; | Yes | Callback used to return the result.|
**Example** **Example**
...@@ -248,7 +242,6 @@ inputDevice.getDeviceIds((error, ids) => { ...@@ -248,7 +242,6 @@ inputDevice.getDeviceIds((error, ids) => {
console.log(`Device id list: ${JSON.stringify(ids)}`); console.log(`Device id list: ${JSON.stringify(ids)}`);
}); });
``` ```
```
## inputDevice.getDeviceIds<sup>(deprecated)</sup> ## inputDevice.getDeviceIds<sup>(deprecated)</sup>
...@@ -262,8 +255,8 @@ This API is deprecated since API version 9. You are advised to use [inputDevice. ...@@ -262,8 +255,8 @@ This API is deprecated since API version 9. You are advised to use [inputDevice.
**Return value** **Return value**
| Parameter | Description | | Parameters | Description |
| ---------------------------------- | ------------------- | | ---------------------------------- | ------------------------------------------- |
| Promise&lt;Array&lt;number&gt;&gt; | Promise used to return the result.| | Promise&lt;Array&lt;number&gt;&gt; | Promise used to return the result.|
**Example** **Example**
...@@ -286,10 +279,10 @@ This API is deprecated since API version 9. You are advised to use [inputDevice. ...@@ -286,10 +279,10 @@ This API is deprecated since API version 9. You are advised to use [inputDevice.
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
| -------- | ---------------------------------------- | ---- | --------------------------- | | -------- | -------------------------------------------------------- | ---- | -------------------------------- |
| deviceId | number | Yes | ID of the input device. | | 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.| | callback | AsyncCallback&lt;[InputDeviceData](#inputdevicedata)&gt; | Yes | Callback used to return the result, which is an **InputDeviceData** object.|
**Example** **Example**
...@@ -316,14 +309,14 @@ This API is deprecated since API version 9. You are advised to use [inputDevice. ...@@ -316,14 +309,14 @@ This API is deprecated since API version 9. You are advised to use [inputDevice.
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
| -------- | ------ | ---- | ------------ | | -------- | ------ | ---- | ------------ |
| deviceId | number | Yes | ID of the input device.| | deviceId | number | Yes | ID of the input device.|
**Return value** **Return value**
| Parameter | Description | | Parameters | Description |
| ---------------------------------------- | ------------------- | | -------------------------------------------------- | ----------------------------------- |
| Promise&lt;[InputDeviceData](#inputdevicedata)&gt; | Promise used to return the result.| | Promise&lt;[InputDeviceData](#inputdevicedata)&gt; | Promise used to return the result.|
**Example** **Example**
...@@ -345,22 +338,22 @@ Obtains the key codes supported by the input device. This API uses an asynchrono ...@@ -345,22 +338,22 @@ Obtains the key codes supported by the input device. This API uses an asynchrono
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | 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.| | 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. | | 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. | | callback | AsyncCallback&lt;Array&lt;boolean&gt;&gt; | Yes | Callback used to return the result. |
**Example** **Example**
```js ```js
// Check whether the input device whose ID is 1 supports key codes 17, 22, and 2055. // Check whether the input device whose ID is 1 supports key codes 17, 22, and 2055.
try { try {
inputDevice.supportKeys(1, [17, 22, 2055], (error, ret) => { inputDevice.supportKeys(1, [17, 22, 2055], (error, supportResult) => {
console.log("The query result is as follows: " + ret); console.log(`Query result: ${JSON.stringify(supportResult)}`);
}); });
} catch (error) { } catch (error) {
console.info("supportKeys " + error.code + " " + error.message); console.log(`Query failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
} }
``` ```
...@@ -374,15 +367,15 @@ Obtains the key codes supported by the input device. This API uses a promise to ...@@ -374,15 +367,15 @@ Obtains the key codes supported by the input device. This API uses a promise to
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | 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.| | 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. | | keys | Array&lt;KeyCode&gt; | Yes | Key codes to be queried. A maximum of five key codes can be specified. |
**Return value** **Return value**
| Parameter | Description | | Parameters | Description |
| ----------------------------------- | ------------------- | | ----------------------------------- | ------------------------------- |
| Promise&lt;Array&lt;boolean&gt;&gt; | Promise used to return the result.| | Promise&lt;Array&lt;boolean&gt;&gt; | Promise used to return the result.|
**Example** **Example**
...@@ -390,11 +383,11 @@ Obtains the key codes supported by the input device. This API uses a promise to ...@@ -390,11 +383,11 @@ Obtains the key codes supported by the input device. This API uses a promise to
```js ```js
// Check whether the input device whose ID is 1 supports key codes 17, 22, and 2055. // Check whether the input device whose ID is 1 supports key codes 17, 22, and 2055.
try { try {
inputDevice.supportKeys(1, [17, 22, 2055]).then((ret) => { inputDevice.supportKeys(1, [17, 22, 2055]).then((supportResult) => {
console.log("The query result is as follows: " + ret); console.log(`Query result: ${JSON.stringify(supportResult)}`);
}); });
} catch (error) { } catch (error) {
console.info("supportKeys " + error.code + " " + error.message); console.log(`Query failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
} }
``` ```
...@@ -408,41 +401,46 @@ Obtains the keyboard type of an input device. This API uses an asynchronous call ...@@ -408,41 +401,46 @@ Obtains the keyboard type of an input device. This API uses an asynchronous call
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | 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.| | 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. | | callback | AsyncCallback&lt;[KeyboardType](#keyboardtype9)&gt; | Yes | Callback used to return the result. |
**Example** **Example**
```js ```js
// Query the keyboard type of the input device whose ID is 1. // Query the keyboard type of the input device whose ID is 1.
try { try {
inputDevice.getKeyboardType(1, (error, number) => { inputDevice.getKeyboardType(1, (error, type) => {
if (error) { if (error) {
console.log(`Failed to get keyboardtype. console.log(`Failed to get keyboard type, error: ${JSON.stringify(error, [`code`, `message`])}`);
error code=${err.code} msg=${err.message}`);
return; return;
} }
console.log("The keyboard type of the device is: " + number); console.log(`Keyboard type: ${JSON.stringify(type)}`);
}); });
} catch (error) { } catch (error) {
console.info("getKeyboardType " + error.code + " " + error.message); console.log(`Failed to get keyboard type, error: ${JSON.stringify(error, [`code`, `message`])}`);
} }
``` ```
## inputDevice.getKeyboardType<sup>9+</sup> ## inputDevice.getKeyboardType<sup>9+</sup>
getKeyboardType(deviceId: number,): Promise&lt;KeyboardType&gt; getKeyboardType(deviceId: number): Promise&lt;KeyboardType&gt;
Obtains the keyboard type of an input device. This API uses a promise to return the result. Obtains the keyboard type of an input device. This API uses a promise to return the result.
**System capability**: SystemCapability.MultimodalInput.Input.InputDevice **System capability**: SystemCapability.MultimodalInput.Input.InputDevice
**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.|
**Return value** **Return value**
| Parameter | Description | | Parameters | Description |
| ---------------------------------------- | ------------------- | | --------------------------------------------- | ------------------------------- |
| Promise&lt;[KeyboardType](#keyboardtype9)&gt; | Promise used to return the result.| | Promise&lt;[KeyboardType](#keyboardtype9)&gt; | Promise used to return the result.|
**Example** **Example**
...@@ -450,11 +448,11 @@ Obtains the keyboard type of an input device. This API uses a promise to return ...@@ -450,11 +448,11 @@ Obtains the keyboard type of an input device. This API uses a promise to return
```js ```js
// Query the keyboard type of the input device whose ID is 1. // Query the keyboard type of the input device whose ID is 1.
try { try {
inputDevice.getKeyboardType(1).then((number) => { inputDevice.getKeyboardType(1).then((type) => {
console.log("The keyboard type of the device is: " + number); console.log(`Keyboard type: ${JSON.stringify(type)}`);
}); });
} catch (error) { } catch (error) {
console.info("getKeyboardType " + error.code + " " + error.message); console.log(`Failed to get keyboard type, error: ${JSON.stringify(error, [`code`, `message`])}`);
} }
``` ```
...@@ -496,10 +494,10 @@ Defines the axis type of an input device. ...@@ -496,10 +494,10 @@ Defines the axis type of an input device.
| Name | Type | Readable | Writable | Description | | Name | Type | Readable | Writable | Description |
| --------- | ------ | ---- | ---- | ------- | | --------- | ------ | ---- | ---- | ------- |
| touchmajor | string | Yes| No| touchmajor axis. | | touchMajor | string | Yes| No| touchMajor axis. |
| touchminor | string | Yes| No| touchminor axis. | | touchMinor | string | Yes| No| touchMinor axis. |
| toolminor | string | Yes| No| toolminor axis. | | toolMinor | string | Yes| No| toolMinor axis. |
| toolmajor | string | Yes| No| toolmajor axis. | | toolMajor | string | Yes| No| toolMajor axis. |
| orientation | string | Yes| No| Orientation axis.| | orientation | string | Yes| No| Orientation axis.|
| pressure | string | Yes| No| Pressure axis. | | pressure | string | Yes| No| Pressure axis. |
| x | string | Yes| No| X axis. | | x | string | Yes| No| X axis. |
...@@ -524,7 +522,7 @@ Defines the axis range of an input device. ...@@ -524,7 +522,7 @@ Defines the axis range of an input device.
## SourceType<sup>9+</sup> ## SourceType<sup>9+</sup>
Enumerates the input source types. For example, if a mouse reports an x-axis event, the source of the x-axis is the mouse. 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.
**System capability**: SystemCapability.MultimodalInput.Input.InputDevice **System capability**: SystemCapability.MultimodalInput.Input.InputDevice
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册