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 6fef87683c76e94cedffda11ac46a4b3380be9b2..11b43fba34acd39ddb16acc3e098a054976e8e69 100755 --- a/zh-cn/application-dev/reference/apis/js-apis-inputdevice.md +++ b/zh-cn/application-dev/reference/apis/js-apis-inputdevice.md @@ -33,14 +33,26 @@ on(type: “change”, listener: Callback<DeviceListener>): void **示例:** ```js -inputDevice.on("change", (callback)=>{ - console.log("type: " + callback.type + ", deviceId: " + callback.deviceId); +let isPhysicalKeyboardExist = true; +inputDevice.on("change", (data) => { + console.log("type: " + data.type + ", deviceId: " + data.deviceId); + inputDevice.getKeyboardType(data.deviceId, (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; + } + }); }); +// 根据isPhysicalKeyboardExist的值决定软键盘是否弹出。 ``` ## inputDevice.off9+ -on(type: “change”, listener?: Callback<DeviceListener>): void +off(type: “change”, listener?: Callback<DeviceListener>): void 取消监听设备的热插拔事件。 @@ -56,7 +68,16 @@ on(type: “change”, listener?: Callback<DeviceListener>): void **示例:** ```js +listener: function(data) { + console.log("type: " + data.type + ", deviceId: " + data.deviceId); +} + +// 单独取消listener的监听。 +inputDevice.off("change", this.listener); + +// 取消所有监听 inputDevice.off("change"); +// 取消监听后,软键盘默认都弹出 ``` ## inputDevice.getDeviceIds @@ -361,4 +382,4 @@ inputDevice.getKeyboardType().then((ret)=>{ | ALPHABETIC_KEYBOARD | number | 2 | 表示全键盘设备。 | | DIGITAL_KEYBOARD | number | 3 | 表示小键盘设备。 | | HANDWRITING_PEN | number | 4 | 表示手写笔设备。 | -| REMOTE_CONTROL | number | 5 | 表示遥控器设备。 | \ No newline at end of file +| REMOTE_CONTROL | number | 5 | 表示遥控器设备。 | diff --git "a/zh-cn/readme/figures/\345\244\232\346\250\241\346\236\266\346\236\204\345\233\276.png" "b/zh-cn/readme/figures/\345\244\232\346\250\241\346\236\266\346\236\204\345\233\276.png" new file mode 100755 index 0000000000000000000000000000000000000000..aa9521e2aaec982dfd4bbbd206a744239964d313 Binary files /dev/null and "b/zh-cn/readme/figures/\345\244\232\346\250\241\346\236\266\346\236\204\345\233\276.png" differ diff --git "a/zh-cn/readme/\345\244\232\346\250\241\350\276\223\345\205\245\345\255\220\347\263\273\347\273\237.md" "b/zh-cn/readme/\345\244\232\346\250\241\350\276\223\345\205\245\345\255\220\347\263\273\347\273\237.md" index e8bfac49d9b5740af6507635f211882b51f18964..aad5cc34f488533dd6ef09a25ef9a7462f626ac0 100644 --- "a/zh-cn/readme/\345\244\232\346\250\241\350\276\223\345\205\245\345\255\220\347\263\273\347\273\237.md" +++ "b/zh-cn/readme/\345\244\232\346\250\241\350\276\223\345\205\245\345\255\220\347\263\273\347\273\237.md" @@ -1,17 +1,14 @@ -# 多模输入子系统 +# 多模输入子系统 -- [简介](#section11660541593) -- [目录](#section14408467105) -- [使用](#section18111235161011) -- [相关仓](#section135327891219) - -## 简介 +## 简介 OpenHarmony旨在为开发者提供NUI(Natural User Interface)的交互方式,有别于传统操作系统的输入,在OpenHarmony上,我们将多种维度的输入整合在一起,开发者可以借助应用程序框架、系统自带的UI组件或API接口轻松地实现具有多维、自然交互特点的应用程序。 -具体来说,多模输入子系统目前支持传统的输入交互方式,例如按键、触控等。 +具体来说,多模输入子系统基于Linux原生驱动和HDF驱动接收设备输入事件,如键盘、鼠标、触摸屏、触摸板等, 对输入事件进行归一化和标准化后通过innerSDK分发到ArkUI框架,ArkUI框架封装事件后转发到应用,或者innerSDK通过JsKit接口直接分发事件到应用。 + +![](figures/多模架构图.png) -## 目录 +## 目录 ``` /foundation/multimodalinput/input @@ -24,13 +21,52 @@ OpenHarmony旨在为开发者提供NUI(Natural User Interface)的交互方 ├── uinput # 输入事件注入模块 ``` -## 使用 +## 使用 + +### 接口说明 + +多模输入目前提供的接口为按键事件注入接口,该接口仅对系统应用开放。 + +inputEventClient是处理注入事件类。 + +**表 1** inputEventClient的主要接口 + +| 功能分类 | 接口名 | 描述 | +| :------: | :-----------------------------------------------: | :----------------: | +| 注入按键 | function injectEvent(keyEvent: KeyEvent): number; | 注入按键事件的接口 | + +### 使用说明 + +当前仅提供了BACK按键的事件注入。 + +当系统应用需要返回上一层时,通过注入接口将BACK键注入到多模服务,多模服务再上传到应用,以实现返回到上一层级目录的效果。使用方式如下所示: + +``` +// 引入提供的js接口库 +import inputEventClient from '@ohos.multimodalInput.inputEventClient'; + +// 调用注入事件接口 +let keyEvent = { + isPressed: true, // 按键事件的按键类型:true:down false:up + keyCode: 2, // 按键对应的keycode, 例如back键的值为2 + keyDownDuration: 0, // 按键按下到抬起的时长,单位ms + isIntercepted: false // 标注按键事件是否检测拦截 +} +res = inputEventClient.injectEvent({KeyEvent: keyEvent}); +``` + +> **说明:** 新增的接口能力需要兼容原有的能力。 + +### 设备能力支持 -多模输入目前提供的接口为事件注入接口,该接口目前仅对系统应用开放。 +| 设备 | 触摸屏 | 触摸板 | 鼠标 | 键盘 | +| :---------: | :----: | :----: | :--: | :--: | +| rk3568 | 是 | 是 | 是 | 是 | +| hi3516dv300 | 是 | 否 | 否 | 否 | -## 相关仓 +## 相关仓 **多模输入子系统** -[multimodalinput_input](https://gitee.com/openharmony/multimodalinput_input) +multimodalinput\_input