From 56b4f1c67ff8d089e0813bcf581cef579b6e48ac Mon Sep 17 00:00:00 2001 From: Yuanxinying Date: Tue, 5 Sep 2023 10:59:23 +0000 Subject: [PATCH] update zh-cn/application-dev/reference/apis/js-apis-inputconsumer.md. UPDATE Signed-off-by: Yuanxinying --- .../reference/apis/js-apis-inputconsumer.md | 21 ++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/zh-cn/application-dev/reference/apis/js-apis-inputconsumer.md b/zh-cn/application-dev/reference/apis/js-apis-inputconsumer.md index ca66792be2..9104ed04e6 100755 --- a/zh-cn/application-dev/reference/apis/js-apis-inputconsumer.md +++ b/zh-cn/application-dev/reference/apis/js-apis-inputconsumer.md @@ -35,10 +35,17 @@ on(type: 'key', keyOptions: KeyOptions, callback: Callback<KeyOptions>): v ```js let leftAltKey = 2045; 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 { - inputConsumer.on("key", {preKeys: [leftAltKey], finalKey: tabKey, isFinalKeyDown: true, finalKeyDownDuration: 0}, keyOptions => { - console.log(`keyOptions: ${JSON.stringify(keyOptions)}`); - }); + inputConsumer.on("key", keyOptions, callback); } catch (error) { console.log(`Subscribe failed, error: ${JSON.stringify(error, [`code`, `message`])}`); } @@ -67,10 +74,10 @@ off(type: 'key', keyOptions: KeyOptions, callback?: Callback<KeyOptions>): let leftAltKey = 2045; let tabKey = 2049; // 取消订阅单个回调函数 -let callback = function (keyOptions) { +let callback = (keyOptions: inputConsumer.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 { inputConsumer.on("key", keyOption, callback); inputConsumer.off("key", keyOption, callback); @@ -83,10 +90,10 @@ try { let leftAltKey = 2045; let tabKey = 2049; // 取消订阅所有回调函数 -let callback = function (keyOptions) { +let callback = (keyOptions: inputConsumer.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 { inputConsumer.on("key", keyOption, callback); inputConsumer.off("key", keyOption); -- GitLab