diff --git a/en/application-dev/application-models/arkts-ui-widget-image-update.md b/en/application-dev/application-models/arkts-ui-widget-image-update.md index 00c00a744afd8422274617005a50583fef5d92ee..4862fbf747c0275d179eb4a2f988280379f2d262 100644 --- a/en/application-dev/application-models/arkts-ui-widget-image-update.md +++ b/en/application-dev/application-models/arkts-ui-widget-image-update.md @@ -4,7 +4,7 @@ Generally, local images or online images downloaded from the network need to be displayed on a widget. To obtain local and online images, use the FormExtensionAbility. The following exemplifies how to show local and online images on a widget. -1. Internet access is required for downloading online images. Therefore, you need to apply for the **ohos.permission.INTERNET** permission. For details, see[Declaring Permissions in the Configuration File](../security/accesstoken-guidelines.md). +1. Internet access is required for downloading online images. Therefore, you need to apply for the **ohos.permission.INTERNET** permission. For details, see [Declaring Permissions in the Configuration File](../security/accesstoken-guidelines.md). 2. Update local files in the **onAddForm** lifecycle callback of the EntryFormAbility. diff --git a/en/application-dev/reference/apis/js-apis-accessibility.md b/en/application-dev/reference/apis/js-apis-accessibility.md index 2aa842a8d45a8485cd098a0ba5d8f65550026d73..0b00bbfdf4c7c50ae3ffbd0d0fd1cc6effdb2f7d 100644 --- a/en/application-dev/reference/apis/js-apis-accessibility.md +++ b/en/application-dev/reference/apis/js-apis-accessibility.md @@ -370,7 +370,7 @@ Obtains the accessibility application list. This API uses a promise to return th > **NOTE** > > This API is supported since API version 7 and deprecated since API version 9. -> You are advised to use[getAccessibilityExtensionList()](#accessibilitygetaccessibilityextensionlist9). +> You are advised to use [getAccessibilityExtensionList()](#accessibilitygetaccessibilityextensionlist9). **System capability**: SystemCapability.BarrierFree.Accessibility.Core diff --git a/en/application-dev/reference/apis/js-apis-enterprise-adminManager.md b/en/application-dev/reference/apis/js-apis-enterprise-adminManager.md index d6f1383c4689aaec1a55d016f9ef1ddbacd1db9c..330a4de4c144db48f99c0afd2848a9f4dd1fea77 100644 --- a/en/application-dev/reference/apis/js-apis-enterprise-adminManager.md +++ b/en/application-dev/reference/apis/js-apis-enterprise-adminManager.md @@ -54,7 +54,7 @@ let enterpriseInfo = { name: "enterprise name", description: "enterprise description" } -adminManager.enableAdmin(wantTemp, enterpriseInfo, adminManager.AdminType.ADMIN_TYPE_NORMAL, error => { +adminManager.enableAdmin(wantTemp, enterpriseInfo, adminManager.AdminType.ADMIN_TYPE_SUPER, error => { if (error != null) { console.log("error occurs" + error); return; @@ -955,5 +955,5 @@ Enumerates the system management events that can be subscribed to. | -------------------------- | ---- | ------------- | | MANAGED_EVENT_BUNDLE_ADDED | 0 | Bundle added.| | MANAGED_EVENT_BUNDLE_REMOVED | 1 | Bundle removed.| -| MANAGED_EVENT_APP_START | 2 | Application started.| -| MANAGED_EVENT_APP_STOP | 3 | Application stopped.| +| MANAGED_EVENT_APP_START10+ | 2 | Application started.| +| MANAGED_EVENT_APP_STOP10+ | 3 | Application stopped.| diff --git a/en/application-dev/reference/apis/js-apis-inputmethod-InputMethodCommon.md b/en/application-dev/reference/apis/js-apis-inputmethod-InputMethodCommon.md deleted file mode 100644 index ed0c80507f40597592206e195dd6780de7133401..0000000000000000000000000000000000000000 --- a/en/application-dev/reference/apis/js-apis-inputmethod-InputMethodCommon.md +++ /dev/null @@ -1,41 +0,0 @@ -# InputMethodCommon - -> **NOTE** -> -> The initial APIs of this module are supported since API version 10. Newly added APIs will be marked with a superscript to indicate their earliest API version. - -The **InputMethodCommon** module provides the common attributes defined by the input method framework. - -## Direction - -Enumerates the directions of cursor movement. - - **System capability**: SystemCapability.MiscServices.InputMethodFramework - -| Name | Value | Description | -| ------------ | ---- | ---------- | -| CURSOR_UP | 1 | The cursor moves upward.| -| CURSOR_DOWN | 2 | The cursor moves downward.| -| CURSOR_LEFT | 3 | The caret moves leftward.| -| CURSOR_RIGHT | 4 | The caret moves rightward.| - -## Range - -Describes the range of the selected text. - - **System capability**: SystemCapability.MiscServices.InputMethodFramework - -| Name | Type | Readable| Writable| Description | -| ----- | ------ | ---- | ---- | ---------------------------------- | -| start | number | Yes | Yes | Index of the first selected character in the text box.| -| end | number | Yes | Yes | Index of the last selected character in the text box.| - -## Movement - -Describes the direction in which the cursor moves when the text is selected. - - **System capability**: SystemCapability.MiscServices.InputMethodFramework - -| Name | Type | Readable| Writable| Description | -| --------- | ----------------------- | ---- | ---- | ---------------------------------- | -| direction | [Direction](#direction) | Yes | Yes | Direction in which the cursor moves when the text is selected.| diff --git a/en/application-dev/reference/apis/js-apis-inputmethod-extension-ability.md b/en/application-dev/reference/apis/js-apis-inputmethod-extension-ability.md index a61dd42ece2d52f0da53dd51f33770483b37757e..7f2230493ad977a556e29318466184bab6868a94 100644 --- a/en/application-dev/reference/apis/js-apis-inputmethod-extension-ability.md +++ b/en/application-dev/reference/apis/js-apis-inputmethod-extension-ability.md @@ -38,9 +38,9 @@ Called when the **InputMethodExtension** ability is started to implement initial ```js class InputMethodExt extends InputMethodExtensionAbility { - onCreate(want) { - console.log('onCreate, want:' + want.abilityName); - } + onCreate(want) { + console.log('onCreate, want:' + want.abilityName); + } } ``` @@ -56,8 +56,8 @@ Called when this **InputMethodExtension** ability is destroyed to clear resource ```js class InputMethodExt extends InputMethodExtensionAbility { - onDestroy() { - console.log('onDestroy'); - } + onDestroy() { + console.log('onDestroy'); + } } ``` diff --git a/en/application-dev/reference/apis/js-apis-inputmethod-extension-context.md b/en/application-dev/reference/apis/js-apis-inputmethod-extension-context.md index d9d1bb857067e3f9482f564968e8107dc13db010..0033c3560fd0d00728f9a95e981df6ef4f9165dd 100644 --- a/en/application-dev/reference/apis/js-apis-inputmethod-extension-context.md +++ b/en/application-dev/reference/apis/js-apis-inputmethod-extension-context.md @@ -21,9 +21,9 @@ Before using the **InputMethodExtensionContext** module, you must define a child ```js import InputMethodExtensionAbility from '@ohos.InputMethodExtensionAbility'; class EntryAbility extends InputMethodExtensionAbility { - onCreate() { - let context = this.context; - } + onCreate() { + let context = this.context; + } } ``` @@ -44,8 +44,8 @@ Terminates this ability. This API uses an asynchronous callback to return the re **Example** ```js -this.context.destroy((err) => { - console.log('destroy result:' + JSON.stringify(err)); +this.context.destroy(() => { + console.log('Succeeded in destroying context.'); }); ``` @@ -67,8 +67,6 @@ Terminates this ability. This API uses a promise to return the result. ```js this.context.destroy().then(() => { - console.log('Succeeded in destroying context.'); -}).catch((error) => { - console.log('Failed to destroy context: ' + JSON.stringify(error)); + console.log('Succeed in destroying context.'); }); ``` diff --git a/en/application-dev/reference/apis/js-apis-inputmethod.md b/en/application-dev/reference/apis/js-apis-inputmethod.md index f6f1cf9ca6cf7a77d9e55c7ce329d81cbef1dc7f..a9da8c45a00184fad7554b021bd1497d9b4f4645 100644 --- a/en/application-dev/reference/apis/js-apis-inputmethod.md +++ b/en/application-dev/reference/apis/js-apis-inputmethod.md @@ -31,13 +31,13 @@ Describes the input method application attributes. | Name| Type| Readable| Writable| Description| | -------- | -------- | -------- | -------- | -------- | -| name9+ | string | Yes| No| Internal name of the input method. Mandatory.| -| id9+ | string | Yes| No| Unique ID of the input method. Mandatory.| -| label9+ | string | Yes| No| External name of the input method. Optional.| -| labelId10+ | string | Yes| No| External ID of the input method. Optional.| -| icon9+ | string | Yes| No| Icon of the input method. Optional.| -| iconId9+ | number | Yes| No| Icon ID of the input method. Optional.| -| extra9+ | object | Yes| Yes| Extra information about the input method. Optional.
**NOTE**
This parameter is optional since API version 10.| +| name9+ | string | Yes| No| Mandatory. Internal name of the input method.| +| id9+ | string | Yes| No| Mandatory. Unique ID of the input method.| +| label9+ | string | Yes| No| Optional. External name of the input method.| +| labelId10+ | string | Yes| No| Optional. External ID of the input method.| +| icon9+ | string | Yes| No| Optional. Icon of the input method.| +| iconId9+ | number | Yes| No| Optional. Icon ID of the input method.| +| extra9+ | object | Yes| Yes| Extra information about the input method.
- API version 10 and later: optional
- API version 9: mandatory| | packageName(deprecated) | string | Yes| No| Name of the input method package. Mandatory.
**NOTE**
This API is supported since API version 8 and deprecated since API version 9. You are advised to use **name**.| | methodId(deprecated) | string | Yes| No| Unique ID of the input method. Mandatory.
**NOTE**
This API is supported since API version 8 and deprecated since API version 9. You are advised to use **id**.| @@ -61,7 +61,7 @@ For details about the error codes, see [Input Method Framework Error Codes](../e | Error Code ID| Error Message | | -------- | ------------------------------ | -| 12800006 | Input method controller error. | +| 12800006 | input method controller error. | **Example** @@ -89,7 +89,7 @@ For details about the error codes, see [Input Method Framework Error Codes](../e | Error Code ID| Error Message | | -------- | -------------------------------------- | -| 12800007 | Input method settings extension error. | +| 12800007 | settings extension error. | **Example** @@ -103,7 +103,7 @@ switchInputMethod(target: InputMethodProperty, callback: AsyncCallback<boolea Switches to another input method. This API uses an asynchronous callback to return the result. -**Required permissions**: ohos.permission.CONNECT_IME_ABILITY (available only to system applications) +**Required permissions**: ohos.permission.CONNECT_IME_ABILITY (for system applications only) **System capability**: SystemCapability.MiscServices.InputMethodFramework @@ -120,34 +120,27 @@ For details about the error codes, see [Input Method Framework Error Codes](../e | Error Code ID| Error Message | | -------- | -------------------------------------- | -| 12800005 | Configuration persisting error. | -| 12800008 | Input method manager service error. | +| 12800005 | configuration persisting error. | +| 12800008 | input method manager service error. | **Example** ```js -let im = inputMethod.getCurrentInputMethod(); -let prop = { - packageName: im.packageName, - methodId: im.methodId, - name: im.packageName, - id: im.methodId, - extra: {} -} +let currentIme = inputMethod.getCurrentInputMethod(); try{ - inputMethod.switchInputMethod(prop, (err, result) => { - if (err !== undefined) { - console.error('Failed to switchInputMethod: ' + JSON.stringify(err)); - return; - } - if (result) { - console.info('Succeeded in switching inputmethod.'); - } else { - console.error('Failed to switchInputMethod.'); - } - }); + inputMethod.switchInputMethod(currentIme, (err, result) => { + if (err) { + console.error(`Failed to switchInputMethod: ${JSON.stringify(err)}`); + return; + } + if (result) { + console.log('Succeeded in switching inputmethod.'); + } else { + console.error('Failed to switchInputMethod.'); + } + }); } catch(err) { - console.error('Failed to switchInputMethod: ' + JSON.stringify(err)); + console.error(`Failed to switchInputMethod: ${JSON.stringify(err)}`); } ``` ## inputMethod.switchInputMethod9+ @@ -155,7 +148,7 @@ switchInputMethod(target: InputMethodProperty): Promise<boolean> Switches to another input method. This API uses a promise to return the result. -**Required permissions**: ohos.permission.CONNECT_IME_ABILITY (available only to system applications) +**Required permissions**: ohos.permission.CONNECT_IME_ABILITY (for system applications only) **System capability**: SystemCapability.MiscServices.InputMethodFramework @@ -177,32 +170,25 @@ For details about the error codes, see [Input Method Framework Error Codes](../e | Error Code ID| Error Message | | -------- | -------------------------------------- | -| 12800005 | Configuration persisting error. | -| 12800008 | Input method manager service error. | +| 12800005 | configuration persisting error. | +| 12800008 | input method manager service error. | **Example** ```js -let im = inputMethod.getCurrentInputMethod(); -let prop = { - packageName: im.packageName, - methodId: im.methodId, - name: im.packageName, - id: im.methodId, - extra: {} -} +let currentIme = inputMethod.getCurrentInputMethod(); try { - inputMethod.switchInputMethod(prop).then((result) => { - if (result) { - console.info('Succeeded in switching inputmethod.'); - } else { - console.error('Failed to switchInputMethod.'); - } - }).catch((err) => { - console.error('Failed to switchInputMethod: ' + JSON.stringify(err)); - }) + inputMethod.switchInputMethod(currentIme).then((result) => { + if (result) { + console.log('Succeeded in switching inputmethod.'); + } else { + console.error('Failed to switchInputMethod.'); + } + }).catch((err) => { + console.error(`Failed to switchInputMethod: ${JSON.stringify(err)}`); + }) } catch(err) { - console.error('Failed to switchInputMethod: ' + JSON.stringify(err)); + console.error(`Failed to switchInputMethod: ${JSON.stringify(err)}`); } ``` @@ -232,7 +218,7 @@ switchCurrentInputMethodSubtype(target: InputMethodSubtype, callback: AsyncCallb Switches to another subtype of the current input method. This API uses an asynchronous callback to return the result. -**Required permissions**: ohos.permission.CONNECT_IME_ABILITY (available only to system applications)
**NOTE**
Since API version 10, this permission is not required if the caller is the current input method. +**Required permissions**: ohos.permission.CONNECT_IME_ABILITY
**NOTE**
- API version 10 and later: This API can be called by system applications and the current input method application.
- API version 9: This API can be called by system applications only. **System capability**: SystemCapability.MiscServices.InputMethodFramework @@ -249,36 +235,36 @@ For details about the error codes, see [Input Method Framework Error Codes](../e | Error Code ID| Error Message | | -------- | -------------------------------------- | -| 12800005 | Configuration persisting error. | -| 12800008 | Input method manager service error. | +| 12800005 | configuration persisting error. | +| 12800008 | input method manager service error. | **Example** ```js try { - inputMethod.switchCurrentInputMethodSubtype({ - id: "ServiceExtAbility", - label: "", - name: "com.example.kikakeyboard", - mode: "upper", - locale: "", - language: "", - icon: "", - iconId: 0, - extra: {} - }, (err, result) => { - if (err !== undefined) { - console.error('Failed to switchCurrentInputMethodSubtype: ' + JSON.stringify(err)); - return; - } - if (result) { - console.info('Succeeded in switching currentInputMethodSubtype.'); - } else { - console.error('Failed to switchCurrentInputMethodSubtype'); - } - }); + inputMethod.switchCurrentInputMethodSubtype({ + id: "ServiceExtAbility", + label: "", + name: "com.example.kikakeyboard", + mode: "upper", + locale: "", + language: "", + icon: "", + iconId: 0, + extra: {} + }, (err, result) => { + if (err) { + console.error(`Failed to switchCurrentInputMethodSubtype: ${JSON.stringify(err)}`); + return; + } + if (result) { + console.log('Succeeded in switching currentInputMethodSubtype.'); + } else { + console.error('Failed to switchCurrentInputMethodSubtype'); + } + }); } catch(err) { - console.error('Failed to switchCurrentInputMethodSubtype: ' + JSON.stringify(err)); + console.error(`Failed to switchCurrentInputMethodSubtype: ${JSON.stringify(err)}`); } ``` @@ -288,7 +274,7 @@ switchCurrentInputMethodSubtype(target: InputMethodSubtype): Promise<boolean& Switches to another subtype of the current input method. This API uses a promise to return the result. -**Required permissions**: ohos.permission.CONNECT_IME_ABILITY (available only to system applications)
**NOTE**
Since API version 10, this permission is not required if the caller is the current input method. +**Required permissions**: ohos.permission.CONNECT_IME_ABILITY
**NOTE**
- API version 10 and later: This API can be called by system applications and the current input method application.
- API version 9: This API can be called by system applications only. **System capability**: SystemCapability.MiscServices.InputMethodFramework @@ -310,34 +296,34 @@ For details about the error codes, see [Input Method Framework Error Codes](../e | Error Code ID| Error Message | | -------- | -------------------------------------- | -| 12800005 | Configuration persisting error. | -| 12800008 | Input method manager service error. | +| 12800005 | configuration persisting error. | +| 12800008 | input method manager service error. | **Example** ```js try { - inputMethod.switchCurrentInputMethodSubtype({ - id: "ServiceExtAbility", - label: "", - name: "com.example.kikakeyboard", - mode: "upper", - locale: "", - language: "", - icon: "", - iconId: 0, - extra: {} - }).then((result) => { - if (result) { - console.info('Succeeded in switching currentInputMethodSubtype.'); - } else { - console.error('Failed to switchCurrentInputMethodSubtype.'); - } - }).catch((err) => { - console.error('Failed to switchCurrentInputMethodSubtype: ' + JSON.stringify(err)); - }) + inputMethod.switchCurrentInputMethodSubtype({ + id: "ServiceExtAbility", + label: "", + name: "com.example.kikakeyboard", + mode: "upper", + locale: "", + language: "", + icon: "", + iconId: 0, + extra: {} + }).then((result) => { + if (result) { + console.log('Succeeded in switching currentInputMethodSubtype.'); + } else { + console.error('Failed to switchCurrentInputMethodSubtype.'); + } + }).catch((err) => { + console.error(`Failed to switchCurrentInputMethodSubtype: ${JSON.stringify(err)}`); + }) } catch(err) { - console.error('Failed to switchCurrentInputMethodSubtype: ' + JSON.stringify(err)); + console.error(`Failed to switchCurrentInputMethodSubtype: ${JSON.stringify(err)}`); } ``` @@ -365,19 +351,1306 @@ let currentImeSubType = inputMethod.getCurrentInputMethodSubtype(); switchCurrentInputMethodAndSubtype(inputMethodProperty: InputMethodProperty, inputMethodSubtype: InputMethodSubtype, callback: AsyncCallback\): void -Switches to a specified subtype of a specified input method. This API uses an asynchronous callback to return the result. +Switches to a specified subtype of a specified input method. This API uses an asynchronous callback to return the result. + +**Required permissions**: ohos.permission.CONNECT_IME_ABILITY (for system applications only) + +**System capability**: SystemCapability.MiscServices.InputMethodFramework + +**Parameters** + +| Name| Type| Mandatory| Description| +| -------- | -------- | -------- | -------- | +|inputMethodProperty | [InputMethodProperty](#inputmethodproperty8)| Yes| Input method to switch to.| +|inputMethodSubtype | [InputMethodSubtype](./js-apis-inputmethod-subtype.md)| Yes| Input method subtype to switch to.| +| callback | AsyncCallback<boolean> | Yes| Callback used to return the result. If the operation is successful, **err** is **undefined** and **data** is **true**. Otherwise, **err** is an error object.| + +**Error codes** + +For details about the error codes, see [Input Method Framework Error Codes](../errorcodes/errorcode-inputmethod-framework.md). + +| Error Code ID| Error Message | +| -------- | -------------------------------------- | +| 12800005 | configuration persisting error. | +| 12800008 | input method manager service error. | + +**Example** + +```js +let currentIme = inputMethod.getCurrentInputMethod(); +let imSubType = inputMethod.getCurrentInputMethodSubtype(); +try { + inputMethod.switchCurrentInputMethodAndSubtype(currentIme, imSubType, (err,result) => { + if (err) { + console.error(`Failed to switchCurrentInputMethodAndSubtype: ${JSON.stringify(err)}`); + return; + } + if (result) { + console.log('Succeeded in switching currentInputMethodAndSubtype.'); + } else { + console.error('Failed to switchCurrentInputMethodAndSubtype.'); + } + }); +} catch (err) { + console.error(`Failed to switchCurrentInputMethodAndSubtype: ${JSON.stringify(err)}`); +} +``` + +## inputMethod.switchCurrentInputMethodAndSubtype9+ + +switchCurrentInputMethodAndSubtype(inputMethodProperty: InputMethodProperty, inputMethodSubtype: InputMethodSubtype): Promise<boolean> + +Switches to a specified subtype of a specified input method. This API uses a promise to return the result. + +**Required permissions**: ohos.permission.CONNECT_IME_ABILITY (for system applications only) + +**System capability**: SystemCapability.MiscServices.InputMethodFramework + +**Parameters** + +| Name| Type| Mandatory| Description| +| -------- | -------- | -------- | -------- | +|inputMethodProperty | [InputMethodProperty](#inputmethodproperty8)| Yes| Input method to switch to.| +|inputMethodSubtype | [InputMethodSubtype](./js-apis-inputmethod-subtype.md)| Yes| Input method subtype to switch to.| + +**Return value** + +| Type | Description | +| ----------------------------------------- | ---------------------------- | +| Promise\ | Promise used to return the result. The value **true** means that the switching is successful, and **false** means the opposite.| + +**Error codes** + +For details about the error codes, see [Input Method Framework Error Codes](../errorcodes/errorcode-inputmethod-framework.md). + +| Error Code ID| Error Message | +| -------- | -------------------------------------- | +| 12800005 | configuration persisting error. | +| 12800008 | input method manager service error. | + +**Example** + +```js +let currentIme = inputMethod.getCurrentInputMethod(); +let imSubType = inputMethod.getCurrentInputMethodSubtype(); +try { + inputMethod.switchCurrentInputMethodAndSubtype(currentIme, imSubType).then((result) => { + if (result) { + console.log('Succeeded in switching currentInputMethodAndSubtype.'); + } else { + console.error('Failed to switchCurrentInputMethodAndSubtype.'); + } + }).catch((err) => { + console.error(`Failed to switchCurrentInputMethodAndSubtype: ${JSON.stringify(err)}`); + }) +} catch(err) { + console.error(`Failed to switchCurrentInputMethodAndSubtype: ${JSON.stringify(err)}`); +} +``` + +## inputMethod.getInputMethodController(deprecated) + +getInputMethodController(): InputMethodController + +Obtains an **[InputMethodController](#inputmethodcontroller)** instance. + +> **NOTE** +> +> This API is supported since API version 6 and deprecated since API version 9. You are advised to use [getController()](#inputmethodgetcontroller9) instead. + +**System capability**: SystemCapability.MiscServices.InputMethodFramework + +**Return value** + +| Type | Description | +| ----------------------------------------------- | ------------------------ | +| [InputMethodController](#inputmethodcontroller) | Current **InputMethodController** instance.| + +**Example** + +```js +let inputMethodController = inputMethod.getInputMethodController(); +``` + +## inputMethod.getInputMethodSetting(deprecated) + +getInputMethodSetting(): InputMethodSetting + +Obtains an **[InputMethodSetting](#inputmethodsetting8)** instance. + +> **NOTE** +> +> This API is supported since API version 6 and deprecated since API version 9. You are advised to use [getSetting()](#inputmethodgetsetting9) instead. + +**System capability**: SystemCapability.MiscServices.InputMethodFramework + +**Return value** + +| Type | Description | +| ----------------------------------------- | ---------------------------- | +| [InputMethodSetting](#inputmethodsetting8) | Current **InputMethodSetting** instance.| + +**Example** + +```js +let inputMethodSetting = inputMethod.getInputMethodSetting(); +``` + +## TextInputType10+ + +Enumerates the text input types. + +**System capability**: SystemCapability.MiscServices.InputMethodFramework + +| Name| Value|Description| +| -------- | -------- |-------- | +| NONE | -1 |None.| +| TEXT | 0 |Text.| +| MULTILINE | 1 |Multi-line.| +| NUMBER | 2 |Number.| +| PHONE | 3 |Phone number.| +| DATETIME | 4 |Date.| +| EMAIL_ADDRESS | 5 |Email address.| +| URL | 6 |URL.| +| VISIBLE_PASSWORD | 7 |Password.| + +## EnterKeyType10+ + +Enumerates the function types represented by the Enter key of the input method. + +**System capability**: SystemCapability.MiscServices.InputMethodFramework + +| Name| Value|Description| +| -------- | -------- |-------- | +| UNSPECIFIED | 0 |Not specified.| +| NONE | 1 |None.| +| GO | 2 |Go.| +| SEARCH | 3 |Search.| +| SEND | 4 |Send.| +| NEXT | 5 |Next.| +| DONE | 6 |Done.| +| PREVIOUS | 7 |Previous.| + +## KeyboardStatus10+ + +Enumerates the soft keyboard states of the input method. + +**System capability**: SystemCapability.MiscServices.InputMethodFramework + +| Name| Value|Description| +| -------- | -------- |-------- | +| NONE | 0 |None.| +| HIDE | 1 |Hidden.| +| SHOW | 2 |Shown.| + +## Direction10+ + +Enumerates the directions of cursor movement of the input method. + +**System capability**: SystemCapability.MiscServices.InputMethodFramework + +| Name| Value|Description| +| -------- | -------- |-------- | +| CURSOR_UP | 1 |Upward.| +| CURSOR_DOWN | 2 |Downward.| +| CURSOR_LEFT | 3 |Leftward.| +| CURSOR_RIGHT | 4 |Rightward.| + +## ExtendAction10+ + +Describes the type of the extended edit action on the text box. + +**System capability**: SystemCapability.MiscServices.InputMethodFramework + +| Name| Value|Description| +| -------- | -------- |-------- | +| SELECT_ALL | 0 |Select all.| +| CUT | 3 |Cut.| +| COPY | 4 |Copy.| +| PASTE | 5 |Paste.| + +## FunctionKey10+ + +Describes the type of the input method function key. + +**System capability**: SystemCapability.MiscServices.InputMethodFramework + +| Name| Type| Readable| Writable| Description| +| -------- | -------- | -------- | -------- | -------- | +| enterKeyType10+ | [EnterKeyType](#enterkeytype10) | Yes| Yes| Function type represented by the Enter key of the input method.| + +## InputAttribute10+ + +Describes the attributes of the edit box, including the text input type and Enter key function type. + +**System capability**: SystemCapability.MiscServices.InputMethodFramework + +| Name| Type| Readable| Writable| Description| +| -------- | -------- | -------- | -------- | -------- | +| textInputType10+ | [TextInputType](#textinputtype10) | Yes| Yes| Enumerates the text input types.| +| enterKeyType10+ | [EnterKeyType](#enterkeytype10) | Yes| Yes| Function type represented by the Enter key.| + +## TextConfig10+ + +Describes the configuration of the editor component. When the editor component requests to bind the input method, this parameter is transferred to save the configuration of the editor component to the input method framework. + +**System capability**: SystemCapability.MiscServices.InputMethodFramework + +| Name| Type| Readable| Writable| Description| +| -------- | -------- | -------- | -------- | -------- | +| inputAttribute10+ | [InputAttribute](#inputattribute10) | Yes| Yes| Edit box attribute.| + +## CursorInfo10+ + +Describes the cursor information. + +**System capability**: SystemCapability.MiscServices.InputMethodFramework + +| Name| Type| Readable| Writable| Description| +| -------- | -------- | -------- | -------- | -------- | +| left | number | Yes| Yes| Left coordinate of the cursor.| +| top | number | Yes| Yes| Top coordinate of the cursor.| +| width | number | Yes| Yes| Width of the cursor.| +| height | number | Yes| Yes| Height of the cursor.| + +## Range10+ + +Describes the range of the selected text. + +**System capability**: SystemCapability.MiscServices.InputMethodFramework + +| Name| Type| Readable| Writable| Description| +| -------- | -------- | -------- | -------- | -------- | +| start | number | Yes| Yes| Index of the first selected character in the text box.| +| end | number | Yes| Yes| Index of the last selected character in the text box.| + +## Movement10+ + +Describes the direction in which the cursor moves when the text is selected. + +**System capability**: SystemCapability.MiscServices.InputMethodFramework + +| Name| Type| Readable| Writable| Description| +| -------- | -------- | -------- | -------- | -------- | +| direction | [Direction](#direction10) | Yes| Yes| Direction in which the cursor moves when the text is selected.| + +## InputWindowInfo10+ + +Describes the window information of the input method keyboard. + +**System capability**: SystemCapability.MiscServices.InputMethodFramework + +| Name| Type| Readable| Writable| Description| +| -------- | -------- | -------- | -------- | -------- | +| name | string | Yes| Yes| Name of the input method keyboard window.| +| left | number | Yes| Yes| Horizontal coordinate of the upper left corner of the input method keyboard window, in px.| +| top | number | Yes| Yes| Vertical coordinate of the upper left corner of the input method keyboard window, in px.| +| width | number | Yes| Yes| Width of the input method keyboard window, in px.| +| height | number | Yes| Yes| Height of the input method keyboard window, in px.| + +## InputMethodController + +In the following API examples, you must first use [getController](#inputmethodgetcontroller9) to obtain an **InputMethodController** instance, and then call the APIs using the obtained instance. + +### attach10+ + +attach(showKeyboard: boolean, textConfig: TextConfig, callback: AsyncCallback<void>): void + +Attaches a self-drawing component to the input method. This API uses an asynchronous callback to return the result. + +An input method can use the features provided by the input method framework only when it has a self-drawing component attached to it. + +**System capability**: SystemCapability.MiscServices.InputMethodFramework + +**Parameters** + +| Name| Type| Mandatory| Description| +| -------- | -------- | -------- | -------- | +| showKeyboard | boolean | Yes| Whether to start the input method keyboard after the self-drawing component is attached to the input method.| +| textConfig | [TextConfig](#textconfig10) | Yes| Configuration of the editor component.| +| callback | AsyncCallback<void> | Yes| Callback used to return the result. If the operation is successful, **err** is **undefined**. Otherwise, **err** is an error object.| + +**Error codes** + +For details about the error codes, see [Input Method Framework Error Codes](../errorcodes/errorcode-inputmethod-framework.md). + +| Error Code ID| Error Message | +| -------- | -------------------------------------- | +| 12800003 | input method client error. | +| 12800008 | input method manager service error. | + +**Example** + +```js +try { + let textConfig: inputMethod.TextConfig = { + inputAttribute: { + textInputType: 0, + enterKeyType: 1 + } + }; + inputMethodController.attach(true, textConfig, (err) => { + if (err) { + console.error(`Failed to attach: ${JSON.stringify(err)}`); + return; + } + console.log('Succeeded in attaching the inputMethod.'); + }); +} catch(err) { + console.error(`Failed to attach: ${JSON.stringify(err)}`); +} +``` + +### attach10+ + +attach(showKeyboard: boolean, textConfig: TextConfig): Promise<void> + +Attaches a self-drawing component to the input method. This API uses an asynchronous callback to return the result. + +An input method can use the features provided by the input method framework only when it has a self-drawing component attached to it. + +**System capability**: SystemCapability.MiscServices.InputMethodFramework + +**Parameters** + +| Name| Type| Mandatory| Description| +| -------- | -------- | -------- | -------- | +| showKeyboard | boolean | Yes| Whether to start the input method keyboard after the self-drawing component is attached to the input method.| +| textConfig | [TextConfig](#textconfig10) | Yes| Edit box attribute.| + +**Return value** + +| Type| Description| +| -------- | -------- | +| Promise<void> | Promise that returns no value.| + +**Error codes** + +For details about the error codes, see [Input Method Framework Error Codes](../errorcodes/errorcode-inputmethod-framework.md). + +| Error Code ID| Error Message | +| -------- | -------------------------------------- | +| 12800003 | input method client error. | +| 12800008 | input method manager service error. | + +**Example** + +```js +try { + let textConfig: inputMethod.TextConfig = { + inputAttribute: { + textInputType: 0, + enterKeyType: 1 + } + }; + inputMethodController.attach(true, textConfig).then(() => { + console.log('Succeeded in attaching inputMethod.'); + }).catch((err) => { + console.error(`Failed to attach: ${JSON.stringify(err)}`); + }) +} catch(err) { + console.error(`Failed to attach: ${JSON.stringify(err)}`); +} +``` + +### showTextInput10+ + +showTextInput(callback: AsyncCallback<void>): void + +Enters the text editing mode. This API uses an asynchronous callback to return the result. + +This API can be called to start the soft keyboard after the editor component is attached to the input method. + +**System capability**: SystemCapability.MiscServices.InputMethodFramework + +**Parameters** + +| Name| Type| Mandatory| Description| +| -------- | -------- | -------- | -------- | +| callback | AsyncCallback<void> | Yes| Callback used to return the result. If the operation is successful, **err** is **undefined**. Otherwise, **err** is an error object.| + +**Error codes** + +For details about the error codes, see [Input Method Framework Error Codes](../errorcodes/errorcode-inputmethod-framework.md). + +| Error Code ID| Error Message | +| -------- | -------------------------------------- | +| 12800003 | input method client error. | +| 12800008 | input method manager service error. | +| 12800009 | input method client is detached. | + +**Example** + +```js +inputMethodController.showTextInput((err) => { + if (err) { + console.error(`Failed to showTextInput: ${JSON.stringify(err)}`); + return; + } + console.log('Succeeded in showing the inputMethod.'); +}); +``` + +### showTextInput10+ + +showTextInput(): Promise<void> + +Enters the text editing mode. This API uses a promise to return the result. + +This API can be called to start the soft keyboard after the editor component is bound to the input method. + +**System capability**: SystemCapability.MiscServices.InputMethodFramework + +**Return value** + +| Type| Description| +| -------- | -------- | +| Promise<void> | Promise that returns no value.| + +**Error codes** + +For details about the error codes, see [Input Method Framework Error Codes](../errorcodes/errorcode-inputmethod-framework.md). + +| Error Code ID| Error Message | +| -------- | -------------------------------------- | +| 12800003 | input method client error. | +| 12800008 | input method manager service error. | +| 12800009 | input method client is detached. | + +**Example** + +```js +inputMethodController.showTextInput().then(() => { + console.log('Succeeded in showing text input.'); +}).catch((err) => { + console.error(`Failed to showTextInput: ${JSON.stringify(err)}`); +}); +``` + +### hideTextInput10+ + +hideTextInput(callback: AsyncCallback<void>): void + +Exits the text editing mode. This API uses an asynchronous callback to return the result. + +The editor component can call this API to exit the text editing mode. If the soft keyboard is displayed when this API is called, it will be hidden. + +Calling this API does not detach the editor component from the input method. The editor component can call [showTextInput](#showtextinput10) again to reenter the text editing mode. + +**System capability**: SystemCapability.MiscServices.InputMethodFramework + +**Parameters** + +| Name| Type| Mandatory| Description| +| -------- | -------- | -------- | -------- | +| callback | AsyncCallback<void> | Yes| Callback used to return the result. If the operation is successful, **err** is **undefined**. Otherwise, **err** is an error object.| + +**Error codes** + +For details about the error codes, see [Input Method Framework Error Codes](../errorcodes/errorcode-inputmethod-framework.md). + +| Error Code ID| Error Message | +| -------- | -------------------------------------- | +| 12800003 | input method client error. | +| 12800008 | input method manager service error. | +| 12800009 | input method client is detached. | + +**Example** + +```js +inputMethodController.hideTextInput((err) => { + if (err) { + console.error(`Failed to hideTextInput: ${JSON.stringify(err)}`); + return; + } + console.log('Succeeded in hiding text input.'); +}); +``` + +### hideTextInput10+ + +hideTextInput(): Promise<void> + +Exits the text editing mode. This API uses a promise to return the result. + +The editor component can call this API to exit the text editing mode. If the soft keyboard is displayed when this API is called, it will be hidden. + +Calling this API does not detach the editor component from the input method. The editor component can call [showTextInput](#showtextinput10) again to reenter the text editing mode. + +**System capability**: SystemCapability.MiscServices.InputMethodFramework + +**Return value** + +| Type| Description| +| -------- | -------- | +| Promise<void> | Promise that returns no value.| + +**Error codes** + +For details about the error codes, see [Input Method Framework Error Codes](../errorcodes/errorcode-inputmethod-framework.md). + +| Error Code ID| Error Message | +| -------- | -------------------------------------- | +| 12800003 | input method client error. | +| 12800008 | input method manager service error. | +| 12800009 | input method client is detached. | + +**Example** + +```js +inputMethodController.hideTextInput().then(() => { + console.log('Succeeded in hiding inputMethod.'); +}).catch((err) => { + console.error(`Failed to hideTextInput: ${JSON.stringify(err)}`); +}) +``` + +### detach10+ + +detach(callback: AsyncCallback<void>): void + +Detaches from the input method. This API uses an asynchronous callback to return the result. + +**System capability**: SystemCapability.MiscServices.InputMethodFramework + +**Parameters** + +| Name| Type| Mandatory| Description| +| -------- | -------- | -------- | -------- | +| callback | AsyncCallback<void> | Yes| Callback used to return the result. If the operation is successful, **err** is **undefined**. Otherwise, **err** is an error object.| + +**Error codes** + +For details about the error codes, see [Input Method Framework Error Codes](../errorcodes/errorcode-inputmethod-framework.md). + +| Error Code ID| Error Message | +| -------- | -------------------------------------- | +| 12800003 | input method client error. | +| 12800008 | input method manager service error. | + +**Example** + +```js +inputMethodController.detach((err) => { + if (err) { + console.error(`Failed to detach: ${JSON.stringify(err)}`); + return; + } + console.log('Succeeded in detaching inputMethod.'); +}); +``` + +### detach10+ + +detach(): Promise<void> + +Detaches from the input method. This API uses a promise to return the result. + +**System capability**: SystemCapability.MiscServices.InputMethodFramework + +**Return value** + +| Type| Description| +| -------- | -------- | +| Promise<void> | Promise that returns no value.| + +**Error codes** + +For details about the error codes, see [Input Method Framework Error Codes](../errorcodes/errorcode-inputmethod-framework.md). + +| Error Code ID| Error Message | +| -------- | -------------------------------------- | +| 12800003 | input method client error. | +| 12800008 | input method manager service error. | + +**Example** + +```js +inputMethodController.detach().then(() => { + console.log('Succeeded in detaching inputMethod.'); +}).catch((err) => { + console.error(`Failed to detach: ${JSON.stringify(err)}`); +}); +``` + +### setCallingWindow10+ + +setCallingWindow(windowId: number, callback: AsyncCallback<void>): void + +Sets the window to be avoided by the input method. This API uses an asynchronous callback to return the result. + +After the window ID of the application bound to the input method is passed in the API, the input method window will not cover the window holding the application. This API is reserved. Currently, the window ID cannot be obtained. + +**System capability**: SystemCapability.MiscServices.InputMethodFramework + +**Parameters** + +| Name| Type| Mandatory| Description| +| -------- | -------- | -------- | -------- | +| windowId | number | Yes| ID of the window to be avoided.| +| callback | AsyncCallback<void> | Yes| Callback used to return the result. If the operation is successful, **err** is **undefined**. Otherwise, **err** is an error object.| + +**Error codes** + +For details about the error codes, see [Input Method Framework Error Codes](../errorcodes/errorcode-inputmethod-framework.md). + +| Error Code ID| Error Message | +| -------- | -------------------------------------- | +| 12800003 | input method client error. | +| 12800008 | input method manager service error. | +| 12800009 | input method client is detached. | + +**Example** + +```js +try { + let windowId: number = 2000; + inputMethodController.setCallingWindow(windowId, (err) => { + if (err) { + console.error(`Failed to setCallingWindow: ${JSON.stringify(err)}`); + return; + } + console.log('Succeeded in setting callingWindow.'); + }); +} catch(err) { + console.error(`Failed to setCallingWindow: ${JSON.stringify(err)}`); +} +``` + +### setCallingWindow10+ + +setCallingWindow(windowId: number): Promise<void> + +Sets the window to be avoided by the input method. This API uses a promise to return the result. + +After the window ID of the application bound to the input method is passed in the API, the input method window will not cover the window holding the application. This API is reserved. Currently, the window ID cannot be obtained. + +**System capability**: SystemCapability.MiscServices.InputMethodFramework + +**Parameters** + +| Name| Type| Mandatory| Description| +| -------- | -------- | -------- | -------- | +| windowId | number | Yes| ID of the window to be avoided.| + +**Return value** + +| Type| Description| +| -------- | -------- | +| Promise<void> | Promise that returns no value.| + +**Error codes** + +For details about the error codes, see [Input Method Framework Error Codes](../errorcodes/errorcode-inputmethod-framework.md). + +| Error Code ID| Error Message | +| -------- | -------------------------------------- | +| 12800003 | input method client error. | +| 12800008 | input method manager service error. | +| 12800009 | input method client is detached. | + +**Example** + +```js +try { + let windowId: number = 2000; + inputMethodController.setCallingWindow(windowId).then(() => { + console.log('Succeeded in setting callingWindow.'); + }).catch((err) => { + console.error(`Failed to setCallingWindow: ${JSON.stringify(err)}`); + }) +} catch(err) { + console.error(`Failed to setCallingWindow: ${JSON.stringify(err)}`); +} +``` + +### updateCursor10+ + +updateCursor(cursorInfo: CursorInfo, callback: AsyncCallback<void>): void + +Updates the cursor information in this edit box. This API uses an asynchronous callback to return the result. + +This API can be called to notify the input method of the cursor changes. + +**System capability**: SystemCapability.MiscServices.InputMethodFramework + +**Parameters** + +| Name| Type| Mandatory| Description| +| -------- | -------- | -------- | -------- | +| cursorInfo | [CursorInfo](#cursorinfo10) | Yes| Cursor information.| +| callback | AsyncCallback<void> | Yes| Callback used to return the result. If the operation is successful, **err** is **undefined**. Otherwise, **err** is an error object.| + +**Error codes** + +For details about the error codes, see [Input Method Framework Error Codes](../errorcodes/errorcode-inputmethod-framework.md). + +| Error Code ID| Error Message | +| -------- | -------------------------------------- | +| 12800003 | input method client error. | +| 12800008 | input method manager service error. | +| 12800009 | input method client is detached. | + +**Example** + +```js +try { + inputMethodController.updateCursor({left: 0, top: 0, width: 600, height: 800}, (err) => { + if (err) { + console.error(`Failed to updateCursor: ${JSON.stringify(err)}`); + return; + } + console.log('Succeeded in updating cursorInfo.'); + }); +} catch(err) { + console.error(`Failed to updateCursor: ${JSON.stringify(err)}`); +} +``` + +### updateCursor10+ + +updateCursor(cursorInfo: CursorInfo): Promise<void> + +Updates the cursor information in this edit box. This API uses a promise to return the result. + +This API can be called to notify the input method of the cursor changes. + +**System capability**: SystemCapability.MiscServices.InputMethodFramework + +**Parameters** + +| Name| Type| Mandatory| Description| +| -------- | -------- | -------- | -------- | +| cursorInfo | [CursorInfo](#cursorinfo10) | Yes| Cursor information.| + +**Return value** + +| Type| Description| +| -------- | -------- | +| Promise<void> | Promise that returns no value.| + +**Error codes** + +For details about the error codes, see [Input Method Framework Error Codes](../errorcodes/errorcode-inputmethod-framework.md). + +| Error Code ID| Error Message | +| -------- | -------------------------------------- | +| 12800003 | input method client error. | +| 12800008 | input method manager service error. | +| 12800009 | input method client is detached. | + +**Example** + +```js +try { + inputMethodController.updateCursor({left: 0, top: 0, width: 600, height: 800}).then(() => { + console.log('Succeeded in updating cursorInfo.'); + }).catch((err) => { + console.error(`Failed to updateCursor: ${JSON.stringify(err)}`); + }) +} catch(err) { + console.error(`Failed to updateCursor: ${JSON.stringify(err)}`); +} +``` + +### changeSelection10+ + +changeSelection(text: string, start: number, end: number, callback: AsyncCallback<void>): void + +Updates the information of selected text in this edit box, to notify the input method when the selected text content or text range changes. This API uses an asynchronous callback to return the result. + +**System capability**: SystemCapability.MiscServices.InputMethodFramework + +**Parameters** + +| Name| Type| Mandatory| Description| +| -------- | -------- | -------- | -------- | +| text | string | Yes| All input text.| +| start | number | Yes| Start position of the selected text.| +| end | number | Yes| End position of the selected text.| +| callback | AsyncCallback<void> | Yes| Callback used to return the result. If the operation is successful, **err** is **undefined**. Otherwise, **err** is an error object.| + +**Error codes** + +For details about the error codes, see [Input Method Framework Error Codes](../errorcodes/errorcode-inputmethod-framework.md). + +| Error Code ID| Error Message | +| -------- | -------------------------------------- | +| 12800003 | input method client error. | +| 12800008 | input method manager service error. | +| 12800009 | input method client is detached. | + +**Example** + +```js +try { + inputMethodController.changeSelection('text', 0, 5, (err) => { + if (err) { + console.error(`Failed to changeSelection: ${JSON.stringify(err)}`); + return; + } + console.log('Succeeded in changing selection.'); + }); +} catch(err) { + console.error(`Failed to changeSelection: ${JSON.stringify(err)}`); +} +``` + +### changeSelection10+ + +changeSelection(text: string, start: number, end: number): Promise<void> + +Updates the information of selected text in this edit box, to notify the input method when the selected text content or text range changes. This API uses a promise to return the result. + +**System capability**: SystemCapability.MiscServices.InputMethodFramework + +**Parameters** + +| Name| Type| Mandatory| Description| +| -------- | -------- | -------- | -------- | +| text | string | Yes| All input text.| +| start | number | Yes| Start position of the selected text.| +| end | number | Yes| End position of the selected text.| + +**Return value** + +| Type| Description| +| -------- | -------- | +| Promise<void> | Promise that returns no value.| + +**Error codes** + +For details about the error codes, see [Input Method Framework Error Codes](../errorcodes/errorcode-inputmethod-framework.md). + +| Error Code ID| Error Message | +| -------- | -------------------------------------- | +| 12800003 | input method client error. | +| 12800008 | input method manager service error. | +| 12800009 | input method client is detached. | + +**Example** + +```js +try { + inputMethodController.changeSelection('test', 0, 5).then(() => { + console.log('Succeeded in changing selection.'); + }).catch((err) => { + console.error(`Failed to changeSelection: ${JSON.stringify(err)}`); + }) +} catch(err) { + console.error(`Failed to changeSelection: ${JSON.stringify(err)}`); +} +``` + +### updateAttribute10+ + +updateAttribute(attribute: InputAttribute, callback: AsyncCallback<void>): void + +Updates the attribute configuration of the edit box. This API uses an asynchronous callback to return the result. + +**System capability**: SystemCapability.MiscServices.InputMethodFramework + +**Parameters** + +| Name| Type| Mandatory| Description| +| -------- | -------- | -------- | -------- | +| attribute | [InputAttribute](#inputattribute10) | Yes| Attribute configuration.| +| callback | AsyncCallback<void> | Yes| Callback used to return the result. If the operation is successful, **err** is **undefined**. Otherwise, **err** is an error object.| + +**Error codes** + +For details about the error codes, see [Input Method Framework Error Codes](../errorcodes/errorcode-inputmethod-framework.md). + +| Error Code ID| Error Message | +| -------- | -------------------------------------- | +| 12800003 | input method client error. | +| 12800008 | input method manager service error. | +| 12800009 | input method client is detached. | + +**Example** + +```js +try { + inputMethodController.updateAttribute({textInputType: 0, enterKeyType: 1}, (err) => { + if (err) { + console.error(`Failed to updateAttribute: ${JSON.stringify(err)}`); + return; + } + console.log('Succeeded in updating attribute.'); + }); +} catch(err) { + console.error(`Failed to updateAttribute: ${JSON.stringify(err)}`); +} +``` + +### updateAttribute10+ + +updateAttribute(attribute: InputAttribute): Promise<void> + +Updates the attribute configuration of the edit box. This API uses a promise to return the result. + +**System capability**: SystemCapability.MiscServices.InputMethodFramework + +**Parameters** + +| Name| Type| Mandatory| Description| +| -------- | -------- | -------- | -------- | +| attribute | [InputAttribute](#inputattribute10) | Yes| Attribute configuration.| + +**Return value** + +| Type| Description| +| -------- | -------- | +| Promise<void> | Promise that returns no value.| + +**Error codes** + +For details about the error codes, see [Input Method Framework Error Codes](../errorcodes/errorcode-inputmethod-framework.md). + +| Error Code ID| Error Message | +| -------- | -------------------------------------- | +| 12800003 | input method client error. | +| 12800008 | input method manager service error. | +| 12800009 | input method client is detached. | + +**Example** + +```js +try { + inputMethodController.updateAttribute({textInputType: 0, enterKeyType: 1}).then(() => { + console.log('Succeeded in updating attribute.'); + }).catch((err) => { + console.error(`Failed to updateAttribute: ${JSON.stringify(err)}`); + }) +} catch(err) { + console.error(`Failed to updateAttribute: ${JSON.stringify(err)}`); +} +``` + +### stopInputSession9+ + +stopInputSession(callback: AsyncCallback<boolean>): void + +Ends this input session. This API uses an asynchronous callback to return the result. + +This API must be used with the editor component (for example, a text box). It can be called only when the editor component is focused. + +**System capability**: SystemCapability.MiscServices.InputMethodFramework + +**Parameters** + +| Name| Type| Mandatory| Description| +| -------- | -------- | -------- | -------- | +| callback | AsyncCallback<boolean> | Yes| Callback used to return the result. If the operation is successful, **err** is **undefined** and **data** is **true**. Otherwise, **err** is an error object.| + +**Error codes** + +For details about the error codes, see [Input Method Framework Error Codes](../errorcodes/errorcode-inputmethod-framework.md). + +| Error Code ID| Error Message | +| -------- | -------------------------------------- | +| 12800003 | input method client error. | +| 12800008 | input method manager service error. | + +**Example** + +```js +try { + inputMethodController.stopInputSession((err, result) => { + if (err) { + console.error(`Failed to stopInputSession: ${JSON.stringify(err)}`); + return; + } + if (result) { + console.log('Succeeded in stopping inputSession.'); + } else { + console.error('Failed to stopInputSession.'); + } + }); +} catch(err) { + console.error(`Failed to stopInputSession: ${JSON.stringify(err)}`); +} +``` + +### stopInputSession9+ + +stopInputSession(): Promise<boolean> + +Ends this input session. This API uses a promise to return the result. + +This API must be used with the editor component (for example, a text box). It can be called only when the editor component is focused. + +**System capability**: SystemCapability.MiscServices.InputMethodFramework + +**Return value** + +| Type| Description| +| -------- | -------- | +| Promise<boolean> | Promise used to return the result. The value **true** means that the ending is successful, and **false** means the opposite.| + +**Error codes** + +For details about the error codes, see [Input Method Framework Error Codes](../errorcodes/errorcode-inputmethod-framework.md). + +| Error Code ID| Error Message | +| -------- | -------------------------------------- | +| 12800003 | input method client error. | +| 12800008 | input method manager service error. | + +**Example** + +```js +try { + inputMethodController.stopInputSession().then((result) => { + if (result) { + console.log('Succeeded in stopping inputSession.'); + } else { + console.error('Failed to stopInputSession.'); + } + }).catch((err) => { + console.error(`Failed to stopInputSession: ${JSON.stringify(err)}`); + }) +} catch(err) { + console.error(`Failed to stopInputSession: ${JSON.stringify(err)}`); +} +``` + +### showSoftKeyboard9+ + +showSoftKeyboard(callback: AsyncCallback<void>): void + +Shows this soft keyboard. This API uses an asynchronous callback to return the result. + +This API must be used with the editor component (for example, a text box). It can be called only when the editor component is focused. + +**Required permissions**: ohos.permission.CONNECT_IME_ABILITY (for system applications only) + +**System capability**: SystemCapability.MiscServices.InputMethodFramework + +**Parameters** + +| Name | Type | Mandatory| Description | +| -------- | ------------------------- | ---- | ---------- | +| callback | AsyncCallback<void> | Yes | Callback used to return the result. If the operation is successful, **err** is **undefined**. Otherwise, **err** is an error object.| + +**Error codes** + +For details about the error codes, see [Input Method Framework Error Codes](../errorcodes/errorcode-inputmethod-framework.md). + +| Error Code ID| Error Message | +| -------- | -------------------------------------- | +| 12800003 | input method client error. | +| 12800008 | input method manager service error. | + +**Example** + +```js +inputMethodController.showSoftKeyboard((err) => { + if (!err) { + console.log('Succeeded in showing softKeyboard.'); + } else { + console.error(`Failed to show softKeyboard: ${JSON.stringify(err)}`); + } +}) +``` + +### showSoftKeyboard9+ + +showSoftKeyboard(): Promise<void> + +Shows this soft keyboard. This API uses a promise to return the result. + +This API must be used with the editor component (for example, a text box). It can be called only when the editor component is focused. + +**Required permissions**: ohos.permission.CONNECT_IME_ABILITY (for system applications only) + +**System capability**: SystemCapability.MiscServices.InputMethodFramework + +**Return value** + +| Type | Description | +| ------------------- | ------------------------- | +| Promise<void> | Promise that returns no value.| + +**Error codes** + +For details about the error codes, see [Input Method Framework Error Codes](../errorcodes/errorcode-inputmethod-framework.md). + +| Error Code ID| Error Message | +| -------- | -------------------------------------- | +| 12800003 | input method client error. | +| 12800008 | input method manager service error. | + +**Example** + +```js +inputMethodController.showSoftKeyboard().then(() => { + console.log('Succeeded in showing softKeyboard.'); +}).catch((err) => { + console.error(`Failed to show softKeyboard: ${JSON.stringify(err)}`); +}); +``` + +### hideSoftKeyboard9+ + +hideSoftKeyboard(callback: AsyncCallback<void>): void + +Hides this soft keyboard. This API uses an asynchronous callback to return the result. + +This API must be used with the editor component (for example, a text box). It can be called only when the editor component is focused. + +**Required permissions**: ohos.permission.CONNECT_IME_ABILITY (for system applications only) + +**System capability**: SystemCapability.MiscServices.InputMethodFramework + +**Parameters** + +| Name | Type | Mandatory| Description | +| -------- | ------------------------- | ---- | ---------- | +| callback | AsyncCallback<void> | Yes | Callback used to return the result. If the operation is successful, **err** is **undefined**. Otherwise, **err** is an error object.| + +**Error codes** + +For details about the error codes, see [Input Method Framework Error Codes](../errorcodes/errorcode-inputmethod-framework.md). + +| Error Code ID| Error Message | +| -------- | -------------------------------------- | +| 12800003 | input method client error. | +| 12800008 | input method manager service error. | + +**Example** + +```js +inputMethodController.hideSoftKeyboard((err) => { + if (!err) { + console.log('Succeeded in hiding softKeyboard.'); + } else { + console.error(`Failed to hide softKeyboard: ${JSON.stringify(err)}`); + } +}) +``` + +### hideSoftKeyboard9+ + +hideSoftKeyboard(): Promise<void> + +Hides this soft keyboard. This API uses a promise to return the result. + +This API must be used with the editor component (for example, a text box). It can be called only when the editor component is focused. + +**Required permissions**: ohos.permission.CONNECT_IME_ABILITY (for system applications only) + +**System capability**: SystemCapability.MiscServices.InputMethodFramework + +**Return value** + +| Type | Description | +| ------------------- | ------------------------- | +| Promise<void> | Promise that returns no value.| + +**Error codes** + +For details about the error codes, see [Input Method Framework Error Codes](../errorcodes/errorcode-inputmethod-framework.md). + +| Error Code ID| Error Message | +| -------- | -------------------------------------- | +| 12800003 | input method client error. | +| 12800008 | input method manager service error. | + +**Example** + +```js +inputMethodController.hideSoftKeyboard().then(() => { + console.log('Succeeded in hiding softKeyboard.'); +}).catch((err) => { + console.error(`Failed to hide softKeyboard: ${JSON.stringify(err)}`); +}); +``` + +### stopInput(deprecated) + +stopInput(callback: AsyncCallback<boolean>): void + +Ends this input session. This API uses an asynchronous callback to return the result. + +This API must be used with the editor component (for example, a text box). It can be called only when the editor component is focused. + +> **NOTE** +> +> This API is supported since API version 6 and deprecated since API version 9. You are advised to use [stopInputSession()](#stopinputsession9) instead. + +**System capability**: SystemCapability.MiscServices.InputMethodFramework + +**Parameters** + +| Name| Type| Mandatory| Description| +| -------- | -------- | -------- | -------- | +| callback | AsyncCallback<boolean> | Yes| Callback used to return the result. If the operation is successful, **err** is **undefined** and **data** is **true**. Otherwise, **err** is an error object.| + +**Example** + +```js +inputMethodController.stopInput((err, result) => { + if (err) { + console.error(`Failed to stopInput: ${JSON.stringify(err)}`); + return; + } + if (result) { + console.log('Succeeded in stopping input.'); + } else { + console.error('Failed to stopInput.'); + } +}); +``` + +### stopInput(deprecated) + +stopInput(): Promise<boolean> + +Ends this input session. This API uses a promise to return the result. + +This API must be used with the editor component (for example, a text box). It can be called only when the editor component is focused. + +> **NOTE** +> +> This API is supported since API version 6 and deprecated since API version 9. You are advised to use [stopInputSession()](#stopinputsession9) instead. + +**System capability**: SystemCapability.MiscServices.InputMethodFramework + +**Return value** + +| Type| Description| +| -------- | -------- | +| Promise<boolean> | Promise used to return the result. The value **true** means that the hiding is successful, and **false** means the opposite.| + +**Example** + +```js +inputMethodController.stopInput().then((result) => { + if (result) { + console.log('Succeeded in stopping input.'); + } else { + console.error('Failed to stopInput.'); + } +}).catch((err) => { + console.error(`Failed to stopInput: ${JSON.stringify(err)}`); +}) +``` + +### on('insertText')10+ + +on(type: 'insertText', callback: (text: string) => void): void; -**Required permissions**: ohos.permission.CONNECT_IME_ABILITY (available only to system applications) +Enables listening for the text insertion event of the input method. This API uses an asynchronous callback to return the result. **System capability**: SystemCapability.MiscServices.InputMethodFramework **Parameters** -| Name| Type| Mandatory| Description| -| -------- | -------- | -------- | -------- | -|inputMethodProperty | [InputMethodProperty](#inputmethodproperty8)| Yes| Input method to switch to.| -|inputMethodSubtype | [InputMethodSubtype](./js-apis-inputmethod-subtype.md)| Yes| Input method subtype to switch to.| -| callback | AsyncCallback<boolean> | Yes| Callback used to return the result. If the operation is successful, **err** is **undefined** and **data** is **true**. Otherwise, **err** is an error object.| +| Name | Type | Mandatory| Description | +| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | +| type | string | Yes | Listening type.
The value **'insertText'** indicates the text insertion event.| +| callback | (text: string) => void | Yes | Callback used to return the text to be inserted.
Your application needs to operate the content in the edit box based on the text content returned in the callback.| **Error codes** @@ -385,53 +1658,54 @@ For details about the error codes, see [Input Method Framework Error Codes](../e | Error Code ID| Error Message | | -------- | -------------------------------------- | -| 12800005 | Configuration persisting error. | -| 12800008 | Input method manager service error. | +| 12800009 | input method client is detached. | **Example** ```js -let im = inputMethod.getCurrentInputMethod(); -let imSubType = inputMethod.getCurrentInputMethodSubtype(); try { - inputMethod.switchCurrentInputMethodAndSubtype(im, imSubType, (err,result) => { - if (err !== undefined) { - console.error('Failed to switchCurrentInputMethodAndSubtype: ' + JSON.stringify(err)); - return; - } - if (result) { - console.info('Succeeded in switching currentInputMethodAndSubtype.'); - } else { - console.error('Failed to switchCurrentInputMethodAndSubtype.'); - } - }); -} catch (err) { - console.error('Failed to switchCurrentInputMethodAndSubtype: ' + JSON.stringify(err)); + inputMethodController.on('insertText', (text) => { + console.log(`Succeeded in subscribing insertText: ${text}`); + }); +} catch(err) { + console.error(`Failed to subscribe insertText: ${JSON.stringify(err)}`); } ``` -## inputMethod.switchCurrentInputMethodAndSubtype9+ - -switchCurrentInputMethodAndSubtype(inputMethodProperty: InputMethodProperty, inputMethodSubtype: InputMethodSubtype): Promise<boolean> +### off('insertText')10+ -Switches to a specified subtype of a specified input method. This API uses a promise to return the result. +off(type: 'insertText'): void -**Required permissions**: ohos.permission.CONNECT_IME_ABILITY (available only to system applications) +Disables listening for the text insertion event of the input method. **System capability**: SystemCapability.MiscServices.InputMethodFramework **Parameters** -| Name| Type| Mandatory| Description| -| -------- | -------- | -------- | -------- | -|inputMethodProperty | [InputMethodProperty](#inputmethodproperty8)| Yes| Input method to switch to.| -|inputMethodSubtype | [InputMethodSubtype](./js-apis-inputmethod-subtype.md)| Yes| Input method subtype to switch to.| +| Name| Type | Mandatory| Description | +| ------ | ------ | ---- | ------------------------------------------------------------ | +| type | string | Yes | Listening type.
The value **'insertText'** indicates the text insertion event.| -**Return value** +**Example** -| Type | Description | -| ----------------------------------------- | ---------------------------- | -| Promise\ | Promise used to return the result. The value **true** means that the switching is successful, and **false** means the opposite.| +```js +inputMethodController.off('insertText'); +``` + +### on('deleteLeft' | 'deleteRight')10+ + +on(type: 'deleteLeft' | 'deleteRight', callback: (length: number) => void): void + +Enables listening for the delete-to-the-left or delete-to-the-right event of the input method. This API uses an asynchronous callback to return the result. + +**System capability**: SystemCapability.MiscServices.InputMethodFramework + +**Parameters** + +| Name | Type| Mandatory| Description| +| -------- | ----- | ---- | ----- | +| type | string | Yes | Listening type.
- The value **'deleteLeft'** indicates the delete-to-the-left event.
- The value **'deleteRight'** indicates the delete-to-the-right event.| +| callback | (length: number) => void | Yes | Callback used to return the length of the text to be deleted to the left or to the right.
Your application needs to operate the content in the edit box based on the length returned in the callback.| **Error codes** @@ -439,94 +1713,63 @@ For details about the error codes, see [Input Method Framework Error Codes](../e | Error Code ID| Error Message | | -------- | -------------------------------------- | -| 12800005 | Configuration persisting error. | -| 12800008 | Input method manager service error. | +| 12800009 | input method client is detached. | **Example** ```js -let im = inputMethod.getCurrentInputMethod(); -let imSubType = inputMethod.getCurrentInputMethodSubtype(); try { - inputMethod.switchCurrentInputMethodAndSubtype(im, imSubType).then((result) => { - if (result) { - console.info('Succeeded in switching currentInputMethodAndSubtype.'); - } else { - console.error('Failed to switchCurrentInputMethodAndSubtype.'); - } - }).catch((err) => { - console.error('Failed to switchCurrentInputMethodAndSubtype: ' + JSON.stringify(err)); - }) + inputMethodController.on('deleteLeft', (length) => { + console.log(`Succeeded in subscribing deleteLeft, length: ${length}`); + }); } catch(err) { - console.error('Failed to switchCurrentInputMethodAndSubtype: ' + JSON.stringify(err)); + console.error(`Failed to subscribe deleteLeft: ${JSON.stringify(err)}`); } -``` - -## inputMethod.getInputMethodController(deprecated) - -getInputMethodController(): InputMethodController - -Obtains an **[InputMethodController](#inputmethodcontroller)** instance. - -> **NOTE** -> -> This API is supported since API version 6 and deprecated since API version 9. You are advised to use [getController()](#inputmethodgetcontroller9). - -**System capability**: SystemCapability.MiscServices.InputMethodFramework - -**Return value** - -| Type | Description | -| ----------------------------------------------- | ------------------------ | -| [InputMethodController](#inputmethodcontroller) | Current **InputMethodController** instance.| - -**Example** -```js -let inputMethodController = inputMethod.getInputMethodController(); +try { + inputMethodController.on('deleteRight', (length) => { + console.log(`Succeeded in subscribing deleteRight, length: ${length}`); + }); +} catch(err) { + console.error(`Failed to subscribe deleteRight: ${JSON.stringify(err)}`); +} ``` -## inputMethod.getInputMethodSetting(deprecated) - -getInputMethodSetting(): InputMethodSetting +### off('deleteLeft' | 'deleteRight')10+ -Obtains an **[InputMethodSetting](#inputmethodsetting8)** instance. +off(type: 'deleteLeft' | 'deleteRight'): void -> **NOTE** -> -> This API is supported since API version 6 and deprecated since API version 9. You are advised to use [getSetting()](#inputmethodgetsetting9). +Disables listening for the delete-to-the-left or delete-to-the-right event of the input method. **System capability**: SystemCapability.MiscServices.InputMethodFramework -**Return value** +**Parameters** -| Type | Description | -| ----------------------------------------- | ---------------------------- | -| [InputMethodSetting](#inputmethodsetting8) | Current **InputMethodSetting** instance.| +| Name| Type | Mandatory| Description | +| ------ | ------ | ---- | ------------------------------------------------------------ | +| type | string | Yes | Listening type.
- The value **'deleteLeft'** indicates the delete-to-the-left event.
- The value **'deleteRight'** indicates the delete-to-the-right event.| **Example** ```js -let inputMethodSetting = inputMethod.getInputMethodSetting(); +inputMethodController.off('deleteLeft'); +inputMethodController.off('deleteRight'); ``` -## InputMethodController - -In the following API examples, you must first use [getController](#inputmethodgetcontroller9) to obtain an **InputMethodController** instance, and then call the APIs using the obtained instance. - -### stopInputSession9+ +### on('sendKeyboardStatus')10+ -stopInputSession(callback: AsyncCallback<boolean>): void +on(type: 'sendKeyboardStatus', callback: (keyBoardStatus: KeyboardStatus) => void): void -Ends this input session. The invoking of this API takes effect only after the input session is enabled by clicking the text box. This API uses an asynchronous callback to return the result. +Enables listening for the keyboard status event of the input method. This API uses an asynchronous callback to return the result. **System capability**: SystemCapability.MiscServices.InputMethodFramework **Parameters** -| Name| Type| Mandatory| Description| -| -------- | -------- | -------- | -------- | -| callback | AsyncCallback<boolean> | Yes| Callback used to return the result. If the operation is successful, **err** is **undefined** and **data** is **true**. Otherwise, **err** is an error object.| +| Name | Type | Mandatory| Description | +| -------- | ------ | ---- | ---- | +| type | string | Yes | Listening type.
The value **'sendKeyboardStatus'** indicates the keyboard status event.| +| callback | (keyBoardStatus: [KeyboardStatus](#keyboardstatus10)) => void | Yes | Callback used to return the keyboard status.
Your application needs to perform operations based on the keyboard state returned in the callback.| **Error codes** @@ -534,85 +1777,54 @@ For details about the error codes, see [Input Method Framework Error Codes](../e | Error Code ID| Error Message | | -------- | -------------------------------------- | -| 12800003 | Input method client error. | -| 12800008 | Input method manager service error. | +| 12800009 | input method client is detached. | **Example** ```js try { - inputMethodController.stopInputSession((error, result) => { - if (error !== undefined) { - console.error('Failed to stopInputSession: ' + JSON.stringify(error)); - return; - } - if (result) { - console.info('Succeeded in stopping inputSession.'); - } else { - console.error('Failed to stopInputSession.'); - } - }); -} catch(error) { - console.error('Failed to stopInputSession: ' + JSON.stringify(error)); + inputMethodController.on('sendKeyboardStatus', (keyBoardStatus) => { + console.log(`Succeeded in subscribing sendKeyboardStatus, keyBoardStatus: ${keyBoardStatus}`); + }); +} catch(err) { + console.error(`Failed to subscribe sendKeyboardStatus: ${JSON.stringify(err)}`); } ``` -### stopInputSession9+ +### off('sendKeyboardStatus')10+ -stopInputSession(): Promise<boolean> +off(type: 'sendKeyboardStatus'): void -Ends this input session. The invoking of this API takes effect only after the input session is enabled by clicking the text box. This API uses a promise to return the result. +Disables listening for the keyboard status event of the input method. **System capability**: SystemCapability.MiscServices.InputMethodFramework -**Return value** - -| Type| Description| -| -------- | -------- | -| Promise<boolean> | Promise used to return the result. The value **true** means that the ending is successful, and **false** means the opposite.| - -**Error codes** - -For details about the error codes, see [Input Method Framework Error Codes](../errorcodes/errorcode-inputmethod-framework.md). +**Parameters** -| Error Code ID| Error Message | -| -------- | -------------------------------------- | -| 12800003 | Input method client error. | -| 12800008 | Input method manager service error. | +| Name| Type | Mandatory| Description | +| ------ | ------ | ---- | ------------------------------------------------------------ | +| type | string | Yes | Listening type.
The value **'sendKeyboardStatus'** indicates the keyboard status event.| **Example** ```js -try { - inputMethodController.stopInputSession().then((result) => { - if (result) { - console.info('Succeeded in stopping inputSession.'); - } else { - console.error('Failed to stopInputSession.'); - } - }).catch((err) => { - console.error('Failed to stopInputSession: ' + JSON.stringify(err)); - }) -} catch(err) { - console.error('Failed to stopInputSession: ' + JSON.stringify(err)); -} +inputMethodController.off('sendKeyboardStatus'); ``` -### showSoftKeyboard9+ - -showSoftKeyboard(callback: AsyncCallback<void>): void +### on('sendFunctionKey')10+ -Shows this soft keyboard. This API must be used with the input text box and works only when the input text box is activated. This API uses an asynchronous callback to return the result. +on(type: 'sendFunctionKey', callback: (functionKey: FunctionKey) => void): void -**Required permissions**: ohos.permission.CONNECT_IME_ABILITY (available only to system applications) +Enables listening for the function key sending event of the input method. This API uses an asynchronous callback to return the result. **System capability**: SystemCapability.MiscServices.InputMethodFramework **Parameters** -| Name | Type | Mandatory| Description | -| -------- | ------------------------- | ---- | ---------- | -| callback | AsyncCallback<void> | Yes | Callback used to return the result. If the operation is successful, **err** is **undefined**. Otherwise, **err** is an error object.| +| Name | Type | Mandatory| Description | +| -------- | -------- | ---- | ----- | +| type | string | Yes | Listening type.
The value **'sendFunctionKey'** indicates the function key sending event.| +| callback | (functionKey: [FunctionKey](#functionkey10)) => void | Yes | Callback used to return the function key information sent by the input method.
Your application needs to perform operations based on the function key information returned in the callback.| **Error codes** @@ -620,214 +1832,170 @@ For details about the error codes, see [Input Method Framework Error Codes](../e | Error Code ID| Error Message | | -------- | -------------------------------------- | -| 12800003 | Input method client error. | -| 12800008 | Input method manager service error. | +| 12800009 | input method client is detached. | **Example** ```js -inputMethodController.showSoftKeyboard((err) => { - if (err === undefined) { - console.info('Succeeded in showing softKeyboard.'); - } else { - console.error('Failed to showSoftKeyboard: ' + JSON.stringify(err)); - } -}) +try { + inputMethodController.on('sendFunctionKey', (functionKey) => { + console.log(`Succeeded in subscribing sendFunctionKey, functionKey.enterKeyType: ${functionKey.enterKeyType}`); + }); +} catch(err) { + console.error(`Failed to subscribe sendFunctionKey: ${JSON.stringify(err)}`); +} ``` -### showSoftKeyboard9+ - -showSoftKeyboard(): Promise<void> +### off('sendFunctionKey')10+ -Shows this soft keyboard. This API must be used with the input text box and works only when the input text box is activated. This API uses a promise to return the result. +off(type: 'sendFunctionKey'): void -**Required permissions**: ohos.permission.CONNECT_IME_ABILITY (available only to system applications) +Disables listening for the function key sending event of the input method. **System capability**: SystemCapability.MiscServices.InputMethodFramework -**Return value** - -| Type | Description | -| ------------------- | ------------------------- | -| Promise<void> | Promise that returns no value.| - -**Error codes** - -For details about the error codes, see [Input Method Framework Error Codes](../errorcodes/errorcode-inputmethod-framework.md). +**Parameters** -| Error Code ID| Error Message | -| -------- | -------------------------------------- | -| 12800003 | Input method client error. | -| 12800008 | Input method manager service error. | +| Name| Type | Mandatory| Description | +| ------ | ------ | ---- | ------------------------------------------------------------ | +| type | string | Yes | Listening type.
The value **'sendFunctionKey'** indicates the function key sending event.| **Example** ```js -inputMethodController.showSoftKeyboard().then(() => { - console.log('Succeeded in showing softKeyboard.'); -}).catch((err) => { - console.error('Failed to showSoftKeyboard: ' + JSON.stringify(err)); -}); +inputMethodController.off('sendFunctionKey'); ``` -### hideSoftKeyboard9+ - -hideSoftKeyboard(callback: AsyncCallback<void>): void +### on('moveCursor')10+ -Hides this soft keyboard. This API must be used with the input text box and works only when the input text box is activated. This API uses an asynchronous callback to return the result. +on(type: 'moveCursor', callback: (direction: Direction) => void): void -**Required permissions**: ohos.permission.CONNECT_IME_ABILITY (available only to system applications) +Enables listening for the cursor movement event of the input method. This API uses an asynchronous callback to return the result. **System capability**: SystemCapability.MiscServices.InputMethodFramework **Parameters** -| Name | Type | Mandatory| Description | -| -------- | ------------------------- | ---- | ---------- | -| callback | AsyncCallback<void> | Yes | Callback used to return the result. If the operation is successful, **err** is **undefined**. Otherwise, **err** is an error object.| +| Name | Type| Mandatory| Description | +| -------- | ------ | ---- | ------ | +| type | string | Yes | Listening type.
The value **'moveCursor'** indicates the cursor movement event.| +| callback | callback: (direction: [Direction10+](#direction10)) => void | Yes | Callback used to return the cursor movement direction.
Your application needs to change the cursor position based on the cursor movement direction returned in the callback.| **Error codes** For details about the error codes, see [Input Method Framework Error Codes](../errorcodes/errorcode-inputmethod-framework.md). -| Error Code ID| Error Message | -| -------- | -------------------------------------- | -| 12800003 | Input method client error. | -| 12800008 | Input method manager service error. | +| Error Code ID| Error Message | +| -------- | -------------------------------- | +| 12800009 | input method client is detached. | **Example** ```js -inputMethodController.hideSoftKeyboard((err) => { - if (err === undefined) { - console.info('Succeeded in hiding softKeyboard.'); - } else { - console.error('Failed to hideSoftKeyboard: ' + JSON.stringify(err)); - } -}) +try { + inputMethodController.on('moveCursor', (direction) => { + console.log(`Succeeded in subscribing moveCursor, direction: ${direction}`); + }); +} catch(err) { + console.error(`Failed to subscribe moveCursor: ${JSON.stringify(err)}`); +} ``` -### hideSoftKeyboard9+ - -hideSoftKeyboard(): Promise<void> +### off('moveCursor')10+ -Hides this soft keyboard. This API must be used with the input text box and works only when the input text box is activated. This API uses a promise to return the result. +off(type: 'moveCursor'): void -**Required permissions**: ohos.permission.CONNECT_IME_ABILITY (available only to system applications) +Disables listening for the cursor movement event of the input method. **System capability**: SystemCapability.MiscServices.InputMethodFramework -**Return value** - -| Type | Description | -| ------------------- | ------------------------- | -| Promise<void> | Promise that returns no value.| - -**Error codes** - -For details about the error codes, see [Input Method Framework Error Codes](../errorcodes/errorcode-inputmethod-framework.md). +**Parameters** -| Error Code ID| Error Message | -| -------- | -------------------------------------- | -| 12800003 | Input method client error. | -| 12800008 | Input method manager service error. | +| Name | Type | Mandatory| Description | +| ------ | ------ | ---- | ---- | +| type | string | Yes | Listening type.
The value **'moveCursor'** indicates the cursor movement event.| **Example** ```js -inputMethodController.hideSoftKeyboard().then(() => { - console.log('Succeeded in hiding softKeyboard.'); -}).catch((err) => { - console.error('Failed to hideSoftKeyboard: ' + JSON.stringify(err)); -}); +inputMethodController.off('moveCursor'); ``` -### stopInput(deprecated) - -stopInput(callback: AsyncCallback<boolean>): void +### on('handleExtendAction')10+ -Ends this input session. The invoking of this API takes effect only after the input session is enabled by clicking the text box. This API uses an asynchronous callback to return the result. +on(type: 'handleExtendAction', callback: (action: ExtendAction) => void): void -> **NOTE** -> -> This API is supported since API version 6 and deprecated since API version 9. You are advised to use [stopInputSession()](#stopinputsession9). +Enables listening for the extended action handling event of the input method. This API uses an asynchronous callback to return the result. **System capability**: SystemCapability.MiscServices.InputMethodFramework **Parameters** -| Name| Type| Mandatory| Description| -| -------- | -------- | -------- | -------- | -| callback | AsyncCallback<boolean> | Yes| Callback used to return the result. If the operation is successful, **err** is **undefined** and **data** is **true**. Otherwise, **err** is an error object.| +| Name | Type | Mandatory| Description | +| -------- | ------ | ---- | -------- | +| type | string | Yes | Listening type.
The value **'handleExtendAction'** indicates the extended action handling event.| +| callback | callback: (action: [ExtendAction](#extendaction10)) => void | Yes | Callback used to return the extended action type.
Your application needs to perform operations based on the extended action type returned in the callback.| + +**Error codes** + +For details about the error codes, see [Input Method Framework Error Codes](../errorcodes/errorcode-inputmethod-framework.md). + +| Error Code ID| Error Message | +| -------- | -------------------------------------- | +| 12800009 | input method client is detached. | **Example** ```js -inputMethodController.stopInput((error, result) => { - if (error !== undefined) { - console.error('Failed to stopInput: ' + JSON.stringify(error)); - return; - } - if (result) { - console.info('Succeeded in stopping input.'); - } else { - console.error('Failed to stopInput.'); - } -}); +try { + inputMethodController.on('handleExtendAction', (action) => { + console.log(`Succeeded in subscribing handleExtendAction, action: ${action}`); + }); +} catch(err) { + console.error(`Failed to subscribe handleExtendAction: ${JSON.stringify(err)}`); +} ``` -### stopInput(deprecated) - -stopInput(): Promise<boolean> +### off('handleExtendAction')10+ -Ends this input session. The invoking of this API takes effect only after the input session is enabled by clicking the text box. This API uses a promise to return the result. +off(type: 'handleExtendAction'): void -> **NOTE** -> -> This API is supported since API version 6 and deprecated since API version 9. You are advised to use [stopInputSession()](#stopinputsession9). +Disables listening for the extended action handling event of the input method. **System capability**: SystemCapability.MiscServices.InputMethodFramework -**Return value** +**Parameters** -| Type| Description| -| -------- | -------- | -| Promise<boolean> | Promise used to return the result. The value **true** means that the hiding is successful, and **false** means the opposite.| +| Name| Type | Mandatory| Description | +| ------ | ------ | ---- | ------- | +| type | string | Yes | Listening type.
The value **'handleExtendAction'** indicates the extended action handling event.| **Example** ```js -inputMethodController.stopInput().then((result) => { - if (result) { - console.info('Succeeded in stopping input.'); - } else { - console.error('Failed to stopInput.'); - } -}).catch((err) => { - console.error('Failed to stopInput: ' + err); -}) +inputMethodController.off('handleExtendAction'); ``` ### on('selectByRange')10+ on(type: 'selectByRange', callback: Callback<Range>): void -Enables listening for the selection-by-range event. This API uses an asynchronous callback to return the result. +Enables listening for the select-by-range event. This API uses an asynchronous callback to return the result. **System capability**: SystemCapability.MiscServices.InputMethodFramework **Parameters** -| Name | Type | Mandatory| Description | -| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | -| type | string | Yes | Listening type.
The value **selectByRange** indicates the selection-by-range event.| -| callback | Callback<[Range](./js-apis-inputmethod-InputMethodCommon.md#range)> | Yes | Callback used to return the range of the text to be selected.
Your application needs to select the text in the returned range in the text box.| +| Name | Type | Mandatory| Description | +| -------- | ---- | ---- | ------- | +| type | string | Yes | Listening type.
The value **'selectByRange'** indicates the select-by-range event.| +| callback | Callback<[Range](#range10)> | Yes | Callback used to return the range of the text to be selected.
Your application needs to select the text in the returned range in the text box.| **Example** ```js inputMethodController.on('selectByRange', (range) => { - console.info('Succeeded in subscribing selectByRange: start: ' + range.start + " , end: " + range.end); + console.log(`Succeeded in subscribing selectByRange: start: ${range.start} , end: ${range.end}`); }); ``` @@ -835,7 +2003,7 @@ inputMethodController.on('selectByRange', (range) => { off(type: 'selectByRange'): void -Disables listening for the selection-by-range event. +Disables listening for the select-by-range event. **System capability**: SystemCapability.MiscServices.InputMethodFramework @@ -843,7 +2011,7 @@ Disables listening for the selection-by-range event. | Name| Type | Mandatory| Description | | ------ | ------ | ---- | ------------------------------------------------------------ | -| type | string | Yes | Listening type.
The value **selectByRange** indicates the selection-by-range event.| +| type | string | Yes | Listening type.
The value **'selectByRange'** indicates the select-by-range event.| **Example** @@ -861,16 +2029,16 @@ Enables listening for the select-by-cursor-movement event. This API uses an asyn **Parameters** -| Name | Type | Mandatory| Description | -| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | -| type | string | Yes | Listening type.
The value **selectByMovement** indicates the select-by-cursor-movement event.| -| callback | Callback<[Movement](./js-apis-inputmethod-InputMethodCommon.md#movement)> | Yes | Callback used to return the range of the text to be selected.
Your application needs to select the text in the returned range in the text box.| +| Name | Type | Mandatory| Description | +| -------- | ----- | ---- | ------ | +| type | string | Yes | Listening type.
The value **'selectByMovement'** indicates the select-by-cursor-movement event.| +| callback | Callback<[Movement](#movement10)> | Yes | Callback used to return the range of the text to be selected.
Your application needs to select the text in the returned range in the text box.| **Example** ```js inputMethodController.on('selectByMovement', (movement) => { - console.info('Succeeded in subscribing selectByMovement: direction: ' + movement.direction); + console.log('Succeeded in subscribing selectByMovement: direction: ' + movement.direction); }); ``` @@ -886,7 +2054,7 @@ Disables listening for the select-by-cursor-movement event. | Name| Type | Mandatory| Description | | ------ | ------ | ---- | ------------------------------------------------------------ | -| type | string | Yes | Listening type.
The value **selectByMovement** indicates the select-by-cursor-movement event.| +| type | string | Yes | Listening type.
The value **'selectByMovement'** indicates the select-by-cursor-movement event.| **Example** @@ -917,7 +2085,7 @@ Enables listening for the input method and subtype change event. This API uses a ```js inputMethodSetting.on('imeChange', (inputMethodProperty, inputMethodSubtype) => { - console.info('Succeeded in subscribing imeChange: inputMethodProperty: ' + JSON.stringify(inputMethodProperty) + " , inputMethodSubtype: " + JSON.stringify(inputMethodSubtype)); + console.log('Succeeded in subscribing imeChange: inputMethodProperty: ' + JSON.stringify(inputMethodProperty) + " , inputMethodSubtype: " + JSON.stringify(inputMethodSubtype)); }); ``` @@ -931,9 +2099,9 @@ Disables listening for the input method and subtype change event. This API uses **Parameters** -| Name | Type | Mandatory| Description | -| -------- | ------------------------------- | ---- | ------------------------------------------------------------ | -| type | string | Yes | Listening type.
The value **'imeChange'** indicates the input method and subtype change event.| +| Name | Type | Mandatory| Description | +| -------- | --------- | ---- | --------------- | +| type | string | Yes | Listening type.
The value **'imeChange'** indicates the input method and subtype change event.| | callback | (inputMethodProperty: [InputMethodProperty](#inputmethodproperty8), inputMethodSubtype: [InputMethodSubtype](./js-apis-inputmethod-subtype.md)) => void | No| Callback used to return the input method attributes and subtype.| **Example** @@ -942,6 +2110,54 @@ Disables listening for the input method and subtype change event. This API uses inputMethodSetting.off('imeChange'); ``` +### on('imeShow'|'imeHide')10+ + +on(type: 'imeShow'|'imeHide', callback: (info: Array\) => void): void + +Enables listening for a soft keyboard visibility event of the input method. This API uses an asynchronous callback to return the result. + +**System API**: This is a system API. + +**System capability**: SystemCapability.MiscServices.InputMethodFramework + +**Parameters** + +| Name | Type| Mandatory| Description| +| -------- | ---- | ---- | ---- | +| type | string | Yes| Listening type.
- The value **'imeShow'** indicates the soft keyboard display event.
- The value **'imeHide'** indicates the soft keyboard hiding event.| +| callback | (info: Array\) => void | Yes| Callback used to return the information about the soft keyboard of the input method.| + +**Example** + +```js +inputMethodSetting.on('imeShow', (info) => { + console.info('Succeeded in subscribing imeShow event.'); +}); +``` + +### off('imeShow'|'imeHide')10+ + +off(type: 'imeShow'|'imeHide', callback?: (info: Array\) => void): void + +Disables listening for a soft keyboard visibility event of the input method. + +**System API**: This is a system API. + +**System capability**: SystemCapability.MiscServices.InputMethodFramework + +**Parameters** + +| Name | Type| Mandatory| Description | +| -------- | ---- | ---- | ------ | +| type | string | Yes| Listening type.
- The value **'imeShow'** indicates the soft keyboard display event.
- The value **'imeHide'** indicates the soft keyboard hiding event.| +| callback | (info: Array\) => void | No| Callback used for disable listening. If this parameter is not specified, all callbacks corresponding to the set event are invoked.| + +**Example** + +```js +inputMethodSetting.off('imeShow'); +``` + ### listInputMethodSubtype9+ listInputMethodSubtype(inputMethodProperty: InputMethodProperty, callback: AsyncCallback<Array<InputMethodSubtype>>): void @@ -954,7 +2170,7 @@ Obtains all subtypes of a specified input method. This API uses an asynchronous | Name | Type | Mandatory| Description | | -------- | -------------------------------------------------- | ---- | ---------------------- | -| inputMethodProperty | InputMethodProperty| Yes| Input method to which the subtypes belong.| +| inputMethodProperty | [InputMethodProperty](#inputmethodproperty8)| Yes| Input method to which the subtypes belong.| | callback | AsyncCallback<Array<[InputMethodSubtype](./js-apis-inputmethod-subtype.md)>> | Yes| Callback used to return all subtypes of the specified input method.| **Error codes** @@ -963,29 +2179,26 @@ For details about the error codes, see [Input Method Framework Error Codes](../e | Error Code ID| Error Message | | -------- | -------------------------------------- | -| 12800001 | Package manager error. | -| 12800008 | Input method manager service error. | +| 12800001 | package manager error. | +| 12800008 | input method manager service error. | **Example** ```js let inputMethodProperty = { - packageName: 'com.example.kikakeyboard', - methodId: 'com.example.kikakeyboard', - name: 'com.example.kikakeyboard', - id: 'com.example.kikakeyboard', - extra:{} + name: 'com.example.kikakeyboard', + id: 'propertyId', } try { - inputMethodSetting.listInputMethodSubtype(inputMethodProperty, (err,data) => { - if (err !== undefined) { - console.error('Failed to listInputMethodSubtype: ' + JSON.stringify(err)); - return; - } - console.log('Succeeded in listing inputMethodSubtype.'); - }); + inputMethodSetting.listInputMethodSubtype(inputMethodProperty, (err, data) => { + if (err) { + console.error(`Failed to listInputMethodSubtype: ${JSON.stringify(err)}`); + return; + } + console.log('Succeeded in listing inputMethodSubtype.'); + }); } catch (err) { - console.error('Failed to listInputMethodSubtype: ' + JSON.stringify(err)); + console.error(`Failed to listInputMethodSubtype: ${JSON.stringify(err)}`); } ``` @@ -1001,7 +2214,7 @@ Obtains all subtypes of a specified input method. This API uses a promise to ret | Name | Type | Mandatory| Description | | -------- | -------------------------------------------------- | ---- | ---------------------- | -| inputMethodProperty | InputMethodProperty| Yes| Input method to which the subtypes belong.| +| inputMethodProperty | [InputMethodProperty](#inputmethodproperty8)| Yes| Input method to which the subtypes belong.| **Return value** @@ -1015,27 +2228,24 @@ For details about the error codes, see [Input Method Framework Error Codes](../e | Error Code ID| Error Message | | -------- | -------------------------------------- | -| 12800001 | Package manager error. | -| 12800008 | Input method manager service error. | +| 12800001 | package manager error. | +| 12800008 | input method manager service error. | **Example** ```js let inputMethodProperty = { - packageName: 'com.example.kikakeyboard', - methodId: 'com.example.kikakeyboard', - name: 'com.example.kikakeyboard', - id: 'com.example.kikakeyboard', - extra:{} + name: 'com.example.kikakeyboard', + id: 'propertyId', } try { - inputMethodSetting.listInputMethodSubtype(inputMethodProperty).then((data) => { - console.info('Succeeded in listing inputMethodSubtype.'); - }).catch((err) => { - console.error('Failed to listInputMethodSubtype: ' + JSON.stringify(err)); - }) + inputMethodSetting.listInputMethodSubtype(inputMethodProperty).then((data) => { + console.log('Succeeded in listing inputMethodSubtype.'); + }).catch((err) => { + console.error(`Failed to listInputMethodSubtype: ${JSON.stringify(err)}`); + }) } catch(err) { - console.error('Failed to listInputMethodSubtype: ' + JSON.stringify(err)); + console.error(`Failed to listInputMethodSubtype: ${JSON.stringify(err)}`); } ``` @@ -1059,22 +2269,22 @@ For details about the error codes, see [Input Method Framework Error Codes](../e | Error Code ID| Error Message | | -------- | -------------------------------------- | -| 12800001 | Package manager error. | -| 12800008 | Input method manager service error. | +| 12800001 | package manager error. | +| 12800008 | input method manager service error. | **Example** ```js try { - inputMethodSetting.listCurrentInputMethodSubtype((err, data) => { - if (err !== undefined) { - console.error('Failed to listCurrentInputMethodSubtype: ' + JSON.stringify(err)); - return; - } - console.log('Succeeded in listing currentInputMethodSubtype.'); - }); + inputMethodSetting.listCurrentInputMethodSubtype((err, data) => { + if (err) { + console.error(`Failed to listCurrentInputMethodSubtype: ${JSON.stringify(err)}`); + return; + } + console.log('Succeeded in listing currentInputMethodSubtype.'); + }); } catch(err) { - console.error('Failed to listCurrentInputMethodSubtype: ' + JSON.stringify(err)); + console.error(`Failed to listCurrentInputMethodSubtype: ${JSON.stringify(err)}`); } ``` @@ -1098,20 +2308,20 @@ For details about the error codes, see [Input Method Framework Error Codes](../e | Error Code ID| Error Message | | -------- | -------------------------------------- | -| 12800001 | Package manager error. | -| 12800008 | Input method manager service error. | +| 12800001 | package manager error. | +| 12800008 | input method manager service error. | **Example** ```js try { - inputMethodSetting.listCurrentInputMethodSubtype().then((data) => { - console.info('Succeeded in listing currentInputMethodSubtype.'); - }).catch((err) => { - console.error('Failed to listCurrentInputMethodSubtype: ' + JSON.stringify(err)); - }) + inputMethodSetting.listCurrentInputMethodSubtype().then((data) => { + console.log('Succeeded in listing currentInputMethodSubtype.'); + }).catch((err) => { + console.error(`Failed to listCurrentInputMethodSubtype: ${JSON.stringify(err)}`); + }) } catch(err) { - console.error('Failed to listCurrentInputMethodSubtype: ' + JSON.stringify(err)); + console.error(`Failed to listCurrentInputMethodSubtype: ${JSON.stringify(err)}`); } ``` @@ -1119,7 +2329,9 @@ try { getInputMethods(enable: boolean, callback: AsyncCallback<Array<InputMethodProperty>>): void -Obtains a list of activated or deactivated input methods. In the current version, an activated input method is the input method in use, and a deactivated one is any of the installed input methods except the one in use. This API uses an asynchronous callback to return the result. +Obtains a list of activated or deactivated input methods. This API uses an asynchronous callback to return the result. + +In the current version, an activated input method is the input method in use, and a deactivated one is any of the installed input methods except the one in use. **System capability**: SystemCapability.MiscServices.InputMethodFramework @@ -1136,22 +2348,22 @@ For details about the error codes, see [Input Method Framework Error Codes](../e | Error Code ID| Error Message | | -------- | -------------------------------------- | -| 12800001 | Package manager error. | -| 12800008 | Input method manager service error. | +| 12800001 | package manager error. | +| 12800008 | input method manager service error. | **Example** ```js try { - inputMethodSetting.getInputMethods(true, (err,data) => { - if (err !== undefined) { - console.error('Failed to getInputMethods: ' + JSON.stringify(err)); - return; - } - console.log('Succeeded in getting inputMethods.'); - }); + inputMethodSetting.getInputMethods(true, (err, data) => { + if (err) { + console.error(`Failed to getInputMethods: ${JSON.stringify(err)}`); + return; + } + console.log('Succeeded in getting inputMethods.'); + }); } catch (err) { - console.error('Failed to getInputMethods: ' + JSON.stringify(err)); + console.error(`Failed to getInputMethods: ${JSON.stringify(err)}`); } ``` @@ -1159,7 +2371,9 @@ try { getInputMethods(enable: boolean): Promise<Array<InputMethodProperty>> -Obtains a list of activated or deactivated input methods. In the current version, an activated input method is the input method in use, and a deactivated one is any of the installed input methods except the one in use. This API uses a promise to return the result. +Obtains a list of activated or deactivated input methods. This API uses a promise to return the result. + +In the current version, an activated input method is the input method in use, and a deactivated one is any of the installed input methods except the one in use. **System capability**: SystemCapability.MiscServices.InputMethodFramework @@ -1175,8 +2389,8 @@ For details about the error codes, see [Input Method Framework Error Codes](../e | Error Code ID| Error Message | | -------- | -------------------------------------- | -| 12800001 | Package manager error. | -| 12800008 | Input method manager service error. | +| 12800001 | package manager error. | +| 12800008 |input method manager service error. | **Return value** @@ -1188,13 +2402,13 @@ For details about the error codes, see [Input Method Framework Error Codes](../e ```js try { - inputMethodSetting.getInputMethods(true).then((data) => { - console.info('Succeeded in getting inputMethods.'); - }).catch((err) => { - console.error('Failed to getInputMethods: ' + JSON.stringify(err)); - }) + inputMethodSetting.getInputMethods(true).then((data) => { + console.log('Succeeded in getting inputMethods.'); + }).catch((err) => { + console.error(`Failed to getInputMethods: ${JSON.stringify(err)}`); + }) } catch(err) { - console.error('Failed to getInputMethods: ' + JSON.stringify(err)); + console.error(`Failed to getInputMethods: ${JSON.stringify(err)}`); } ``` @@ -1218,21 +2432,21 @@ For details about the error codes, see [Input Method Framework Error Codes](../e | Error Code ID| Error Message | | -------- | -------------------------------------- | -| 12800008 | Input method manager service error. | +| 12800008 | input method manager service error. | **Example** ```js try { - inputMethodSetting.showOptionalInputMethods((err, data) => { - if (err !== undefined) { - console.error('Failed to showOptionalInputMethods: ' + JSON.stringify(err)); - return; - } - console.info('Succeeded in showing optionalInputMethods.'); - }); + inputMethodSetting.showOptionalInputMethods((err, data) => { + if (err) { + console.error(`Failed to showOptionalInputMethods: ${JSON.stringify(err)}`); + return; + } + console.log('Succeeded in showing optionalInputMethods.'); + }); } catch (err) { - console.error('Failed to showOptionalInputMethods: ' + JSON.stringify(err)); + console.error(`Failed to showOptionalInputMethods: ${JSON.stringify(err)}`); } ``` @@ -1256,15 +2470,15 @@ For details about the error codes, see [Input Method Framework Error Codes](../e | Error Code ID| Error Message | | -------- | -------------------------------------- | -| 12800008 | Input method manager service error. | +| 12800008 | input method manager service error. | **Example** ```js inputMethodSetting.showOptionalInputMethods().then((data) => { - console.info('Succeeded in showing optionalInputMethods.'); + console.log('Succeeded in showing optionalInputMethods.'); }).catch((err) => { - console.error('Failed to showOptionalInputMethods: ' + JSON.stringify(err)); + console.error(`Failed to showOptionalInputMethods: ${JSON.stringify(err)}`); }) ``` @@ -1276,7 +2490,7 @@ Obtains a list of installed input methods. This API uses an asynchronous callbac > **NOTE** > -> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [getInputMethods](#getinputmethods9). +> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [getInputMethods](#getinputmethods9) instead. **System capability**: SystemCapability.MiscServices.InputMethodFramework @@ -1289,12 +2503,12 @@ Obtains a list of installed input methods. This API uses an asynchronous callbac **Example** ```js -inputMethodSetting.listInputMethod((err,data) => { - if (err !== undefined) { - console.error('Failed to listInputMethod: ' + JSON.stringify(err)); - return; - } - console.log('Succeeded in listing inputMethod.'); +inputMethodSetting.listInputMethod((err, data) => { + if (err) { + console.error(`Failed to listInputMethod: ${JSON.stringify(err)}`); + return; + } + console.log('Succeeded in listing inputMethod.'); }); ``` @@ -1306,7 +2520,7 @@ Obtains a list of installed input methods. This API uses a promise to return the > **NOTE** > -> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [getInputMethods](#getinputmethods9-1). +> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [getInputMethods](#getinputmethods9-1) instead. **System capability**: SystemCapability.MiscServices.InputMethodFramework @@ -1320,9 +2534,9 @@ Obtains a list of installed input methods. This API uses a promise to return the ```js inputMethodSetting.listInputMethod().then((data) => { - console.info('Succeeded in listing inputMethod.'); + console.log('Succeeded in listing inputMethod.'); }).catch((err) => { - console.error('Failed to listInputMethod: ' + JSON.stringify(err)); + console.error(`Failed to listInputMethod: ${JSON.stringify(err)}`); }) ``` @@ -1334,7 +2548,7 @@ Displays a dialog box for selecting an input method. This API uses an asynchrono > **NOTE** > -> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [showOptionalInputMethods()](#showoptionalinputmethods9). +> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [showOptionalInputMethods()](#showoptionalinputmethods9) instead. **System capability**: SystemCapability.MiscServices.InputMethodFramework @@ -1348,11 +2562,11 @@ Displays a dialog box for selecting an input method. This API uses an asynchrono ```js inputMethodSetting.displayOptionalInputMethod((err) => { - if (err !== undefined) { - console.error('Failed to displayOptionalInputMethod: ' + JSON.stringify(err)); - return; - } - console.info('Succeeded in displaying optionalInputMethod.'); + if (err) { + console.error(`Failed to displayOptionalInputMethod: ${JSON.stringify(err)}`); + return; + } + console.log('Succeeded in displaying optionalInputMethod.'); }); ``` @@ -1364,7 +2578,7 @@ Displays a dialog box for selecting an input method. This API uses a promise to > **NOTE** > -> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [showOptionalInputMethods()](#showoptionalinputmethods9-1). +> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [showOptionalInputMethods()](#showoptionalinputmethods9-1) instead. **System capability**: SystemCapability.MiscServices.InputMethodFramework @@ -1378,8 +2592,8 @@ Displays a dialog box for selecting an input method. This API uses a promise to ```js inputMethodSetting.displayOptionalInputMethod().then(() => { - console.info('Succeeded in displaying optionalInputMethod.'); + console.log('Succeeded in displaying optionalInputMethod.'); }).catch((err) => { - console.error('Failed to displayOptionalInputMethod: ' + JSON.stringify(err)); + console.error(`Failed to displayOptionalInputMethod: ${JSON.stringify(err)}`); }) ``` diff --git a/en/application-dev/reference/apis/js-apis-inputmethodengine.md b/en/application-dev/reference/apis/js-apis-inputmethodengine.md index a2e087795857ff8a788b72826bf64f7ec1961f82..43b396fca5c68edbdda3b6146c9a42192421e1d0 100644 --- a/en/application-dev/reference/apis/js-apis-inputmethodengine.md +++ b/en/application-dev/reference/apis/js-apis-inputmethodengine.md @@ -56,7 +56,9 @@ Provides the constant values of function keys, edit boxes, and the cursor. getInputMethodAbility(): InputMethodAbility -Obtains an [InputMethodAbility](#inputmethodability) instance for the input method. The input method can use the obtained instance to subscribe to a soft keyboard display/hide request event, create/destroy an input method panel, and the like. +Obtains an [InputMethodAbility](#inputmethodability) instance for the input method. +This API can be called only by an input method. +The input method can use the obtained instance to subscribe to a soft keyboard display/hide request event, create/destroy an input method panel, and the like. **System capability**: SystemCapability.MiscServices.InputMethodFramework @@ -96,11 +98,11 @@ let KeyboardDelegate = inputMethodEngine.getKeyboardDelegate(); getInputMethodEngine(): InputMethodEngine -Obtains an [InputMethodEngine](#inputmethodengine-1) instance for the input method. The input method can use the obtained instance to subscribe to a soft keyboard display/hide request event. +Obtains an [InputMethodEngine](#inputmethodengine) instance for the input method. The input method can use the obtained instance to subscribe to a soft keyboard display/hide request event. > **NOTE** > -> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [getInputMethodAbility()](#inputmethodenginegetinputmethodability9). +> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [getInputMethodAbility()](#inputmethodenginegetinputmethodability9) instead. **System capability**: SystemCapability.MiscServices.InputMethodFramework @@ -108,7 +110,7 @@ Obtains an [InputMethodEngine](#inputmethodengine-1) instance for the input meth | Type | Description | | ----------------------------------------- | ------------------ | -| [InputMethodEngine](#inputmethodengine-1) | **InputMethodAbility** instance.| +| [InputMethodEngine](#inputmethodengine) | **InputMethodAbility** instance.| **Example** @@ -124,7 +126,7 @@ Obtains a [KeyboardDelegate](#keyboarddelegate) instance for the input method. T > **NOTE** > ->This API is supported since API version 8 and deprecated since API version 9. You are advised to use [getKeyboardDelegate()](#inputmethodenginegetkeyboarddelegate9). +>This API is supported since API version 8 and deprecated since API version 9. You are advised to use [getKeyboardDelegate()](#inputmethodenginegetkeyboarddelegate9) instead. **System capability**: SystemCapability.MiscServices.InputMethodFramework @@ -163,8 +165,8 @@ Enables listening for the input method binding event. This API uses an asynchron ```js inputMethodEngine.getInputMethodEngine().on('inputStart', (kbController, textClient) => { - let keyboardController = kbController; - let textInputClient = textClient; + let keyboardController = kbController; + let textInputClient = textClient; }); ``` @@ -187,7 +189,7 @@ Cancels listening for the input method binding event. ```js inputMethodEngine.getInputMethodEngine().off('inputStart', (kbController, textInputClient) => { - console.log('delete inputStart notification.'); + console.log('delete inputStart notification.'); }); ``` @@ -210,10 +212,10 @@ Enables listening for a keyboard visibility event. This API uses an asynchronous ```js inputMethodEngine.getInputMethodEngine().on('keyboardShow', () => { - console.log('inputMethodEngine keyboardShow.'); + console.log('inputMethodEngine keyboardShow.'); }); inputMethodEngine.getInputMethodEngine().on('keyboardHide', () => { - console.log('inputMethodEngine keyboardHide.'); + console.log('inputMethodEngine keyboardHide.'); }); ``` @@ -262,8 +264,8 @@ Enables listening for the input method binding event. This API uses an asynchron ```js inputMethodEngine.getInputMethodAbility().on('inputStart', (kbController, client) => { - let keyboardController = kbController; - let inputClient = client; + let keyboardController = kbController; + let inputClient = client; }); ``` @@ -307,7 +309,7 @@ Enables listening for the input method unbinding event. This API uses an asynchr ```js inputMethodEngine.getInputMethodAbility().on('inputStop', () => { - console.log('inputMethodAbility inputStop'); + console.log('inputMethodAbility inputStop'); }); ``` @@ -330,7 +332,7 @@ Cancels listening for the input method stop event. This API uses an asynchronous ```js inputMethodEngine.getInputMethodAbility().off('inputStop', () => { - console.log('inputMethodAbility delete inputStop notification.'); + console.log('inputMethodAbility delete inputStop notification.'); }); ``` @@ -353,7 +355,7 @@ Enables listening for the window invocation setting event. This API uses an asyn ```js inputMethodEngine.getInputMethodAbility().on('setCallingWindow', (wid) => { - console.log('inputMethodAbility setCallingWindow'); + console.log('inputMethodAbility setCallingWindow'); }); ``` @@ -375,8 +377,8 @@ Disables listening for the window invocation setting event. This API uses an asy **Example** ```js -inputMethodEngine.getInputMethodAbility().off('setCallingWindow', () => { - console.log('inputMethodAbility delete setCallingWindow notification.'); +inputMethodEngine.getInputMethodAbility().off('setCallingWindow', (wid) => { + console.log('inputMethodAbility delete setCallingWindow notification.'); }); ``` @@ -384,7 +386,7 @@ inputMethodEngine.getInputMethodAbility().off('setCallingWindow', () => { on(type: 'keyboardShow'|'keyboardHide', callback: () => void): void -Enables listening for a keyboard event. This API uses an asynchronous callback to return the result. +Enables listening for a keyboard visibility event. This API uses an asynchronous callback to return the result. **System capability**: SystemCapability.MiscServices.InputMethodFramework @@ -399,10 +401,10 @@ Enables listening for a keyboard event. This API uses an asynchronous callback t ```js inputMethodEngine.getInputMethodAbility().on('keyboardShow', () => { - console.log('InputMethodAbility keyboardShow.'); + console.log('InputMethodAbility keyboardShow.'); }); inputMethodEngine.getInputMethodAbility().on('keyboardHide', () => { - console.log('InputMethodAbility keyboardHide.'); + console.log('InputMethodAbility keyboardHide.'); }); ``` @@ -410,7 +412,7 @@ inputMethodEngine.getInputMethodAbility().on('keyboardHide', () => { off(type: 'keyboardShow'|'keyboardHide', callback?: () => void): void -Disables listening for a keyboard event. This API uses an asynchronous callback to return the result. +Disables listening for a keyboard visibility event. This API uses an asynchronous callback to return the result. **System capability**: SystemCapability.MiscServices.InputMethodFramework @@ -425,10 +427,10 @@ Disables listening for a keyboard event. This API uses an asynchronous callback ```js inputMethodEngine.getInputMethodAbility().off('keyboardShow', () => { - console.log('InputMethodAbility delete keyboardShow notification.'); + console.log('InputMethodAbility delete keyboardShow notification.'); }); inputMethodEngine.getInputMethodAbility().off('keyboardHide', () => { - console.log('InputMethodAbility delete keyboardHide notification.'); + console.log('InputMethodAbility delete keyboardHide notification.'); }); ``` @@ -442,16 +444,16 @@ Enables listening for the input method subtype setting event. This API uses an a **Parameters** -| Name | Type | Mandatory| Description | -| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | -| type | string | Yes | Listening type.
The value **'setSubtype'** indicates the input method subtype setting event.| +| Name | Type| Mandatory | Description| +| -------- | --- | ---- | --- | +| type | string | Yes | Listening type.
The value **'setSubtype'** indicates the input method subtype setting event.| | callback | (inputMethodSubtype: [InputMethodSubtype](js-apis-inputmethod-subtype.md)) => void | Yes | Callback used to return the input method subtype. | **Example** ```js inputMethodEngine.getInputMethodAbility().on('setSubtype', (inputMethodSubtype) => { - console.log('InputMethodAbility setSubtype.'); + console.log('InputMethodAbility setSubtype.'); }); ``` @@ -465,16 +467,16 @@ Disables listening for the input method subtype setting event. This API uses an **Parameters** -| Name | Type | Mandatory| Description | -| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | -| type | string | Yes | Listening type.
The value **'setSubtype'** indicates the input method subtype setting event.| +| Name | Type | Mandatory| Description | +| ------- | ----- | ---- | ---- | +| type | string | Yes | Listening type.
The value **'setSubtype'** indicates the input method subtype setting event.| | callback | (inputMethodSubtype: [InputMethodSubtype](js-apis-inputmethod-subtype.md)) => void | No | Callback used to return the input method subtype. | **Example** ```js inputMethodEngine.getInputMethodAbility().off('setSubtype', () => { - console.log('InputMethodAbility delete setSubtype notification.'); + console.log('InputMethodAbility delete setSubtype notification.'); }); ``` @@ -482,7 +484,9 @@ inputMethodEngine.getInputMethodAbility().off('setSubtype', () => { createPanel(ctx: BaseContext, info: PanelInfo, callback: AsyncCallback\): void -Creates an input method panel. This API can be called only by input method applications and system applications with the system_core permission. Only one SOFT_KEYBOARD panel and one STATUS_BAR panel can be created for a single input method application. This API uses an asynchronous callback to return the result. +Creates an input method panel. This API uses an asynchronous callback to return the result. + +This API can be called only by an input method. Only one SOFT_KEYBOARD panel and one STATUS_BAR panel can be created for a single input method application. **System capability**: SystemCapability.MiscServices.InputMethodFramework @@ -490,7 +494,7 @@ Creates an input method panel. This API can be called only by input method appli | Name | Type | Mandatory| Description | | ------- | ----------- | ---- | ------------------------ | -| ctx | [BaseContext](./js-apis-inner-application-baseContext.md) | Yes | Context of the current input method.| +| ctx | [BaseContext](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/reference/apis/js-apis-inner-application-baseContext.md) | Yes | Context of the current input method.| | info | [PanelInfo](#panelinfo10) | Yes | Information about the input method panel.| | callback | AsyncCallback\<[Panel](#panel10)> | Yes | Callback used to return the result. If the operation is successful, the created input method panel is returned. | @@ -504,19 +508,19 @@ Creates an input method panel. This API can be called only by input method appli ```js let panelInfo: inputMethodEngine.PanelInfo = { - panelType: SOFT_KEYBOARD, - panelFlag: FLG_FIXED + panelType: inputMethodEngine.PanelType.SOFT_KEYBOARD, + panelFlag: inputMethodEngine.PanelFlag.FLG_FIXED } try { inputMethodEngine.getInputMethodAbility().createPanel(this.context, panelInfo, (err, panel) => { - if (err !== undefined) { - console.log('Failed to create panel, err: ' + JSON.stringify(err)); + if (err) { + console.error(`Failed to createPanel: ${JSON.stringify(err)}`); return; } console.log('Succeed in creating panel.'); }) } catch(err) { - console.log('Failed to create panel, err: ' + JSON.stringify(err)); + console.error(`Failed to createPanel: ${JSON.stringify(err)}`); } ``` @@ -524,7 +528,9 @@ try { createPanel(ctx: BaseContext, info: PanelInfo): Promise\ -Creates an input method panel. This API can be called only by input method applications and system applications with the system_core permission. Only one SOFT_KEYBOARD panel and one STATUS_BAR panel can be created for a single input method application. This API uses a promise to return the result. +Creates an input method panel. This API uses a promise to return the result. + +This API can be called only by an input method. Only one SOFT_KEYBOARD panel and one STATUS_BAR panel can be created for a single input method application. **System capability**: SystemCapability.MiscServices.InputMethodFramework @@ -550,13 +556,13 @@ Creates an input method panel. This API can be called only by input method appli ```js let panelInfo: inputMethodEngine.PanelInfo = { - panelType: SOFT_KEYBOARD, - panelFlag: FLG_FIXED + panelType: inputMethodEngine.PanelType.SOFT_KEYBOARD, + panelFlag: inputMethodEngine.PanelFlag.FLG_FIXED } inputMethodEngine.getInputMethodAbility().createPanel(this.context, panelInfo).then((panel) => { console.log('Succeed in creating panel.'); }).catch((err) => { - console.log('Failed to create panel, err: ' + JSON.stringify(err)); + console.error(`Failed to create panel: ${JSON.stringify(err)}`); }) ``` @@ -579,32 +585,32 @@ Destroys an input method panel. This API uses an asynchronous callback to return ```js let panelInfo: inputMethodEngine.PanelInfo = { - panelType: SOFT_KEYBOARD, - panelFlag: FLG_FIXED + panelType: inputMethodEngine.PanelType.SOFT_KEYBOARD, + panelFlag: inputMethodEngine.PanelFlag.FLG_FIXED } try { inputMethodEngine.getInputMethodAbility().createPanel(this.context, panelInfo, (err, panel) => { - if (err !== undefined) { - console.log('Failed to create panel, err: ' + JSON.stringify(err)); + if (err) { + console.error(`Failed to create panel: ${JSON.stringify(err)}`); return; } globalThis.inputMethodPanel = panel; console.log('Succeed in creating panel.'); }) } catch(err) { - console.log('Failed to create panel, err: ' + JSON.stringify(err)); + console.error(`Failed to create panel: ${JSON.stringify(err)}`); } try { inputMethodEngine.getInputMethodAbility().destroyPanel(globalThis.inputMethodPanel, (err) => { if(err !== undefined) { - console.log('Failed to destroy panel, err: ' + JSON.stringify(err)); + console.error(`Failed to destroy panel: ${JSON.stringify(err)}`); return; } console.log('Succeed in destroying panel.'); }) } catch(err) { - console.log('Failed to destroy panel, err: ' + JSON.stringify(err)); + console.error(`Failed to destroy panel: ${JSON.stringify(err)}`); } ``` @@ -631,30 +637,30 @@ Destroys an input method panel. This API uses a promise to return the result. ```js let panelInfo: inputMethodEngine.PanelInfo = { - panelType: SOFT_KEYBOARD, - panelFlag: FLG_FIXED + panelType: inputMethodEngine.PanelType.SOFT_KEYBOARD, + panelFlag: inputMethodEngine.PanelFlag.FLG_FIXED } try { inputMethodEngine.getInputMethodAbility().createPanel(this.context, panelInfo, (err, panel) => { - if (err !== undefined) { - console.log('Failed to create panel, err: ' + JSON.stringify(err)); + if (err) { + console.error(`Failed to create panel: ${JSON.stringify(err)}`); return; } globalThis.inputMethodPanel = panel; console.log('Succeed in creating panel.'); }) } catch(err) { - console.log('Failed to create panel, err: ' + JSON.stringify(err)); + console.error(`Failed to create panel: ${JSON.stringify(err)}`); } try { inputMethodEngine.getInputMethodAbility().destroyPanel(globalThis.inputMethodPanel).then(() => { console.log('Succeed in destroying panel.'); }).catch((err) => { - console.log('Failed to destroy panel, err: ' + JSON.stringify(err)); + console.error(`Failed to destroy panel: ${JSON.stringify(err)}`); }); } catch (err) { - console.log('Failed to destroy panel, err: ' + JSON.stringify(err)); + console.error(`Failed to destroy panel: ${JSON.stringify(err)}`); } ``` @@ -681,14 +687,14 @@ Enables listening for a keyboard event. This API uses an asynchronous callback t ```js inputMethodEngine.getKeyboardDelegate().on('keyUp', (keyEvent) => { - console.info('inputMethodEngine keyCode.(keyUp):' + JSON.stringify(keyEvent.keyCode)); - console.info('inputMethodEngine keyAction.(keyUp):' + JSON.stringify(keyEvent.keyAction)); - return true; + console.log('inputMethodEngine keyCode.(keyUp):' + JSON.stringify(keyEvent.keyCode)); + console.log('inputMethodEngine keyAction.(keyUp):' + JSON.stringify(keyEvent.keyAction)); + return true; }); inputMethodEngine.getKeyboardDelegate().on('keyDown', (keyEvent) => { - console.info('inputMethodEngine keyCode.(keyDown):' + JSON.stringify(keyEvent.keyCode)); - console.info('inputMethodEngine keyAction.(keyDown):' + JSON.stringify(keyEvent.keyAction)); - return true; + console.log('inputMethodEngine keyCode.(keyDown):' + JSON.stringify(keyEvent.keyCode)); + console.log('inputMethodEngine keyAction.(keyDown):' + JSON.stringify(keyEvent.keyAction)); + return true; }); ``` @@ -702,21 +708,21 @@ Disables listening for a keyboard event. This API uses an asynchronous callback **Parameters** -| Name | Type | Mandatory| Description | -| -------- | ----------------------------------------- | ---- | ------------------------------------------------------------ | -| type | string | Yes | Listening type.
The value **'keyDown'** indicates the keydown event.
The value **'keyUp'** indicates the keyup event.| +| Name | Type | Mandatory | Description | +| -------- | ------- | ---- | ----- | +| type | string | Yes | Listening type.
The value **'keyDown'** indicates the keydown event.
The value **'keyUp'** indicates the keyup event.| | callback | (event: [KeyEvent](#keyevent)) => boolean | No | Callback used to return the key information. | **Example** ```js inputMethodEngine.getKeyboardDelegate().off('keyUp', (keyEvent) => { - console.log('delete keyUp notification.'); - return true; + console.log('delete keyUp notification.'); + return true; }); inputMethodEngine.getKeyboardDelegate().off('keyDown', (keyEvent) => { - console.log('delete keyDown notification.'); - return true; + console.log('delete keyDown notification.'); + return true; }); ``` @@ -730,18 +736,18 @@ Enables listening for the cursor change event. This API uses an asynchronous cal **Parameters** -| Name | Type | Mandatory| Description | -| -------- | ---------------------------------------------- | ---- | ------------------------------------------------------------ | -| type | string | Yes | Listening type.
The value **'cursorContextChange'** indicates the cursor change event.| +| Name | Type | Mandatory | Description | +| -------- | ---- | ---- | ----- | +| type | string | Yes | Listening type.
The value **'cursorContextChange'** indicates the cursor change event.| | callback | (x: number, y: number, height: number) => void | Yes | Callback used to return the cursor information.
- **x**: x coordinate of the top of the cursor.
- **y**: x coordinate of the bottom of the cursor.
- **height**: height of the cursor.| **Example** ```js inputMethodEngine.getKeyboardDelegate().on('cursorContextChange', (x, y, height) => { - console.log('inputMethodEngine cursorContextChange x:' + x); - console.log('inputMethodEngine cursorContextChange y:' + y); - console.log('inputMethodEngine cursorContextChange height:' + height); + console.log('inputMethodEngine cursorContextChange x:' + x); + console.log('inputMethodEngine cursorContextChange y:' + y); + console.log('inputMethodEngine cursorContextChange height:' + height); }); ``` @@ -755,9 +761,9 @@ Cancels listening for cursor context changes. This API uses an asynchronous call **Parameters** -| Name | Type | Mandatory| Description | -| -------- | -------------------------------------------- | ---- | ------------------------------------------------------------ | -| type | string | Yes | Listening type.
The value **'cursorContextChange'** indicates the cursor change event.| +| Name | Type | Mandatory | Description | +| -------- | ---- | ---- | ------ | +| type | string | Yes | Listening type.
The value **'cursorContextChange'** indicates the cursor change event.| | callback | (x: number, y:number, height:number) => void | No | Callback used to return the cursor information.
- **x**: x coordinate of the top of the cursor.
- **y**: x coordinate of the bottom of the cursor.
- **height**: height of the cursor.
| @@ -765,7 +771,7 @@ Cancels listening for cursor context changes. This API uses an asynchronous call ```js inputMethodEngine.getKeyboardDelegate().off('cursorContextChange', (x, y, height) => { - console.log('delete cursorContextChange notification.'); + console.log('delete cursorContextChange notification.'); }); ``` ### on('selectionChange') @@ -778,19 +784,19 @@ Enables listening for the text selection change event. This API uses an asynchro **Parameters** -| Name | Type | Mandatory| Description | -| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | -| type | string | Yes | Listening type.
The value **'selectionChange'** indicates the text selection change event.| +| Name | Type | Mandatory| Description | +| -------- | ----- | ---- | ---- | +| type | string | Yes | Listening type.
The value **'selectionChange'** indicates the text selection change event.| | callback | (oldBegin: number, oldEnd: number, newBegin: number, newEnd: number) => void | Yes | Callback used to return the text selection information.
- **oldBegin**: start of the selected text before the change.
- **oldEnd**: end of the selected text before the change.
- **newBegin**: start of the selected text after the change.
- **newEnd**: end of the selected text after the change.| **Example** ```js inputMethodEngine.getKeyboardDelegate().on('selectionChange', (oldBegin, oldEnd, newBegin, newEnd) => { - 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); + 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); }); ``` @@ -804,9 +810,9 @@ Cancels listening for text selection changes. This API uses an asynchronous call **Parameters** -| Name | Type | Mandatory| Description | -| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | -| type | string | Yes | Listening type.
The value **'selectionChange'** indicates the text selection change event.| +| Name | Type | Mandatory| Description | +| -------- | ------- | ---- | ------- | +| type | string | Yes | Listening type.
The value **'selectionChange'** indicates the text selection change event.| | callback | (oldBegin: number, oldEnd: number, newBegin: number, newEnd: number) => void | No | Callback used to return the text selection information.
- **oldBegin**: start of the selected text before the change.
- **oldEnd**: end of the selected text before the change.
- **newBegin**: start of the selected text after the change.
- **newEnd**: end of the selected text after the change.
| **Example** @@ -831,13 +837,13 @@ Enables listening for the text change event. This API uses an asynchronous callb | Name | Type | Mandatory| Description | | -------- | ------ | ---- | ------------------------------------------------------------ | | type | string | Yes | Listening type.
The value **'textChange'** indicates the text change event.| -| callback | (text: string) => void | Yes | Callback used to return the text content. | +| callback | (text: string) => void | Yes | Callback used to return the text content.| **Example** ```js inputMethodEngine.getKeyboardDelegate().on('textChange', (text) => { - console.log('inputMethodEngine textChange. text:' + text); + console.log('inputMethodEngine textChange. text:' + text); }); ``` @@ -860,7 +866,7 @@ Cancels listening for text changes. This API uses an asynchronous callback to re ```js inputMethodEngine.getKeyboardDelegate().off('textChange', (text) => { - console.log('delete textChange notification. text:' + text); + console.log('delete textChange notification. text:' + text); }); ``` @@ -889,13 +895,13 @@ Loads content from a page to this panel. This API uses an asynchronous callback try { panel.setUiContent('pages/page2/page2', (err) => { if (err) { - console.error('Failed to set the content. err:' + JSON.stringify(err)); + console.error(`Failed to setUiContent: ${JSON.stringify(err)}`); return; } - console.info('Succeeded in setting the content.'); + console.log('Succeeded in setting the content.'); }); -} catch (exception) { - console.error('Failed to set the content. err:' + JSON.stringify(exception)); +} catch (err) { + console.error(`Failed to setUiContent: ${JSON.stringify(err)}`); } ``` @@ -925,12 +931,12 @@ Loads content from a page to this panel. This API uses a promise to return the r try { let promise = panel.setUiContent('pages/page2/page2'); promise.then(() => { - console.info('Succeeded in setting the content.'); + console.log('Succeeded in setting the content.'); }).catch((err) =>{ - console.error('Failed to set the content. err: ' + JSON.stringify(err)); + console.error(`Failed to setUiContent: ${JSON.stringify(err)}`); }); -} catch (exception) { - console.error('Failed to set the content. err: ' + JSON.stringify(exception)); +} catch (err) { + console.error(`Failed to setUiContent: ${JSON.stringify(err)}`); } ``` @@ -947,7 +953,7 @@ Loads content from a page linked to LocalStorage to this panel. This API uses an | Name | Type | Mandatory| Description | | -------- | ---------------------- | ---- | -------- | | path | string | Yes | Path of the page from which the content will be loaded.| -| storage | [LocalStorage](../../quick-start/arkts-state-mgmt-application-level.md#localstorage) | Yes | Storage unit that provides storage for mutable and immutable state variables in the application.| +| storage | [LocalStorage](../../quick-start/arkts-localstorage.md) | Yes | Storage unit that provides storage for mutable and immutable state variables in the application.| | callback | AsyncCallback\ | Yes | Callback used to return the result. If the operation is successful, **err** is **undefined**. Otherwise, **err** is an error object.| **Example** @@ -958,13 +964,13 @@ storage.setOrCreate('storageSimpleProp',121); try { panel.setUiContent('pages/page2/page2', storage, (err) => { if (err) { - console.error('Failed to set the content. err:' + JSON.stringify(err)); + console.error(`Failed to setUiContent: ${JSON.stringify(err)}`); return; } - console.info('Succeeded in setting the content.'); + console.log('Succeeded in setting the content.'); }); -} catch (exception) { - console.error('Failed to set the content. err:' + JSON.stringify(exception)); +} catch (err) { + console.error(`Failed to setUiContent: ${JSON.stringify(err)}`); } ``` @@ -981,7 +987,7 @@ Loads content from a page linked to LocalStorage to this panel. This API uses a | Name | Type | Mandatory| Description | | -------- | ---------------------- | ---- | -------- | | path | string | Yes | Path of the page from which the content will be loaded.| -| storage | [LocalStorage](../../quick-start/arkts-state-mgmt-application-level.md#localstorage) | Yes | Storage unit that provides storage for mutable and immutable state variables in the application.| +| storage | [LocalStorage](../../quick-start/arkts-localstorage.md) | Yes | Storage unit that provides storage for mutable and immutable state variables in the application.| **Return value** @@ -997,12 +1003,12 @@ storage.setOrCreate('storageSimpleProp',121); try { let promise = panel.setUiContent('pages/page2/page2'); promise.then(() => { - console.info('Succeeded in setting the content.'); + console.log('Succeeded in setting the content.'); }).catch((err) =>{ - console.error('Failed to set the content. err: ' + JSON.stringify(err)); + console.error(`Failed to setUiContent: ${JSON.stringify(err)}`); }); -} catch (exception) { - console.error('Failed to set the content. err: ' + JSON.stringify(exception)); +} catch (err) { + console.error(`Failed to setUiContent: ${JSON.stringify(err)}`); } ``` @@ -1011,6 +1017,7 @@ try { resize(width: number, height: number, callback: AsyncCallback\): void Resizes this panel. This API uses an asynchronous callback to return the result. + The panel width cannot exceed the screen width, and the panel height cannot be higher than half of the screen height. **System capability**: SystemCapability.MiscServices.InputMethodFramework @@ -1019,8 +1026,8 @@ The panel width cannot exceed the screen width, and the panel height cannot be h | Name | Type | Mandatory| Description | | -------- | ---------------------- | ---- | -------- | -| width | number | Yes | Target width of the panel, in pixels.| -| height | number | Yes | Target height of the panel, in pixels.| +| width | number | Yes | Target width of the panel, in px.| +| height | number | Yes | Target height of the panel, in px.| | callback | AsyncCallback\ | Yes | Callback used to return the result. If the operation is successful, **err** is **undefined**. Otherwise, **err** is an error object.| **Example** @@ -1029,13 +1036,13 @@ The panel width cannot exceed the screen width, and the panel height cannot be h try { panel.resize(500, 1000, (err) => { if (err) { - console.error('Failed to change the panel size. Cause:' + JSON.stringify(err)); + console.error(`Failed to resize panel: ${JSON.stringify(err)}`); return; } - console.info('Succeeded in changing the panel size.'); + console.log('Succeeded in changing the panel size.'); }); -} catch (exception) { - console.error('Failed to change the panel size. Cause:' + JSON.stringify(exception)); +} catch (err) { + console.error(`Failed to resize panel: ${JSON.stringify(err)}`); } ``` @@ -1044,6 +1051,7 @@ try { resize(width: number, height: number): Promise\; Resizes this panel. This API uses a promise to return the result. + The panel width cannot exceed the screen width, and the panel height cannot be higher than half of the screen height. **System capability**: SystemCapability.MiscServices.InputMethodFramework @@ -1052,8 +1060,8 @@ The panel width cannot exceed the screen width, and the panel height cannot be h | Name | Type | Mandatory| Description | | -------- | ---------------------- | ---- | -------- | -| width | number | Yes | Target width of the panel, in pixels.| -| height | number | Yes | Target height of the panel, in pixels.| +| width | number | Yes | Target width of the panel, in px.| +| height | number | Yes | Target height of the panel, in px.| **Return value** @@ -1067,12 +1075,12 @@ The panel width cannot exceed the screen width, and the panel height cannot be h try { let promise = panel.resize(500, 1000); promise.then(() => { - console.info('Succeeded in changing the panel size.'); + console.log('Succeeded in changing the panel size.'); }).catch((err) =>{ - console.error('Failed to change the panel size. err: ' + JSON.stringify(err)); + console.error(`Failed to resize panel: ${JSON.stringify(err)}`); }); -} catch (exception) { - console.error('Failed to change the panel size. err: ' + JSON.stringify(exception)); +} catch (err) { + console.error(`Failed to resize panel: ${JSON.stringify(err)}`); } ``` @@ -1081,6 +1089,7 @@ try { moveTo(x: number, y: number, callback: AsyncCallback\): void Moves this panel to the specified position. This API uses an asynchronous callback to return the result. + This API does not work on panels in the FLG_FIXED state. **System capability**: SystemCapability.MiscServices.InputMethodFramework @@ -1090,7 +1099,7 @@ This API does not work on panels in the FLG_FIXED state. | Name | Type | Mandatory| Description | | -------- | ---------------------- | ---- | -------- | | x | number | Yes | Distance to move along the x-axis, in px. A positive value indicates moving rightwards.| -| y | number | Yes | Distance to move along the y-axis, in pixels. A positive value indicates moving downwards.| +| y | number | Yes | Distance to move along the y-axis, in px. A positive value indicates moving downwards.| | callback | AsyncCallback\ | Yes | Callback used to return the result. If the operation is successful, **err** is **undefined**. Otherwise, **err** is an error object.| **Example** @@ -1099,13 +1108,13 @@ This API does not work on panels in the FLG_FIXED state. try { panel.moveTo(300, 300, (err) =>{ if (err) { - console.error('Failed to move the panel. err:' + JSON.stringify(err)); + console.error(`Failed to move panel: ${JSON.stringify(err)}`); return; } - console.info('Succeeded in moving the panel.'); + console.log('Succeeded in moving the panel.'); }); -} catch (exception) { - console.error('Failed to move the panel. err:' + JSON.stringify(exception)); +} catch (err) { + console.error(`Failed to move panel: ${JSON.stringify(err)}`); } ``` @@ -1113,7 +1122,8 @@ try { moveTo(x: number, y: number): Promise\ -Moves this panel to the specified position. This API uses a promise to return the result. +Moves this panel to the specified position. This API uses a promise to return the result. + This API does not work on panels in the FLG_FIXED state. **System capability**: SystemCapability.MiscServices.InputMethodFramework @@ -1122,8 +1132,8 @@ This API does not work on panels in the FLG_FIXED state. | Name | Type | Mandatory| Description | | -------- | ---------------------- | ---- | -------- | -| x | number | Yes | Distance to move along the x-axis, in pixels. A positive value indicates moving rightwards.| -| y | number | Yes | Distance to move along the y-axis, in pixels. A positive value indicates moving downwards.| +| x | number | Yes | Distance to move along the x-axis, in px. A positive value indicates moving rightwards.| +| y | number | Yes | Distance to move along the y-axis, in px. A positive value indicates moving downwards.| **Return value** @@ -1137,12 +1147,12 @@ This API does not work on panels in the FLG_FIXED state. try { let promise = windowClass.moveTo(300, 300); promise.then(() => { - console.info('Succeeded in moving the panel.'); + console.log('Succeeded in moving the panel.'); }).catch((err) =>{ - console.error('Failed to move the panel. Cause: ' + JSON.stringify(err)); + console.error(`Failed to move panel: ${JSON.stringify(err)}`); }); -} catch (exception) { - console.error('Failed to move the panel. Cause:' + JSON.stringify(exception)); +} catch (err) { + console.error(`Failed to move panel: ${JSON.stringify(err)}`); } ``` @@ -1150,7 +1160,7 @@ try { show(callback: AsyncCallback\): void -Displays this panel. This API uses an asynchronous callback to return the result. +Shows this panel. This API uses an asynchronous callback to return the result. **System capability**: SystemCapability.MiscServices.InputMethodFramework @@ -1165,10 +1175,10 @@ Displays this panel. This API uses an asynchronous callback to return the result ```js panel.show((err) => { if (err) { - console.error('Failed to show the panel. Cause: ' + JSON.stringify(err)); + console.error(`Failed to show panel: ${JSON.stringify(err)}`); return; } - console.info('Succeeded in showing the panel.'); + console.log('Succeeded in showing the panel.'); }); ``` @@ -1176,7 +1186,7 @@ panel.show((err) => { show(): Promise\ -Displays this panel. This API uses a promise to return the result. +Shows this panel. This API uses a promise to return the result. **System capability**: SystemCapability.MiscServices.InputMethodFramework @@ -1191,9 +1201,9 @@ Displays this panel. This API uses a promise to return the result. ```js let promise = panel.show(); promise.then(() => { - console.info('Succeeded in showing the panel.'); + console.log('Succeeded in showing the panel.'); }).catch((err) =>{ - console.error('Failed to show the panel. err: ' + JSON.stringify(err)); + console.error(`Failed to show panel: ${JSON.stringify(err)}`); }); ``` @@ -1216,10 +1226,10 @@ Hides this panel. This API uses an asynchronous callback to return the result. ```js panel.hide((err) => { if (err) { - console.error('Failed to hide the panel. Cause: ' + JSON.stringify(err)); + console.error(`Failed to hide panel: ${JSON.stringify(err)}`); return; } - console.info('Succeeded in hiding the panel.'); + console.log('Succeeded in hiding the panel.'); }); ``` @@ -1242,9 +1252,9 @@ Hides this panel. This API uses a promise to return the result. ```js let promise = panel.hide(); promise.then(() => { - console.info('Succeeded in hiding the panel.'); + console.log('Succeeded in hiding the panel.'); }).catch((err) =>{ - console.error('Failed to hide the panel. err: ' + JSON.stringify(err)); + console.error(`Failed to hide panel: ${JSON.stringify(err)}`); }); ``` @@ -1267,7 +1277,7 @@ Enables listening for a panel visibility event. This API uses an asynchronous ca ```js panel.on('show', () => { - console.info('Panel is showing.'); + console.log('Panel is showing.'); }); ``` @@ -1283,7 +1293,7 @@ Disables listening for a panel visibility event. This API uses an asynchronous c | Name | Type | Mandatory| Description | | -------- | ---------------------- | ---- | -------- | -| type | 'show'/'hide' | Yes| Listening type.
- The value **'show'** indicates the panel display event.
- The value **'hide'** indicates the panel hiding event.| +| type | 'show'\|'hide' | Yes| Listening type.
- The value **'show'** indicates the panel display event.
- The value **'hide'** indicates the panel hiding event.| | callback | () => void | No | Callback used to return the result.| **Example** @@ -1309,7 +1319,7 @@ Changes the panel state type. This API only works for SOFT_KEYBOARD panels. **Example** ```js -let panelFlag = inputMethodEngine.getInputMethodAbility().PanelFlag.FLG_FIXED; +let panelFlag = inputMethodEngine.PanelFlag.FLG_FIXED; panel.changeFlag(panelFlag); ``` @@ -1343,11 +1353,11 @@ For details about the error codes, see [Input Method Framework Error Codes](../e ```js keyboardController.hide((err) => { - if (err !== undefined) { - console.error('Failed to hide keyboard: ' + JSON.stringify(err)); - return; - } - console.log('Succeeded in hiding keyboard.'); + if (err) { + console.error(`Failed to hide: ${JSON.stringify(err)}`); + return; + } + console.log('Succeeded in hiding keyboard.'); }); ``` @@ -1377,9 +1387,9 @@ For details about the error codes, see [Input Method Framework Error Codes](../e ```js keyboardController.hide().then(() => { - console.info('Succeeded in hiding keyboard.'); + console.log('Succeeded in hiding keyboard.'); }).catch((err) => { - console.info('Failed to hide keyboard: ' + JSON.stringify(err)); + console.log(`Failed to hide: ${JSON.stringify(err)}`); }); ``` @@ -1391,7 +1401,7 @@ Hides the keyboard. This API uses an asynchronous callback to return the result. > **NOTE** > -> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [hide](#hide9). +> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [hide](#hide9) instead. **System capability**: SystemCapability.MiscServices.InputMethodFramework @@ -1405,11 +1415,11 @@ Hides the keyboard. This API uses an asynchronous callback to return the result. ```js keyboardController.hideKeyboard((err) => { - if (err !== undefined) { - console.error('Failed to hide Keyboard: ' + JSON.stringify(err)); - return; - } - console.log('Succeeded in hiding keyboard.'); + if (err) { + console.error(`Failed to hideKeyboard: ${JSON.stringify(err)}`); + return; + } + console.log('Succeeded in hiding keyboard.'); }); ``` @@ -1421,7 +1431,7 @@ Hides the keyboard. This API uses a promise to return the result. > **NOTE** > -> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [hide](#hide9-1). +> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [hide](#hide9-1) instead. **System capability**: SystemCapability.MiscServices.InputMethodFramework @@ -1435,12 +1445,59 @@ Hides the keyboard. This API uses a promise to return the result. ```js keyboardController.hideKeyboard().then(() => { - console.info('Succeeded in hiding keyboard.'); + console.log('Succeeded in hiding keyboard.'); }).catch((err) => { - console.info('Failed to hide Keyboard: ' + JSON.stringify(err)); + console.log(`Failed to hideKeyboard: ${JSON.stringify(err)}`); }); ``` +## ExtendAction10+ + +Describes the type of the extended edit action on the text box. + +**System capability**: SystemCapability.MiscServices.InputMethodFramework + +| Name| Value|Description| +| -------- | -------- |-------- | +| SELECT_ALL | 0 |Select all.| +| CUT | 3 |Cut.| +| COPY | 4 |Copy.| +| PASTE | 5 |Paste.| + +## Direction10+ + +Enumerates the directions of cursor movement of the input method. + +**System capability**: SystemCapability.MiscServices.InputMethodFramework + +| Name| Value|Description| +| -------- | -------- |-------- | +| CURSOR_UP | 1 |Upward.| +| CURSOR_DOWN | 2 |Downward.| +| CURSOR_LEFT | 3 |Leftward.| +| CURSOR_RIGHT | 4 |Rightward.| + +## Range10+ + +Describes the range of the selected text. + +**System capability**: SystemCapability.MiscServices.InputMethodFramework + +| Name| Type| Readable| Writable| Description| +| -------- | -------- | -------- | -------- | -------- | +| start | number | Yes| Yes| Index of the first selected character in the text box.| +| end | number | Yes| Yes| Index of the last selected character in the text box.| + +## Movement10+ + +Describes the direction in which the cursor moves when the text is selected. + +**System capability**: SystemCapability.MiscServices.InputMethodFramework + +| Name| Type| Readable| Writable| Description| +| -------- | -------- | -------- | -------- | -------- | +| direction | [Direction](#direction10) | Yes| Yes| Direction in which the cursor moves when the text is selected.| + ## InputClient9+ In the following API examples, you must first use **[on('inputStart')](#oninputstart9)** to obtain an **InputClient** instance, and then call the APIs using the obtained instance. @@ -1457,7 +1514,7 @@ Sends the function key. This API uses an asynchronous callback to return the res | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | -| action | number | Yes| Action of the function key.
**0**: invalid key.
**1**: confirm key (Enter key).| +| action | number | Yes| Action of the function key.
- **0**: invalid key.
- **1**: confirm key (Enter key).| | callback | AsyncCallback<boolean> | Yes| Callback used to return the result. If the operation is successful, **err** is **undefined** and **data** is **true**. Otherwise, **err** is an error object.| **Error codes** @@ -1473,19 +1530,19 @@ For details about the error codes, see [Input Method Framework Error Codes](../e ```js let action = 1; try { - inputClient.sendKeyFunction(action, (err, result) => { - if (err !== undefined) { - console.error('Failed to sendKeyFunction: ' + JSON.stringify(err)); - return; - } - if (result) { - console.info('Succeeded in sending key function. '); - } else { - console.error('Failed to sendKeyFunction. '); - } - }); + inputClient.sendKeyFunction(action, (err, result) => { + if (err) { + console.error(`Failed to sendKeyFunction: ${JSON.stringify(err)}`); + return; + } + if (result) { + console.log('Succeeded in sending key function.'); + } else { + console.error('Failed to sendKeyFunction.'); + } + }); } catch (err) { - console.error('sendKeyFunction err: ' + JSON.stringify(err)); + console.error(`Failed to sendKeyFunction: ${JSON.stringify(err)}`); } ``` @@ -1522,17 +1579,17 @@ For details about the error codes, see [Input Method Framework Error Codes](../e ```js let action = 1; try { - inputClient.sendKeyFunction(action).then((result) => { - if (result) { - console.info('Succeeded in sending key function. '); - } else { - console.error('Failed to sendKeyFunction. '); - } - }).catch((err) => { - console.error('Failed to sendKeyFunction:' + JSON.stringify(err)); - }); + inputClient.sendKeyFunction(action).then((result) => { + if (result) { + console.log('Succeeded in sending key function.'); + } else { + console.error('Failed to sendKeyFunction.'); + } + }).catch((err) => { + console.error(`Failed to sendKeyFunction: ${JSON.stringify(err)}`); + }); } catch (err) { - console.error('Failed to sendKeyFunction: ' + JSON.stringify(err)); + console.error(`Failed to sendKeyFunction: ${JSON.stringify(err)}`); } ``` @@ -1565,15 +1622,15 @@ For details about the error codes, see [Input Method Framework Error Codes](../e ```js let length = 1; try { - inputClient.getForward(length, (err, text) => { - if (err !== undefined) { - console.error('Failed to getForward: ' + JSON.stringify(err)); - return; - } - console.log('Succeeded in getting forward, text: ' + text); - }); + inputClient.getForward(length, (err, text) => { + if (err) { + console.error(`Failed to getForward: ${JSON.stringify(err)}`); + return; + } + console.log('Succeeded in getting forward, text: ' + text); + }); } catch (err) { - console.error('Failed to getForward: ' + JSON.stringify(err)); + console.error(`Failed to getForward: ${JSON.stringify(err)}`); } ``` @@ -1611,13 +1668,13 @@ For details about the error codes, see [Input Method Framework Error Codes](../e ```js let length = 1; try { - inputClient.getForward(length).then((text) => { - console.info('Succeeded in getting forward, text: ' + text); - }).catch((err) => { - console.error('Failed to getForward: ' + JSON.stringify(err)); - }); + inputClient.getForward(length).then((text) => { + console.log('Succeeded in getting forward, text: ' + text); + }).catch((err) => { + console.error(`Failed to getForward: ${JSON.stringify(err)}`); + }); } catch (err) { - console.error('Failed to getForward: ' + JSON.stringify(err)); + console.error(`Failed to getForward: ${JSON.stringify(err)}`); } ``` @@ -1650,15 +1707,15 @@ For details about the error codes, see [Input Method Framework Error Codes](../e ```js let length = 1; try { - inputClient.getBackward(length, (err, text) => { - if (err !== undefined) { - console.error('Failed to getForward: ' + JSON.stringify(err)); - return; - } - console.log('Succeeded in getting backward, text: ' + text); - }); + inputClient.getBackward(length, (err, text) => { + if (err) { + console.error(`Failed to getBackward: ${JSON.stringify(err)}`); + return; + } + console.log('Succeeded in getting backward, text: ' + text); + }); } catch (err) { - console.error('Failed to getForward: ' + JSON.stringify(err)); + console.error(`Failed to getBackward: ${JSON.stringify(err)}`); } ``` @@ -1696,13 +1753,13 @@ For details about the error codes, see [Input Method Framework Error Codes](../e ```js let length = 1; try { - inputClient.getBackward(length).then((text) => { - console.info('Succeeded in getting backward, text: ' + text); - }).catch((err) => { - console.error('Failed to getForward: ' + JSON.stringify(err)); - }); + inputClient.getBackward(length).then((text) => { + console.log('Succeeded in getting backward, text: ' + text); + }).catch((err) => { + console.error(`Failed to getBackward: ${JSON.stringify(err)}`); + }); } catch (err) { - console.error('Failed to getForward: ' + JSON.stringify(err)); + console.error(`Failed to getBackward: ${JSON.stringify(err)}`); } ``` @@ -1735,19 +1792,19 @@ For details about the error codes, see [Input Method Framework Error Codes](../e ```js let length = 1; try { - inputClient.deleteForward(length, (err, result) => { - if (err !== undefined) { - console.error('Failed to delete forward: ' + JSON.stringify(err)); - return; - } - if (result) { - console.info('Succeeded in deleting forward. '); - } else { - console.error('Failed to delete forward: ' + JSON.stringify(err)); - } - }); + inputClient.deleteForward(length, (err, result) => { + if (err) { + console.error(`Failed to deleteForward: ${JSON.stringify(err)}`); + return; + } + if (result) { + console.log('Succeeded in deleting forward.'); + } else { + console.error(`Failed to deleteForward: ${JSON.stringify(err)}`); + } + }); } catch (err) { - console.error('Failed to delete forward: ' + JSON.stringify(err)); + console.error(`Failed to deleteForward: ${JSON.stringify(err)}`); } ``` @@ -1785,17 +1842,17 @@ For details about the error codes, see [Input Method Framework Error Codes](../e ```js let length = 1; try { - inputClient.deleteForward(length).then((result) => { - if (result) { - console.info('Succeeded in deleting forward. '); - } else { - console.error('Failed to delete Forward. '); - } - }).catch((err) => { - console.error('Failed to delete Forward: ' + JSON.stringify(err)); - }); + inputClient.deleteForward(length).then((result) => { + if (result) { + console.log('Succeeded in deleting forward.'); + } else { + console.error('Failed to delete Forward.'); + } + }).catch((err) => { + console.error(`Failed to deleteForward: ${JSON.stringify(err)}`); + }); } catch (err) { - console.error('Failed to delete Forward: ' + JSON.stringify(err)); + console.error(`Failed to deleteForward: ${JSON.stringify(err)}`); } ``` @@ -1828,19 +1885,19 @@ For details about the error codes, see [Input Method Framework Error Codes](../e ```js let length = 1; try { - inputClient.deleteBackward(length, (err, result) => { - if (err !== undefined) { - console.error('Failed to delete Backward: ' + JSON.stringify(err)); - return; - } - if (result) { - console.info('Succeeded in deleting backward. '); - } else { - console.error('Failed to delete Backward: ' + JSON.stringify(err)); - } - }); + inputClient.deleteBackward(length, (err, result) => { + if (err) { + console.error(`Failed to deleteBackward: ${JSON.stringify(err)}`); + return; + } + if (result) { + console.log('Succeeded in deleting backward.'); + } else { + console.error(`Failed to deleteBackward: ${JSON.stringify(err)}`); + } + }); } catch (err) { - console.error('deleteBackward err: ' + JSON.stringify(err)); + console.error('deleteBackward err: ' + JSON.stringify(err)); } ``` @@ -1848,7 +1905,7 @@ try { deleteBackward(length:number): Promise<boolean> -Deletes the fixed-length text after the cursor. This API uses an asynchronous callback to return the result. +Deletes the fixed-length text after the cursor. This API uses a promise to return the result. **System capability**: SystemCapability.MiscServices.InputMethodFramework @@ -1878,13 +1935,13 @@ For details about the error codes, see [Input Method Framework Error Codes](../e ```js let length = 1; inputClient.deleteBackward(length).then((result) => { - if (result) { - console.info('Succeeded in deleting backward. '); - } else { - console.error('Failed to deleteBackward. '); - } + if (result) { + console.log('Succeeded in deleting backward.'); + } else { + console.error('Failed to deleteBackward.'); + } }).catch((err) => { - console.error('Failed to deleteBackward: ' + JSON.stringify(err)); + console.error(`Failed to deleteBackward: ${JSON.stringify(err)}`); }); ``` @@ -1916,15 +1973,15 @@ For details about the error codes, see [Input Method Framework Error Codes](../e ```js inputClient.insertText('test', (err, result) => { - if (err !== undefined) { - console.error('Failed to insertText: ' + JSON.stringify(err)); - return; - } - if (result) { - console.info('Succeeded in inserting text. '); - } else { - console.error('Failed to insertText. '); - } + if (err) { + console.error(`Failed to insertText: ${JSON.stringify(err)}`); + return; + } + if (result) { + console.log('Succeeded in inserting text.'); + } else { + console.error('Failed to insertText.'); + } }); ``` @@ -1961,17 +2018,17 @@ For details about the error codes, see [Input Method Framework Error Codes](../e ```js try { - inputClient.insertText('test').then((result) => { - if (result) { - console.info('Succeeded in inserting text. '); - } else { - console.error('Failed to insertText. '); - } - }).catch((err) => { - console.error('Failed to insertText: ' + JSON.stringify(err)); - }); + inputClient.insertText('test').then((result) => { + if (result) { + console.log('Succeeded in inserting text.'); + } else { + console.error('Failed to insertText.'); + } + }).catch((err) => { + console.error(`Failed to insertText: ${JSON.stringify(err)}`); + }); } catch (err) { - console.error('Failed to insertText: ' + JSON.stringify(err)); + console.error(`Failed to insertText: ${JSON.stringify(err)}`); } ``` @@ -2001,12 +2058,12 @@ For details about the error codes, see [Input Method Framework Error Codes](../e ```js inputClient.getEditorAttribute((err, editorAttribute) => { - if (err !== undefined) { - console.error('Failed to getEditorAttribute: ' + JSON.stringify(err)); - return; - } - console.log('editorAttribute.inputPattern: ' + JSON.stringify(editorAttribute.inputPattern)); - console.log('editorAttribute.enterKeyType: ' + JSON.stringify(editorAttribute.enterKeyType)); + if (err) { + console.error(`Failed to getEditorAttribute: ${JSON.stringify(err)}`); + return; + } + console.log('editorAttribute.inputPattern: ' + JSON.stringify(editorAttribute.inputPattern)); + console.log('editorAttribute.enterKeyType: ' + JSON.stringify(editorAttribute.enterKeyType)); }); ``` @@ -2036,10 +2093,10 @@ For details about the error codes, see [Input Method Framework Error Codes](../e ```js inputClient.getEditorAttribute().then((editorAttribute) => { - console.info('editorAttribute.inputPattern: ' + JSON.stringify(editorAttribute.inputPattern)); - console.info('editorAttribute.enterKeyType: ' + JSON.stringify(editorAttribute.enterKeyType)); + console.log('editorAttribute.inputPattern: ' + JSON.stringify(editorAttribute.inputPattern)); + console.log('editorAttribute.enterKeyType: ' + JSON.stringify(editorAttribute.enterKeyType)); }).catch((err) => { - console.error('Failed to getEditorAttribute: ' + JSON.stringify(err)); + console.error(`Failed to getEditorAttribute: ${JSON.stringify(err)}`); }); ``` @@ -2070,15 +2127,15 @@ For details about the error codes, see [Input Method Framework Error Codes](../e ```js try { - inputClient.moveCursor(inputMethodEngine.CURSOR_UP, (err) => { - if (err !== undefined) { - console.error('Failed to moveCursor: ' + JSON.stringify(err)); - return; - } - console.info('Succeeded in moving cursor.'); - }); + inputClient.moveCursor(inputMethodEngine.CURSOR_UP, (err) => { + if (err) { + console.error(`Failed to moveCursor: ${JSON.stringify(err)}`); + return; + } + console.log('Succeeded in moving cursor.'); + }); } catch (err) { - console.error('Failed to moveCursor: ' + JSON.stringify(err)); + console.error(`Failed to moveCursor: ${JSON.stringify(err)}`); } ``` @@ -2114,13 +2171,13 @@ For details about the error codes, see [Input Method Framework Error Codes](../e ```js try { - inputClient.moveCursor(inputMethodEngine.CURSOR_UP).then(() => { - console.log('Succeeded in moving cursor.'); - }).catch((err) => { - console.error('Failed to moveCursor: ' + JSON.stringify(err)); - }); + inputClient.moveCursor(inputMethodEngine.CURSOR_UP).then(() => { + console.log('Succeeded in moving cursor.'); + }).catch((err) => { + console.error(`Failed to moveCursor: ${JSON.stringify(err)}`); + }); } catch (err) { - console.log('Failed to moveCursor: ' + JSON.stringify(err)); + console.error(`Failed to moveCursor: ${JSON.stringify(err)}`); } ``` @@ -2136,7 +2193,7 @@ Selects text based on the specified range. This API uses an asynchronous callbac | Name | Type | Mandatory| Description | | -------- | --------------------------------------------------------- | ---- | ------------------------------------------------------------ | -| range | [Range](./js-apis-inputmethod-InputMethodCommon.md#range) | Yes | Range of the selected text. | +| range | [Range](#range10) | Yes | Range of the selected text. | | callback | AsyncCallback<void> | Yes | Callback used to return the result. If the selection event is sent, **err** is **undefined**; otherwise, **err** is an error object.| **Error codes** @@ -2152,15 +2209,15 @@ For details about the error codes, see [Input Method Framework Error Codes](../e ```js try { - inputClient.selectByRange({start: 0, end: 1}, (err) => { - if (err !== undefined) { - console.error('Failed to selectByRange: ${err.message}'); - return; - } - console.info('Succeeded in selecting by range.'); - }); + inputClient.selectByRange({start: 0, end: 1}, (err) => { + if (err) { + console.error(`Failed to selectByRange: ${JSON.stringify(err)}`); + return; + } + console.log('Succeeded in selecting by range.'); + }); } catch (err) { - console.error('Failed to selectByRange: ${err.message}'); + console.error(`Failed to selectByRange: ${JSON.stringify(err)}`); } ``` @@ -2176,7 +2233,7 @@ Selects text based on the specified range. This API uses a promise to return the | Name| Type | Mandatory| Description | | ------ | --------------------------------------------------------- | ---- | ---------------- | -| range | [Range](./js-apis-inputmethod-InputMethodCommon.md#range) | Yes | Range of the selected text.| +| range | [Range](#range10) | Yes | Range of the selected text.| **Return value** @@ -2197,13 +2254,13 @@ For details about the error codes, see [Input Method Framework Error Codes](../e ```js try { - inputClient.selectByRange({start: 0, end:1}).then(() => { - console.log('Succeeded in selecting by range.'); - }).catch((err) => { - console.error('Failed to selectByRange: ${err.message}'); - }); + inputClient.selectByRange({start: 0, end:1}).then(() => { + console.log('Succeeded in selecting by range.'); + }).catch((err) => { + console.error(`Failed to selectByRange: ${JSON.stringify(err)}`); + }); } catch (err) { - console.log('Failed to selectByRange: ${err.message}'); + console.error(`Failed to selectByRange: ${JSON.stringify(err)}`); } ``` @@ -2217,10 +2274,10 @@ Selects text based on the cursor movement direction. This API uses an asynchrono **Parameters** -| Name | Type | Mandatory| Description | -| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | -| movement | [Movement](./js-apis-inputmethod-InputMethodCommon.md#movement) | Yes | Direction in which the cursor moves when the text is selected. | -| callback | AsyncCallback<void> | Yes | Callback used to return the result. If the selection event is sent, **err** is **undefined**; otherwise, **err** is an error object.| +| Name | Type | Mandatory| Description | +| -------- | ------ | ---- | ------ | +| movement | [Movement](#movement10) | Yes | Direction in which the cursor moves when the text is selected. | +| callback | AsyncCallback<void> | Yes | Callback used to return the result. If the selection event is sent, **err** is **undefined**; otherwise, **err** is an error object.| **Error codes** @@ -2235,15 +2292,15 @@ For details about the error codes, see [Input Method Framework Error Codes](../e ```js try { - inputClient.selectByMovement({direction: 1}, (err) => { - if (err !== undefined) { - console.error('Failed to selectByMovement: ${err.message}'); - return; - } - console.info('Succeeded in selecting by movement.'); - }); + inputClient.selectByMovement({direction: 1}, (err) => { + if (err) { + console.error(`Failed to selectByMovement: ${JSON.stringify(err)}`); + return; + } + console.log('Succeeded in selecting by movement.'); + }); } catch (err) { - console.error('Failed to selectByMovement: ${err.message}'); + console.error(`Failed to selectByMovement: ${JSON.stringify(err)}`); } ``` @@ -2259,7 +2316,7 @@ Selects text based on the specified range. This API uses a promise to return the | Name | Type | Mandatory| Description | | -------- | ------------------------------------------------------------ | ---- | ---------------------- | -| movement | [Movement](./js-apis-inputmethod-InputMethodCommon.md#movement) | Yes | Direction in which the cursor moves when the text is selected.| +| movement | [Movement](#movement10) | Yes | Direction in which the cursor moves when the text is selected.| **Return value** @@ -2280,13 +2337,13 @@ For details about the error codes, see [Input Method Framework Error Codes](../e ```js try { - inputClient.selectByMovement({direction: 1}).then(() => { - console.log('Succeeded in selecting by movement.'); - }).catch((err) => { - console.error('Failed to selectByMovement: ${err.message}'); - }); + inputClient.selectByMovement({direction: 1}).then(() => { + console.log('Succeeded in selecting by movement.'); + }).catch((err) => { + console.error(`Failed to selectByMovement: ${JSON.stringify(err)}`); + }); } catch (err) { - console.log('Failed to selectByMovement: ${err.message}'); + console.error(`Failed to selectByMovement: ${JSON.stringify(err)}`); } ``` @@ -2310,7 +2367,6 @@ For details about the error codes, see [Input Method Framework Error Codes](../e | Error Code ID| Error Message | | -------- | ------------------------------ | -| 401 | parameter error. | | 12800003 | input method client error. | | 12800006 | Input method controller error. | @@ -2318,11 +2374,11 @@ For details about the error codes, see [Input Method Framework Error Codes](../e ```js inputClient.getTextIndexAtCursor((err, index) => { - if (err !== undefined) { - console.error('Failed to getTextIndexAtCursor: ${err.message}'); - return; - } - console.info('Succeeded in getTextIndexAtCursor: ' + index); + if (err) { + console.error(`Failed to getTextIndexAtCursor: ${JSON.stringify(err)}`); + return; + } + console.log('Succeeded in getTextIndexAtCursor: ' + index); }); ``` @@ -2353,12 +2409,99 @@ For details about the error codes, see [Input Method Framework Error Codes](../e ```js inputClient.getTextIndexAtCursor().then((index) => { - console.info('Succeeded in getTextIndexAtCursor: ' + index); + console.log('Succeeded in getTextIndexAtCursor: ' + index); }).catch((err) => { - console.error('Failed to getTextIndexAtCursor: ${err.message}'); + console.error(`Failed to getTextIndexAtCursor: ${JSON.stringify(err)}`); }); ``` +### sendExtendAction10+ + +sendExtendAction(action: ExtendAction, callback: AsyncCallback<void>): void + +Sends an extended edit action. This API uses an asynchronous callback to return the result. + +The input method calls this API to send an extended edit action to an editor component (for example, a text box), which in turn listens for the corresponding event [on(handleExtendAction)](./js-apis-inputmethod.md#onhandleextendaction10) for further processing. + +**System capability**: SystemCapability.MiscServices.InputMethodFramework + +**Parameters** + +| Name | Type | Mandatory| Description | +| -------- | --------------------------- | ---- | ------------------------------------------------------------ | +| action | [ExtendAction](#extendaction10) | Yes | Extended edit action to send.| +| callback | AsyncCallback<void> | Yes | Callback used to return the result. If the operation is successful, **err** is **undefined**. Otherwise, **err** is an error object.| + +**Error codes** + +For details about the error codes, see [Input Method Framework Error Codes](../errorcodes/errorcode-inputmethod-framework.md). + +| Error Code ID| Error Message | +| -------- | ------------------------------ | +| 12800003 | input method client error. | +| 12800006 | Input method controller error. | + +**Example** + +```js +try { + inputClient.sendExtendAction(inputMethodEngine.ExtendAction.COPY, (err) => { + if (err) { + console.error(`Failed to sendExtendAction: ${JSON.stringify(err)}`); + return; + } + console.log('Succeeded in sending extend action.'); + }); +} catch(err) { + console.error(`Failed to sendExtendAction: ${JSON.stringify(err)}`); +} +``` + +### sendExtendAction10+ + +sendExtendAction(action: ExtendAction): Promise<void> + +Sends an extended edit action. This API uses a promise to return the result. + +The input method calls this API to send an extended edit action to an editor component (for example, a text box), which in turn listens for the corresponding event [on(handleExtendAction)](./js-apis-inputmethod.md#onhandleextendaction10) for further processing. + +**System capability**: SystemCapability.MiscServices.InputMethodFramework + +**Parameters** + +| Name| Type| Mandatory| Description| +| -------- | -------- | -------- | -------- | +| action | [ExtendAction](#extendaction10) | Yes| Extended edit action to send.| + +**Return value** + +| Type | Description | +| --------------------- | --------------------------------------- | +| Promise<void> | Promise that returns no value.| + +**Error codes** + +For details about the error codes, see [Input Method Framework Error Codes](../errorcodes/errorcode-inputmethod-framework.md). + +| Error Code ID| Error Message | +| -------- | ------------------------------ | +| 12800003 | Input method client error. | +| 12800006 | Input method controller error. | + +**Example** + +```js +try { + inputClient.sendExtendAction(inputMethodEngine.ExtendAction.COPY).then(() => { + console.log('Succeeded in sending extend action.'); + }).catch((err) => { + console.error(`Failed to sendExtendAction: ${JSON.stringify(err)}`); + }); +} catch(err) { + console.error(`Failed to sendExtendAction: ${JSON.stringify(err)}`); +} +``` + ## EditorAttribute Attribute of the edit box. @@ -2418,7 +2561,7 @@ Describes the attributes of the input method panel. > **NOTE** > -> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [InputClient](#inputclient9). +> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [InputClient](#inputclient9) instead. In the following API examples, you must first use **[on('inputStart')](#oninputstart)** to obtain a **TextInputClient** instance, and then call the APIs using the obtained instance. @@ -2430,7 +2573,7 @@ Obtains the specific-length text before the cursor. This API uses an asynchronou > **NOTE** > -> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [getForward](#getforward9). +> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [getForward](#getforward9) instead. **System capability**: SystemCapability.MiscServices.InputMethodFramework @@ -2446,11 +2589,11 @@ Obtains the specific-length text before the cursor. This API uses an asynchronou ```js let length = 1; textInputClient.getForward(length, (err, text) => { - if (err !== undefined) { - console.error('Failed to getForward: ' + JSON.stringify(err)); - return; - } - console.log('Succeeded in getting forward, text: ' + text); + if (err) { + console.error(`Failed to getForward: ${JSON.stringify(err)}`); + return; + } + console.log('Succeeded in getting forward, text: ' + text); }); ``` @@ -2462,7 +2605,7 @@ Obtains the specific-length text before the cursor. This API uses a promise to r > **NOTE** > -> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [getForward](#getforward9). +> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [getForward](#getforward9) instead. **System capability**: SystemCapability.MiscServices.InputMethodFramework @@ -2483,9 +2626,9 @@ Obtains the specific-length text before the cursor. This API uses a promise to r ```js let length = 1; textInputClient.getForward(length).then((text) => { - console.info('Succeeded in getting forward, text: ' + text); + console.log('Succeeded in getting forward, text: ' + text); }).catch((err) => { - console.error('Failed to getForward: ' + JSON.stringify(err)); + console.error(`Failed to getForward: ${JSON.stringify(err)}`); }); ``` @@ -2497,7 +2640,7 @@ Obtains the specific-length text after the cursor. This API uses an asynchronous > **NOTE** > -> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [getBackward](#getbackward9). +> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [getBackward](#getbackward9) instead. **System capability**: SystemCapability.MiscServices.InputMethodFramework @@ -2513,11 +2656,11 @@ Obtains the specific-length text after the cursor. This API uses an asynchronous ```js let length = 1; textInputClient.getBackward(length, (err, text) => { - if (err !== undefined) { - console.error('Failed to getBackward: ' + JSON.stringify(err)); - return; - } - console.log('Succeeded in getting borward, text: ' + text); + if (err) { + console.error(`Failed to getBackward: ${JSON.stringify(err)}`); + return; + } + console.log('Succeeded in getting borward, text: ' + text); }); ``` @@ -2529,7 +2672,7 @@ Obtains the specific-length text after the cursor. This API uses a promise to re > **NOTE** > -> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [getBackward](#getbackward9). +> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [getBackward](#getbackward9) instead. **System capability**: SystemCapability.MiscServices.InputMethodFramework @@ -2550,9 +2693,9 @@ Obtains the specific-length text after the cursor. This API uses a promise to re ```js let length = 1; textInputClient.getBackward(length).then((text) => { - console.info('Succeeded in getting backward: ' + JSON.stringify(text)); + console.log('Succeeded in getting backward: ' + JSON.stringify(text)); }).catch((err) => { - console.error('Failed to getBackward: ' + JSON.stringify(err)); + console.error(`Failed to getBackward: ${JSON.stringify(err)}`); }); ``` @@ -2564,7 +2707,7 @@ Deletes the fixed-length text before the cursor. This API uses an asynchronous c > **NOTE** > -> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [deleteForward](#deleteforward9). +> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [deleteForward](#deleteforward9) instead. **System capability**: SystemCapability.MiscServices.InputMethodFramework @@ -2580,15 +2723,15 @@ Deletes the fixed-length text before the cursor. This API uses an asynchronous c ```js let length = 1; textInputClient.deleteForward(length, (err, result) => { - if (err !== undefined) { - console.error('Failed to deleteForward: ' + JSON.stringify(err)); - return; - } - if (result) { - console.info('Succeeded in deleting forward. '); - } else { - console.error('Failed to deleteForward. '); - } + if (err) { + console.error(`Failed to deleteForward: ${JSON.stringify(err)}`); + return; + } + if (result) { + console.log('Succeeded in deleting forward.'); + } else { + console.error('Failed to deleteForward.'); + } }); ``` @@ -2600,7 +2743,7 @@ Deletes the fixed-length text before the cursor. This API uses a promise to retu > **NOTE** > -> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [deleteForward](#deleteforward9). +> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [deleteForward](#deleteforward9) instead. **System capability**: SystemCapability.MiscServices.InputMethodFramework @@ -2621,13 +2764,13 @@ Deletes the fixed-length text before the cursor. This API uses a promise to retu ```js let length = 1; textInputClient.deleteForward(length).then((result) => { - if (result) { - console.info('Succeeded in deleting forward. '); - } else { - console.error('Failed to delete forward. '); - } + if (result) { + console.log('Succeeded in deleting forward.'); + } else { + console.error('Failed to delete forward.'); + } }).catch((err) => { - console.error('Failed to delete forward: ' + JSON.stringify(err)); + console.error(`Failed to deleteForward: ${JSON.stringify(err)}`); }); ``` @@ -2639,31 +2782,31 @@ Deletes the fixed-length text after the cursor. This API uses an asynchronous ca > **NOTE** > -> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [deleteBackward](#deletebackward9). +> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [deleteBackward](#deletebackward9) instead. **System capability**: SystemCapability.MiscServices.InputMethodFramework - **Parameters** +**Parameters** | Name | Type | Mandatory| Description | | -------- | ---------------------------- | ---- | -------------- | | length | number | Yes | Text length. | | callback | AsyncCallback<boolean> | Yes | Callback used to return the result. If the operation is successful, **err** is **undefined** and **data** is **true**. Otherwise, **err** is an error object.| - **Example** +**Example** ```js let length = 1; textInputClient.deleteBackward(length, (err, result) => { - if (err !== undefined) { - console.error('Failed to delete backward: ' + JSON.stringify(err)); - return; - } - if (result) { - console.info('Succeeded in deleting backward. '); - } else { - console.error('Failed to deleteBackward. '); - } + if (err) { + console.error(`Failed to deleteBackward: ${JSON.stringify(err)}`); + return; + } + if (result) { + console.log('Succeeded in deleting backward.'); + } else { + console.error('Failed to deleteBackward.'); + } }); ``` @@ -2671,11 +2814,11 @@ textInputClient.deleteBackward(length, (err, result) => { deleteBackward(length:number): Promise<boolean> -Deletes the fixed-length text after the cursor. This API uses an asynchronous callback to return the result. +Deletes the fixed-length text after the cursor. This API uses a promise to return the result. > **NOTE** > -> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [deleteBackward](#deletebackward9). +> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [deleteBackward](#deletebackward9) instead. **System capability**: SystemCapability.MiscServices.InputMethodFramework @@ -2696,13 +2839,13 @@ Deletes the fixed-length text after the cursor. This API uses an asynchronous ca ```js let length = 1; textInputClient.deleteBackward(length).then((result) => { - if (result) { - console.info('Succeeded in deleting backward. '); - } else { - console.error('Failed to deleteBackward. '); - } + if (result) { + console.log('Succeeded in deleting backward.'); + } else { + console.error('Failed to deleteBackward.'); + } }).catch((err) => { - console.error('Failed to deleteBackward: ' + JSON.stringify(err)); + console.error(`Failed to deleteBackward: ${JSON.stringify(err)}`); }); ``` ### sendKeyFunction(deprecated) @@ -2713,31 +2856,31 @@ Sends the function key. This API uses an asynchronous callback to return the res > **NOTE** > -> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [sendKeyFunction](#sendkeyfunction9). +> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [sendKeyFunction](#sendkeyfunction9) instead. **System capability**: SystemCapability.MiscServices.InputMethodFramework - **Parameters** +**Parameters** | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | -| action | number | Yes| Action of the function key.
**0**: invalid key.
**1**: confirm key (Enter key).| +| action | number | Yes| Action of the function key.
- **0**: invalid key.
- **1**: confirm key (Enter key).| | callback | AsyncCallback<boolean> | Yes| Callback used to return the result. If the operation is successful, **err** is **undefined** and **data** is **true**. Otherwise, **err** is an error object.| - **Example** +**Example** ```js let action = 1; textInputClient.sendKeyFunction(action, (err, result) => { - if (err !== undefined) { - console.error('Failed to sendKeyFunction: ' + JSON.stringify(err)); - return; - } - if (result) { - console.info('Succeeded in sending key function. '); - } else { - console.error('Failed to sendKeyFunction. '); - } + if (err) { + console.error(`Failed to sendKeyFunction: ${JSON.stringify(err)}`); + return; + } + if (result) { + console.log('Succeeded in sending key function.'); + } else { + console.error('Failed to sendKeyFunction.'); + } }); ``` @@ -2749,7 +2892,7 @@ Sends the function key. This API uses a promise to return the result. > **NOTE** > -> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [sendKeyFunction](#sendkeyfunction9). +> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [sendKeyFunction](#sendkeyfunction9) instead. **System capability**: SystemCapability.MiscServices.InputMethodFramework @@ -2757,7 +2900,7 @@ Sends the function key. This API uses a promise to return the result. | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | -| action | number | Yes| Action of the function key.
**0**: invalid key.
**1**: confirm key (Enter key).| +| action | number | Yes| Action of the function key.
- **0**: invalid key.
- **1**: confirm key (Enter key).| **Return value** @@ -2770,13 +2913,13 @@ Sends the function key. This API uses a promise to return the result. ```js let action = 1; textInputClient.sendKeyFunction(action).then((result) => { - if (result) { - console.info('Succeeded in sending key function. '); - } else { - console.error('Failed to sendKeyFunction. '); - } + if (result) { + console.log('Succeeded in sending key function.'); + } else { + console.error('Failed to sendKeyFunction.'); + } }).catch((err) => { - console.error('Failed to sendKeyFunction:' + JSON.stringify(err)); + console.error(`Failed to sendKeyFunction: ${JSON.stringify(err)}`); }); ``` @@ -2788,7 +2931,7 @@ Inserts text. This API uses an asynchronous callback to return the result. > **NOTE** > -> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [insertText](#inserttext9). +> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [insertText](#inserttext9) instead. **System capability**: SystemCapability.MiscServices.InputMethodFramework @@ -2803,15 +2946,15 @@ Inserts text. This API uses an asynchronous callback to return the result. ```js textInputClient.insertText('test', (err, result) => { - if (err !== undefined) { - console.error('Failed to insertText: ' + JSON.stringify(err)); - return; - } - if (result) { - console.info('Succeeded in inserting text. '); - } else { - console.error('Failed to insertText. '); - } + if (err) { + console.error(`Failed to insertText: ${JSON.stringify(err)}`); + return; + } + if (result) { + console.log('Succeeded in inserting text.'); + } else { + console.error('Failed to insertText.'); + } }); ``` @@ -2823,7 +2966,7 @@ Inserts text. This API uses a promise to return the result. > **NOTE** > -> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [insertText](#inserttext9). +> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [insertText](#inserttext9) instead. **System capability**: SystemCapability.MiscServices.InputMethodFramework @@ -2843,13 +2986,13 @@ Inserts text. This API uses a promise to return the result. ```js textInputClient.insertText('test').then((result) => { - if (result) { - console.info('Succeeded in inserting text. '); - } else { - console.error('Failed to insertText. '); - } + if (result) { + console.log('Succeeded in inserting text.'); + } else { + console.error('Failed to insertText.'); + } }).catch((err) => { - console.error('Failed to insertText: ' + JSON.stringify(err)); + console.error(`Failed to insertText: ${JSON.stringify(err)}`); }); ``` @@ -2861,26 +3004,26 @@ Obtains the attribute of the edit box. This API uses an asynchronous callback to > **NOTE** > -> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [getEditorAttribute](#geteditorattribute9). +> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [getEditorAttribute](#geteditorattribute9) instead. **System capability**: SystemCapability.MiscServices.InputMethodFramework **Parameters** -| Name | Type | Mandatory | Description | -| ------------------------------- | ------------------------------------------------------------ | ------------------------------------------------------------ | ------------------------------------------------------------ | +| Name | Type | Mandatory | Description | +| -------- | ----- | ----- | ----- | | callback | AsyncCallback<[EditorAttribute](#editorattribute)> | Yes| Callback used to return the result. If the operation is successful, **err** is **undefined** and **data** is the attribute of the edit box. Otherwise, **err** is an error object.| **Example** ```js textInputClient.getEditorAttribute((err, editorAttribute) => { - if (err !== undefined) { - console.error('Failed to getEditorAttribute: ' + JSON.stringify(err)); - return; - } - console.log('editorAttribute.inputPattern: ' + JSON.stringify(editorAttribute.inputPattern)); - console.log('editorAttribute.enterKeyType: ' + JSON.stringify(editorAttribute.enterKeyType)); + if (err) { + console.error(`Failed to getEditorAttribute: ${JSON.stringify(err)}`); + return; + } + console.log('editorAttribute.inputPattern: ' + JSON.stringify(editorAttribute.inputPattern)); + console.log('editorAttribute.enterKeyType: ' + JSON.stringify(editorAttribute.enterKeyType)); }); ``` @@ -2892,7 +3035,7 @@ Obtains the attribute of the edit box. This API uses a promise to return the res > **NOTE** > -> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [getEditorAttribute](#geteditorattribute9). +> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [getEditorAttribute](#geteditorattribute9) instead. **System capability**: SystemCapability.MiscServices.InputMethodFramework @@ -2906,10 +3049,10 @@ Obtains the attribute of the edit box. This API uses a promise to return the res ```js textInputClient.getEditorAttribute().then((editorAttribute) => { - console.info('editorAttribute.inputPattern: ' + JSON.stringify(editorAttribute.inputPattern)); - console.info('editorAttribute.enterKeyType: ' + JSON.stringify(editorAttribute.enterKeyType)); + console.log('editorAttribute.inputPattern: ' + JSON.stringify(editorAttribute.inputPattern)); + console.log('editorAttribute.enterKeyType: ' + JSON.stringify(editorAttribute.enterKeyType)); }).catch((err) => { - console.error('Failed to getEditorAttribute: ' + JSON.stringify(err)); + console.error(`Failed to getEditorAttribute: ${JSON.stringify(err)}`); }); ``` diff --git a/en/application-dev/reference/errorcodes/errorcode-inputmethod-framework.md b/en/application-dev/reference/errorcodes/errorcode-inputmethod-framework.md index a35dbe3700e4237c7ce9c1bfa6f4c0c8752a6c3e..3034d6041ed623587f7734c617f8cb014045fe7f 100644 --- a/en/application-dev/reference/errorcodes/errorcode-inputmethod-framework.md +++ b/en/application-dev/reference/errorcodes/errorcode-inputmethod-framework.md @@ -38,7 +38,7 @@ The input method process is suspended. **Solution** -Check whether the input method process is running properly. For example, click the input text box in an appliccation and check whether the input keyboard is displayed. +Check whether the input method process is running properly. For example, click the input text box in an application and check whether the input keyboard is displayed. ## 12800003 Input Method Client Error @@ -58,23 +58,23 @@ The input method is disconnected from the third-party application due to a servi Bind the input method to the third-party application again: Close the background process of the third-party application, start the application again, and touch an input text box. If the keyboard is displayed properly, the issue is resolved. -## 12800004 Key Event Processing Error +## 12800004 Not an Input Method. **Error Message** -Key event processing error. +Not an input method extension. **Description** -This error code is reported when a key event error occurs. +This error code is reported when an API exclusive to input methods is called by an application of another type. **Possible Causes** -An exception occurs during key event distribution, consumption, or listening. +An API that can be called only by an input method is called by an application of another type. **Solution** -None +Call the API only in an input method. ## 12800005 Configuration Persistence Error @@ -147,3 +147,21 @@ The input method manager service fails to be obtained. **Solution** Run the **ps -A|grep inputmethod** command to check for the process ID of the input method service. If the process ID is found, the service is working properly. + +## 12800009 Input Method Client Detached + +**Error Message** + +Input method client is detached. + +**Description** + +This error code is reported when the current application is not attached to an input method. + +**Possible Causes** + +The current application calls **showTextInput** or **hideTextInput** when not attached to an input method. + +**Solution** + +Call the **attach** API and then try again.