提交 60a98c36 编写于 作者: E ester.zhou

add and update docs

Signed-off-by: Nester.zhou <ester.zhou@huawei.com>
上级 6e676c15
......@@ -20,90 +20,187 @@ import inputDevice from '@ohos.multimodalInput.inputDevice';
getDeviceIds(callback: AsyncCallback&lt;Array&lt;number&gt;&gt;): void
Obtains the IDs of all input devices. This method uses an asynchronous callback to return the result.
Obtains the IDs of all input devices. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.MultimodalInput.Input.InputDevice
**Parameters**
| Name | Type | Mandatory | Description |
| -------- | -------- | -------- | -------- |
| callback | AsyncCallback&lt;Array&lt;number&gt;&gt; | Yes | Callback used to return the result. |
**Parameters**
**Example**
| Name | Type | Mandatory | Description |
| -------- | ---------------------------------------- | ---- | ----- |
| callback | AsyncCallback&lt;Array&lt;number&gt;&gt; | Yes | Callback used to return the result.|
**Example**
```
export default {
data: {
deviceIds: Array,
},
callback: function(ids) {
this.deviceIds = ids;
},
testGetDeviceIds: function () {
console.info("InputDeviceJsTest---start---testGetDeviceIds");
inputDevice.getDeviceIds(this.callback);
console.info("InputDeviceJsTest---end---testGetDeviceIds");
}
}
```
## inputDevice.getDeviceIds
function getDeviceIds(): Promise<Array<number>>
Obtains the IDs of all input devices. This API uses a promise to return the result.
**System capability**: SystemCapability.MultimodalInput.Input.InputDevice
**Return value**
| Name | Description |
| ---------------------- | ------------------ |
| Promise<Array<number>> | Promise used to return the result.|
**Example**
```
data: {
deviceIds: Array,
},
callback: function(ids) {
this.deviceIds = ids;
},
testGetDeviceIds: function () {
console.info("InputDeviceJsTest---start---testGetDeviceIds");
inputDevice.getDeviceIds(this.callback);
console.info("InputDeviceJsTest---end---testGetDeviceIds");
export default {
testGetDeviceIds: function () {
console.info("InputDeviceJsTest---start---testGetDeviceIds");
let promise = inputDevice.getDeviceIds();
promise.then((data)=> {
console.info('GetDeviceIds successed, Data: ' + JSON.stringify(data))
}).catch((err)=>{
console.error('Failed GetDeviceIds. Cause: ' + JSON.stringify(err));
});
}
}
```
## inputDevice.getDevice
getDevice(deviceId: number, callback: AsyncCallback&lt;InputDeviceData&gt;): void
Obtains the information about an input device. This method uses an asynchronous callback to return the result.
Obtains the 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 whose information is to be obtained. |
| callback | AsyncCallback&lt;[InputDeviceData](#inputdevicedata)&gt; | Yes | Callback used to return the **InputDeviceData** object. |
**Parameters**
| Name | Type | Mandatory | Description |
| -------- | ---------------------------------------- | ---- | --------------------------- |
| deviceId | number | Yes | ID of the input device whose information is to be obtained. |
| callback | AsyncCallback&lt;[InputDeviceData](#inputdevicedata)&gt; | Yes | Callback used to return the **InputDeviceData** object.|
**Example**
**Example**
```
InputDeviceData {
deviceId : 0,
name : "NA",
sources : Array,
axisRanges : Array,
},
callback: function(deviceData) {
this.InputDeviceData = deviceData;
},
testGetDevice: function () {
// The example is used to obtain the information about the device whose ID is 1.
console.info("InputDeviceJsTest---start---testGetDevice");
inputDevice.getDevice(1, this.callback);
console.info("InputDeviceJsTest---end---testGetDevice");
export default {
InputDeviceData: {
deviceId : 0,
name : "NA",
sources : Array,
axisRanges : Array,
},
callback: function(deviceData) {
this.InputDeviceData = deviceData;
},
testGetDevice: function () {
// The example is used to obtain the information about the device whose ID is 1.
console.info("InputDeviceJsTest---start---testGetDevice");
inputDevice.getDevice(1, this.callback);
console.info("InputDeviceJsTest---end---testGetDevice");
}
}
```
## inputDevice.getDevice
function getDevice(deviceId: number): Promise<InputDeviceData>
Obtains the information about an input device. This API uses a promise to return the result.
**System capability**: SystemCapability.MultimodalInput.Input.InputDevice
**Return value**
| Name | Description |
| ------------------------ | ------------------ |
| Promise<InputDeviceData> | Promise used to return the result.|
**Example**
```
export default {
InputDeviceData: {
deviceId : 0,
name : "NA",
sources : Array,
axisRanges : Array,
},
testGetDevice: function () {
// The example is used to obtain the information about the device whose ID is 1.
console.info("InputDeviceJsTest---start---testGetDevice");
let promise = inputDevice.getDevice(1);
promise.then((data)=> {
console.info('GetDeviceId successed, Data: ' + JSON.stringify(data))
}).catch((err)=>{
console.error('Failed GetDeviceId. Cause: ' + JSON.stringify(err));
});
}
}
```
## InputDeviceData
Defines the information about an input device.
**System capability**: SystemCapability.MultimodalInput.Input.InputDevice
| Name | Type | Description |
| -------- | -------- | -------- |
| id | number | Unique identifier of an input device. If the same physical device is repeatedly inserted and removed, its ID changes. |
| name | string | Name of the input device. |
| sources | Array&lt;[SourceType](#sourcetype)&gt; | Source types of the input device. For example, if a keyboard is attached with a touchpad, the device has two input sources: keyboard and touchpad. |
**System capability**: SystemCapability.MultimodalInput.Input.InputDevice
| Name | Type | Description |
| ------- | -------------------------------------- | ---------------------------------------- |
| id | number | Unique identifier of an input device. If the same physical device is repeatedly inserted and removed, its ID changes. |
| name | string | Name of the input device. |
| sources | Array&lt;[SourceType](#sourcetype)&gt; | Source types of the input device. For example, if a keyboard is attached with a touchpad, the device has two input sources: keyboard and touchpad.|
## AxisType
Axis type. This API is defined but not implemented in OpenHarmony 3.1 Release. It will be available for use in OpenHarmony 3.1 MR.
## AxisRange
Defines the axis information of an input device.
**System capability**: SystemCapability.MultimodalInput.Input.InputDevice
| Name | Type | Description |
| ------ | ------------------------- | -------- |
| source | [SourceType](#sourcetype) | Input source type of the axis.|
| axis | [AxisType](axistype) | Axis type. |
| max | number | Maximum value reported by the axis. |
| min | number | Minimum value reported by the axis. |
## SourceType
Enumerates the input source types.
Enumerates the input source types. For example, if a mouse reports an x-axis event, the source of the x-axis is the mouse.
**System capability**: SystemCapability.MultimodalInput.Input.InputDevice
| Name | Type | Description |
| -------- | -------- | -------- |
| keyboard | string | The input device is a keyboard. |
| touchscreen | string | The input device is a touchscreen. |
| mouse | string | The input device is a mouse. |
| trackball | string | The input device is a trackball. |
| touchpad | string | The input device is a touchpad. |
| joystick | string | The input device is a joystick. |
| Name | Type | Description |
| ----------- | ------ | ----------- |
| keyboard | string | The input device is a keyboard. |
| touchscreen | string | The input device is a touchscreen.|
| mouse | string | The input device is a mouse. |
| trackball | string | The input device is a trackball.|
| touchpad | string | The input device is a touchpad.|
| joystick | string | The input device is a joystick.|
# Input Event Client
> ![icon-note.gif](public_sys-resources/icon-note.gif) **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 APIs of this module are system APIs and cannot be called by third-party applications.
## Modules to Import
```
import inputEventClient from '@ohos.multimodalInput.inputEventClient';
```
## inputEventClient.injectEvent
injectEvent({KeyEvent: KeyEvent}): void
Injects a key.
**System capability**: SystemCapability.MultimodalInput.Input.InputSimulator
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| KeyEvent | [KeyEvent](#keyevent) | Yes| Information about the key to inject.|
**Example**
```
let keyEvent = {
isPressed: true,
keyCode: 2,
keyDownDuration: 0,
isIntercepted: false
}
res = inputEventClient.injectEvent({KeyEvent: keyEvent});
```
## KeyEvent
Defines the information about the key to inject.
**System capability**: SystemCapability.MultimodalInput.Input.InputSimulator
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| isPressed | boolean | Yes| Whether the key is pressed.|
| keyCode | Number | Yes| Key code.|
| keyDownDuration | boolean | Yes| Duration for which the key is pressed.|
| isIntercepted | Number | Yes| Whether the key can be intercepted.|
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册