From 727272e7b446888f0c6082703225a712e22cae40 Mon Sep 17 00:00:00 2001 From: mayunteng_1 Date: Wed, 1 Jun 2022 16:29:31 +0800 Subject: [PATCH] =?UTF-8?q?=E7=A4=BA=E4=BE=8B=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: mayunteng_1 Change-Id: I2d5a4f7a673475f740f31ca7e40163b0e5c913f8 --- .../reference/apis/js-apis-inputdevice.md | 29 ++++++++++++++++--- 1 file changed, 25 insertions(+), 4 deletions(-) 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 6fef87683c..11b43fba34 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 | 表示遥控器设备。 | -- GitLab