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

!11354 修改示例代码错误

Merge pull request !11354 from mayunteng/master1
......@@ -36,9 +36,10 @@ on(type: "key", keyOptions: KeyOptions, callback: Callback<KeyOptions>): v
**示例:**
```js
let powerKeyCode = 18;
let leftAltKey = 2045;
let tabKey = 2049;
try {
inputConsumer.on("key", {preKeys: [], finalKey: powerKeyCode, isFinalKeyDown: true, finalKeyDownDuration: 0}, keyOptions => {
inputConsumer.on("key", {preKeys: [leftAltKey], finalKey: tabKey, isFinalKeyDown: true, finalKeyDownDuration: 0}, keyOptions => {
console.log(`keyOptions: ${JSON.stringify(keyOptions)}`);
});
} catch (error) {
......@@ -66,27 +67,33 @@ off(type: "key", keyOptions: KeyOptions, callback?: Callback<KeyOptions>):
**示例:**
```js
let leftAltKey = 2045;
let tabKey = 2049;
// 取消订阅单个回调函数
let callback = function (keyOptions) {
console.log(`keyOptions: ${JSON.stringify(keyOptions)}`);
}
let keyOption = {preKeys: [], finalKey: powerKeyCode, isFinalKeyDown: true, finalKeyDownDuration: 0};
let keyOption = {preKeys: [leftAltKey], finalKey: tabKey, isFinalKeyDown: true, finalKeyDownDuration: 0};
try {
inputConsumer.on("key", keyOption, callback);
inputConsumer.off("key", keyOption, callback);
console.log(`Unsubscribe success`);
} catch (error) {
console.log(`Execute failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
}
```
```js
let leftAltKey = 2045;
let tabKey = 2049;
// 取消订阅所有回调函数
let callback = function (keyOptions) {
console.log(`keyOptions: ${JSON.stringify(keyOptions)}`);
}
let keyOption = {preKeys: [], finalKey: powerKeyCode, isFinalKeyDown: true, finalKeyDownDuration: 0};
let keyOption = {preKeys: [leftAltKey], finalKey: tabKey, isFinalKeyDown: true, finalKeyDownDuration: 0};
try {
inputConsumer.on("key", keyOption, callback);
inputConsumer.off("key", keyOption);
console.log(`Unsubscribe success`);
} catch (error) {
console.log(`Execute failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
}
......
......@@ -194,19 +194,19 @@ off(type: "change", listener?: Callback<DeviceListener>): void
**示例**
```js
callback: function(data) {
function callback(data) {
console.log(`Report device event info: ${JSON.stringify(data, [`type`, `deviceId`])}`);
}
};
try {
inputDevice.on("change", this.callback);
inputDevice.on("change", callback);
} catch (error) {
console.log(`Listen device event failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
}
// 取消指定的监听。
try {
inputDevice.off("change", this.callback);
inputDevice.off("change", callback);
} catch (error) {
console.log(`Cancel listening device event failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
}
......
......@@ -96,13 +96,14 @@ off(type: "touch", receiver?: TouchEventReceiver): void
```js
// 取消监听单个回调函数
callback: function(touchEvent) {
function callback(touchEvent) {
console.log(`Monitor on success ${JSON.stringify(touchEvent)}`);
return false;
},
};
try {
inputMonitor.on("touch", this.callback);
inputMonitor.off("touch", this.callback);
inputMonitor.on("touch", callback);
inputMonitor.off("touch", callback);
console.log(`Monitor off success`);
} catch (error) {
console.log(`Monitor execute failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
}
......@@ -110,13 +111,14 @@ try {
```js
// 取消监听所有回调函数
callback: function(touchEvent) {
function callback(touchEvent) {
console.log(`Monitor on success ${JSON.stringify(touchEvent)}`);
return false;
},
};
try {
inputMonitor.on("touch", this.callback);
inputMonitor.on("touch", callback);
inputMonitor.off("touch");
console.log(`Monitor off success`);
} catch (error) {
console.log(`Monitor execute failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
}
......@@ -141,12 +143,14 @@ off(type: "mouse", receiver?: Callback<MouseEvent>): void
```js
// 取消监听单个回调函数
callback: function(mouseEvent) {
function callback(mouseEvent) {
console.log(`Monitor on success ${JSON.stringify(mouseEvent)}`);
},
return false;
};
try {
inputMonitor.on("mouse", this.callback);
inputMonitor.off("mouse", this.callback);
inputMonitor.on("mouse", callback);
inputMonitor.off("mouse", callback);
console.log(`Monitor off success`);
} catch (error) {
console.log(`Monitor execute failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
}
......@@ -154,12 +158,14 @@ try {
```js
// 取消监听所有回调函数
callback: function(mouseEvent) {
function callback(mouseEvent) {
console.log(`Monitor on success ${JSON.stringify(mouseEvent)}`);
},
return false;
};
try {
inputMonitor.on("mouse", this.callback);
inputMonitor.on("mouse", callback);
inputMonitor.off("mouse");
console.log(`Monitor off success`);
} catch (error) {
console.log(`Monitor execute failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
}
......
......@@ -153,7 +153,7 @@ try {
}
console.log(`Set pointer speed success`);
});
} catch (err) {
} catch (error) {
console.log(`Set pointer speed failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
}
```
......@@ -208,14 +208,14 @@ getPointerSpeed(callback: AsyncCallback<number>): void
```js
try {
pointer.getPointerSpeed(speed, (error, speed) => {
pointer.getPointerSpeed((error, speed) => {
if (error) {
console.log(`Get pointer speed failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
return;
}
console.log(`Get pointer speed success, speed: ${JSON.stringify(speed)}`);
});
} catch (err) {
} catch (error) {
console.log(`Get pointer speed failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
}
```
......@@ -294,6 +294,12 @@ getPointerStyle(windowId: number): Promise<PointerStyle>
**参数**
| 参数 | 类型 | 必填 | 说明 |
| -------- | ------ | ---- | -------- |
| windowId | number | 是 | 窗口id。 |
**返回值**
| 参数 | 说明 |
| ---------------------------------------- | ------------------- |
| Promise<[PointerStyle](#pointerstyle9)> | Promise实例,异步返回鼠标样式类型。 |
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册