未验证 提交 4da3046e 编写于 作者: O openharmony_ci 提交者: Gitee

!20395 【新增接口描述】新增KeyEvent事件订阅接口说明

Merge pull request !20395 from 赵凌岚/master
...@@ -726,6 +726,57 @@ inputMethodEngine.getKeyboardDelegate().off('keyDown', (keyEvent) => { ...@@ -726,6 +726,57 @@ inputMethodEngine.getKeyboardDelegate().off('keyDown', (keyEvent) => {
}); });
``` ```
### on('keyEvent')<sup>10+</sup>
on(type: 'keyEvent', callback: (event: InputKeyEvent) => boolean): void
订阅硬键盘(即物理键盘)事件。使用callback异步回调。
**系统能力:** SystemCapability.MiscServices.InputMethodFramework
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | ---- | ------------------------------------------------------------ |
| type | string | 是 | 设置监听类型。<br/>-&nbsp;type为'keyEvent',表示订阅硬键盘按键事件。 |
| callback | function | 是 | 回调函数,入参为按键事件信息,返回值类型为布尔类型。<br/>-&nbsp;入参按键事件信息的数据类型为[InputKeyEvent](js-apis-keyevent.md#KeyEvent)。<br/>-&nbsp;若按键事件被事件订阅者消费,则callback应返回true,否则返回false。 |
**示例:**
```js
inputMethodEngine.getKeyboardDelegate().on('keyEvent', (keyEvent) => {
console.log('inputMethodEngine keyEvent.action:' + JSON.stringify(keyEvent.action));
console.log('inputMethodEngine keyEvent.key.code:' + JSON.stringify(keyEvent.key.code));
console.log('inputMethodEngine keyEvent.ctrlKey:' + JSON.stringify(keyEvent.ctrlKey));
return true;
});
```
### off('keyEvent')<sup>10+</sup>
off(type: 'keyEvent', callback?: (event: InputKeyEvent) => boolean): void
取消订阅硬键盘(即物理键盘)事件。使用callback异步回调。
**系统能力:** SystemCapability.MiscServices.InputMethodFramework
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | ---- | ------------------------------------------------------------ |
| type | string | 是 | 设置监听类型。<br/>-&nbsp;type为'keyEvent',表示取消订阅硬键盘按键事件。 |
| callback | function | 否 | 回调函数,入参为按键事件信息,返回值类型为布尔类型。<br/>-&nbsp;入参按键事件信息的数据类型为[InputKeyEvent](js-apis-keyevent.md#KeyEvent)。<br/>-&nbsp;若按键事件被事件订阅者消费,则callback应返回true,否则返回false。<br/>-&nbsp;可选参数,若填写表示不再回调此函数,若不填写则取消注册该事件所有回调函数。 |
**示例:**
```js
inputMethodEngine.getKeyboardDelegate().off('keyEvent', (keyEvent) => {
console.log('This is a callback function which will be deregistered.');
return true;
});
inputMethodEngine.getKeyboardDelegate().off('keyEvent');
```
### on('cursorContextChange') ### on('cursorContextChange')
on(type: 'cursorContextChange', callback: (x: number, y:number, height:number) => void): void on(type: 'cursorContextChange', callback: (x: number, y:number, height:number) => void): void
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册