提交 727272e7 编写于 作者: M mayunteng_1

示例修改

Signed-off-by: Nmayunteng_1 <mayunteng@huawei.com>
Change-Id: I2d5a4f7a673475f740f31ca7e40163b0e5c913f8
上级 5bdfbcdf
......@@ -33,14 +33,26 @@ on(type: “change”, listener: Callback&lt;DeviceListener&gt;): 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.off<sup>9+</sup>
on(type: “change”, listener?: Callback&lt;DeviceListener&gt;): void
off(type: “change”, listener?: Callback&lt;DeviceListener&gt;): void
取消监听设备的热插拔事件。
......@@ -56,7 +68,16 @@ on(type: “change”, listener?: Callback&lt;DeviceListener&gt;): 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 | 表示遥控器设备。 |
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册