提交 1579363f 编写于 作者: M mayunteng_1

inputconsumer和inputeventclient检视修改

Signed-off-by: Nmayunteng_1 <mayunteng@huawei.com>
Change-Id: I979aa2b2d72c98754157e0a06b8742d9d3edf990
上级 60e83038
......@@ -221,7 +221,7 @@
- [@ohos.multimodalInput.inputDevice (输入设备)](js-apis-inputdevice.md)
- [@ohos.multimodalInput.inputDeviceCooperate (键鼠穿越管理)](js-apis-cooperate.md)
- [@ohos.multimodalInput.inputEvent (输入事件)](js-apis-inputevent.md)
- [@ohos.multimodalInput.inputEventClient (注入按键)](js-apis-inputeventclient.md)
- [@ohos.multimodalInput.inputEventClient (按键注入)](js-apis-inputeventclient.md)
- [@ohos.multimodalInput.inputMonitor (输入监听)](js-apis-inputmonitor.md)
- [@ohos.multimodalInput.keyCode (键值)](js-apis-keycode.md)
- [@ohos.multimodalInput.keyEvent (按键输入事件)](js-apis-keyevent.md)
......
# 组合按键
InputConsumer模块提供对按键事件的监听
组合按键订阅模块,用于处理组合按键的订阅
> **说明:**
>
......@@ -21,7 +21,7 @@ import inputConsumer from '@ohos.multimodalInput.inputConsumer';
on(type: "key", keyOptions: KeyOptions, callback: Callback&lt;KeyOptions&gt;): void
开始监听组合按键事件, 当满足条件的组合按键输入事件发生时,将keyOptions回调到入参callback表示的回调函数上
订阅组合按键, 当满足条件的组合按键输入事件发生时,使用Callback异步方式上报组合按键数据
**系统能力:** SystemCapability.MultimodalInput.Input.InputConsumer
......@@ -29,22 +29,20 @@ on(type: "key", keyOptions: KeyOptions, callback: Callback&lt;KeyOptions&gt;): v
| 参数 | 类型 | 必填 | 说明 |
| ---------- | -------------------------- | ---- | ---------------------------------------- |
| type | string | 是 | 监听输入事件类型,只支持“key”。 |
| keyOptions | [keyOptions](#keyoptions) | 是 | 组合键选项,用来指定组合键输入时应该符合的条件。 |
| callback | Callback&lt;KeyOptions&gt; | 是 | 回调函数。当满足条件的按键输入产生时,回调到此函数,以传入的KeyOptions为入参。 |
| type | string | 是 | 事件类型,目前只支持”key“。 |
| keyOptions | [keyOptions](#keyoptions) | 是 | 组合键选项。 |
| callback | Callback&lt;KeyOptions&gt; | 是 | 回调函数,当满足条件的组合按键输入事件发生时,异步上报组合按键数据。 |
**示例:**
```js
let keyOptions = { preKeys: [], finalKey: 18, isFinalKeyDown: true, finalKeyDownDuration: 0 }
let callback = function (keyOptions) {
console.info("preKeys: " + keyOptions.preKeys, "finalKey: " + keyOptions.finalKey,
"isFinalKeyDown: " + keyOptions.isFinalKeyDown, "finalKeyDownDuration: " + keyOptions.finalKeyDownDuration)
}
let powerKeyCode = 18;
try {
inputConsumer.on(inputConsumer.SubscribeType.KEY, keyOptions, callback);
inputConsumer.on("key", {preKeys: [], finalKey: powerKeyCode, isFinalKeyDown: true, finalKeyDownDuration: 0}, keyOptions => {
console.log(`keyOptions: ${JSON.stringify(keyOptions)}`);
});
} catch (error) {
console.info(`inputConsumer.on, error.code=${JSON.stringify(error.code)}, error.msg=${JSON.stringify(error.message)}`);
console.log(`Subscribe failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
}
```
......@@ -53,7 +51,7 @@ try {
off(type: "key", keyOptions: KeyOptions, callback?: Callback&lt;KeyOptions&gt;): void
停止监听组合按键事件
取消订阅组合按键
**系统能力:** SystemCapability.MultimodalInput.Input.InputConsumer
......@@ -61,35 +59,49 @@ off(type: "key", keyOptions: KeyOptions, callback?: Callback&lt;KeyOptions&gt;):
| 参数 | 类型 | 必填 | 说明 |
| ---------- | -------------------------- | ---- | ------------------------------- |
| type | string | 是 | 监听输入事件类型,只支持“key”。 |
| keyOptions | [keyOptions](#keyoptions) | 是 | 开始监听时传入的keyOptions。 |
| callback | Callback&lt;KeyOptions&gt; | 是 | 开始监听时与KeyOption一同传入的回调函数&nbsp;。 |
| type | string | 是 | 事件类型,当前只支持”key“。 |
| keyOptions | [keyOptions](#keyoptions) | 是 | 组合键选项。 |
| callback | Callback&lt;KeyOptions&gt; | 否 | 需要取消订阅的回调函数,若无此参数,则取消当前应用的组合键选项已订阅的所有回调函数。 |
**示例:**
```js
let keyOptions = { preKeys: [], finalKey: 18, isFinalKeyDown: true, finalKeyDownDuration: 0 }
// 取消订阅单个回调函数
let callback = function (keyOptions) {
console.log(`keyOptions: ${JSON.stringify(keyOptions)}`);
}
let keyOption = {preKeys: [], finalKey: powerKeyCode, isFinalKeyDown: true, finalKeyDownDuration: 0};
try {
inputConsumer.on("key", keyOption, callback);
inputConsumer.off("key", keyOption, callback);
} catch (error) {
console.log(`Execute failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
}
```
```js
// 取消订阅所有回调函数
let callback = function (keyOptions) {
console.info("preKeys: " + keyOptions.preKeys, "finalKey: " + keyOptions.finalKey,
"isFinalKeyDown: " + keyOptions.isFinalKeyDown, "finalKeyDownDuration: " + keyOptions.finalKeyDownDuration)
console.log(`keyOptions: ${JSON.stringify(keyOptions)}`);
}
let keyOption = {preKeys: [], finalKey: powerKeyCode, isFinalKeyDown: true, finalKeyDownDuration: 0};
try {
inputConsumer.off(inputConsumer.SubscribeType.KEY, keyOptions, callback);
inputConsumer.on("key", keyOption, callback);
inputConsumer.off("key", keyOption);
} catch (error) {
console.info(`inputConsumer.off, error.code=${JSON.stringify(error.code)}, error.msg=${JSON.stringify(error.message)}`);
console.log(`Execute failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
}
```
## KeyOptions
组合键输入事件发生时,组合键满足的选项。
组合键选项。
**系统能力:** SystemCapability.MultimodalInput.Input.InputConsumer
| 参数 | 类型 | 必填 | 说明 |
| -------------------- | ------- | ---- | ------------------------ |
| preKeys | Array | 是 | 组合键前置按键集合,可为空,前置按键无顺序要求。 |
| finalKey | Number | 是 | 组合键最后按键,不能为空。 |
| isFinalKeyDown | boolean | 是 | 组合键最后按键是按下还是抬起,默认是按下。 |
| finalKeyDownDuration | Number | 是 | 组合键最后按键按下持续时长,默认无时长要求。 |
| preKeys | Array | 是 | 前置按键集合,数量范围[0, 4],前置按键无顺序要求。 |
| finalKey | Number | 是 | 最终按键,此项必填,最终按键触发上报回调函数。 |
| isFinalKeyDown | boolean | 是 | 最终按键状态。 |
| finalKeyDownDuration | Number | 是 | 最终按键保持按下持续时间,为0时立即触发回调函数,大于0时,当isFinalKeyDown为true,则最终按键按下超过此时长后触发回调函数,当isFinalKeyDown为false,则最终按键按下到抬起时间小于此时长时触发回调函数。 |
# 注入按键
# 按键注入
InputEventClient模块提供了注入按键能力。
按键注入模块,提供按键注入能力。
> **说明:**
>
......@@ -21,7 +21,7 @@ import inputEventClient from '@ohos.multimodalInput.inputEventClient';
injectEvent({KeyEvent: KeyEvent}): void
注入按键,KeyEvent为注入按键的描述信息
按键注入,当前仅支持返回键(键值2)注入
**系统能力:** SystemCapability.MultimodalInput.Input.InputSimulator
......@@ -29,41 +29,43 @@ injectEvent({KeyEvent: KeyEvent}): void
| 参数 | 类型 | 必填 | 说明 |
| -------- | --------------------- | ---- | --------- |
| KeyEvent | [KeyEvent](#keyevent) | 是 | 注入按键的描述信息 |
| KeyEvent | [KeyEvent](#keyevent) | 是 | 按键注入描述信息。 |
**示例:**
```js
try {
var keyEvent = {
let backKeyDown = {
isPressed: true,
keyCode: 2,
keyDownDuration: 0,
isIntercepted: false
}
inputEventClient.injectKeyEvent({ KeyEvent: keyEvent });
var keyEvent1 = {
inputEventClient.injectKeyEvent({ KeyEvent: backKeyDown });
let backKeyUp = {
isPressed: false,
keyCode: 2,
keyDownDuration: 0,
isIntercepted: false
};
inputEventClient.injectKeyEvent({ KeyEvent: keyEvent1 });
inputEventClient.injectKeyEvent({ KeyEvent: backKeyUp });
} catch (error) {
console.info("injectKeyEvent " + error.code + " " + error.message);
console.log(`Failed to inject KeyEvent, error: ${JSON.stringify(error, [`code`, `message`])}`);
}
```
## KeyEvent
注入按键的描述信息。
按键注入描述信息。
**系统能力:** SystemCapability.MultimodalInput.Input.InputSimulator
| 参数 | 类型 | 必填 | 说明 |
| --------------- | ------- | ---- | --------- |
| isPressed | boolean | 是 | 按键是否按下 |
| keyCode | number | 是 | 按键键值 |
| keyDownDuration | number | 是 | 按键按下持续时间 |
| isIntercepted | boolean | 是 | 按键是否可以被拦截 |
| 参数 | 类型 | 必填 | 说明 |
| --------------- | ------- | ---- | -------------------------- |
| isPressed | boolean | 是 | 按键是否按下。 |
| keyCode | number | 是 | 按键键值,当前只支持back键。 |
| keyDownDuration | number | 是 | 按键按下持续时间。 |
| isIntercepted | boolean | 是 | 按键是否可以被拦截。 |
......@@ -37,11 +37,11 @@ on(type: "touch", receiver: TouchEventReceiver): void
```js
try {
inputMonitor.on("touch", (data)=> {
console.info(`monitorOnTouchEvent success ${JSON.stringify(data)}`);
console.log(`Monitor on TouchEvent success ${JSON.stringify(data)}`);
return false;
});
} catch (error) {
console.info("onMonitor " + error.code + " " + error.message)
console.log(`Failed to monitor on TouchEvent, error: ${JSON.stringify(error, [`code`, `message`])}`);
}
```
......@@ -66,11 +66,11 @@ on(type: "mouse", receiver: Callback&lt;MouseEvent&gt;): void
```js
try {
inputMonitor.on("mouse", (data)=> {
console.info(`monitorOnMouseEvent success ${JSON.stringify(data)}`);
console.log(`Monitor on MouseEvent success ${JSON.stringify(data)}`);
return false;
});
} catch (error) {
console.info("onMonitor " + error.code + " " + error.message)
console.log(`Failed to monitor on MouseEvent, error: ${JSON.stringify(error, [`code`, `message`])}`);
}
```
......@@ -95,25 +95,25 @@ off(type: "touch", receiver?: TouchEventReceiver): void
**示例:**
```js
// 取消所有监听。
// 取消监听全局触屏事件
try {
inputMonitor.off("touch");
} catch (error) {
console.info("offMonitor " + error.code + " " + error.message)
console.log(`Failed to monitor off TouchEvent, error: ${JSON.stringify(error, [`code`, `message`])}`);
}
// 单独取消receiver的监听。
callback:function(data) {
console.info(`call success ${JSON.stringify(data)}`);
console.log(`call success ${JSON.stringify(data)}`);
},
try {
inputMonitor.on("touch", this.callback);
} catch (error) {
console.info("onTouchMonitor " + error.code + " " + error.message)
}
console.log(`Failed to monitor on TouchEvent, error: ${JSON.stringify(error, [`code`, `message`])}`);
},
try {
inputMonitor.off("touch",this.callback);
} catch (error) {
console.info("offTouchMonitor " + error.code + " " + error.message)
console.log(`Failed to monitor off TouchEvent, error: ${JSON.stringify(error, [`code`, `message`])}`);
}
```
......@@ -135,25 +135,25 @@ off(type: "mouse", receiver?: Callback&lt;MouseEvent&gt;): void
**示例:**
```js
// 取消所有监听。
// 取消监听全局鼠标事件
try {
inputMonitor.off("mouse");
} catch (error) {
console.info("offMonitor " + error.code + " " + error.message)
console.log(`Failed to monitor off MouseEvent, error: ${JSON.stringify(error, [`code`, `message`])}`);
}
// 单独取消receiver的监听。
callback:function(data) {
console.info(`call success ${JSON.stringify(data)}`);
console.log(`call success ${JSON.stringify(data)}`);
},
try {
inputMonitor.on("mouse", this.callback);
} catch (error) {
console.info("onMouseMonitor " + error.code + " " + error.message)
}
console.log(`Failed to monitor on MouseEvent, error: ${JSON.stringify(error, [`code`, `message`])}`);
},
try {
inputMonitor.off("mouse", this.callback);
} catch (error) {
console.info("offMouseMonitor " + error.code + " " + error.message)
console.log(`Failed to monitor off MouseEvent, error: ${JSON.stringify(error, [`code`, `message`])}`);
}
```
......@@ -187,6 +187,6 @@ try {
});
inputMonitor.off("touch");
} catch (error) {
console.info("offMonitor " + error.code + " " + error.message)
console.log(`Failed to monitor off TouchEvent, error: ${JSON.stringify(error, [`code`, `message`])}`);
}
```
......@@ -8,7 +8,7 @@ KeyCode模块提供了按键类设备的键值。
## 导入模块
```js
import {KeyCode} from '@ohos.multimodalInput.keyCode'
import {KeyCode} from '@ohos.multimodalInput.keyCode';
```
## KeyCode
......
......@@ -9,44 +9,44 @@ KeyEvent模块提供了设备可以上报的按键事件。
## 导入模块
```js
import {Action,Key,KeyEvent} from '@ohos.multimodalInput.keyEvent';
import {Action, Key, KeyEvent} from '@ohos.multimodalInput.keyEvent';
```
## Action
**系统能力**:SystemCapability.MultimodalInput.Input.Core
| 名称 | 参数类型 | 可读 | 可写 | 描述 |
| ------ | ------ | ---- | ---- | ---- |
| CANCEL | number | 是 | 否 | 取消 |
| DOWN | number | 是 | 否 | 按下按钮 |
| UP | number | 是 | 否 | 抬起按钮 |
| 名称 | 参数类型 | 可读 | 可写 | 描述 |
| ------ | -------- | ---- | ---- | -------- |
| CANCEL | number | 是 | 否 | 取消按钮 |
| DOWN | number | 是 | 否 | 按下按钮 |
| UP | number | 是 | 否 | 抬起按钮 |
## Key
**系统能力**:SystemCapability.MultimodalInput.Input.Core
| 名称 | 参数类型 | 可读 | 可写 | 描述 |
| ----------- | ------- | ---- | ---- | ------ |
| code | KeyCode | 是 | 否 | 按键码 |
| pressedTime | number | 是 | 否 | 按下时间 |
| deviceId | number | 是 | 否 | 按键所属设备 |
| 名称 | 参数类型 | 可读 | 可写 | 描述 |
| ----------- | -------- | ---- | ---- | -------------- |
| code | KeyCode | 是 | 否 | 按键码 |
| pressedTime | number | 是 | 否 | 按下持续的时间 |
| deviceId | number | 是 | 否 | 按键所属设备 |
## KeyEvent
**系统能力**:SystemCapability.MultimodalInput.Input.Core
| 名称 | 参数类型 | 可读 | 可写 | 描述 |
| ----------- | ------- | ---- | ---- | -------------------- |
| action | Action | 是 | 否 | 按键动作 |
| key | Key | 是 | 否 | 当前发生变化的按键 |
| unicodeChar | number | 是 | 否 | 按键对应的uniCode字符 |
| keys | Key[] | 是 | 否 | 当前处于按下状态的按键列表 |
| ctrlKey | boolean | 是 | 否 | 当前ctrlKey是否处于按下状态 |
| altKey | boolean | 是 | 否 | 当前altKey是否处于按下状态 |
| shiftKey | boolean | 是 | 否 | 当前shiftKey是否处于按下状态 |
| logoKey | boolean | 是 | 否 | 当前logoKey是否处于按下状态 |
| fnKey | boolean | 是 | 否 | 当前fnKey是否处于按下状态 |
| capsLock | boolean | 是 | 否 | 当前capsLock是否处于激活状态 |
| numLock | boolean | 是 | 否 | 当前numLock是否处于激活状态 |
| scrollLock | boolean | 是 | 否 | 当前scrollLock是否处于激活状态 |
\ No newline at end of file
| 名称 | 参数类型 | 可读 | 可写 | 描述 |
| ----------- | -------- | ---- | ---- | ------------------------------ |
| action | Action | 是 | 否 | 按键动作 |
| key | Key | 是 | 否 | 当前发生变化的按键 |
| unicodeChar | number | 是 | 否 | 按键对应的uniCode字符 |
| keys | Key[] | 是 | 否 | 当前处于按下状态的按键列表 |
| ctrlKey | boolean | 是 | 否 | 当前ctrlKey是否处于按下状态 |
| altKey | boolean | 是 | 否 | 当前altKey是否处于按下状态 |
| shiftKey | boolean | 是 | 否 | 当前shiftKey是否处于按下状态 |
| logoKey | boolean | 是 | 否 | 当前logoKey是否处于按下状态 |
| fnKey | boolean | 是 | 否 | 当前fnKey是否处于按下状态 |
| capsLock | boolean | 是 | 否 | 当前capsLock是否处于激活状态 |
| numLock | boolean | 是 | 否 | 当前numLock是否处于激活状态 |
| scrollLock | boolean | 是 | 否 | 当前scrollLock是否处于激活状态 |
......@@ -15,15 +15,15 @@ import {Action,Button,Axis,AxisValue,MouseEvent} from '@ohos.multimodalInput.mou
**系统能力**:SystemCapability.MultimodalInput.Input.Core
| 名称 | 参数类型 | 可读 | 可写 | 描述 |
| ----------- | ------ | ---- | ---- | ---------- |
| CANCEL | number | 是 | 否 | 取消 |
| MOVE | number | 是 | 否 | 鼠标移动 |
| BUTTON_DOWN | number | 是 | 否 | 鼠标按钮按下 |
| BUTTON_UP | number | 是 | 否 | 鼠标按钮抬起 |
| AXIS_BEGIN | number | 是 | 否 | 鼠标关联的轴事件开始 |
| AXIS_UPDATE | number | 是 | 否 | 鼠标关联的轴事件更新 |
| AXIS_END | number | 是 | 否 | 鼠标关联的轴事件结束 |
| 名称 | 参数类型 | 可读 | 可写 | 描述 |
| ----------- | -------- | ---- | ---- | -------------------- |
| CANCEL | number | 是 | 否 | 取消动作 |
| MOVE | number | 是 | 否 | 鼠标移动 |
| BUTTON_DOWN | number | 是 | 否 | 鼠标按钮按下 |
| BUTTON_UP | number | 是 | 否 | 鼠标按钮抬起 |
| AXIS_BEGIN | number | 是 | 否 | 鼠标关联的轴事件开始 |
| AXIS_UPDATE | number | 是 | 否 | 鼠标关联的轴事件更新 |
| AXIS_END | number | 是 | 否 | 鼠标关联的轴事件结束 |
## Button
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册