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 9b73e3ce7fc3e2d0689acfb896cea239d8bae90d..913a7ffef022ed6035f8419b6700d5dc6e294204 100755 --- a/zh-cn/application-dev/reference/apis/js-apis-inputconsumer.md +++ b/zh-cn/application-dev/reference/apis/js-apis-inputconsumer.md @@ -38,10 +38,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`])}`); } @@ -70,10 +77,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); @@ -86,10 +93,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);