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

!24002 inputconsumer挑单monthly0815

Merge pull request !24002 from PingPing2023/cherry-pick-1693921087
...@@ -38,10 +38,17 @@ on(type: "key", keyOptions: KeyOptions, callback: Callback<KeyOptions>): v ...@@ -38,10 +38,17 @@ on(type: "key", keyOptions: KeyOptions, callback: Callback<KeyOptions>): v
```js ```js
let leftAltKey = 2045; let leftAltKey = 2045;
let tabKey = 2049; let tabKey = 2049;
let keyOptions: inputConsumer.KeyOptions = {
preKeys: [ leftAltKey ],
finalKey: tabKey,
isFinalKeyDown: true,
finalKeyDownDuration: 0
};
let callback = (keyOptions: inputConsumer.KeyOptions) => {
console.log(`keyOptions: ${JSON.stringify(keyOptions)}`);
}
try { try {
inputConsumer.on("key", {preKeys: [leftAltKey], finalKey: tabKey, isFinalKeyDown: true, finalKeyDownDuration: 0}, keyOptions => { inputConsumer.on("key", keyOptions, callback);
console.log(`keyOptions: ${JSON.stringify(keyOptions)}`);
});
} catch (error) { } catch (error) {
console.log(`Subscribe failed, error: ${JSON.stringify(error, [`code`, `message`])}`); console.log(`Subscribe failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
} }
...@@ -70,10 +77,10 @@ off(type: "key", keyOptions: KeyOptions, callback?: Callback<KeyOptions>): ...@@ -70,10 +77,10 @@ off(type: "key", keyOptions: KeyOptions, callback?: Callback<KeyOptions>):
let leftAltKey = 2045; let leftAltKey = 2045;
let tabKey = 2049; let tabKey = 2049;
// 取消订阅单个回调函数 // 取消订阅单个回调函数
let callback = function (keyOptions) { let callback = (keyOptions: inputConsumer.KeyOptions) => {
console.log(`keyOptions: ${JSON.stringify(keyOptions)}`); console.log(`keyOptions: ${JSON.stringify(keyOptions)}`);
} }
let keyOption = {preKeys: [leftAltKey], finalKey: tabKey, isFinalKeyDown: true, finalKeyDownDuration: 0}; let keyOption: inputConsumer.KeyOptions = {preKeys: [leftAltKey], finalKey: tabKey, isFinalKeyDown: true, finalKeyDownDuration: 0};
try { try {
inputConsumer.on("key", keyOption, callback); inputConsumer.on("key", keyOption, callback);
inputConsumer.off("key", keyOption, callback); inputConsumer.off("key", keyOption, callback);
...@@ -86,10 +93,10 @@ try { ...@@ -86,10 +93,10 @@ try {
let leftAltKey = 2045; let leftAltKey = 2045;
let tabKey = 2049; let tabKey = 2049;
// 取消订阅所有回调函数 // 取消订阅所有回调函数
let callback = function (keyOptions) { let callback = (keyOptions: inputConsumer.KeyOptions) => {
console.log(`keyOptions: ${JSON.stringify(keyOptions)}`); console.log(`keyOptions: ${JSON.stringify(keyOptions)}`);
} }
let keyOption = {preKeys: [leftAltKey], finalKey: tabKey, isFinalKeyDown: true, finalKeyDownDuration: 0}; let keyOption: inputConsumer.KeyOptions = {preKeys: [leftAltKey], finalKey: tabKey, isFinalKeyDown: true, finalKeyDownDuration: 0};
try { try {
inputConsumer.on("key", keyOption, callback); inputConsumer.on("key", keyOption, callback);
inputConsumer.off("key", keyOption); inputConsumer.off("key", keyOption);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册