diff --git a/zh-cn/application-dev/reference/apis/js-apis-cooperate.md b/zh-cn/application-dev/reference/apis/js-apis-cooperate.md
new file mode 100755
index 0000000000000000000000000000000000000000..8d8f418dd386cfdd26ffbf030b0198cc3087b0fe
--- /dev/null
+++ b/zh-cn/application-dev/reference/apis/js-apis-cooperate.md
@@ -0,0 +1,345 @@
+# 键鼠穿越管理
+
+键鼠穿越功能,即两台或多台设备组网协同后可以共用一套键盘鼠标。
+键鼠穿越管理模块,提供实现键盘、鼠标等外接输入设备的跨设备协同操作。在设备组网的情况下,提供多设备间共享键鼠的开关,设备穿越状态更新以及键鼠穿越光标自适应显示。
+
+> **说明**
+>
+> 本模块首批接口从API version 9开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
+
+## 导入模块
+
+```js
+import inputDeviceCooperate from '@ohos.multimodalInput.inputDeviceCooperate'
+```
+
+## inputDeviceCooperate.enable9+
+
+enable(enable: boolean, callback: AsyncCallback\): void
+
+键鼠穿越开关开启或关闭,使用callback异步回调。
+
+**系统能力**:SystemCapability.MultimodalInput.Input.InputDeviceCooperate
+
+**参数**:
+
+| 参数名 | 类型 | 必填 | 说明 |
+| -------- | ------------------- | ---- | ------------------------------------------------------------ |
+| enable | boolean | 是 | 键鼠穿越开关开启或关闭状态。true: 键鼠穿越开关开启; false: 键鼠穿越开关关闭。 |
+| callback | AsyncCallback | 是 | 异步回调函数。当键鼠穿越开关开启或关闭成功,err为undefined,否则为错误对象。 |
+
+ **示例**:
+
+```js
+try {
+ inputDeviceCooperate.enable(true, (err) => {
+ if (err) {
+ console.log(`Turn on the key mouse crossing switch failed. error code=${JSON.stringify(err.code)} msg=${JSON.stringify(err.message)}`);
+ return;
+ }
+ console.log(`Turn on the key mouse crossing switch success.`);
+ });
+} catch (err) {
+ console.log(`Turn on the key mouse crossing switch failed. error code=${JSON.stringify(err.code)} msg=${JSON.stringify(err.message)}`);
+}
+```
+
+## inputDeviceCooperate.enable9+
+
+enable(enable: boolean): Promise\
+
+键鼠穿越开关开启或关闭,使用Promise方式作为异步方法。
+
+**系统能力**:SystemCapability.MultimodalInput.Input.InputDeviceCooperate
+
+**参数**:
+
+| 参数名 | 类型 | 必填 | 说明 |
+| --------- | ------- | ---- | ------------------------------------------------------------------- |
+| enable | boolean | 是 | 键鼠穿越开关开启或关闭状态。true: 键鼠穿越开关开启; false: 键鼠穿越开关关闭。 |
+
+**返回值**:
+
+| 参数 | 说明 |
+| ------------------- | ------------------------------- |
+| Promise\ | Promise实例,用于异步获取结果。 |
+
+**示例**:
+
+```js
+try {
+ inputDeviceCooperate.enable(false).then((err) => {
+ console.log(`Turn on the key mouse crossing switch success`);
+ }, (err) => {
+ console.log(`Turn on the key mouse crossing switch failed. error code=${JSON.stringify(err.code)} msg=${JSON.stringify(err.message)}`);
+ });
+} catch (err) {
+ console.log(`Turn on the key mouse crossing switch failed. error code=${JSON.stringify(err.code)} msg=${JSON.stringify(err.message)}`);
+}
+```
+
+## inputDeviceCooperate.start9+
+
+start(sinkDeviceDescriptor: string, srcInputDeviceId: number, callback: AsyncCallback\): void
+
+启动键鼠穿越,使用callback异步回调。
+
+**系统能力**:SystemCapability.MultimodalInput.Input.InputDeviceCooperate
+
+**参数**:
+
+| 参数名 | 类型 | 必填 | 说明 |
+| -------- | ---------------------------- | ---- | ---------------------------- |
+| sinkDeviceDescriptor | string | 是 | 键鼠穿越目标设备描述符。 |
+| srcInputDeviceId | number | 是 | 键鼠穿越待穿越外设标识符。 |
+| callback | AsyncCallback\ | 是 | 异步回调函数。当键鼠穿越启动成功,err为undefined,否则为错误对象。|
+
+**示例**:
+
+```js
+try {
+ inputDeviceCooperate.start(sinkDeviceDescriptor, srcInputDeviceId, (err) => {
+ if (err) {
+ console.log(`Start key mouse crossing failed. error code=${JSON.stringify(err.code)} msg=${JSON.stringify(err.message)}`);
+ return;
+ }
+ console.log(`Start key mouse crossing success.`);
+ });
+} catch (err) {
+ console.log(`Start key mouse crossing failed. error code=${JSON.stringify(err.code)} msg=${JSON.stringify(err.message)}`);
+}
+```
+
+## inputDeviceCooperate.start9+
+
+start(sinkDeviceDescriptor: string, srcInputDeviceId: number): Promise\
+
+启动键鼠穿越,使用Promise方式作为异步方法。
+
+**系统能力**: SystemCapability.MultimodalInput.Input.InputDeviceCooperate
+
+**参数**:
+
+| 参数名 | 类型 | 必填 | 说明 |
+| -------- | ---------------------------- | ---- | ---------------------------- |
+| sinkDeviceDescriptor | string | 是 | 键鼠穿越目标设备描述符。 |
+| srcInputDeviceId | number | 是 | 键鼠穿越待穿越外设标识符。 |
+
+**返回值**:
+
+| 参数名 | 说明 |
+| ---------------------- | ------------------------------- |
+| Promise\ | Promise实例,用于异步获取结果。 |
+
+**示例**:
+
+```js
+try {
+ inputDeviceCooperate.start(sinkDeviceDescriptor, srcInputDeviceId).then((err) => {
+ console.log(`Start key mouse crossing success.`);
+ }, (err) => {
+ console.log(`Start key mouse crossing failed. error code=${JSON.stringify(err.code)} msg=${JSON.stringify(err.message)}`);
+ });
+} catch (err) {
+ console.log(`Start key mouse crossing failed. error code=${JSON.stringify(err.code)} msg=${JSON.stringify(err.message)}`);
+}
+```
+
+## inputDeviceCooperate.stop9+
+
+stop(callback: AsyncCallback\): void
+
+停止键鼠穿越,使用callback异步回调。
+
+**系统能力**:SystemCapability.MultimodalInput.Input.InputDeviceCooperate
+
+**参数**:
+
+| 参数名 | 类型 | 必填 | 说明 |
+| -------- | ---------------------------- | ---- | ---------------------------- |
+| callback | AsyncCallback\ | 是 | 异步回调函数,返回查询结果。 |
+
+**示例**:
+
+```js
+try {
+ inputDeviceCooperate.stop((err) => {
+ if (err) {
+ console.log(`Stop key mouse crossing failed. error code=${JSON.stringify(err.code)} msg=${JSON.stringify(err.message)}`);
+ return;
+ }
+ console.log(`Stop key mouse crossing success.`);
+ });
+} catch (err) {
+ console.log(`Stop key mouse crossing failed. error code=${JSON.stringify(err.code)} msg=${JSON.stringify(err.message)}`);
+}
+```
+
+## inputDeviceCooperate.stop9+
+
+stop(): Promise\
+
+停止键鼠穿越,使用Promise异步回调。
+
+**系统能力**:SystemCapability.MultimodalInput.Input.InputDeviceCooperate
+
+**参数**:
+
+| 参数名 | 说明 |
+| -------- | ---------------------------- |
+| Promise\ | Promise实例,用于异步获取结果。 |
+
+**示例**:
+
+```js
+try {
+ inputDeviceCooperate.stop().then((err) => {
+ console.log(`Stop key mouse crossing success.`);
+ }, (err) => {
+ console.log(`Stop key mouse crossing failed. error code=${JSON.stringify(err.code)} msg=${JSON.stringify(err.message)}`);
+ });
+} catch (err) {
+ console.log(`Stop key mouse crossing failed. error code=${JSON.stringify(err.code)} msg=${JSON.stringify(err.message)}`);
+}
+```
+
+## inputDeviceCooperate.getState9+
+
+getState(deviceDescriptor: string, callback: AsyncCallback<{ state: boolean }>): void
+
+获取键鼠穿越开关的状态,使用callback异步回调。
+
+**系统能力**:SystemCapability.MultimodalInput.Input.InputDeviceCooperate
+
+**参数**:
+
+| 参数名 | 类型 | 必填 | 说明 |
+| -------- | --------- | ---- | ---------------------------- |
+| deviceDescriptor | string | 是 | 键鼠穿越目标设备描述符。 |
+| callback | AsyncCallback<{ state: boolean }> | 是 | 异步回调函数,接收键鼠穿越开关状态。 |
+
+**示例**:
+
+```js
+try {
+ inputDeviceCooperate.getState(deviceDescriptor, (err, data) => {
+ if (err) {
+ console.log(`Get the status failed. error code=${JSON.stringify(err.code)} msg=${JSON.stringify(err.message)}`);
+ return;
+ }
+ console.log(`Get the status success. data=${JSON.stringify(data)}`);
+ });
+} catch (err) {
+ console.log(`Get the status failed. error code=${JSON.stringify(err.code)} msg=${JSON.stringify(err.message)}`);
+}
+```
+
+## inputDeviceCooperate.getState9+
+
+getState(deviceDescriptor: string): Promise<{ state: boolean }>
+
+获取键鼠穿越开关的状态,使用Promise异步回调。
+
+**系统能力**:SystemCapability.MultimodalInput.Input.InputDeviceCooperate
+
+**参数**:
+
+| 参数名 | 类型 | 必填 | 说明 |
+| -------- | --------- | ---- | ---------------------------- |
+| deviceDescriptor | string | 是 | 键鼠穿越目标设备描述符。 |
+
+**返回值**:
+
+| 参数 | 说明 |
+| ------------------- | ------------------------------- |
+| Promise<{ state: boolean }>| Promise实例,用于异步获取结果。 |
+
+**示例**:
+
+```js
+try {
+ inputDeviceCooperate.getState(deviceDescriptor).then((data) => {
+ console.log(`Get the status success. data=${JSON.stringify(data)}`);
+ }, (err) => {
+ console.log(`Get the status failed. error code=${JSON.stringify(err.code)} msg=${JSON.stringify(err.message)}`);
+ });
+} catch (err) {
+ console.log(`Get the status failed. error code=${JSON.stringify(err.code)} msg=${JSON.stringify(err.message)}`);
+}
+```
+
+## on('cooperation')9+
+
+on(type: 'cooperation', callback: AsyncCallback<{ deviceDescriptor: string, eventMsg: EventMsg }>): void
+
+注册监听键鼠穿越状态。
+
+**系统能力**:SystemCapability.MultimodalInput.Input.InputDeviceCooperate
+
+**参数**:
+
+| 参数名 | 类型 | 必填 | 说明 |
+| -------- | ---------------------------- | ---- | ---------------------------- |
+| type | string | 是 | 注册类型,'cooperation'。 |
+| callback | AsyncCallback<{ deviceDescriptor: string, eventMsg: [EventMsg](#eventmsg) }> | 是 | 异步回调函数,接收键鼠穿越事件消息。 |
+
+**示例**:
+
+```js
+try {
+ inputDeviceCooperate.on('cooperation', (data) => {
+ if (data) {
+ console.log(`error: ${JSON.stringify(data)}`);
+ } else {
+ console.log(`cooperation: ${JSON.stringify(data)}`);
+ }
+ });
+} catch (err) {
+ console.log(`Registered failed. error code=${JSON.stringify(err.code)} msg=${JSON.stringify(err.message)}`);
+}
+```
+
+## off('cooperation')9+
+
+off(type: 'cooperation', callback?: AsyncCallback\): void
+
+关闭监听键鼠穿越状态。
+
+**系统能力**:SystemCapability.MultimodalInput.Input.InputDeviceCooperate
+
+**参数**:
+
+| 参数名 | 类型 | 必填 | 说明 |
+| -------- | ---------------------------- | ---- | ---------------------------- |
+| type | string | 是 | 注册类型,'cooperation'。 |
+| callback | AsyncCallback | 否 | 异步回调函数,用于返回结果。 |
+
+**示例**:
+
+```js
+try {
+ inputDeviceCooperate.off('cooperation', (err) => {
+ if (err) {
+ console.log(`error: ${JSON.stringify(err)}`);
+ } else {
+ console.log(`Unregistered succeed`);
+ }
+ });
+} catch (err) {
+ console.log(`Unregistered failed. error code=${JSON.stringify(err.code)} msg=${JSON.stringify(err.message)}`);
+}
+```
+
+## EventMsg9+
+
+键鼠穿越事件。
+
+**系统能力**:SystemCapability.MultimodalInput.Input.InputDeviceCooperate
+
+| 参数名 | 值 | 说明 |
+| -------- | --------- | ----------------- |
+| MSG_COOPERATE_INFO_START | 200 | 键鼠穿越消息,表示键鼠穿越开始。 |
+| MSG_COOPERATE_INFO_SUCCESS | 201 | 键鼠穿越消息,表示键鼠穿越成功。 |
+| MSG_COOPERATE_INFO_FAIL | 202 | 键鼠穿越消息,表示键鼠穿越失败。 |
+| MSG_COOPERATE_STATE_ON | 500 | 键鼠穿越状态,表示键鼠穿越状态开启。 |
+| MSG_COOPERATE_STATE_OFF | 501 | 键鼠穿越状态,表示键鼠穿越状态关闭。 |
\ No newline at end of file
diff --git a/zh-cn/application-dev/reference/apis/js-apis-inputconsumer.md b/zh-cn/application-dev/reference/apis/js-apis-inputconsumer.md
index d47a7f5604c3609161e6da3faeee04697685b811..12b468dea4e2948d2698f4b6373efa94631552f6 100755
--- a/zh-cn/application-dev/reference/apis/js-apis-inputconsumer.md
+++ b/zh-cn/application-dev/reference/apis/js-apis-inputconsumer.md
@@ -36,12 +36,16 @@ on(type: "key", keyOptions: KeyOptions, callback: Callback<KeyOptions>): v
**示例:**
```js
-let keyOptions = {preKeys: [], finalKey: 3, isFinalKeyDown: true, finalKeyDownDuration: 0}
-let callback = function(keyOptions) {
- console.info("preKeys: " + keyOptions.preKeys, "finalKey: " + keyOptions.finalKey,
- "isFinalKeyDown: " + keyOptions.isFinalKeyDown, "finalKeyDownDuration: " + keyOptions.finalKeyDownDuration)
+let keyOptions = { preKeys: [], finalKey: 3, isFinalKeyDown: true, finalKeyDownDuration: 0 }
+let callback = function (keyOptions) {
+ console.info("preKeys: " + keyOptions.preKeys, "finalKey: " + keyOptions.finalKey,
+ "isFinalKeyDown: " + keyOptions.isFinalKeyDown, "finalKeyDownDuration: " + keyOptions.finalKeyDownDuration)
+}
+try {
+ inputConsumer.on(inputConsumer.SubscribeType.KEY, keyOptions, callback);
+} catch (error) {
+ console.info(`inputConsumer.on, error.code=${JSON.stringify(error.code)}, error.msg=${JSON.stringify(error.message)}`);
}
-inputConsumer.on('key', keyOptions, callback);
```
@@ -64,12 +68,16 @@ off(type: "key", keyOptions: KeyOptions, callback?: Callback<KeyOptions>):
**示例:**
```js
-let keyOptions = {preKeys: [], finalKey: 3, isFinalKeyDown: true, finalKeyDownDuration: 0}
-let callback = function(keyOptions) {
- console.info("preKeys: " + keyOptions.preKeys, "finalKey: " + keyOptions.finalKey,
- "isFinalKeyDown: " + keyOptions.isFinalKeyDown, "finalKeyDownDuration: " + keyOptions.finalKeyDownDuration)
+let keyOptions = { preKeys: [], finalKey: 3, isFinalKeyDown: true, finalKeyDownDuration: 0 }
+let callback = function (keyOptions) {示例:**
+ console.info("preKeys: " + keyOptions.preKeys, "finalKey: " + keyOptions.finalKey,
+ "isFinalKeyDown: " + keyOptions.isFinalKeyDown, "finalKeyDownDuration: " + keyOptions.finalKeyDownDuration)
+}
+try {
+ inputConsumer.off(inputConsumer.SubscribeType.KEY, keyOptions, callback);
+} catch (error) {
+ console.info(`inputConsumer.off, error.code=${JSON.stringify(error.code)}, error.msg=${JSON.stringify(error.message)}`);
}
-inputConsumer.off('key', keyOptions, callback);
```
diff --git a/zh-cn/application-dev/reference/apis/js-apis-inputdevice.md b/zh-cn/application-dev/reference/apis/js-apis-inputdevice.md
index e7536e336b6cd7f61d2822276ad5d91703427f41..b255b0a2f4a3fc86fb06170ae182267c33d3c339 100755
--- a/zh-cn/application-dev/reference/apis/js-apis-inputdevice.md
+++ b/zh-cn/application-dev/reference/apis/js-apis-inputdevice.md
@@ -16,6 +16,130 @@
import inputDevice from '@ohos.multimodalInput.inputDevice';
```
+## inputDevice.getDeviceList9+
+
+getDeviceList(callback: AsyncCallback<Array<number>>): void
+
+获取所有输入设备的id列表,使用callback方式作为异步方法。
+
+**系统能力**:SystemCapability.MultimodalInput.Input.InputDevice
+
+**参数**:
+
+| 参数 | 类型 | 必填 | 说明 |
+| -------- | ---------------------------------------- | ---- | ---------- |
+| callback | AsyncCallback<Array<number>> | 是 | 回调函数。 |
+
+**示例**:
+
+```js
+try {
+ inputDevice.getDeviceList((error, ids) => {
+ if (error) {
+ console.log(`Failed to get device list.
+ error code=${JSON.stringify(err.code)} msg=${JSON.stringify(err.message)}`);
+ return;
+ }
+ this.data = ids;
+ console.log("The device ID list is: " + ids);
+ });
+} catch (error) {
+ console.info("getDeviceList " + error.code + " " + error.message);
+}
+```
+
+## inputDevice.getDeviceList9+
+
+getDeviceList(): Promise<Array<number>>
+
+获取所有输入设备的id列表,使用Promise方式作为异步方法。
+
+**系统能力**:SystemCapability.MultimodalInput.Input.InputDevice
+
+**返回值**:
+
+| 参数 | 说明 |
+| ---------------------------------- | ------------------------------- |
+| Promise<Array<number>> | Promise实例,用于异步获取结果。 |
+
+**示例**:
+
+```js
+try {
+ inputDevice.getDeviceList().then((ids) => {
+ console.log("The device ID list is: " + ids);
+ });
+} catch (error) {
+ console.info("getDeviceList " + error.code + " " + error.message);
+}
+```
+
+## inputDevice.getDeviceInfo9+
+
+getDeviceInfo(deviceId: number, callback: AsyncCallback<InputDeviceData>): void
+
+获取输入设备的描述信息,使用callback方式作为异步方法。
+
+**系统能力**:SystemCapability.MultimodalInput.Input.InputDevice
+
+**参数**:
+
+| 参数 | 类型 | 必填 | 说明 |
+| -------- | -------------------------------------------------------- | ---- | --------------------------------------- |
+| deviceId | number | 是 | 需要获取信息的设备id。 |
+| callback | AsyncCallback<[InputDeviceData](#inputdevicedata)> | 是 | 回调函数,异步返回InputDeviceData对象。 |
+
+**示例**:
+
+```js
+// 示例获取设备id为1的设备name信息。
+try {
+ inputDevice.getDeviceInfo(1, (error, inputDevice) => {
+ if (error) {
+ console.log(`Failed to get device information.
+ error code=${JSON.stringify(err.code)} msg=${JSON.stringify(err.message)}`);
+ return;
+ }
+ console.log("The device name is: " + inputDevice.name);
+ });
+} catch (error) {
+ console.info("getDeviceInfo " + error.code + " " + error.message);
+}
+```
+
+## inputDevice.getDeviceInfo9+
+
+getDeviceInfo(deviceId: number): Promise<InputDeviceData>
+
+获取输入设备的描述信息,使用Promise方式作为异步方法。
+
+**系统能力**:SystemCapability.MultimodalInput.Input.InputDevice
+
+**参数**:
+
+| 参数 | 类型 | 必填 | 说明 |
+| -------- | ------ | ---- | ---------------------- |
+| deviceId | number | 是 | 需要获取信息的设备id。 |
+
+**返回值**:
+
+| 参数 | 说明 |
+| -------------------------------------------------- | ------------------------------- |
+| Promise<[InputDeviceData](#inputdevicedata)> | Promise实例,用于异步获取结果。 |
+
+**示例**:
+
+```js
+// 示例获取设备id为1的设备name信息。
+try {
+ inputDevice.getDeviceInfo(id).then((inputDevice) => {
+ console.log("The device name is: " + inputDevice.name);
+ });
+} catch (error) {
+ console.info("getDeviceInfo " + error.code + " " + error.message);
+}
+```
+
## inputDevice.on9+
on(type: “change”, listener: Callback<DeviceListener>): void
@@ -35,20 +159,24 @@ on(type: “change”, listener: Callback<DeviceListener>): void
```js
let isPhysicalKeyboardExist = true;
-inputDevice.on("change", (data) => {
+try {
+ inputDevice.on("change", (data) => {
console.log("type: " + data.type + ", deviceId: " + data.deviceId);
inputDevice.getKeyboardType(data.deviceId, (err, ret) => {
- console.log("The keyboard type of the device is: " + ret);
- if (ret == inputDevice.KeyboardType.ALPHABETIC_KEYBOARD && data.type == 'add') {
- // 监听物理键盘已连接。
- isPhysicalKeyboardExist = true;
- } else if (ret == inputDevice.KeyboardType.ALPHABETIC_KEYBOARD && data.type == 'remove') {
- // 监听物理键盘已断开。
- isPhysicalKeyboardExist = false;
- }
+ console.log("The keyboard type of the device is: " + ret);
+ if (ret == inputDevice.KeyboardType.ALPHABETIC_KEYBOARD && data.type == 'add') {
+ // 监听物理键盘已连接。
+ isPhysicalKeyboardExist = true;
+ } else if (ret == inputDevice.KeyboardType.ALPHABETIC_KEYBOARD && data.type == 'remove') {
+ // 监听物理键盘已断开。
+ isPhysicalKeyboardExist = false;
+ }
});
-});
-// 根据isPhysicalKeyboardExist的值决定软键盘是否弹出。
+ });
+ // 根据isPhysicalKeyboardExist的值决定软键盘是否弹出。
+} catch (error) {
+ console.info("oninputdevcie " + error.code + " " + error.message);
+}
```
## inputDevice.off9+
@@ -69,27 +197,40 @@ off(type: “change”, listener?: Callback<DeviceListener>): void
**示例**:
```js
-function listener(data) {
- console.log("type: " + data.type + ", deviceId: " + data.deviceId);
+callback: function(data) {
+ console.log("type: " + data.type + ", deviceId: " + data.deviceId);
}
-// 监听输入设备的热插拔事件
-inputDevice.on("change", listener);
+try {
+ inputDevice.on("change", this.callback);
+} catch (error) {
+ console.info("oninputdevcie " + error.code + " " + error.message)
+}
// 单独取消listener的监听。
-inputDevice.off("change", listener);
+try {
+ inputDevice.off("change", this.callback);
+} catch (error) {
+ console.info("offinputdevcie " + error.code + " " + error.message)
+}
// 取消所有监听。
-inputDevice.off("change");
+try {
+ inputDevice.off("change");
+} catch (error) {
+ console.info("offinputdevcie " + error.code + " " + error.message);
+}
// 取消监听后,软键盘默认都弹出。
```
-## inputDevice.getDeviceIds
+## inputDevice.getDeviceIds(deprecated)
getDeviceIds(callback: AsyncCallback<Array<number>>): void
获取所有输入设备的id列表,使用callback方式作为异步方法。
+从API version 9 开始不再维护,建议使用[inputDevice.getDeviceList](#inputdevicegetdevicelist9)代替。
+
**系统能力**:SystemCapability.MultimodalInput.Input.InputDevice
**参数**:
@@ -106,12 +247,14 @@ inputDevice.getDeviceIds((ids)=>{
});
```
-## inputDevice.getDeviceIds
+## inputDevice.getDeviceIds(deprecated)
getDeviceIds(): Promise<Array<number>>
获取所有输入设备的id列表,使用Promise方式作为异步方法。
+从API version 9 开始不再维护,建议使用[inputDevice.getDeviceList](#inputdevicegetdevicelist9)代替。
+
**系统能力**:SystemCapability.MultimodalInput.Input.InputDevice
**返回值**:
@@ -128,12 +271,14 @@ inputDevice.getDeviceIds().then((ids)=>{
});
```
-## inputDevice.getDevice
+## inputDevice.getDevice(deprecated)
getDevice(deviceId: number, callback: AsyncCallback<InputDeviceData>): void
获取输入设备的描述信息,使用callback方式作为异步方法。
+从API version 9 开始不再维护,建议使用[inputDevice.getDeviceInfo](#inputdevicegetdeviceinfo9)代替。
+
**系统能力**:SystemCapability.MultimodalInput.Input.InputDevice
**参数**:
@@ -152,12 +297,14 @@ inputDevice.getDevice(1, (inputDevice)=>{
});
```
-## inputDevice.getDevice
+## inputDevice.getDevice(deprecated)
getDevice(deviceId: number): Promise<InputDeviceData>
获取输入设备的描述信息,使用Promise方式作为异步方法。
+从API version 9 开始不再维护,建议使用[inputDevice.getDeviceInfo](#inputdevicegetdeviceinfo9)代替。
+
**系统能力**:SystemCapability.MultimodalInput.Input.InputDevice
**参数**:
@@ -201,9 +348,13 @@ supportKeys(deviceId: number, keys: Array<KeyCode>, callback: Callback<
```js
// 示例查询id为1的设备对于17、22和2055按键的支持情况。
-inputDevice.supportKeys(1, [17, 22, 2055], (ret)=>{
+try {
+ inputDevice.supportKeys(1, [17, 22, 2055], (error, ret) => {
console.log("The query result is as follows: " + ret);
-});
+ });
+} catch (error) {
+ console.info("supportKeys " + error.code + " " + error.message);
+}
```
## inputDevice.supportKeys9+
@@ -231,9 +382,13 @@ supportKeys(deviceId: number, keys: Array<KeyCode>): Promise<Array<b
```js
// 示例查询id为1的设备对于17、22和2055按键的支持情况。
-inputDevice.supportKeys(1, [17, 22, 2055]).then((ret)=>{
+try {
+ inputDevice.supportKeys(1, [17, 22, 2055]).then((ret) => {
console.log("The query result is as follows: " + ret);
-})
+ });
+} catch (error) {
+ console.info("supportKeys " + error.code + " " + error.message);
+}
```
## inputDevice.getKeyboardType9+
@@ -255,9 +410,18 @@ getKeyboardType(deviceId: number, callback: AsyncCallback<KeyboardType>):
```js
// 示例查询设备id为1的设备键盘类型。
-inputDevice.getKeyboardType(1, (ret)=>{
- console.log("The keyboard type of the device is: " + ret);
-});
+try {
+ inputDevice.getKeyboardType(1, (error, number) => {
+ if (error) {
+ console.log(`Failed to get keyboardtype.
+ error code=${JSON.stringify(err.code)} msg=${JSON.stringify(err.message)}`);
+ return;
+ }
+ console.log("The keyboard type of the device is: " + number);
+ });
+} catch (error) {
+ console.info("getKeyboardType " + error.code + " " + error.message);
+}
```
## inputDevice.getKeyboardType9+
@@ -278,9 +442,13 @@ getKeyboardType(deviceId: number): Promise<KeyboardType>
```js
// 示例查询设备id为1的设备键盘类型。
-inputDevice.getKeyboardType(1).then((ret)=>{
- console.log("The keyboard type of the device is: " + ret);
-})
+try {
+ inputDevice.getKeyboardType(1).then((number) => {
+ console.log("The keyboard type of the device is: " + number);
+ });
+} catch (error) {
+ console.info("getKeyboardType " + error.code + " " + error.message);
+}
```
## DeviceListener9+
diff --git a/zh-cn/application-dev/reference/apis/js-apis-inputeventclient.md b/zh-cn/application-dev/reference/apis/js-apis-inputeventclient.md
index 82c05b94b72c330b921d6d868768d19268fcc023..2d23dafed8ca28324c9aee446a2f2b364a4af3e7 100755
--- a/zh-cn/application-dev/reference/apis/js-apis-inputeventclient.md
+++ b/zh-cn/application-dev/reference/apis/js-apis-inputeventclient.md
@@ -16,10 +16,9 @@ InputEventClient模块提供了注入按键能力。
import inputEventClient from '@ohos.multimodalInput.inputEventClient';
```
+## inputEventClient.injectKeyEvent9+
-## inputEventClient.injectEvent
-
-injectEvent({KeyEvent: KeyEvent}): void
+injectKeyEvent({ KeyEvent: KeyEvent }): void;
注入按键,KeyEvent为注入按键的描述信息。
@@ -27,20 +26,31 @@ injectEvent({KeyEvent: KeyEvent}): void
**参数:**
-| 参数 | 类型 | 必填 | 说明 |
-| -------- | --------------------- | ---- | --------- |
-| KeyEvent | [KeyEvent](#keyevent) | 是 | 注入按键的描述信息 |
+| 参数 | 类型 | 必填 | 说明 |
+| -------- | --------------------- | ---- | ------------------ |
+| KeyEvent | [KeyEvent](#keyevent) | 是 | 注入按键的描述信息 |
**示例:**
-```js
-let keyEvent = {
+```
+try {
+ var keyEvent = {
isPressed: true,
keyCode: 2,
keyDownDuration: 0,
isIntercepted: false
+ }
+ inputEventClient.injectKeyEvent({ KeyEvent: keyEvent });
+ var keyEvent1 = {
+ isPressed: false,
+ keyCode: 2,
+ keyDownDuration: 0,
+ isIntercepted: false
+ };
+ inputEventClient.injectKeyEvent({ KeyEvent: keyEvent1 });
+} catch (error) {
+ console.info("injectKeyEvent " + error.code + " " + error.message);
}
-let res = inputEventClient.injectEvent({KeyEvent: keyEvent});
```
@@ -56,3 +66,31 @@ let res = inputEventClient.injectEvent({KeyEvent: keyEvent});
| keyCode | number | 是 | 按键键值 |
| keyDownDuration | number | 是 | 按键按下持续时间 |
| isIntercepted | boolean | 是 | 按键是否可以被拦截 |
+
+## inputEventClient.injectEvent(deprecated)
+
+injectEvent({KeyEvent: KeyEvent}): void
+
+注入按键,KeyEvent为注入按键的描述信息。
+
+从API version 9 开始不再维护,建议使用[inputEventClient.injectKeyEvent](#inputEventClientinjectKeyEvent9)代替。
+
+**系统能力:** SystemCapability.MultimodalInput.Input.InputSimulator
+
+**参数:**
+
+| 参数 | 类型 | 必填 | 说明 |
+| -------- | --------------------- | ---- | ------------------ |
+| KeyEvent | [KeyEvent](#keyevent) | 是 | 注入按键的描述信息 |
+
+**示例:**
+
+```js
+let keyEvent = {
+ isPressed: true,
+ keyCode: 2,
+ keyDownDuration: 0,
+ isIntercepted: false
+}
+let res = inputEventClient.injectEvent({KeyEvent: keyEvent});
+```
\ No newline at end of file
diff --git a/zh-cn/application-dev/reference/apis/js-apis-inputmonitor.md b/zh-cn/application-dev/reference/apis/js-apis-inputmonitor.md
index 6659984f7fa36cafaaae252913f4c84e5f3e6d1a..caaa2fe384f7439fd28d2a42da4c8779970038ea 100755
--- a/zh-cn/application-dev/reference/apis/js-apis-inputmonitor.md
+++ b/zh-cn/application-dev/reference/apis/js-apis-inputmonitor.md
@@ -35,10 +35,14 @@ on(type: "touch", receiver: TouchEventReceiver): void
**示例:**
```js
-inputMonitor.off("touch", (event) => {
- // 消费触屏事件
- return false;
-});
+try {
+ inputMonitor.on("touch", (data)=> {
+ console.info(`monitorOnTouchEvent success ${JSON.stringify(data)}`);
+ return false;
+ });
+} catch (error) {
+ console.info("onMonitor " + error.code + " " + error.message)
+}
```
@@ -60,9 +64,14 @@ on(type: "mouse", receiver: Callback<MouseEvent>): void
**示例:**
```js
-inputMonitor.off("mouse", (event) => {
- // 消费鼠标事件
-});
+try {
+ inputMonitor.on("mouse", (data)=> {
+ console.info(`monitorOnMouseEvent success ${JSON.stringify(data)}`);
+ return false;
+ });
+} catch (error) {
+ console.info("onMonitor " + error.code + " " + error.message)
+}
```
@@ -86,7 +95,26 @@ off(type: "touch", receiver?: TouchEventReceiver): void
**示例:**
```js
-inputMonitor.off("touch");
+// 取消所有监听。
+try {
+ inputMonitor.off("touch");
+} catch (error) {
+ console.info("offMonitor " + error.code + " " + error.message)
+}
+// 单独取消receiver的监听。
+callback:function(data) {
+ console.info(`call success ${JSON.stringify(data)}`);
+},
+try {
+ inputMonitor.on("touch", this.callback);
+} catch (error) {
+ console.info("onTouchMonitor " + error.code + " " + error.message)
+},
+try {
+ inputMonitor.off("touch",this.callback);
+} catch (error) {
+ console.info("offTouchMonitor " + error.code + " " + error.message)
+}
```
off(type: "mouse", receiver?: Callback<MouseEvent>): void
@@ -107,7 +135,26 @@ off(type: "mouse", receiver?: Callback<MouseEvent>): void
**示例:**
```js
-inputMonitor.off("mouse");
+// 取消所有监听。
+try {
+ inputMonitor.off("mouse");
+} catch (error) {
+ console.info("offMonitor " + error.code + " " + error.message)
+}
+// 单独取消receiver的监听。
+callback:function(data) {
+ console.info(`call success ${JSON.stringify(data)}`);
+},
+try {
+ inputMonitor.on("mouse", this.callback);
+} catch (error) {
+ console.info("onMouseMonitor " + error.code + " " + error.message)
+},
+try {
+ inputMonitor.off("mouse", this.callback);
+} catch (error) {
+ console.info("offMouseMonitor " + error.code + " " + error.message)
+}
```
@@ -133,9 +180,13 @@ inputMonitor.off("mouse");
**示例:**
```js
-inputMonitor.on("touch", (event) => {
- // 消费触摸输入事件
- return false;
-});
-inputMonitor.off("touch");
+try {
+ inputMonitor.on("touch", (event) => {
+ // 消费触摸输入事件
+ return false;
+ });
+ inputMonitor.off("touch");
+} catch (error) {
+ console.info("offMonitor " + error.code + " " + error.message)
+}
```
diff --git a/zh-cn/application-dev/reference/apis/js-apis-pointer.md b/zh-cn/application-dev/reference/apis/js-apis-pointer.md
index 15ded243b7583d8ecc33e7c6734f36ef364b332b..6a9c09f1a21e7d18e21643085d2023eabd21ef85 100644
--- a/zh-cn/application-dev/reference/apis/js-apis-pointer.md
+++ b/zh-cn/application-dev/reference/apis/js-apis-pointer.md
@@ -30,13 +30,13 @@ setPointerVisible(visible: boolean, callback: AsyncCallback<void>): void
**示例**:
```js
-pointer.setPointerVisible(true, (err, data) => {
- if (err) {
- console.log(`set pointer visible failed. err=${JSON.stringify(err)}`);
- return;
- }
- console.log(`set pointer visible success.`);
-);
+try {
+ pointer.setPointerVisible(true, (err, data) => {
+ console.log(`Set pointer visible success`);
+ });
+} catch (err) {
+ console.log(`Set pointer visible failed. err=${JSON.stringify(err)}, msg=${JSON.stringify(message)}`);
+}
```
## pointer.setPointerVisible9+
@@ -62,11 +62,13 @@ setPointerVisible(visible: boolean): Promise<void>
**示例**:
```js
-pointer.setPointerVisible(false).then(data => {
- console.log(`set mouse pointer visible success`);
-}, data => {
- console.log(`set mouse pointer visible failed err=${JSON.stringify(data)}`);
-});
+try {
+ pointer.setPointerVisible(false).then(data => {
+ console.log(`Set mouse pointer visible success`);
+ });
+} catch {
+ console.log(`Set mouse pointer visible failed err=${JSON.stringify(data)}, msg=${JSON.stringify(message)}`);
+}
```
## pointer.isPointerVisible9+
@@ -86,9 +88,13 @@ isPointerVisible(callback: AsyncCallback<boolean>): void
**示例**:
```js
-pointer.isPointerVisible((visible)=>{
- console.log("The mouse pointer visible attributes is " + visible);
-});
+try {
+ pointer.isPointerVisible(visible, (err, data) => {
+ console.log(`The mouse pointer visible attributes is ` + visible);
+ });
+} catch (err) {
+ console.log(`The mouse pointer visible attributes is failed. err=${JSON.stringify(err)}, msg=${JSON.stringify(message)}`);
+}
```
## pointer.isPointerVisible9+
@@ -108,9 +114,13 @@ isPointerVisible(): Promise<boolean>
**示例**:
```js
-pointer.isPointerVisible().then( data => {
- console.log(`isPointerThen success data=${JSON.stringify(data)}`);
-});
+try {
+ pointer.isPointerVisible().then((data) => {
+ console.log(`The mouse pointer visible attributes is success. data=${JSON.stringify(data)}`);
+ });
+} catch (err) {
+ ponsole.info(`The mouse pointer visible attributes is failed. err=${JSON.stringify(err)}, msg=${JSON.stringify(message)}`);
+}
```
## pointer.setPointerSpeed9+
@@ -131,13 +141,13 @@ setPointerSpeed(speed: number, callback: AsyncCallback<void>): void
**示例**:
```js
-pointer.setPointerSpeed(5, (err, data) => {
- if (err) {
- console.log(`set pointer speed failed. err=${JSON.stringify(err)}`);
- return;
- }
- console.log(`set pointer speed success.`);
-);
+try {
+ pointer.setPointerSpeed(5, (err, data) => {
+ console.log(`Set pointer speed success`);
+ });
+} catch (err) {
+ console.log(`Set pointer speed failed. err=${JSON.stringify(err)}, msg=${JSON.stringify(message)}`);
+}
```
## pointer.setPointerSpeed9+
@@ -163,11 +173,13 @@ setPointerSpeed(speed: number): Promise<void>
**示例**:
```js
-pointer.setPointerSpeed(5).then(data => {
- console.log(`set pointer speed success`);
-}, err => {
- console.log(`set pointer speed failed err=${JSON.stringify(err)}`);
-});
+try {
+ pointer.setPointerSpeed(5).then(data => {
+ console.log(`Set pointer speed success`);
+ });
+} catch (err) {
+ console.log(`Set pointer speed failed err=${JSON.stringify(err)}, msg=${JSON.stringify(message)}`);
+}
```
## pointer.getPointerSpeed9+
@@ -187,9 +199,13 @@ getPointerSpeed(callback: AsyncCallback<number>): void
**示例**:
```js
-pointer.getPointerSpeed((speed)=>{
- console.log("The pointer speed is " + speed);
-});
+try {
+ pointer.getPointerSpeed(speed, (err, data) => {
+ console.log(`The pointer speed is ` + speed);
+ });
+} catch (err) {
+ console.log(`Failed to get the pointer speed. err=${JSON.stringify(err)}, msg=${JSON.stringify(message)}`);
+}
```
## pointer.getPointerSpeed9+
@@ -209,9 +225,13 @@ getPointerSpeed(): Promise<number>
**示例**:
```js
-pointer.getPointerSpeed().then( data => {
- console.log(`getPointerSpeed success data=${JSON.stringify(data)}`);
-});
+try {
+ pointer.getPointerSpeed().then(data => {
+ console.log(`Get pointer speed success. data=${JSON.stringify(data)}`);
+ });
+} catch (err) {
+ console.log(`Get pointer speed failed err=${JSON.stringify(err)}, msg=${JSON.stringify(message)}`);
+}
```
## pointer.getPointerStyle9+
@@ -239,9 +259,17 @@ window.getTopWindow((err, data) => {
windowClass = data;
windowClass.getProperties((err, data) => {
var windowId = data.id;
- pointer.getPointerStyle(windowId, (err, ret) => {
- console.log("The mouse pointer style is: " + ret);
- });
+ if (windowId < 0) {
+ console.log(`Invalid windowId`);
+ return;
+ }
+ try {
+ pointer.getPointerStyle(windowId, (err, ret) => {
+ console.log(`The mouse pointer style is: ` + ret);
+ });
+ } catch (err) {
+ console.log(`Failed to get the pointer style. err=${JSON.stringify(err)}, msg=${JSON.stringify(message)}`);
+ }
});
});
```
@@ -260,7 +288,6 @@ getPointerStyle(windowId: number): Promise<PointerStyle>
| ---------------------------------------- | ------------------- |
| Promise<[PointerStyle](#pointerstyle9)> | Promise实例,用于异步获取结果。 |
-
**示例**:
```js
@@ -271,9 +298,17 @@ window.getTopWindow((err, data) => {
windowClass = data;
windowClass.getProperties((err, data) => {
var windowId = data.id;
- pointer.getPointerStyle(windowId).then((ret) => {
- console.log("The mouse pointer style is: " + ret);
- });
+ if (windowId < 0) {
+ console.log(`Invalid windowId`);
+ return;
+ }
+ try {
+ pointer.getPointerStyle(windowId).then((ret) => {
+ console.log(`The mouse pointer style is: ` + ret);
+ });
+ } catch (err) {
+ console.log(`Get pointer style failed err=${JSON.stringify(err)}, msg=${JSON.stringify(message)}`);
+ }
});
});
```
@@ -304,9 +339,17 @@ window.getTopWindow((err, data) => {
windowClass = data;
windowClass.getProperties((err, data) => {
var windowId = data.id;
- pointer.setPointerStyle(windowId, pointer.PointerStyle.CROSS, (err) => {
- console.log(`Set mouse pointer style success.`);
- });
+ if (windowId < 0) {
+ console.log(`Invalid windowId`);
+ return;
+ }
+ try {
+ pointer.setPointerStyle(windowId, pointer.PointerStyle.CROSS, (err) => {
+ console.log(`Successfully set mouse pointer style`);
+ });
+ } catch (err) {
+ console.log(`Failed to set the pointer style. err=${JSON.stringify(err)}, msg=${JSON.stringify(message)}`);
+ }
});
});
```
@@ -336,9 +379,17 @@ window.getTopWindow((err, data) => {
windowClass = data;
windowClass.getProperties((err, data) => {
var windowId = data.id;
- pointer.setPointerStyle(windowId, pointer.PointerStyle.CROSS).then(() => {
- console.log(`Set mouse pointer style success`);
- });
+ if (windowId < 0) {
+ console.log(`Invalid windowId`);
+ return;
+ }
+ try {
+ pointer.setPointerStyle(windowId, pointer.PointerStyle.CROSS).then(() => {
+ console.log(`Successfully set mouse pointer style`);
+ });
+ } catch (err) {
+ console.log(`Failed to set the pointer style. err=${JSON.stringify(err)}, msg=${JSON.stringify(message)}`);
+ }
});
});
```
diff --git a/zh-cn/application-dev/reference/errorcodes/errorcodes-multimodalinput.md b/zh-cn/application-dev/reference/errorcodes/errorcodes-multimodalinput.md
new file mode 100644
index 0000000000000000000000000000000000000000..b0fa2e82b06e5db0dad15bf0c255c855493b99ee
--- /dev/null
+++ b/zh-cn/application-dev/reference/errorcodes/errorcodes-multimodalinput.md
@@ -0,0 +1,42 @@
+# 多模输入子系统错误码
+
+## 4400001 目标设备描述符错误
+
+### 错误信息
+
+Incorrect descriptor for the target device.
+
+### 错误描述
+
+当调用键鼠穿越start接口时,若设备无效,会报此错误码。
+
+### 可能原因
+
+1.穿越目标设备不存在(设备未组网)。
+
+2.目标设备描述符为空。
+
+### 处理步骤
+
+1. 确认键鼠穿越目标设备是否已正确与本地设备完整组网。
+2. 正确使用穿越目标设备的设备描述符。
+
+## 4400002 输入设备操作失败
+
+### 错误信息
+
+Input device operation failed.
+
+### 错误描述
+
+当调用键鼠穿越start接口时,若穿越状态异常,会报此错误码。
+
+### 可能原因
+
+1. 发起键鼠穿越时,本机键鼠穿越为穿出状态。
+2. 关闭键鼠穿越时,本机键鼠穿越为自由态。
+3. 发起关闭键鼠穿越时,本机键鼠穿越状态正在切换中。
+
+### 处理步骤
+
+1. 键鼠穿越业务逻辑设计上,应满足键鼠穿越状态机基本约束。