diff --git a/en/application-dev/reference/apis/js-apis-inputdevice.md b/en/application-dev/reference/apis/js-apis-inputdevice.md index 0913e6e3ce52acbcf57959768599dde89fed4d87..02b81d4a512f7e08ea27866fc43dc0bc853f4521 100644 --- a/en/application-dev/reference/apis/js-apis-inputdevice.md +++ b/en/application-dev/reference/apis/js-apis-inputdevice.md @@ -20,90 +20,187 @@ import inputDevice from '@ohos.multimodalInput.inputDevice'; getDeviceIds(callback: AsyncCallback<Array<number>>): 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<Array<number>> | Yes | Callback used to return the result. | +**Parameters** - **Example** +| Name | Type | Mandatory | Description | +| -------- | ---------------------------------------- | ---- | ----- | +| callback | AsyncCallback<Array<number>> | 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> + +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> | 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<InputDeviceData>): 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<[InputDeviceData](#inputdevicedata)> | 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<[InputDeviceData](#inputdevicedata)> | 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 + +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 | 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<[SourceType](#sourcetype)> | 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<[SourceType](#sourcetype)> | 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.| diff --git a/en/application-dev/reference/apis/js-apis-inputeventclient.md b/en/application-dev/reference/apis/js-apis-inputeventclient.md new file mode 100644 index 0000000000000000000000000000000000000000..ed3942bb5920474b06ae829521a77bf483d1cac0 --- /dev/null +++ b/en/application-dev/reference/apis/js-apis-inputeventclient.md @@ -0,0 +1,57 @@ +# 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.|