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

!23965 update inputconsumer for arkts gramma

Merge pull request !23965 from Yuanxinying/master
...@@ -35,10 +35,17 @@ on(type: 'key', keyOptions: KeyOptions, callback: Callback<KeyOptions>): v ...@@ -35,10 +35,17 @@ on(type: 'key', keyOptions: KeyOptions, callback: Callback<KeyOptions>): v
```js ```js
let leftAltKey = 2045; let leftAltKey = 2045;
let tabKey = 2049; let tabKey = 2049;
try { let keyOptions: inputConsumer.KeyOptions = {
inputConsumer.on("key", {preKeys: [leftAltKey], finalKey: tabKey, isFinalKeyDown: true, finalKeyDownDuration: 0}, keyOptions => { preKeys: [ leftAltKey ],
finalKey: tabKey,
isFinalKeyDown: true,
finalKeyDownDuration: 0
};
let callback = (keyOptions: inputConsumer.KeyOptions) => {
console.log(`keyOptions: ${JSON.stringify(keyOptions)}`); console.log(`keyOptions: ${JSON.stringify(keyOptions)}`);
}); }
try {
inputConsumer.on("key", keyOptions, callback);
} catch (error) { } catch (error) {
console.log(`Subscribe failed, error: ${JSON.stringify(error, [`code`, `message`])}`); console.log(`Subscribe failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
} }
...@@ -67,10 +74,10 @@ off(type: 'key', keyOptions: KeyOptions, callback?: Callback<KeyOptions>): ...@@ -67,10 +74,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);
...@@ -83,10 +90,10 @@ try { ...@@ -83,10 +90,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.
先完成此消息的编辑!
想要评论请 注册