From 8dc7325d5f47978e0fc64c3b6ee766bc00b9cf7f Mon Sep 17 00:00:00 2001 From: gaoshangqi Date: Wed, 6 Sep 2023 08:00:50 +0000 Subject: [PATCH] =?UTF-8?q?update=20en/application-dev/reference/apis/js-a?= =?UTF-8?q?pis-inputconsumer.md.=20ArkTS=E8=AF=AD=E6=B3=95=E8=A7=84?= =?UTF-8?q?=E5=88=99=E6=95=B4=E6=94=B9=E8=B7=9F=E8=B8=AA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: gaoshangqi --- .../reference/apis/js-apis-inputconsumer.md | 21 ++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/en/application-dev/reference/apis/js-apis-inputconsumer.md b/en/application-dev/reference/apis/js-apis-inputconsumer.md index 4de59dd132..dafc758638 100644 --- a/en/application-dev/reference/apis/js-apis-inputconsumer.md +++ b/en/application-dev/reference/apis/js-apis-inputconsumer.md @@ -36,10 +36,17 @@ Enables listening for combination key events. This API uses an asynchronous call ```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`])}`); } @@ -68,10 +75,10 @@ Disables listening for combination key events. let leftAltKey = 2045; let tabKey = 2049; // Disable listening for a single callback function. -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); @@ -84,10 +91,10 @@ try { let leftAltKey = 2045; let tabKey = 2049; // Disable listening for all callback functions. -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