提交 d0b410d9 编写于 作者: M mayunteng_1

多模md修改

Signed-off-by: Nmayunteng_1 <mayunteng@huawei.com>
Change-Id: Ic05fe42ece5d3699be708ce694c740c66a4f9c9d
上级 cf3cc5d4
# 键鼠穿越管理
键鼠穿越功能,即两台或多台设备组网协同后可以共用一套键盘鼠标。
键鼠穿越管理模块,提供实现键盘、鼠标等外接输入设备的跨设备协同操作。在设备组网的情况下,提供多设备间共享键鼠的开关,设备穿越状态更新以及键鼠穿越光标自适应显示。
> **说明**
>
> 本模块首批接口从API version 9开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
## 导入模块
```js
import inputDeviceCooperate from '@ohos.multimodalInput.inputDeviceCooperate'
```
## inputDeviceCooperate.enable<sup>9+</sup>
enable(enable: boolean, callback: AsyncCallback\<void>): void
键鼠穿越开关开启或关闭,使用callback异步回调。
**系统能力**:SystemCapability.MultimodalInput.Input.InputDeviceCooperate
**参数**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | ------------------- | ---- | ------------------------------------------------------------ |
| enable | boolean | 是 | 键鼠穿越开关开启或关闭状态。true: 键鼠穿越开关开启; false: 键鼠穿越开关关闭。 |
| callback | AsyncCallback<void> | 是 | 异步回调函数。当键鼠穿越开关开启或关闭成功,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.enable<sup>9+</sup>
enable(enable: boolean): Promise\<void>
键鼠穿越开关开启或关闭,使用Promise方式作为异步方法。
**系统能力**:SystemCapability.MultimodalInput.Input.InputDeviceCooperate
**参数**
| 参数名 | 类型 | 必填 | 说明 |
| --------- | ------- | ---- | ------------------------------------------------------------------- |
| enable | boolean | 是 | 键鼠穿越开关开启或关闭状态。true: 键鼠穿越开关开启; false: 键鼠穿越开关关闭。 |
**返回值**
| 参数 | 说明 |
| ------------------- | ------------------------------- |
| Promise\<void> | 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.start<sup>9+</sup>
start(sinkDeviceDescriptor: string, srcInputDeviceId: number, callback: AsyncCallback\<void>): void
启动键鼠穿越,使用callback异步回调。
**系统能力**:SystemCapability.MultimodalInput.Input.InputDeviceCooperate
**参数**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | ---------------------------- | ---- | ---------------------------- |
| sinkDeviceDescriptor | string | 是 | 键鼠穿越目标设备描述符。 |
| srcInputDeviceId | number | 是 | 键鼠穿越待穿越外设标识符。 |
| callback | AsyncCallback\<void> | 是 | 异步回调函数。当键鼠穿越启动成功,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.start<sup>9+</sup>
start(sinkDeviceDescriptor: string, srcInputDeviceId: number): Promise\<void>
启动键鼠穿越,使用Promise方式作为异步方法。
**系统能力**: SystemCapability.MultimodalInput.Input.InputDeviceCooperate
**参数**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | ---------------------------- | ---- | ---------------------------- |
| sinkDeviceDescriptor | string | 是 | 键鼠穿越目标设备描述符。 |
| srcInputDeviceId | number | 是 | 键鼠穿越待穿越外设标识符。 |
**返回值**
| 参数名 | 说明 |
| ---------------------- | ------------------------------- |
| Promise\<void> | 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.stop<sup>9+</sup>
stop(callback: AsyncCallback\<void>): void
停止键鼠穿越,使用callback异步回调。
**系统能力**:SystemCapability.MultimodalInput.Input.InputDeviceCooperate
**参数**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | ---------------------------- | ---- | ---------------------------- |
| callback | AsyncCallback\<void> | 是 | 异步回调函数,返回查询结果。 |
**示例**
```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.stop<sup>9+</sup>
stop(): Promise\<void>
停止键鼠穿越,使用Promise异步回调。
**系统能力**:SystemCapability.MultimodalInput.Input.InputDeviceCooperate
**参数**
| 参数名 | 说明 |
| -------- | ---------------------------- |
| Promise\<void> | 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.getState<sup>9+</sup>
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.getState<sup>9+</sup>
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')<sup>9+</sup>
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')<sup>9+</sup>
off(type: 'cooperation', callback?: AsyncCallback\<void>): void
关闭监听键鼠穿越状态。
**系统能力**:SystemCapability.MultimodalInput.Input.InputDeviceCooperate
**参数**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | ---------------------------- | ---- | ---------------------------- |
| type | string | 是 | 注册类型,'cooperation'。 |
| callback | AsyncCallback<void> | 否 | 异步回调函数,用于返回结果。 |
**示例**
```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)}`);
}
```
## EventMsg<sup>9+</sup>
键鼠穿越事件。
**系统能力**: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
...@@ -36,12 +36,16 @@ on(type: "key", keyOptions: KeyOptions, callback: Callback&lt;KeyOptions&gt;): v ...@@ -36,12 +36,16 @@ on(type: "key", keyOptions: KeyOptions, callback: Callback&lt;KeyOptions&gt;): v
**示例:** **示例:**
```js ```js
let keyOptions = {preKeys: [], finalKey: 3, isFinalKeyDown: true, finalKeyDownDuration: 0} let keyOptions = { preKeys: [], finalKey: 3, isFinalKeyDown: true, finalKeyDownDuration: 0 }
let callback = function(keyOptions) { let callback = function (keyOptions) {
console.info("preKeys: " + keyOptions.preKeys, "finalKey: " + keyOptions.finalKey, console.info("preKeys: " + keyOptions.preKeys, "finalKey: " + keyOptions.finalKey,
"isFinalKeyDown: " + keyOptions.isFinalKeyDown, "finalKeyDownDuration: " + keyOptions.finalKeyDownDuration) "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&lt;KeyOptions&gt;): ...@@ -64,12 +68,16 @@ off(type: "key", keyOptions: KeyOptions, callback?: Callback&lt;KeyOptions&gt;):
**示例:** **示例:**
```js ```js
let keyOptions = {preKeys: [], finalKey: 3, isFinalKeyDown: true, finalKeyDownDuration: 0} let keyOptions = { preKeys: [], finalKey: 3, isFinalKeyDown: true, finalKeyDownDuration: 0 }
let callback = function(keyOptions) { let callback = function (keyOptions) {示例**
console.info("preKeys: " + keyOptions.preKeys, "finalKey: " + keyOptions.finalKey, console.info("preKeys: " + keyOptions.preKeys, "finalKey: " + keyOptions.finalKey,
"isFinalKeyDown: " + keyOptions.isFinalKeyDown, "finalKeyDownDuration: " + keyOptions.finalKeyDownDuration) "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);
``` ```
......
...@@ -16,6 +16,130 @@ ...@@ -16,6 +16,130 @@
import inputDevice from '@ohos.multimodalInput.inputDevice'; import inputDevice from '@ohos.multimodalInput.inputDevice';
``` ```
## inputDevice.getDeviceList<sup>9+</sup>
getDeviceList(callback: AsyncCallback&lt;Array&lt;number&gt;&gt;): void
获取所有输入设备的id列表,使用callback方式作为异步方法。
**系统能力**:SystemCapability.MultimodalInput.Input.InputDevice
**参数**
| 参数 | 类型 | 必填 | 说明 |
| -------- | ---------------------------------------- | ---- | ---------- |
| callback | AsyncCallback&lt;Array&lt;number&gt;&gt; | 是 | 回调函数。 |
**示例**
```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.getDeviceList<sup>9+</sup>
getDeviceList(): Promise&lt;Array&lt;number&gt;&gt;
获取所有输入设备的id列表,使用Promise方式作为异步方法。
**系统能力**:SystemCapability.MultimodalInput.Input.InputDevice
**返回值**
| 参数 | 说明 |
| ---------------------------------- | ------------------------------- |
| Promise&lt;Array&lt;number&gt;&gt; | 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.getDeviceInfo<sup>9+</sup>
getDeviceInfo(deviceId: number, callback: AsyncCallback&lt;InputDeviceData&gt;): void
获取输入设备的描述信息,使用callback方式作为异步方法。
**系统能力**:SystemCapability.MultimodalInput.Input.InputDevice
**参数**
| 参数 | 类型 | 必填 | 说明 |
| -------- | -------------------------------------------------------- | ---- | --------------------------------------- |
| deviceId | number | 是 | 需要获取信息的设备id。 |
| callback | AsyncCallback&lt;[InputDeviceData](#inputdevicedata)&gt; | 是 | 回调函数,异步返回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.getDeviceInfo<sup>9+</sup>
getDeviceInfo(deviceId: number): Promise&lt;InputDeviceData&gt;
获取输入设备的描述信息,使用Promise方式作为异步方法。
**系统能力**:SystemCapability.MultimodalInput.Input.InputDevice
**参数**
| 参数 | 类型 | 必填 | 说明 |
| -------- | ------ | ---- | ---------------------- |
| deviceId | number | 是 | 需要获取信息的设备id。 |
**返回值**
| 参数 | 说明 |
| -------------------------------------------------- | ------------------------------- |
| Promise&lt;[InputDeviceData](#inputdevicedata)&gt; | 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.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
...@@ -35,20 +159,24 @@ on(type: “change”, listener: Callback&lt;DeviceListener&gt;): void ...@@ -35,20 +159,24 @@ on(type: “change”, listener: Callback&lt;DeviceListener&gt;): void
```js ```js
let isPhysicalKeyboardExist = true; let isPhysicalKeyboardExist = true;
inputDevice.on("change", (data) => { try {
inputDevice.on("change", (data) => {
console.log("type: " + data.type + ", deviceId: " + data.deviceId); console.log("type: " + data.type + ", deviceId: " + data.deviceId);
inputDevice.getKeyboardType(data.deviceId, (err, ret) => { inputDevice.getKeyboardType(data.deviceId, (err, ret) => {
console.log("The keyboard type of the device is: " + ret); console.log("The keyboard type of the device is: " + ret);
if (ret == inputDevice.KeyboardType.ALPHABETIC_KEYBOARD && data.type == 'add') { if (ret == inputDevice.KeyboardType.ALPHABETIC_KEYBOARD && data.type == 'add') {
// 监听物理键盘已连接。 // 监听物理键盘已连接。
isPhysicalKeyboardExist = true; isPhysicalKeyboardExist = true;
} else if (ret == inputDevice.KeyboardType.ALPHABETIC_KEYBOARD && data.type == 'remove') { } else if (ret == inputDevice.KeyboardType.ALPHABETIC_KEYBOARD && data.type == 'remove') {
// 监听物理键盘已断开。 // 监听物理键盘已断开。
isPhysicalKeyboardExist = false; isPhysicalKeyboardExist = false;
} }
}); });
}); });
// 根据isPhysicalKeyboardExist的值决定软键盘是否弹出。 // 根据isPhysicalKeyboardExist的值决定软键盘是否弹出。
} catch (error) {
console.info("oninputdevcie " + error.code + " " + error.message);
}
``` ```
## inputDevice.off<sup>9+</sup> ## inputDevice.off<sup>9+</sup>
...@@ -69,27 +197,40 @@ off(type: “change”, listener?: Callback&lt;DeviceListener&gt;): void ...@@ -69,27 +197,40 @@ off(type: “change”, listener?: Callback&lt;DeviceListener&gt;): void
**示例** **示例**
```js ```js
function listener(data) { callback: function(data) {
console.log("type: " + data.type + ", deviceId: " + data.deviceId); console.log("type: " + data.type + ", deviceId: " + data.deviceId);
} }
// 监听输入设备的热插拔事件 try {
inputDevice.on("change", listener); inputDevice.on("change", this.callback);
} catch (error) {
console.info("oninputdevcie " + error.code + " " + error.message)
}
// 单独取消listener的监听。 // 单独取消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<sup>(deprecated)</sup>
getDeviceIds(callback: AsyncCallback&lt;Array&lt;number&gt;&gt;): void getDeviceIds(callback: AsyncCallback&lt;Array&lt;number&gt;&gt;): void
获取所有输入设备的id列表,使用callback方式作为异步方法。 获取所有输入设备的id列表,使用callback方式作为异步方法。
从API version 9 开始不再维护,建议使用[inputDevice.getDeviceList](#inputdevicegetdevicelist9)代替。
**系统能力**:SystemCapability.MultimodalInput.Input.InputDevice **系统能力**:SystemCapability.MultimodalInput.Input.InputDevice
**参数** **参数**
...@@ -106,12 +247,14 @@ inputDevice.getDeviceIds((ids)=>{ ...@@ -106,12 +247,14 @@ inputDevice.getDeviceIds((ids)=>{
}); });
``` ```
## inputDevice.getDeviceIds ## inputDevice.getDeviceIds<sup>(deprecated)</sup>
getDeviceIds(): Promise&lt;Array&lt;number&gt;&gt; getDeviceIds(): Promise&lt;Array&lt;number&gt;&gt;
获取所有输入设备的id列表,使用Promise方式作为异步方法。 获取所有输入设备的id列表,使用Promise方式作为异步方法。
从API version 9 开始不再维护,建议使用[inputDevice.getDeviceList](#inputdevicegetdevicelist9)代替。
**系统能力**:SystemCapability.MultimodalInput.Input.InputDevice **系统能力**:SystemCapability.MultimodalInput.Input.InputDevice
**返回值** **返回值**
...@@ -128,12 +271,14 @@ inputDevice.getDeviceIds().then((ids)=>{ ...@@ -128,12 +271,14 @@ inputDevice.getDeviceIds().then((ids)=>{
}); });
``` ```
## inputDevice.getDevice ## inputDevice.getDevice<sup>(deprecated)</sup>
getDevice(deviceId: number, callback: AsyncCallback&lt;InputDeviceData&gt;): void getDevice(deviceId: number, callback: AsyncCallback&lt;InputDeviceData&gt;): void
获取输入设备的描述信息,使用callback方式作为异步方法。 获取输入设备的描述信息,使用callback方式作为异步方法。
从API version 9 开始不再维护,建议使用[inputDevice.getDeviceInfo](#inputdevicegetdeviceinfo9)代替。
**系统能力**:SystemCapability.MultimodalInput.Input.InputDevice **系统能力**:SystemCapability.MultimodalInput.Input.InputDevice
**参数** **参数**
...@@ -152,12 +297,14 @@ inputDevice.getDevice(1, (inputDevice)=>{ ...@@ -152,12 +297,14 @@ inputDevice.getDevice(1, (inputDevice)=>{
}); });
``` ```
## inputDevice.getDevice ## inputDevice.getDevice<sup>(deprecated)</sup>
getDevice(deviceId: number): Promise&lt;InputDeviceData&gt; getDevice(deviceId: number): Promise&lt;InputDeviceData&gt;
获取输入设备的描述信息,使用Promise方式作为异步方法。 获取输入设备的描述信息,使用Promise方式作为异步方法。
从API version 9 开始不再维护,建议使用[inputDevice.getDeviceInfo](#inputdevicegetdeviceinfo9)代替。
**系统能力**:SystemCapability.MultimodalInput.Input.InputDevice **系统能力**:SystemCapability.MultimodalInput.Input.InputDevice
**参数** **参数**
...@@ -201,9 +348,13 @@ supportKeys(deviceId: number, keys: Array&lt;KeyCode&gt;, callback: Callback&lt; ...@@ -201,9 +348,13 @@ supportKeys(deviceId: number, keys: Array&lt;KeyCode&gt;, callback: Callback&lt;
```js ```js
// 示例查询id为1的设备对于17、22和2055按键的支持情况。 // 示例查询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); console.log("The query result is as follows: " + ret);
}); });
} catch (error) {
console.info("supportKeys " + error.code + " " + error.message);
}
``` ```
## inputDevice.supportKeys<sup>9+</sup> ## inputDevice.supportKeys<sup>9+</sup>
...@@ -231,9 +382,13 @@ supportKeys(deviceId: number, keys: Array&lt;KeyCode&gt;): Promise&lt;Array&lt;b ...@@ -231,9 +382,13 @@ supportKeys(deviceId: number, keys: Array&lt;KeyCode&gt;): Promise&lt;Array&lt;b
```js ```js
// 示例查询id为1的设备对于17、22和2055按键的支持情况。 // 示例查询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); console.log("The query result is as follows: " + ret);
}) });
} catch (error) {
console.info("supportKeys " + error.code + " " + error.message);
}
``` ```
## inputDevice.getKeyboardType<sup>9+</sup> ## inputDevice.getKeyboardType<sup>9+</sup>
...@@ -255,9 +410,18 @@ getKeyboardType(deviceId: number, callback: AsyncCallback&lt;KeyboardType&gt;): ...@@ -255,9 +410,18 @@ getKeyboardType(deviceId: number, callback: AsyncCallback&lt;KeyboardType&gt;):
```js ```js
// 示例查询设备id为1的设备键盘类型。 // 示例查询设备id为1的设备键盘类型。
inputDevice.getKeyboardType(1, (ret)=>{ try {
console.log("The keyboard type of the device is: " + ret); 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.getKeyboardType<sup>9+</sup> ## inputDevice.getKeyboardType<sup>9+</sup>
...@@ -278,9 +442,13 @@ getKeyboardType(deviceId: number): Promise&lt;KeyboardType&gt; ...@@ -278,9 +442,13 @@ getKeyboardType(deviceId: number): Promise&lt;KeyboardType&gt;
```js ```js
// 示例查询设备id为1的设备键盘类型。 // 示例查询设备id为1的设备键盘类型。
inputDevice.getKeyboardType(1).then((ret)=>{ try {
console.log("The keyboard type of the device is: " + ret); inputDevice.getKeyboardType(1).then((number) => {
}) console.log("The keyboard type of the device is: " + number);
});
} catch (error) {
console.info("getKeyboardType " + error.code + " " + error.message);
}
``` ```
## DeviceListener<sup>9+</sup> ## DeviceListener<sup>9+</sup>
......
...@@ -16,10 +16,9 @@ InputEventClient模块提供了注入按键能力。 ...@@ -16,10 +16,9 @@ InputEventClient模块提供了注入按键能力。
import inputEventClient from '@ohos.multimodalInput.inputEventClient'; import inputEventClient from '@ohos.multimodalInput.inputEventClient';
``` ```
## inputEventClient.injectKeyEvent<sup>9+</sup>
## inputEventClient.injectEvent injectKeyEvent({ KeyEvent: KeyEvent }): void;
injectEvent({KeyEvent: KeyEvent}): void
注入按键,KeyEvent为注入按键的描述信息。 注入按键,KeyEvent为注入按键的描述信息。
...@@ -27,20 +26,31 @@ injectEvent({KeyEvent: KeyEvent}): void ...@@ -27,20 +26,31 @@ injectEvent({KeyEvent: KeyEvent}): void
**参数:** **参数:**
| 参数 | 类型 | 必填 | 说明 | | 参数 | 类型 | 必填 | 说明 |
| -------- | --------------------- | ---- | --------- | | -------- | --------------------- | ---- | ------------------ |
| KeyEvent | [KeyEvent](#keyevent) | 是 | 注入按键的描述信息 | | KeyEvent | [KeyEvent](#keyevent) | 是 | 注入按键的描述信息 |
**示例:** **示例:**
```js ```
let keyEvent = { try {
var keyEvent = {
isPressed: true, isPressed: true,
keyCode: 2, keyCode: 2,
keyDownDuration: 0, keyDownDuration: 0,
isIntercepted: false 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}); ...@@ -56,3 +66,31 @@ let res = inputEventClient.injectEvent({KeyEvent: keyEvent});
| keyCode | number | 是 | 按键键值 | | keyCode | number | 是 | 按键键值 |
| keyDownDuration | number | 是 | 按键按下持续时间 | | keyDownDuration | number | 是 | 按键按下持续时间 |
| isIntercepted | boolean | 是 | 按键是否可以被拦截 | | isIntercepted | boolean | 是 | 按键是否可以被拦截 |
## inputEventClient.injectEvent<sup>(deprecated)</sup>
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
...@@ -35,10 +35,14 @@ on(type: "touch", receiver: TouchEventReceiver): void ...@@ -35,10 +35,14 @@ on(type: "touch", receiver: TouchEventReceiver): void
**示例:** **示例:**
```js ```js
inputMonitor.off("touch", (event) => { try {
// 消费触屏事件 inputMonitor.on("touch", (data)=> {
return false; 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&lt;MouseEvent&gt;): void ...@@ -60,9 +64,14 @@ on(type: "mouse", receiver: Callback&lt;MouseEvent&gt;): void
**示例:** **示例:**
```js ```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 ...@@ -86,7 +95,26 @@ off(type: "touch", receiver?: TouchEventReceiver): void
**示例:** **示例:**
```js ```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&lt;MouseEvent&gt;): void off(type: "mouse", receiver?: Callback&lt;MouseEvent&gt;): void
...@@ -107,7 +135,26 @@ off(type: "mouse", receiver?: Callback&lt;MouseEvent&gt;): void ...@@ -107,7 +135,26 @@ off(type: "mouse", receiver?: Callback&lt;MouseEvent&gt;): void
**示例:** **示例:**
```js ```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"); ...@@ -133,9 +180,13 @@ inputMonitor.off("mouse");
**示例:** **示例:**
```js ```js
inputMonitor.on("touch", (event) => { try {
// 消费触摸输入事件 inputMonitor.on("touch", (event) => {
return false; // 消费触摸输入事件
}); return false;
inputMonitor.off("touch"); });
inputMonitor.off("touch");
} catch (error) {
console.info("offMonitor " + error.code + " " + error.message)
}
``` ```
...@@ -30,13 +30,13 @@ setPointerVisible(visible: boolean, callback: AsyncCallback&lt;void&gt;): void ...@@ -30,13 +30,13 @@ setPointerVisible(visible: boolean, callback: AsyncCallback&lt;void&gt;): void
**示例** **示例**
```js ```js
pointer.setPointerVisible(true, (err, data) => { try {
if (err) { pointer.setPointerVisible(true, (err, data) => {
console.log(`set pointer visible failed. err=${JSON.stringify(err)}`); console.log(`Set pointer visible success`);
return; });
} } catch (err) {
console.log(`set pointer visible success.`); console.log(`Set pointer visible failed. err=${JSON.stringify(err)}, msg=${JSON.stringify(message)}`);
); }
``` ```
## pointer.setPointerVisible<sup>9+</sup> ## pointer.setPointerVisible<sup>9+</sup>
...@@ -62,11 +62,13 @@ setPointerVisible(visible: boolean): Promise&lt;void&gt; ...@@ -62,11 +62,13 @@ setPointerVisible(visible: boolean): Promise&lt;void&gt;
**示例** **示例**
```js ```js
pointer.setPointerVisible(false).then(data => { try {
console.log(`set mouse pointer visible success`); pointer.setPointerVisible(false).then(data => {
}, data => { console.log(`Set mouse pointer visible success`);
console.log(`set mouse pointer visible failed err=${JSON.stringify(data)}`); });
}); } catch {
console.log(`Set mouse pointer visible failed err=${JSON.stringify(data)}, msg=${JSON.stringify(message)}`);
}
``` ```
## pointer.isPointerVisible<sup>9+</sup> ## pointer.isPointerVisible<sup>9+</sup>
...@@ -86,9 +88,13 @@ isPointerVisible(callback: AsyncCallback&lt;boolean&gt;): void ...@@ -86,9 +88,13 @@ isPointerVisible(callback: AsyncCallback&lt;boolean&gt;): void
**示例** **示例**
```js ```js
pointer.isPointerVisible((visible)=>{ try {
console.log("The mouse pointer visible attributes is " + visible); 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.isPointerVisible<sup>9+</sup> ## pointer.isPointerVisible<sup>9+</sup>
...@@ -108,9 +114,13 @@ isPointerVisible(): Promise&lt;boolean&gt; ...@@ -108,9 +114,13 @@ isPointerVisible(): Promise&lt;boolean&gt;
**示例** **示例**
```js ```js
pointer.isPointerVisible().then( data => { try {
console.log(`isPointerThen success data=${JSON.stringify(data)}`); 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.setPointerSpeed<sup>9+</sup> ## pointer.setPointerSpeed<sup>9+</sup>
...@@ -131,13 +141,13 @@ setPointerSpeed(speed: number, callback: AsyncCallback&lt;void&gt;): void ...@@ -131,13 +141,13 @@ setPointerSpeed(speed: number, callback: AsyncCallback&lt;void&gt;): void
**示例** **示例**
```js ```js
pointer.setPointerSpeed(5, (err, data) => { try {
if (err) { pointer.setPointerSpeed(5, (err, data) => {
console.log(`set pointer speed failed. err=${JSON.stringify(err)}`); console.log(`Set pointer speed success`);
return; });
} } catch (err) {
console.log(`set pointer speed success.`); console.log(`Set pointer speed failed. err=${JSON.stringify(err)}, msg=${JSON.stringify(message)}`);
); }
``` ```
## pointer.setPointerSpeed<sup>9+</sup> ## pointer.setPointerSpeed<sup>9+</sup>
...@@ -163,11 +173,13 @@ setPointerSpeed(speed: number): Promise&lt;void&gt; ...@@ -163,11 +173,13 @@ setPointerSpeed(speed: number): Promise&lt;void&gt;
**示例** **示例**
```js ```js
pointer.setPointerSpeed(5).then(data => { try {
console.log(`set pointer speed success`); pointer.setPointerSpeed(5).then(data => {
}, err => { console.log(`Set pointer speed success`);
console.log(`set pointer speed failed err=${JSON.stringify(err)}`); });
}); } catch (err) {
console.log(`Set pointer speed failed err=${JSON.stringify(err)}, msg=${JSON.stringify(message)}`);
}
``` ```
## pointer.getPointerSpeed<sup>9+</sup> ## pointer.getPointerSpeed<sup>9+</sup>
...@@ -187,9 +199,13 @@ getPointerSpeed(callback: AsyncCallback&lt;number&gt;): void ...@@ -187,9 +199,13 @@ getPointerSpeed(callback: AsyncCallback&lt;number&gt;): void
**示例** **示例**
```js ```js
pointer.getPointerSpeed((speed)=>{ try {
console.log("The pointer speed is " + speed); 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.getPointerSpeed<sup>9+</sup> ## pointer.getPointerSpeed<sup>9+</sup>
...@@ -209,9 +225,13 @@ getPointerSpeed(): Promise&lt;number&gt; ...@@ -209,9 +225,13 @@ getPointerSpeed(): Promise&lt;number&gt;
**示例** **示例**
```js ```js
pointer.getPointerSpeed().then( data => { try {
console.log(`getPointerSpeed success data=${JSON.stringify(data)}`); 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.getPointerStyle<sup>9+</sup> ## pointer.getPointerStyle<sup>9+</sup>
...@@ -239,9 +259,17 @@ window.getTopWindow((err, data) => { ...@@ -239,9 +259,17 @@ window.getTopWindow((err, data) => {
windowClass = data; windowClass = data;
windowClass.getProperties((err, data) => { windowClass.getProperties((err, data) => {
var windowId = data.id; var windowId = data.id;
pointer.getPointerStyle(windowId, (err, ret) => { if (windowId < 0) {
console.log("The mouse pointer style is: " + ret); 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&lt;PointerStyle&gt; ...@@ -260,7 +288,6 @@ getPointerStyle(windowId: number): Promise&lt;PointerStyle&gt;
| ---------------------------------------- | ------------------- | | ---------------------------------------- | ------------------- |
| Promise&lt;[PointerStyle](#pointerstyle9)&gt; | Promise实例,用于异步获取结果。 | | Promise&lt;[PointerStyle](#pointerstyle9)&gt; | Promise实例,用于异步获取结果。 |
**示例** **示例**
```js ```js
...@@ -271,9 +298,17 @@ window.getTopWindow((err, data) => { ...@@ -271,9 +298,17 @@ window.getTopWindow((err, data) => {
windowClass = data; windowClass = data;
windowClass.getProperties((err, data) => { windowClass.getProperties((err, data) => {
var windowId = data.id; var windowId = data.id;
pointer.getPointerStyle(windowId).then((ret) => { if (windowId < 0) {
console.log("The mouse pointer style is: " + ret); 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) => { ...@@ -304,9 +339,17 @@ window.getTopWindow((err, data) => {
windowClass = data; windowClass = data;
windowClass.getProperties((err, data) => { windowClass.getProperties((err, data) => {
var windowId = data.id; var windowId = data.id;
pointer.setPointerStyle(windowId, pointer.PointerStyle.CROSS, (err) => { if (windowId < 0) {
console.log(`Set mouse pointer style success.`); 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) => { ...@@ -336,9 +379,17 @@ window.getTopWindow((err, data) => {
windowClass = data; windowClass = data;
windowClass.getProperties((err, data) => { windowClass.getProperties((err, data) => {
var windowId = data.id; var windowId = data.id;
pointer.setPointerStyle(windowId, pointer.PointerStyle.CROSS).then(() => { if (windowId < 0) {
console.log(`Set mouse pointer style success`); 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)}`);
}
}); });
}); });
``` ```
......
# 多模输入子系统错误码
## 4400001 目标设备描述符错误
### 错误信息
Incorrect descriptor for the target device.
### 错误描述
当调用键鼠穿越start接口时,若设备无效,会报此错误码。
### 可能原因
1.穿越目标设备不存在(设备未组网)。
2.目标设备描述符为空。
### 处理步骤
1. 确认键鼠穿越目标设备是否已正确与本地设备完整组网。
2. 正确使用穿越目标设备的设备描述符。
## 4400002 输入设备操作失败
### 错误信息
Input device operation failed.
### 错误描述
当调用键鼠穿越start接口时,若穿越状态异常,会报此错误码。
### 可能原因
1. 发起键鼠穿越时,本机键鼠穿越为穿出状态。
2. 关闭键鼠穿越时,本机键鼠穿越为自由态。
3. 发起关闭键鼠穿越时,本机键鼠穿越状态正在切换中。
### 处理步骤
1. 键鼠穿越业务逻辑设计上,应满足键鼠穿越状态机基本约束。
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册