From 64a0049619d1424790892a7bc1c5c61e2aa9f620 Mon Sep 17 00:00:00 2001 From: ma-shaoyin Date: Thu, 18 Aug 2022 11:53:42 +0800 Subject: [PATCH] Signed-off-by: ma-shaoyin Changes to be committed: --- .../reference/apis/js-apis-inputmethod.md | 96 +++--- .../apis/js-apis-inputmethodengine.md | 299 ++++++++++++------ 2 files changed, 266 insertions(+), 129 deletions(-) diff --git a/zh-cn/application-dev/reference/apis/js-apis-inputmethod.md b/zh-cn/application-dev/reference/apis/js-apis-inputmethod.md index 3cd283c8f0..0ebf4980b7 100644 --- a/zh-cn/application-dev/reference/apis/js-apis-inputmethod.md +++ b/zh-cn/application-dev/reference/apis/js-apis-inputmethod.md @@ -45,9 +45,9 @@ getInputMethodController(): InputMethodController **返回值:** - | 类型 | 说明 | - | -------- | -------- | - | [InputMethodController](#inputmethodcontroller) | 回调返回当前客户端实例。 | +| 类型 | 说明 | +| ----------------------------------------------- | ------------------------ | +| [InputMethodController](#inputmethodcontroller) | 回调返回当前客户端实例。 | **示例:** @@ -79,7 +79,7 @@ getInputMethodSetting(): InputMethodSetting switchInputMethod(target: InputmethodProperty, callback: AsyncCallback<boolean>): void; -切换输入法。此接口仅可在Stage模型下使用。 +切换输入法。此接口仅可在Stage模型下使用。使用callback形式返回结果。参数个数为2,否则抛出异常。 **系统能力**:SystemCapability.Miscservices.InputMethodFramework @@ -102,7 +102,7 @@ switchInputMethod(target: InputmethodProperty, callback: AsyncCallback<boolea ## inputMethod.switchInputMethod9+ switchInputMethod(target: InputmethodProperty): Promise<boolean> -切换输入法。此接口仅可在Stage模型下使用。 +切换输入法。此接口仅可在Stage模型下使用。使用promise形式返回结果。参数个数为1,否则抛出异常。 **系统能力**: SystemCapability.Miscservices.InputMethodFramework @@ -133,7 +133,7 @@ switchInputMethod(target: InputmethodProperty): Promise<boolean> stopInput(callback: AsyncCallback<boolean>): void -隐藏输入法。 +隐藏输入法。使用callback形式返回结果。参数个数为1,否则抛出异常。 **系统能力**:SystemCapability.MiscServices.InputMethodFramework @@ -146,16 +146,24 @@ stopInput(callback: AsyncCallback<boolean>): void **示例:** ```js - InputMethodController.stopInput((error)=>{ - console.info('stopInput'); - }); +inputMethodController.stopInput((err, result) => { + if (err == undefined) { + console.error("stopInput callback result---err: " + err.msg); + return; + } + if (result) { + console.info("Success to stopInput.(callback)"); + } else { + console.info("Failed to stopInput.(callback)"); + } +}); ``` ### stopInput stopInput(): Promise<boolean> -隐藏输入法。 +隐藏输入法。使用promise形式返回结果。参数个数为0,否则抛出异常。 **系统能力**: SystemCapability.MiscServices.InputMethodFramework @@ -169,15 +177,22 @@ stopInput(): Promise<boolean> ```js - var isSuccess = InputMethodController.stopInput(); - console.info('stopInput isSuccess = ' + isSuccess); +await inputMethodController.stopInput().then((result)=>{ + if (result) { + console.info("Success to stopInput.(promise)"); + } else { + console.info("Failed to stopInput.(promise)"); + } +}).catch((err) => { + console.error("stopInput promise err: " + err.msg); +}); ``` ### showSoftKeyboard9+ ### showSoftKeyboard(callback: AsyncCallback<void>): void -显示软键盘,使用callback异步回调。 +显示软键盘,使用callback异步回调。参数个数为1,否则抛出异常。 **系统能力:** SystemCapability.MiscServices.InputMethodFramework @@ -204,7 +219,7 @@ InputMethodController.showSoftKeyboard((err) => { showSoftKeyboard(): Promise<void> -显示软键盘,使用Promise异步回调。 +显示软键盘,使用Promise异步回调。参数个数为0,否则抛出异常。 **系统能力:** SystemCapability.MiscServices.InputMethodFramework @@ -228,7 +243,7 @@ InputMethodController.showSoftKeyboard().then(async (err) => { hideSoftKeyboard(callback: AsyncCallback<void>): void -隐藏软键盘,使用callback异步回调。 +隐藏软键盘,使用callback异步回调。参数个数为1,否则抛出异常。 **系统能力:** SystemCapability.MiscServices.InputMethodFramework @@ -255,7 +270,7 @@ InputMethodController.hideSoftKeyboard((err) => { hideSoftKeyboard(): Promise<void> -隐藏软键盘,使用Promise异步回调。 +隐藏软键盘,使用Promise异步回调。参数个数为0,否则抛出异常。 **系统能力:** SystemCapability.MiscServices.InputMethodFramework @@ -283,7 +298,7 @@ InputMethodController.hideSoftKeyboard().then(async (err) => { listInputMethod(callback: AsyncCallback<Array<InputMethodProperty>>): void -查询已安装的输入法列表。 +查询已安装的输入法列表。使用callback形式返回结果。参数个数为1,否则抛出异常。 **系统能力**: SystemCapability.MiscServices.InputMethodFramework @@ -295,19 +310,20 @@ listInputMethod(callback: AsyncCallback<Array<InputMethodProperty>>) **示例:** ```js - InputMethodSetting.listInputMethod((properties)=>{ - for (var i = 0;i < properties.length; i++) { - var property = properties[i]; - console.info(property.packageName + "/" + property.methodId); +inputMethodSetting.listInputMethod((err,data) => { + if (err == undefined) { + console.error("listInputMethod callback result---err: " + err.msg); + return; } - }); + console.info("listInputMethod callback result---data: " + JSON.stringify(data)); + }); ``` ### listInputMethod -listInputMethod(): Array<InputMethodProperty> +listInputMethod(): Promise>; -查询已安装的输入法列表。 +查询已安装的输入法列表。使用promise形式返回结果。参数个数为0,否则抛出异常。 **系统能力**: SystemCapability.MiscServices.InputMethodFramework @@ -319,18 +335,18 @@ listInputMethod(): Array<InputMethodProperty> **示例:** ```js - var properties = InputMethodSetting.listInputMethod(); - for (var i = 0;i < properties.length; i++) { - var property = properties[i]; - console.info(property.packageName + "/" + property.methodId); - } +await inputMethodSetting.listInputMethod().then((data)=>{ + console.info("listInputMethod promise result---data: " + JSON.stringify(data)); +}).catch((err) => { + console.info("listInputMethod promise err:" + err.msg); +}); ``` ### displayOptionalInputMethod displayOptionalInputMethod(callback: AsyncCallback<void>): void -显示输入法选择对话框。 +显示输入法选择对话框。使用callback形式返回结果。参数个数为1,否则抛出异常。 **系统能力**: SystemCapability.MiscServices.InputMethodFramework @@ -343,16 +359,20 @@ displayOptionalInputMethod(callback: AsyncCallback<void>): void **示例:** ```js - InputMethodSetting.displayOptionalInputMethod(()=>{ - console.info('displayOptionalInputMethod is called'); - }); +inputMethodSetting.displayOptionalInputMethod((err) => { + if (err == undefined) { + console.error("displayOptionalInputMethod callback---err: " + err.msg); + return; + } + console.info("displayOptionalInputMethod callback"); +}); ``` ### displayOptionalInputMethod displayOptionalInputMethod(): Promise<void> - 显示输入法选择对话框。 + 显示输入法选择对话框。使用promise形式返回结果。参数个数为0,否则抛出异常。 **系统能力**: SystemCapability.MiscServices.InputMethodFramework @@ -360,10 +380,14 @@ displayOptionalInputMethod(callback: AsyncCallback<void>): void | 类型 | 说明 | | -------- | -------- | -| Promise<void> | 回调函数。 | +| Promise<void> | 无返回结果的Promise对象。 | **示例:** ```js - InputMethodSetting.displayOptionalInputMethod(); +await inputMethodSetting.displayOptionalInputMethod().then(()=>{ + console.info("displayOptionalInputMethod promise"); +}).catch((err) => { + console.info("listInputMethod promise err: " + err.msg); +}); ``` \ No newline at end of file diff --git a/zh-cn/application-dev/reference/apis/js-apis-inputmethodengine.md b/zh-cn/application-dev/reference/apis/js-apis-inputmethodengine.md index c9129e8d0c..1b52015504 100644 --- a/zh-cn/application-dev/reference/apis/js-apis-inputmethodengine.md +++ b/zh-cn/application-dev/reference/apis/js-apis-inputmethodengine.md @@ -94,7 +94,7 @@ createKeyboardDelegate(): KeyboardDelegate on(type: 'inputStart', callback: (kbController: KeyboardController, textInputClient: TextInputClient) => void): void -订阅输入法绑定成功事件,使用callback回调返回输入法操作相关实例。 +订阅输入法绑定成功事件,使用callback回调返回输入法操作相关实例。参数个数为2,参数1为napi_string,参数2为napi_function,否则抛出异常。 **系统能力**: SystemCapability.MiscServices.InputMethodFramework @@ -118,7 +118,7 @@ on(type: 'inputStart', callback: (kbController: KeyboardController, textInputCli off(type: 'inputStart', callback?: (kbController: KeyboardController, textInputClient: TextInputClient) => void): void -取消订阅输入法绑定成功事件。 +取消订阅输入法绑定成功事件。参数个数不为1或2抛出异常,若为1,参数不为napi_string抛出异常,若为2,参数1不为napi_string,参数2不为napi_function抛出异常。参数若为1,取消此类型所有监听,参数若为2,取消此类型当前监听。 **系统能力**: SystemCapability.MiscServices.InputMethodFramework @@ -134,14 +134,16 @@ off(type: 'inputStart', callback?: (kbController: KeyboardController, textInputC **示例:** ```js - InputMethodEngine.off('inputStart'); + InputMethodEngine.off('inputStart', (kbController, textInputClient) => { + console.log("delete inputStart notification."); + }); ``` ### on('keyboardShow'|'keyboardHide') on(type: 'keyboardShow'|'keyboardHide', callback: () => void): void -订阅输入法事件。 +订阅输入法事件。参数个数为2,参数1为napi_string,参数2为napi_function,否则抛出异常。 **系统能力**: SystemCapability.MiscServices.InputMethodFramework @@ -155,8 +157,11 @@ on(type: 'keyboardShow'|'keyboardHide', callback: () => void): void **示例:** ```js - InputMethodEngine.on('keyboardShow', (err) => { - console.info('keyboardShow'); + InputMethodEngine.on('keyboardShow', () => { + console.log("inputMethodEngine keyboardShow."); + }); + InputMethodEngine.on('keyboardHide', () => { + console.log("inputMethodEngine keyboardHide."); }); ``` @@ -164,7 +169,7 @@ on(type: 'keyboardShow'|'keyboardHide', callback: () => void): void off(type: 'keyboardShow'|'keyboardHide', callback?: () => void): void -取消订阅输入法事件。 +取消订阅输入法事件。参数个数不为1或2抛出异常,若为1,参数不为napi_string抛出异常,若为2,参数1不为napi_string,参数2不为napi_function抛出异常。参数若为1,取消此类型所有监听,参数若为2,取消此类型当前监听。 **系统能力**: SystemCapability.MiscServices.InputMethodFramework @@ -178,7 +183,12 @@ off(type: 'keyboardShow'|'keyboardHide', callback?: () => void): void **示例:** ```js - InputMethodEngine.off('keyboardShow'); + InputMethodEngine.off('keyboardShow', () => { + console.log("inputMethodEngine delete keyboardShow notification."); + }); + InputMethodEngine.off('keyboardHide', () => { + console.log("inputMethodEngine delete keyboardHide notification."); + }); ``` @@ -190,7 +200,7 @@ off(type: 'keyboardShow'|'keyboardHide', callback?: () => void): void on(type: 'keyDown'|'keyUp', callback: (event: KeyEvent) => boolean): void -订阅硬键盘事件,使用callback回调返回按键信息。 +订阅硬键盘事件,使用callback回调返回按键信息。参数个数为2,参数1为napi_string,参数2为napi_function,否则抛出异常。 **系统能力**: SystemCapability.MiscServices.InputMethodFramework @@ -206,8 +216,15 @@ on(type: 'keyDown'|'keyUp', callback: (event: KeyEvent) => boolean): void **示例:** ```js - KeyboardDelegate.on('keyDown', (event) => { - console.info('keyDown'); + KeyboardDelegate.on('keyUp', (keyEvent) => { + console.info("inputMethodEngine keyCode.(keyUp):" + JSON.stringify(keyEvent.keyCode)); + console.info("inputMethodEngine keyAction.(keyUp):" + JSON.stringify(keyEvent.keyAction)); + return true; + }); + KeyboardDelegate.on('keyDown', (keyEvent) => { + console.info("inputMethodEngine keyCode.(keyDown):" + JSON.stringify(keyEvent.keyCode)); + console.info("inputMethodEngine keyAction.(keyDown):" + JSON.stringify(keyEvent.keyAction)); + return true; }); ``` @@ -215,7 +232,7 @@ on(type: 'keyDown'|'keyUp', callback: (event: KeyEvent) => boolean): void off(type: 'keyDown'|'keyUp', callback?: (event: KeyEvent) => boolean): void -取消订阅硬键盘事件。 +取消订阅硬键盘事件。参数个数不为1或2抛出异常,若为1,参数不为napi_string抛出异常,若为2,参数1不为napi_string,参数2不为napi_function抛出异常。参数若为1,取消此类型所有监听,参数若为2,取消此类型当前监听。 **系统能力**: SystemCapability.MiscServices.InputMethodFramework @@ -229,14 +246,21 @@ off(type: 'keyDown'|'keyUp', callback?: (event: KeyEvent) => boolean): void **示例:** ```js - KeyboardDelegate.off('keyDown'); + KeyboardDelegate.off('keyUp', (keyEvent) => { + console.log("delete keyUp notification."); + return true; + }); + KeyboardDelegate.off('keyDown', (keyEvent) => { + console.log("delete keyDown notification."); + return true; + }); ``` ### on('cursorContextChange') on(type: 'cursorContextChange', callback: (x: number, y:number, height:number) => void): void -订阅光标变化事件,使用callback回调返回光标信息。 +订阅光标变化事件,使用callback回调返回光标信息。使用callback回调返回光标信息,使用callback回调返回按键信息。参数个数为2,参数1为napi_string,参数2为napi_function,否则抛出异常。 **系统能力**: SystemCapability.MiscServices.InputMethodFramework @@ -252,18 +276,18 @@ on(type: 'cursorContextChange', callback: (x: number, y:number, height:number) = **示例:** ```js - KeyboardDelegate.on('cursorContextChange', (x, y, height) => { - console.info('cursorContextChange'); + console.log("inputMethodEngine cursorContextChange x:" + x); + console.log("inputMethodEngine cursorContextChange y:" + y); + console.log("inputMethodEngine cursorContextChange height:" + height); }); - ``` ### off('cursorContextChange') off(type: 'cursorContextChange', callback?: (x: number, y:number, height:number) => void): void -取消订阅光标变化事件。 +取消订阅光标变化事件。参数个数不为1或2抛出异常,若为1,参数不为napi_string抛出异常,若为2,参数1不为napi_string,参数2不为napi_function抛出异常。参数若为1,取消此类型所有监听,参数若为2,取消此类型当前监听。 **系统能力**: SystemCapability.MiscServices.InputMethodFramework @@ -278,15 +302,15 @@ off(type: 'cursorContextChange', callback?: (x: number, y:number, height:number) **示例:** ```js - -KeyboardDelegate.off('cursorContextChange'); - +KeyboardDelegate.off('cursorContextChange', (x, y, height) => { + console.log("delete cursorContextChange notification."); +}); ``` ### on('selectionChange') on(type: 'selectionChange', callback: (oldBegin: number, oldEnd: number, newBegin: number, newEnd: number) => void): void -订阅文本选择变化事件,使用callback回调返回文本选择信息。 +订阅文本选择变化事件,使用callback回调返回文本选择信息,使用callback回调返回按键信息。参数个数为2,参数1为napi_string,参数2为napi_function,否则抛出异常。 **系统能力**: SystemCapability.MiscServices.InputMethodFramework @@ -300,18 +324,19 @@ on(type: 'selectionChange', callback: (oldBegin: number, oldEnd: number, newBegi **示例:** ```js - KeyboardDelegate.on('selectionChange', (oldBegin, oldEnd, newBegin, newEnd) => { - console.info('selectionChange'); + console.log("inputMethodEngine beforeEach selectionChange oldBegin:" + oldBegin); + console.log("inputMethodEngine beforeEach selectionChange oldEnd:" + oldEnd); + console.log("inputMethodEngine beforeEach selectionChange newBegin:" + newBegin); + console.log("inputMethodEngine beforeEach selectionChange newEnd:" + newEnd); }); - ``` ### off('selectionChange') off(type: 'selectionChange', callback?: (oldBegin: number, oldEnd: number, newBegin: number, newEnd: number) => void): void -取消订阅文本选择变化事件。 +取消订阅文本选择变化事件。参数个数不为1或2抛出异常,若为1,参数不为napi_string抛出异常,若为2,参数1不为napi_string,参数2不为napi_function抛出异常。参数若为1,取消此类型所有监听,参数若为2,取消此类型当前监听。 **系统能力**: SystemCapability.MiscServices.InputMethodFramework @@ -325,9 +350,9 @@ off(type: 'selectionChange', callback?: (oldBegin: number, oldEnd: number, newBe **示例:** ```js - -KeyboardDelegate.off('selectionChange'); - +KeyboardDelegate.off('selectionChange', (oldBegin, oldEnd, newBegin, newEnd) => { + console.log("delete selectionChange notification."); +}); ``` @@ -335,7 +360,7 @@ KeyboardDelegate.off('selectionChange'); on(type: 'textChange', callback: (text: string) => void): void -订阅文本变化事件,使用callback回调返回当前文本内容。 +订阅文本变化事件,使用callback回调返回当前文本内容,使用callback回调返回按键信息。参数个数为2,参数1为napi_string,参数2为napi_function,否则抛出异常。 **系统能力**: SystemCapability.MiscServices.InputMethodFramework @@ -349,18 +374,16 @@ on(type: 'textChange', callback: (text: string) => void): void **示例:** ```js - KeyboardDelegate.on('textChange', (text) => { - console.info('textChange'); + console.log("inputMethodEngine textChange. text:" + text); }); - ``` ### off('textChange') off(type: 'textChange', callback?: (text: string) => void): void -取消订阅文本变化事件。 +取消订阅文本变化事件。参数个数不为1或2抛出异常,若为1,参数不为napi_string抛出异常,若为2,参数1不为napi_string,参数2不为napi_function抛出异常。参数若为1,取消此类型所有监听,参数若为2,取消此类型当前监听。 **系统能力**: SystemCapability.MiscServices.InputMethodFramework @@ -374,7 +397,9 @@ off(type: 'textChange', callback?: (text: string) => void): void **示例:** ```js -KeyboardDelegate.off('textChange'); +keyboardDelegate.off('textChange', (text) => { + console.log("delete textChange notification. text:" + text); +}); ``` ## KeyboardController @@ -385,7 +410,7 @@ KeyboardDelegate.off('textChange'); hideKeyboard(callback: AsyncCallback<void>): void -隐藏输入法。 +隐藏输入法。使用callback形式返回结果。参数个数为1,否则抛出异常。 **系统能力**: SystemCapability.MiscServices.InputMethodFramework @@ -399,28 +424,37 @@ hideKeyboard(callback: AsyncCallback<void>): void ```js - KeyboardController.hideKeyboard(()=>{ - }); +KeyboardController.hideKeyboard((err) => { + if (err == undefined) { + console.error("hideKeyboard callback result---err: " + err.msg); + return; + } + console.log("hideKeyboard callback."); +}); ``` ### hideKeyboard hideKeyboard(): Promise<void> -隐藏输入法。 +隐藏输入法。使用peomise形式返回结果。参数个数为0,否则抛出异常。 **系统能力**: SystemCapability.MiscServices.InputMethodFramework **返回值:** -| 类型 | 说明 | -| ---------------- | -------- | -| Promise<void> | 回调函数 | +| 类型 | 说明 | +| ---------------- | ------------------------- | +| Promise<void> | 无返回结果的Promise对象。 | **示例:** ```js - KeyboardController.hideKeyboard(); +await KeyboardController.hideKeyboard().then(() => { + console.info("hideKeyboard promise."); +}).catch((err) => { + console.info("hideKeyboard promise err: " + err.msg); +}); ``` ## TextInputClient @@ -431,7 +465,7 @@ hideKeyboard(): Promise<void> getForward(length:number, callback: AsyncCallback<string>): void -获取光标前固定长度的文本。 +获取光标前固定长度的文本。使用callback形式返回结果。参数个数为2,否侧抛出异常。 **系统能力**: SystemCapability.MiscServices.InputMethodFramework @@ -445,16 +479,21 @@ getForward(length:number, callback: AsyncCallback<string>): void **示例:** ```js - TextInputClient.getForward(5,(text) =>{ - console.info("text = " + text); - }); + var length = 1; + TextInputClient.getForward(length, (err, text) => { + if (err == undefined) { + console.error("getForward callback result---err: " + err.msg); + return; + } + console.log("getForward callback result---text: " + text); + }); ``` ### getForward getForward(length:number): Promise<string> -获取光标前固定长度的文本。 +获取光标前固定长度的文本。使用promise形式返回结果。参数个数为1,否侧抛出异常。 **系统能力**: SystemCapability.MiscServices.InputMethodFramework @@ -473,15 +512,19 @@ getForward(length:number): Promise<string> **示例:** ```js - var text = TextInputClient.getForward(5); - console.info("text = " + text); + var length = 1; + await client.getForward(length).then((text) => { + console.info("getForward promise result---res: " + text); + }).catch((err) => { + console.error("getForward promise err: " + err.msg); + }); ``` ### getBackward getBackward(length:number, callback: AsyncCallback<string>): void -获取光标后固定长度的文本。 +获取光标后固定长度的文本。使用callback形式返回结果。参数个数为2,否侧抛出异常。 **系统能力**: SystemCapability.MiscServices.InputMethodFramework @@ -495,8 +538,12 @@ getBackward(length:number, callback: AsyncCallback<string>): void **示例:** ```js - TextInputClient.getBackward(5,(text)=>{ - console.info("text = " + text); + TextInputClient.getBackward(length, (err, text) => { + if (err == undefined) { + console.error("getBackward callback result---err: " + err.msg); + return; + } + console.log("getBackward callback result---text: " + text); }); ``` @@ -504,7 +551,7 @@ getBackward(length:number, callback: AsyncCallback<string>): void getBackward(length:number): Promise<string> -获取光标后固定长度的文本。 +获取光标后固定长度的文本。使用promise形式返回结果。参数个数为1,否侧抛出异常。 **系统能力**: SystemCapability.MiscServices.InputMethodFramework @@ -523,15 +570,18 @@ getBackward(length:number): Promise<string> **示例:** ```js - var text = TextInputClient.getBackward(5); - console.info("text = " + text); + await TextInputClient.getBackward(length).then((text) => { + console.info("getBackward promise result---res: " + text); + }).catch((err) => { + console.error("getBackward promise err: " + err.msg); + }); ``` ### deleteForward deleteForward(length:number, callback: AsyncCallback<boolean>): void -删除光标前固定长度的文本。 +删除光标前固定长度的文本。使用callback形式返回结果。参数个数为2,否侧抛出异常。 **系统能力**: SystemCapability.MiscServices.InputMethodFramework @@ -545,15 +595,23 @@ deleteForward(length:number, callback: AsyncCallback<boolean>): void **示例:** ```js - TextInputClient.deleteForward(5,(isSuccess)=>{ - console.info("isSuccess = " + isSuccess); + TextInputClient.deleteForward(length, (err, result) => { + if (err == undefined) { + console.error('deleteForward callback result---err: ' + err.msg); + return; + } + if (result) { + console.info("Success to deleteForward.(callback) "); + } else { + console.error("Failed to deleteForward.(callback) "); + } }); ``` ### deleteForward deleteForward(length:number): Promise<boolean> -删除光标前固定长度的文本。 +删除光标前固定长度的文本。使用promise形式返回结果。参数个数为1,否侧抛出异常。 **系统能力**: SystemCapability.MiscServices.InputMethodFramework @@ -572,15 +630,22 @@ deleteForward(length:number): Promise<boolean> **示例:** ```js -var isSuccess = TextInputClient.deleteForward(5); - console.info("isSuccess = " + isSuccess); +await TextInputClient.deleteForward(length).then((result) => { + if (result) { + console.info("Success to deleteForward.(promise) "); + } else { + console.error("Failed to deleteForward.(promise) "); + } +}).catch((err) => { + console.error("deleteForward promise err: " + err.msg); +}); ``` ### deleteBackward deleteBackward(length:number, callback: AsyncCallback<boolean>): void -删除光标后固定长度的文本。 +删除光标后固定长度的文本。使用callback形式返回结果。参数个数为2,否侧抛出异常。 **系统能力**: SystemCapability.MiscServices.InputMethodFramework @@ -594,18 +659,24 @@ deleteBackward(length:number, callback: AsyncCallback<boolean>): void **示例:** ```js - - TextInputClient.deleteBackward(5, (isSuccess)=>{ - console.info("isSuccess = " + isSuccess); +TextInputClient.deleteBackward(length, (err, result) => { + if (err == undefined) { + console.error("deleteBackward callback result---err: " + err.msg); + return; + } + if (result) { + console.info("Success to deleteBackward.(callback) "); + } else { + console.error("Failed to deleteBackward.(callback) "); + } }); - ``` ### deleteBackward deleteBackward(length:number): Promise<boolean> -删除光标后固定长度的文本。 +删除光标后固定长度的文本。使用callback形式返回结果。参数个数为2,否侧抛出异常。 **系统能力**: SystemCapability.MiscServices.InputMethodFramework @@ -623,16 +694,21 @@ deleteBackward(length:number): Promise<boolean> **示例:** ```js - - var isSuccess = TextInputClient.deleteBackward(5); - console.info("isSuccess = " + isSuccess); - +await TextInputClient.deleteBackward(length).then((result) => { + if (result) { + console.info("Success to deleteBackward.(promise) "); + } else { + console.error("Failed to deleteBackward.(promise) "); + } +}).catch((err) => { + console.error("deleteBackward promise err: " + err.msg); +}); ``` ### sendKeyFunction sendKeyFunction(action:number, callback: AsyncCallback<boolean>): void -发送功能键。 +发送功能键。使用callback形式返回结果。参数个数为2,否侧抛出异常。 **系统能力**: SystemCapability.MiscServices.InputMethodFramework @@ -646,18 +722,24 @@ sendKeyFunction(action:number, callback: AsyncCallback<boolean>): void **示例:** ```js - - TextInputClient.sendKeyFunction(inputMethod.ENTER_KEY_TYPE_NEXT,(isSuccess)=>{ - console.info("isSuccess = " + isSuccess); +TextInputClient.sendKeyFunction(keyFunction, (err, result) => { + if (err == undefined) { + console.error("sendKeyFunction callback result---err: " + err.msg); + return; + } + if (result) { + console.info("Success to sendKeyFunction.(callback) "); + } else { + console.error("Failed to sendKeyFunction.(callback) "); + } }); - ``` ### sendKeyFunction sendKeyFunction(action:number): Promise<boolean> -发送功能键。 +发送功能键。使用promise形式返回结果。参数个数为1,否侧抛出异常。 **系统能力**: SystemCapability.MiscServices.InputMethodFramework @@ -676,15 +758,22 @@ sendKeyFunction(action:number): Promise<boolean> **示例:** ```js - var isSuccess = TextInputClient.sendKeyFunction(inputMethod.ENTER_KEY_TYPE_NEXT); - console.info("isSuccess = " + isSuccess); + await client.sendKeyFunction(keyFunction).then((result) => { + if (result) { + console.info("Success to sendKeyFunction.(promise) "); + } else { + console.error("Failed to sendKeyFunction.(promise) "); + } + }).catch((err) => { + console.error("sendKeyFunction promise err:" + err.msg); + }); ``` ### insertText insertText(text:string, callback: AsyncCallback<boolean>): void -插入文本。 +插入文本。使用callback形式返回结果。参数个数为2,否侧抛出异常。 **系统能力**: SystemCapability.MiscServices.InputMethodFramework @@ -698,18 +787,24 @@ insertText(text:string, callback: AsyncCallback<boolean>): void **示例:** ```js - -TextInputClient.insertText("test", (isSuccess)=>{ - console.info("isSuccess = " + isSuccess); +TextInputClient.insertText('test', (err, result) => { + if (err == undefined) { + console.error("insertText callback result---err: " + err.msg); + return; + } + if (result) { + console.info("Success to insertText.(callback) "); + } else { + console.error("Failed to insertText.(callback) "); + } }); - ``` ### insertText insertText(text:string): Promise<boolean> -插入文本。 +插入文本。使用promise形式返回结果。参数个数为1,否侧抛出异常。 **系统能力**: SystemCapability.MiscServices.InputMethodFramework @@ -728,15 +823,22 @@ insertText(text:string): Promise<boolean> **示例:** ```js - var isSuccess = TextInputClient.insertText("test"); - console.info("isSuccess = " + isSuccess); + await TextInputClient.insertText('test').then((result) => { + if (result) { + console.info("Success to insertText.(promise) "); + } else { + console.error("Failed to insertText.(promise) "); + } + }).catch((err) => { + console.error("insertText promise err: " + err.msg); + }); ``` ### getEditorAttribute getEditorAttribute(callback: AsyncCallback<EditorAttribute>): void -获取编辑框属性值。 +获取编辑框属性值。使用callback形式返回结果。参数个数为1,否侧抛出异常。 **系统能力**: SystemCapability.MiscServices.InputMethodFramework @@ -749,15 +851,21 @@ getEditorAttribute(callback: AsyncCallback<EditorAttribute>): void **示例:** ```js - TextInputClient.getEditorAttribute((EditorAttribute)=>{ - }); + TextInputClient.getEditorAttribute((err, editorAttribute) => { + if (err == undefined) { + console.error("getEditorAttribute callback result---err: " + err.msg); + return; + } + console.log("editorAttribute.inputPattern(callback): " + JSON.stringify(editorAttribute.inputPattern)); + console.log("editorAttribute.enterKeyType(callback): " + JSON.stringify(editorAttribute.enterKeyType)); + }); ``` ### getEditorAttribute getEditorAttribute(): EditorAttribute -获取编辑框属性值。 +获取编辑框属性值。使用promise形式返回结果。参数个数为0,否侧抛出异常。 **系统能力**: SystemCapability.MiscServices.InputMethodFramework @@ -770,7 +878,12 @@ getEditorAttribute(): EditorAttribute **示例:** ```js - var EditorAttribute = TextInputClient.getEditorAttribute(); + await TextInputClient.getEditorAttribute().then((editorAttribute) => { + console.info("editorAttribute.inputPattern(promise): " + JSON.stringify(editorAttribute.inputPattern)); + console.info("editorAttribute.enterKeyType(promise): " + JSON.stringify(editorAttribute.enterKeyType)); + }).catch((err) => { + console.error("getEditorAttribute promise err: " + err.msg); + }); ``` ## EditorAttribute -- GitLab