# @ohos.inputMethod (Input Method Framework) The **inputMethod** module is oriented to common foreground applications (third-party applications and system applications such as Notes, Messaging, and Settings). It provides input method control and management capabilities, including displaying or hiding the soft keyboard, switching between input methods, and obtaining the list of all input methods. > **NOTE** > > The initial APIs of this module are supported since API version 6. Newly added APIs will be marked with a superscript to indicate their earliest API version. ## Modules to Import ```ts import { inputMethod } from '@kit.IMEKit'; ``` ## Constants Provides the constants. **System capability**: SystemCapability.MiscServices.InputMethodFramework | Name| Type| Value| Description| | -------- | -------- | -------- | -------- | | MAX_TYPE_NUM8+ | number | 128 | Maximum number of supported input methods.| ## InputMethodProperty8+ Describes the input method application attributes. **System capability**: SystemCapability.MiscServices.InputMethodFramework | Name| Type| Read-only| Optional| Description| | -------- | -------- | -------- | -------- | -------- | | name9+ | string | Yes| No| Mandatory. Name of the input method package.| | id9+ | string | Yes| No| Mandatory. Unique identifier of an input method extension in an app. **id** and **name** form a globally unique identifier of the input method extension.| | label9+ | string | Yes| Yes| Optional. External label of the input method extension. Use the label configured for the InputmethodExtensionAbility. If no label is configured, the label of the application entry ability is automatically used. If no label is configured for the application entry ability, the label configured in **AppScope** is automatically used.| | labelId10+ | number | Yes| Yes| Optional. External ID of the input method.| | icon9+ | string | Yes| Yes| Optional. Icon of the input method. It can be obtained by using **iconId**. This parameter is reserved.| | iconId9+ | number | Yes| Yes| Optional. Icon ID of the input method.| | extra9+ | object | No| Yes| Extra information about the input method. This parameter is reserved and currently has no specific meaning.
- 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** instead.| | 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** instead.| ## inputMethod.getController9+ getController(): InputMethodController Obtains an [InputMethodController](#inputmethodcontroller) instance. **System capability**: SystemCapability.MiscServices.InputMethodFramework **Return value** | Type | Description | | ----------------------------------------------- | ---------------------- | | [InputMethodController](#inputmethodcontroller) | **InputMethodController** instance.| **Error codes** For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md). | ID| Error Message | | -------- | ------------------------------ | | 12800006 | input method controller error. | **Example** ```ts let inputMethodController = inputMethod.getController(); ``` ## inputMethod.getDefaultInputMethod11+ getDefaultInputMethod(): InputMethodProperty Obtains the default input method. **System capability**: SystemCapability.MiscServices.InputMethodFramework **Return value** | Type | Description | | -------------------------------------------- | ------------------------ | | [InputMethodProperty](#inputmethodproperty8) | Default input method.| **Error codes** For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md). | ID| Error Message | | -------- | -------------------------------------- | | 12800008 | input method manager service error. | **Example** ```ts try { let defaultIme = inputMethod.getDefaultInputMethod(); } catch(err) { console.error(`Failed to getDefaultInputMethod: ${JSON.stringify(err)}`); } ``` ## inputMethod.getSystemInputMethodConfigAbility11+ getSystemInputMethodConfigAbility(): ElementName Obtains the information about the input method configuration page ability. **System capability**: SystemCapability.MiscServices.InputMethodFramework **Return value** | Type | Description | | -------------------------------------------- | ------------------------ | | [ElementName](../apis-ability-kit/js-apis-bundleManager-elementName.md) | Element name of the input method configuration page ability.| **Error codes** For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md). | ID| Error Message | | -------- | -------------------------------------- | | 12800008 | input method manager service error. | **Example** ```ts try { let inputMethodConfig = inputMethod.getSystemInputMethodConfigAbility(); } catch(err) { console.error(`Failed to get getSystemInputMethodConfigAbility: ${JSON.stringify(err)}`); } ``` ## inputMethod.getSetting9+ getSetting(): InputMethodSetting Obtains an [InputMethodSetting](#inputmethodsetting8) instance. **System capability**: SystemCapability.MiscServices.InputMethodFramework **Return value** | Type | Description | | ----------------------------------------- | -------------------------- | | [InputMethodSetting](#inputmethodsetting8) | **InputMethodSetting** instance.| **Error codes** For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md). | ID| Error Message | | -------- | -------------------------------------- | | 12800007 | setter error. | **Example** ```ts let inputMethodSetting = inputMethod.getSetting(); ``` ## inputMethod.switchInputMethod9+ switchInputMethod(target: InputMethodProperty, callback: AsyncCallback<boolean>): void Switches to another input method. This API uses an asynchronous callback to return the result. > **NOTE** > > - In API versions 9 and 10, this API can only be called by system applications granted the **ohos.permission.CONNECT_IME_ABILITY** permission. > - Since API version 11, this API can only be called by the current input method application. **System capability**: SystemCapability.MiscServices.InputMethodFramework **Parameters** | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | | target | [InputMethodProperty](#inputmethodproperty8) | Yes| Target input method.| | 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](errorcode-inputmethod-framework.md) and [Universal Error Codes](../errorcode-universal.md). | ID| Error Message | | -------- | -------------------------------------- | | 401 | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | | 12800005 | configuration persistence error. | | 12800008 | input method manager service error. | **Example** ```ts import { BusinessError } from '@kit.BasicServicesKit'; let currentIme = inputMethod.getCurrentInputMethod(); try{ inputMethod.switchInputMethod(currentIme, (err: BusinessError, result: boolean) => { 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)}`); } ``` > **NOTE** > > Since API version 11, the error code `201 permissions check fails` is removed. ## inputMethod.switchInputMethod9+ switchInputMethod(target: InputMethodProperty): Promise<boolean> Switches to another input method. This API uses a promise to return the result. > **NOTE** > > - In API versions 9 and 10, this API can only be called by system applications granted the **ohos.permission.CONNECT_IME_ABILITY** permission. > - Since API version 11, this API can only be called by the current input method application. **System capability**: SystemCapability.MiscServices.InputMethodFramework **Parameters** | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | |target | [InputMethodProperty](#inputmethodproperty8)| Yes| Target input method.| **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](errorcode-inputmethod-framework.md) and [Universal Error Codes](../errorcode-universal.md). | ID| Error Message | | -------- | -------------------------------------- | | 401 | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | | 12800005 | configuration persistence error. | | 12800008 | input method manager service error. | **Example** ```ts import { BusinessError } from '@kit.BasicServicesKit'; let currentIme = inputMethod.getCurrentInputMethod(); try { inputMethod.switchInputMethod(currentIme).then((result: boolean) => { if (result) { console.log('Succeeded in switching inputmethod.'); } else { console.error('Failed to switchInputMethod.'); } }).catch((err: BusinessError) => { console.error(`Failed to switchInputMethod: ${JSON.stringify(err)}`); }) } catch (err) { console.error(`Failed to switchInputMethod: ${JSON.stringify(err)}`); } ``` > **NOTE** > > Since API version 11, the error code `201 permissions check fails` is removed. ## inputMethod.getCurrentInputMethod9+ getCurrentInputMethod(): InputMethodProperty Obtains the current input method. This API returns the result synchronously. **System capability**: SystemCapability.MiscServices.InputMethodFramework **Return value** | Type | Description | | -------------------------------------------- | ------------------------ | | [InputMethodProperty](#inputmethodproperty8) | **InputmethodProperty** instance of the current input method.| **Example** ```ts let currentIme = inputMethod.getCurrentInputMethod(); ``` ## inputMethod.switchCurrentInputMethodSubtype9+ switchCurrentInputMethodSubtype(target: InputMethodSubtype, callback: AsyncCallback\): void Switches to another subtype of this input method. This API uses an asynchronous callback to return the result. > **NOTE** > > - In API version 9 , this API can only be called by system applications granted the **ohos.permission.CONNECT_IME_ABILITY** permission. > - In API version 10, this API can only be called by system applications and the current input method application, and the **ohos.permission.CONNECT_IME_ABILITY** permission is required. > - Since API version 11, this API can only be called by the current input method application. **System capability**: SystemCapability.MiscServices.InputMethodFramework **Parameters** | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | | target | [InputMethodSubtype](./js-apis-inputmethod-subtype.md#inputmethodsubtype)| Yes| Target input method subtype.| | 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](errorcode-inputmethod-framework.md) and [Universal Error Codes](../errorcode-universal.md). | ID| Error Message | | -------- | -------------------------------------- | | 401 | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | | 12800005 | configuration persistence error. | | 12800008 | input method manager service error. | **Example** ```ts import { BusinessError } from '@kit.BasicServicesKit'; try { let extra: Record = {} inputMethod.switchCurrentInputMethodSubtype({ id: "ServiceExtAbility", label: "", name: "com.example.kikakeyboard", mode: "upper", locale: "", language: "", icon: "", iconId: 0, extra: extra }, (err: BusinessError, result: boolean) => { 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)}`); } ``` > **NOTE** > > Since API version 11, the error code `201 permissions check fails` is removed. ## inputMethod.switchCurrentInputMethodSubtype9+ switchCurrentInputMethodSubtype(target: InputMethodSubtype): Promise<boolean> Switches to another subtype of this input method. This API uses a promise to return the result. > **NOTE** > > - In API version 9 , this API can only be called by system applications granted the **ohos.permission.CONNECT_IME_ABILITY** permission. > - In API version 10, this API can only be called by system applications and the current input method application, and the **ohos.permission.CONNECT_IME_ABILITY** permission is required. > - Since API version 11, this API can only be called by the current input method application. **System capability**: SystemCapability.MiscServices.InputMethodFramework **Parameters** | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | |target | [InputMethodSubtype](./js-apis-inputmethod-subtype.md#inputmethodsubtype)| Yes| Target input method subtype.| **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](errorcode-inputmethod-framework.md) and [Universal Error Codes](../errorcode-universal.md). | ID| Error Message | | -------- | -------------------------------------- | | 401 | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | | 12800005 | configuration persistence error. | | 12800008 | input method manager service error. | **Example** ```ts import { BusinessError } from '@kit.BasicServicesKit'; try { let extra: Record = {} inputMethod.switchCurrentInputMethodSubtype({ id: "ServiceExtAbility", label: "", name: "com.example.kikakeyboard", mode: "upper", locale: "", language: "", icon: "", iconId: 0, extra: extra }).then((result: boolean) => { if (result) { console.log('Succeeded in switching currentInputMethodSubtype.'); } else { console.error('Failed to switchCurrentInputMethodSubtype.'); } }).catch((err: BusinessError) => { console.error(`Failed to switchCurrentInputMethodSubtype: ${JSON.stringify(err)}`); }) } catch(err) { console.error(`Failed to switchCurrentInputMethodSubtype: ${JSON.stringify(err)}`); } ``` > **NOTE** > > Since API version 11, the error code `201 permissions check fails` is removed. ## inputMethod.getCurrentInputMethodSubtype9+ getCurrentInputMethodSubtype(): InputMethodSubtype Obtains the current input method subtype. **System capability**: SystemCapability.MiscServices.InputMethodFramework **Return value** | Type | Description | | -------------------------------------------- | ------------------------ | | [InputMethodSubtype](./js-apis-inputmethod-subtype.md#inputmethodsubtype) | Current input method subtype.| **Example** ```ts let currentImeSubType = inputMethod.getCurrentInputMethodSubtype(); ``` ## inputMethod.switchCurrentInputMethodAndSubtype9+ 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. > **NOTE** > > - In API versions 9 and 10, this API can only be called by system applications granted the **ohos.permission.CONNECT_IME_ABILITY** permission. > - Since API version 11, this API can only be called by the current input method application. **System capability**: SystemCapability.MiscServices.InputMethodFramework **Parameters** | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | |inputMethodProperty | [InputMethodProperty](#inputmethodproperty8)| Yes| Target input method.| |inputMethodSubtype | [InputMethodSubtype](./js-apis-inputmethod-subtype.md#inputmethodsubtype)| Yes| Target input method subtype.| | 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](errorcode-inputmethod-framework.md) and [Universal Error Codes](../errorcode-universal.md). | ID| Error Message | | -------- | -------------------------------------- | | 401 | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | | 12800005 | configuration persistence error. | | 12800008 | input method manager service error. | **Example** ```ts import { BusinessError } from '@kit.BasicServicesKit'; let currentIme = inputMethod.getCurrentInputMethod(); let imSubType = inputMethod.getCurrentInputMethodSubtype(); try { inputMethod.switchCurrentInputMethodAndSubtype(currentIme, imSubType, (err: BusinessError, result: boolean) => { 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)}`); } ``` > **NOTE** > > Since API version 11, the error code `201 permissions check fails` is removed. ## 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. > **NOTE** > > - In API versions 9 and 10, this API can only be called by system applications granted the **ohos.permission.CONNECT_IME_ABILITY** permission. > - Since API version 11, this API can only be called by the current input method application. **System capability**: SystemCapability.MiscServices.InputMethodFramework **Parameters** | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | |inputMethodProperty | [InputMethodProperty](#inputmethodproperty8)| Yes| Target input method.| |inputMethodSubtype | [InputMethodSubtype](./js-apis-inputmethod-subtype.md#inputmethodsubtype)| Yes| Target input method subtype.| **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](errorcode-inputmethod-framework.md) and [Universal Error Codes](../errorcode-universal.md). | ID| Error Message | | -------- | -------------------------------------- | | 401 | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | | 12800005 | configuration persistence error. | | 12800008 | input method manager service error. | **Example** ```ts import { BusinessError } from '@kit.BasicServicesKit'; let currentIme = inputMethod.getCurrentInputMethod(); let imSubType = inputMethod.getCurrentInputMethodSubtype(); try { inputMethod.switchCurrentInputMethodAndSubtype(currentIme, imSubType).then((result: boolean) => { if (result) { console.log('Succeeded in switching currentInputMethodAndSubtype.'); } else { console.error('Failed to switchCurrentInputMethodAndSubtype.'); } }).catch((err: BusinessError) => { console.error(`Failed to switchCurrentInputMethodAndSubtype: ${JSON.stringify(err)}`); }) } catch(err) { console.error(`Failed to switchCurrentInputMethodAndSubtype: ${JSON.stringify(err)}`); } ``` > **NOTE** > > Since API version 11, the error code `201 permissions check fails` is removed. ## 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** ```ts 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) | **InputMethodSetting** instance.| **Example** ```ts 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.| | NUMBER_PASSWORD11+ | 8 |Numeric 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.| | NEWLINE12+ | 8 | Line break.| ## 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| Read-only| Optional| Description| | -------- | -------- | -------- | -------- | -------- | | enterKeyType10+ | [EnterKeyType](#enterkeytype10) | No| No| 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| Read-only| Optional| Description| | -------- | -------- | -------- | -------- | -------- | | textInputType10+ | [TextInputType](#textinputtype10) | No| No| Enumerates the text input types.| | enterKeyType10+ | [EnterKeyType](#enterkeytype10) | No| No| Function type represented by the Enter key.| ## TextConfig10+ Describes the configuration of the edit box. **System capability**: SystemCapability.MiscServices.InputMethodFramework | Name| Type| Read-only| Optional| Description| | -------- | -------- | -------- | -------- | -------- | | inputAttribute10+ | [InputAttribute](#inputattribute10) | No| No| Edit box attribute.| | cursorInfo10+ | [CursorInfo](#cursorinfo10) | No| Yes| Cursor information.| | selection10+ | [Range](#range10) | No| Yes| Text selection range.| | windowId10+ | number | No| Yes| ID of the window where the edit box is located.| ## CursorInfo10+ Represents the cursor information. **System capability**: SystemCapability.MiscServices.InputMethodFramework | Name| Type| Read-only| Optional| Description| | -------- | -------- | -------- | -------- | -------- | | left | number | No| No| Left coordinate of the cursor.| | top | number | No| No| Top coordinate of the cursor.| | width | number | No| No| Width of the cursor.| | height | number | No| No| Height of the cursor.| ## Range10+ Describes the range of the selected text. **System capability**: SystemCapability.MiscServices.InputMethodFramework | Name| Type| Read-only| Optional| Description| | -------- | -------- | -------- | -------- | -------- | | start | number | No| No| Index of the first selected character in the text box.| | end | number | No| No| 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| Read-only| Optional| Description| | -------- | -------- | -------- | -------- | -------- | | direction | [Direction](#direction10) | No| No| 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| Read-only| Optional| Description| | -------- | -------- | -------- | -------- | -------- | | name | string | No| No| Name of the input method keyboard window.| | left | number | No| No| Horizontal coordinate of the upper left corner of the input method keyboard window, in px.| | top | number | No| No| Vertical coordinate of the upper left corner of the input method keyboard window, in px.| | width | number | No| No| Width of the input method keyboard window, in px.| | height | number | No| No| 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. > **NOTE** > > An input method can use the following features only when it has a self-drawing component attached to it: showing or hiding the keyboard, updating the cursor information, changing the selection range of the edit box, saving the configuration information, and listening for and processing the information or commands sent by the input method. **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.
- The value **true** means to start the input method keyboard, and **false** means the opposite.| | textConfig | [TextConfig](#textconfig10) | Yes| Configuration of the edit box.| | 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](errorcode-inputmethod-framework.md) and [Universal Error Codes](../errorcode-universal.md). | ID| Error Message | | -------- | -------------------------------------- | | 401 | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | | 12800003 | input method client error. | | 12800008 | input method manager service error. | **Example** ```ts import { BusinessError } from '@kit.BasicServicesKit'; try { let textConfig: inputMethod.TextConfig = { inputAttribute: { textInputType: 0, enterKeyType: 1 } }; inputMethodController.attach(true, textConfig, (err: BusinessError) => { 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 a promise to return the result. > **NOTE** > > An input method can use the following features only when it has a self-drawing component attached to it: showing or hiding the keyboard, updating the cursor information, changing the selection range of the edit box, saving the configuration information, and listening for and processing the information or commands sent by the input method. **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.
- The value **true** means to start the input method keyboard, and **false** means the opposite.| | textConfig | [TextConfig](#textconfig10) | Yes| Configuration of the edit box.| **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](errorcode-inputmethod-framework.md) and [Universal Error Codes](../errorcode-universal.md). | ID| Error Message | | -------- | -------------------------------------- | | 401 | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | | 12800003 | input method client error. | | 12800008 | input method manager service error. | **Example** ```ts import { BusinessError } from '@kit.BasicServicesKit'; try { let textConfig: inputMethod.TextConfig = { inputAttribute: { textInputType: 0, enterKeyType: 1 } }; inputMethodController.attach(true, textConfig).then(() => { console.log('Succeeded in attaching inputMethod.'); }).catch((err: BusinessError) => { 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. > **NOTE** > > After the edit box is attached to an input method, this API can be called to start the soft keyboard and enter the text editing state. **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](errorcode-inputmethod-framework.md). | ID| Error Message | | -------- | -------------------------------------- | | 12800003 | input method client error. | | 12800008 | input method manager service error. | | 12800009 | input method client detached. | **Example** ```ts import { BusinessError } from '@kit.BasicServicesKit'; inputMethodController.showTextInput((err: BusinessError) => { 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. > **NOTE** > > After the edit box is attached to an input method, this API can be called to start the soft keyboard and enter the text editing state. **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](errorcode-inputmethod-framework.md). | ID| Error Message | | -------- | -------------------------------------- | | 12800003 | input method client error. | | 12800008 | input method manager service error. | | 12800009 | input method client detached. | **Example** ```ts import { BusinessError } from '@kit.BasicServicesKit'; inputMethodController.showTextInput().then(() => { console.log('Succeeded in showing text input.'); }).catch((err: BusinessError) => { 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. > **NOTE** > > If the soft keyboard is displayed when this API is called, it will be hidden. > > Calling this API does not detach the edit box from the input method. The edit box 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](errorcode-inputmethod-framework.md). | ID| Error Message | | -------- | -------------------------------------- | | 12800003 | input method client error. | | 12800008 | input method manager service error. | | 12800009 | input method client detached. | **Example** ```ts import { BusinessError } from '@kit.BasicServicesKit'; inputMethodController.hideTextInput((err: BusinessError) => { 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. > **NOTE** > > If the soft keyboard is displayed when this API is called, it will be hidden. > > Calling this API does not detach the edit box from the input method. The edit box 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](errorcode-inputmethod-framework.md). | ID| Error Message | | -------- | -------------------------------------- | | 12800003 | input method client error. | | 12800008 | input method manager service error. | | 12800009 | input method client detached. | **Example** ```ts import { BusinessError } from '@kit.BasicServicesKit'; inputMethodController.hideTextInput().then(() => { console.log('Succeeded in hiding inputMethod.'); }).catch((err: BusinessError) => { console.error(`Failed to hideTextInput: ${JSON.stringify(err)}`); }) ``` ### detach10+ detach(callback: AsyncCallback<void>): void Detaches the self-drawing component 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](errorcode-inputmethod-framework.md). | ID| Error Message | | -------- | -------------------------------------- | | 12800003 | input method client error. | | 12800008 | input method manager service error. | **Example** ```ts import { BusinessError } from '@kit.BasicServicesKit'; inputMethodController.detach((err: BusinessError) => { if (err) { console.error(`Failed to detach: ${JSON.stringify(err)}`); return; } console.log('Succeeded in detaching inputMethod.'); }); ``` ### detach10+ detach(): Promise<void> Detaches the self-drawing component 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](errorcode-inputmethod-framework.md). | ID| Error Message | | -------- | -------------------------------------- | | 12800003 | input method client error. | | 12800008 | input method manager service error. | **Example** ```ts import { BusinessError } from '@kit.BasicServicesKit'; inputMethodController.detach().then(() => { console.log('Succeeded in detaching inputMethod.'); }).catch((err: BusinessError) => { 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. > **NOTE** > > 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. **System capability**: SystemCapability.MiscServices.InputMethodFramework **Parameters** | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | | windowId | number | Yes| Window ID of the application bound to the input method.| | 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](errorcode-inputmethod-framework.md) and [Universal Error Codes](../errorcode-universal.md). | ID| Error Message | | -------- | -------------------------------------- | | 401 | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | | 12800003 | input method client error. | | 12800008 | input method manager service error. | | 12800009 | input method client detached. | **Example** ```ts import { BusinessError } from '@kit.BasicServicesKit'; try { let windowId: number = 2000; inputMethodController.setCallingWindow(windowId, (err: BusinessError) => { 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. > **NOTE** > > 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. **System capability**: SystemCapability.MiscServices.InputMethodFramework **Parameters** | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | | windowId | number | Yes| Window ID of the application bound to the input method.| **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](errorcode-inputmethod-framework.md) and [Universal Error Codes](../errorcode-universal.md). | ID| Error Message | | -------- | -------------------------------------- | | 401 | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | | 12800003 | input method client error. | | 12800008 | input method manager service error. | | 12800009 | input method client detached. | **Example** ```ts import { BusinessError } from '@kit.BasicServicesKit'; try { let windowId: number = 2000; inputMethodController.setCallingWindow(windowId).then(() => { console.log('Succeeded in setting callingWindow.'); }).catch((err: BusinessError) => { 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 can be called to notify the input method of the cursor changes. This API uses an asynchronous callback to return the result. **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](errorcode-inputmethod-framework.md) and [Universal Error Codes](../errorcode-universal.md). | ID| Error Message | | -------- | -------------------------------------- | | 401 | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | | 12800003 | input method client error. | | 12800008 | input method manager service error. | | 12800009 | input method client detached. | **Example** ```ts import { BusinessError } from '@kit.BasicServicesKit'; try { let cursorInfo: inputMethod.CursorInfo = { left: 0, top: 0, width: 600, height: 800 }; inputMethodController.updateCursor(cursorInfo, (err: BusinessError) => { 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 can be called to notify the input method of the cursor changes. This API uses a promise to return the result. **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](errorcode-inputmethod-framework.md) and [Universal Error Codes](../errorcode-universal.md). | ID| Error Message | | -------- | -------------------------------------- | | 401 | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | | 12800003 | input method client error. | | 12800008 | input method manager service error. | | 12800009 | input method client detached. | **Example** ```ts import { BusinessError } from '@kit.BasicServicesKit'; try { let cursorInfo: inputMethod.CursorInfo = { left: 0, top: 0, width: 600, height: 800 }; inputMethodController.updateCursor(cursorInfo).then(() => { console.log('Succeeded in updating cursorInfo.'); }).catch((err: BusinessError) => { 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 about the 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](errorcode-inputmethod-framework.md) and [Universal Error Codes](../errorcode-universal.md). | ID| Error Message | | -------- | -------------------------------------- | | 401 | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | | 12800003 | input method client error. | | 12800008 | input method manager service error. | | 12800009 | input method client detached. | **Example** ```ts import { BusinessError } from '@kit.BasicServicesKit'; try { inputMethodController.changeSelection('text', 0, 5, (err: BusinessError) => { 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 about the 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](errorcode-inputmethod-framework.md) and [Universal Error Codes](../errorcode-universal.md). | ID| Error Message | | -------- | -------------------------------------- | | 401 | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | | 12800003 | input method client error. | | 12800008 | input method manager service error. | | 12800009 | input method client detached. | **Example** ```ts import { BusinessError } from '@kit.BasicServicesKit'; try { inputMethodController.changeSelection('test', 0, 5).then(() => { console.log('Succeeded in changing selection.'); }).catch((err: BusinessError) => { 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 information of this 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 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](errorcode-inputmethod-framework.md) and [Universal Error Codes](../errorcode-universal.md). | ID| Error Message | | -------- | -------------------------------------- | | 401 | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | | 12800003 | input method client error. | | 12800008 | input method manager service error. | | 12800009 | input method client detached. | **Example** ```ts import { BusinessError } from '@kit.BasicServicesKit'; try { let inputAttribute: inputMethod.InputAttribute = { textInputType: 0, enterKeyType: 1 }; inputMethodController.updateAttribute(inputAttribute, (err: BusinessError) => { 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 information of this 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 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](errorcode-inputmethod-framework.md) and [Universal Error Codes](../errorcode-universal.md). | ID| Error Message | | -------- | -------------------------------------- | | 401 | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | | 12800003 | input method client error. | | 12800008 | input method manager service error. | | 12800009 | input method client detached. | **Example** ```ts import { BusinessError } from '@kit.BasicServicesKit'; try { let inputAttribute: inputMethod.InputAttribute = { textInputType: 0, enterKeyType: 1 }; inputMethodController.updateAttribute(inputAttribute).then(() => { console.log('Succeeded in updating attribute.'); }).catch((err: BusinessError) => { 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. > **NOTE** > > This API can be called only when the edit box is attached to the input method. That is, it can be called to end the input session only when the edit box 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](errorcode-inputmethod-framework.md). | ID| Error Message | | -------- | -------------------------------------- | | 12800003 | input method client error. | | 12800008 | input method manager service error. | **Example** ```ts import { BusinessError } from '@kit.BasicServicesKit'; try { inputMethodController.stopInputSession((err: BusinessError, result: boolean) => { 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. > **NOTE** > > This API can be called only when the edit box is attached to the input method. That is, it can be called to end the input session only when the edit box 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 operation is successful, and **false** means the opposite.| **Error codes** For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md). | ID| Error Message | | -------- | -------------------------------------- | | 12800003 | input method client error. | | 12800008 | input method manager service error. | **Example** ```ts import { BusinessError } from '@kit.BasicServicesKit'; try { inputMethodController.stopInputSession().then((result: boolean) => { if (result) { console.log('Succeeded in stopping inputSession.'); } else { console.error('Failed to stopInputSession.'); } }).catch((err: BusinessError) => { 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 the soft keyboard. This API uses an asynchronous callback to return the result. > **NOTE** > > This API can be called only when the edit box is attached to the input method. That is, it can be called to show the soft keyboard only when the edit box 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](errorcode-inputmethod-framework.md) and [Universal Error Codes](../errorcode-universal.md). | ID| Error Message | | -------- | -------------------------------------- | | 201 | permissions check fails. | | 12800003 | input method client error. | | 12800008 | input method manager service error. | **Example** ```ts import { BusinessError } from '@kit.BasicServicesKit'; inputMethodController.showSoftKeyboard((err: BusinessError) => { if (!err) { console.log('Succeeded in showing softKeyboard.'); } else { console.error(`Failed to show softKeyboard: ${JSON.stringify(err)}`); } }) ``` ### showSoftKeyboard9+ showSoftKeyboard(): Promise<void> Shows the soft keyboard. This API uses a promise to return the result. > **NOTE** > > This API can be called only when the edit box is attached to the input method. That is, it can be called to show the soft keyboard only when the edit box 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](errorcode-inputmethod-framework.md) and [Universal Error Codes](../errorcode-universal.md). | ID| Error Message | | -------- | -------------------------------------- | | 201 | permissions check fails. | | 12800003 | input method client error. | | 12800008 | input method manager service error. | **Example** ```ts import { BusinessError } from '@kit.BasicServicesKit'; inputMethodController.showSoftKeyboard().then(() => { console.log('Succeeded in showing softKeyboard.'); }).catch((err: BusinessError) => { console.error(`Failed to show softKeyboard: ${JSON.stringify(err)}`); }); ``` ### hideSoftKeyboard9+ hideSoftKeyboard(callback: AsyncCallback<void>): void Hides the soft keyboard. This API uses an asynchronous callback to return the result. > **NOTE** > > This API can be called only when the edit box is attached to the input method. That is, it can be called to hide the soft keyboard only when the edit box 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](errorcode-inputmethod-framework.md) and [Universal Error Codes](../errorcode-universal.md). | ID| Error Message | | -------- | -------------------------------------- | | 201 | permissions check fails. | | 12800003 | input method client error. | | 12800008 | input method manager service error. | **Example** ```ts import { BusinessError } from '@kit.BasicServicesKit'; inputMethodController.hideSoftKeyboard((err: BusinessError) => { if (!err) { console.log('Succeeded in hiding softKeyboard.'); } else { console.error(`Failed to hide softKeyboard: ${JSON.stringify(err)}`); } }) ``` ### hideSoftKeyboard9+ hideSoftKeyboard(): Promise<void> Hides the soft keyboard. This API uses a promise to return the result. > **NOTE** > > This API can be called only when the edit box is attached to the input method. That is, it can be called to hide the soft keyboard only when the edit box 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](errorcode-inputmethod-framework.md) and [Universal Error Codes](../errorcode-universal.md). | ID| Error Message | | -------- | -------------------------------------- | | 201 | permissions check fails. | | 12800003 | input method client error. | | 12800008 | input method manager service error. | **Example** ```ts import { BusinessError } from '@kit.BasicServicesKit'; inputMethodController.hideSoftKeyboard().then(() => { console.log('Succeeded in hiding softKeyboard.'); }).catch((err: BusinessError) => { 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. > **NOTE** > > This API can be called only when the edit box is attached to the input method. That is, it can be called to end the input session only when the edit box is focused. > > 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** ```ts import { BusinessError } from '@kit.BasicServicesKit'; inputMethodController.stopInput((err: BusinessError, result: boolean) => { 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. > **NOTE** > > This API can be called only when the edit box is attached to the input method. That is, it can be called to end the input session only when the edit box is focused. > > 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 operation is successful, and **false** means the opposite.| **Example** ```ts import { BusinessError } from '@kit.BasicServicesKit'; inputMethodController.stopInput().then((result: boolean) => { if (result) { console.log('Succeeded in stopping input.'); } else { console.error('Failed to stopInput.'); } }).catch((err: BusinessError) => { console.error(`Failed to stopInput: ${JSON.stringify(err)}`); }) ``` ### on('insertText')10+ on(type: 'insertText', callback: (text: string) => void): void 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 | | -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | | type | string | Yes | Listening type. The value is fixed at **'insertText'**.| | callback | (text: string) => void | Yes | Callback used to return the text to be inserted.
The application needs to operate the content in the edit box based on the text content returned in the callback.| **Error codes** For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md) and [Universal Error Codes](../errorcode-universal.md). | ID| Error Message | | -------- | -------------------------------------- | | 401 | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | | 12800009 | input method client detached. | **Example** ```ts function callback1(text: string) { console.info('Succeeded in getting callback1 data: ' + JSON.stringify(text)); } function callback2(text: string) { console.info('Succeeded in getting callback2 data: ' + JSON.stringify(text)); } try { inputMethodController.on('insertText', callback1); inputMethodController.on('insertText', callback2); // Cancel only callback1 of insertText. inputMethodController.off('insertText', callback1); // Cancel all callbacks of insertText. inputMethodController.off('insertText'); } catch(err) { console.error(`Failed to subscribe insertText: ${JSON.stringify(err)}`); } ``` ### off('insertText')10+ off(type: 'insertText', callback?: (text: string) => void): void Disables listening for the text insertion event of the input method. **System capability**: SystemCapability.MiscServices.InputMethodFramework **Parameters** | Name | Type | Mandatory| Description | | -------- | ---------------------- | ---- | ------------------------------------------------------------ | | type | string | Yes | Listening type. The value is fixed at **'insertText'**.| | callback | (text: string) => void | No | Callback used for disable listening, which must be the same as that passed by the **on** API.
If this parameter is not specified, listening will be disabled for all callbacks corresponding to the specified type.| **Example** ```ts let onInsertTextCallback = (text: string) => { console.log(`Succeeded in subscribing insertText: ${text}`); }; inputMethodController.off('insertText', onInsertTextCallback); inputMethodController.off('insertText'); ``` ### on('deleteLeft')10+ on(type: 'deleteLeft', callback: (length: number) => void): void Enables listening for the leftward delete 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 is fixed at **'deleteLeft'**.| | callback | (length: number) => void | Yes | Callback used to return the length of the text to be deleted leftward.
The application needs to operate the content in the edit box based on the length returned in the callback.| **Error codes** For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md) and [Universal Error Codes](../errorcode-universal.md). | ID| Error Message | | -------- | -------------------------------------- | | 401 | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | | 12800009 | input method client detached. | **Example** ```ts try { inputMethodController.on('deleteLeft', (length: number) => { console.log(`Succeeded in subscribing deleteLeft, length: ${length}`); }); } catch(err) { console.error(`Failed to subscribe deleteLeft: ${JSON.stringify(err)}`); } ``` ### off('deleteLeft')10+ off(type: 'deleteLeft', callback?: (length: number) => void): void Disables listening for the leftward delete event. **System capability**: SystemCapability.MiscServices.InputMethodFramework **Parameters** | Name | Type | Mandatory| Description | | -------- | ------------------------ | ---- | ------------------------------------------------------------ | | type | string | Yes | Listening type. The value is fixed at **'deleteLeft'**.| | callback | (length: number) => void | No | Callback used for disable listening, which must be the same as that passed by the **on** API.
If this parameter is not specified, listening will be disabled for all callbacks corresponding to the specified type.| **Example** ```ts let onDeleteLeftCallback = (length: number) => { console.log(`Succeeded in subscribing deleteLeft, length: ${length}`); }; inputMethodController.off('deleteLeft', onDeleteLeftCallback); inputMethodController.off('deleteLeft'); ``` ### on('deleteRight')10+ on(type: 'deleteRight', callback: (length: number) => void): void Enables listening for the rightward delete 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 is fixed at **'deleteRight'**.| | callback | (length: number) => void | Yes | Callback used to return the length of the text to be deleted rightward.
The application needs to operate the content in the edit box based on the length returned in the callback.| **Error codes** For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md) and [Universal Error Codes](../errorcode-universal.md). | ID| Error Message | | -------- | -------------------------------------- | | 401 | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | | 12800009 | input method client detached. | **Example** ```ts try { inputMethodController.on('deleteRight', (length: number) => { console.log(`Succeeded in subscribing deleteRight, length: ${length}`); }); } catch(err) { console.error(`Failed to subscribe deleteRight: ${JSON.stringify(err)}`); } ``` ### off('deleteRight')10+ off(type: 'deleteRight', callback?: (length: number) => void): void Disables listening for the rightward delete event. **System capability**: SystemCapability.MiscServices.InputMethodFramework **Parameters** | Name | Type | Mandatory| Description | | -------- | ------------------------ | ---- | ------------------------------------------------------------ | | type | string | Yes | Listening type. The value is fixed at `deleteRight`.| | callback | (length: number) => void | No | Callback used for disable listening, which must be the same as that passed by the **on** API.
If this parameter is not specified, listening will be disabled for all callbacks corresponding to the specified type.| **Example** ```ts let onDeleteRightCallback = (length: number) => { console.log(`Succeeded in subscribing deleteRight, length: ${length}`); }; inputMethodController.off('deleteRight', onDeleteRightCallback); inputMethodController.off('deleteRight'); ``` ### on('sendKeyboardStatus')10+ on(type: 'sendKeyboardStatus', callback: (keyboardStatus: KeyboardStatus) => void): void Enables listening for the soft 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 | | -------- | ------ | ---- | ---- | | type | string | Yes | Listening type. The value is fixed at **'sendKeyboardStatus'**.| | callback | (keyboardStatus: [KeyboardStatus](#keyboardstatus10)) => void | Yes | Callback used to return the soft keyboard status.
The application needs to perform operations based on the soft keyboard state returned in the callback.| **Error codes** For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md) and [Universal Error Codes](../errorcode-universal.md). | ID| Error Message | | -------- | -------------------------------------- | | 401 | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | | 12800009 | input method client detached. | **Example** ```ts try { inputMethodController.on('sendKeyboardStatus', (keyboardStatus: inputMethod.KeyboardStatus) => { console.log(`Succeeded in subscribing sendKeyboardStatus, keyboardStatus: ${keyboardStatus}`); }); } catch(err) { console.error(`Failed to subscribe sendKeyboardStatus: ${JSON.stringify(err)}`); } ``` ### off('sendKeyboardStatus')10+ off(type: 'sendKeyboardStatus', callback?: (keyboardStatus: KeyboardStatus) => void): void Disables listening for the soft keyboard status event of the input method. **System capability**: SystemCapability.MiscServices.InputMethodFramework **Parameters** | Name | Type | Mandatory| Description | | -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | | type | string | Yes | Listening type. The value is fixed at **'sendKeyboardStatus'**.| | callback | (keyboardStatus: [KeyboardStatus](#keyboardstatus10)) => void | No | Callback used for disable listening. If this parameter is not specified, listening will be disabled for all callbacks corresponding to the specified type.| **Example** ```ts let onSendKeyboardStatus = (keyboardStatus: inputMethod.KeyboardStatus) => { console.log(`Succeeded in subscribing sendKeyboardStatus, keyboardStatus: ${keyboardStatus}`); }; inputMethodController.off('sendKeyboardStatus', onSendKeyboardStatus); inputMethodController.off('sendKeyboardStatus'); ``` ### on('sendFunctionKey')10+ on(type: 'sendFunctionKey', callback: (functionKey: FunctionKey) => void): void 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 | | -------- | -------- | ---- | ----- | | type | string | Yes | Listening type. The value is fixed at **'sendFunctionKey'**.| | callback | (functionKey: [FunctionKey](#functionkey10)) => void | Yes | Callback used to return the function key information sent by the input method.
The application needs to perform operations based on the function key information returned in the callback.| **Error codes** For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md) and [Universal Error Codes](../errorcode-universal.md). | ID| Error Message | | -------- | -------------------------------------- | | 401 | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | | 12800009 | input method client detached. | **Example** ```ts try { inputMethodController.on('sendFunctionKey', (functionKey: inputMethod.FunctionKey) => { console.log(`Succeeded in subscribing sendFunctionKey, functionKey.enterKeyType: ${functionKey.enterKeyType}`); }); } catch(err) { console.error(`Failed to subscribe sendFunctionKey: ${JSON.stringify(err)}`); } ``` ### off('sendFunctionKey')10+ off(type: 'sendFunctionKey', callback?: (functionKey: FunctionKey) => void): void Disables listening for the function key sending event of the input method. **System capability**: SystemCapability.MiscServices.InputMethodFramework **Parameters** | Name | Type | Mandatory| Description | | -------- | ---------------------------------------------------- | ---- | ------------------------------------------------------------ | | type | string | Yes | Listening type. The value is fixed at **'sendFunctionKey'**.| | callback | (functionKey: [FunctionKey](#functionkey10)) => void | No | Callback used for disable listening, which must be the same as that passed by the **on** API.
If this parameter is not specified, listening will be disabled for all callbacks corresponding to the specified type.| **Example** ```ts let onSendFunctionKey = (functionKey: inputMethod.FunctionKey) => { console.log(`Succeeded in subscribing sendFunctionKey, functionKey: ${functionKey.enterKeyType}`); }; inputMethodController.off('sendFunctionKey', onSendFunctionKey); inputMethodController.off('sendFunctionKey'); ``` ### on('moveCursor')10+ on(type: 'moveCursor', callback: (direction: Direction) => void): void 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 | | -------- | ------ | ---- | ------ | | type | string | Yes | Listening type. The value is fixed at **'moveCursor'**.| | callback | callback: (direction: [Direction10+](#direction10)) => void | Yes | Callback used to return the cursor movement direction.
The 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](errorcode-inputmethod-framework.md) and [Universal Error Codes](../errorcode-universal.md). | ID| Error Message | | -------- | -------------------------------- | | 401 | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | | 12800009 | input method client detached. | **Example** ```ts try { inputMethodController.on('moveCursor', (direction: inputMethod.Direction) => { console.log(`Succeeded in subscribing moveCursor, direction: ${direction}`); }); } catch(err) { console.error(`Failed to subscribe moveCursor: ${JSON.stringify(err)}`); } ``` ### off('moveCursor')10+ off(type: 'moveCursor', callback?: (direction: Direction) => void): void Disables listening for the cursor movement event of the input method. **System capability**: SystemCapability.MiscServices.InputMethodFramework **Parameters** | Name | Type | Mandatory| Description | | ------ | ------ | ---- | ---- | | type | string | Yes | Listening type. The value is fixed at **'moveCursor'**.| | callback | (direction: [Direction10+](#direction10)) => void | No| Callback used for disable listening, which must be the same as that passed by the **on** API.
If this parameter is not specified, listening will be disabled for all callbacks corresponding to the specified type.| **Example** ```ts let onMoveCursorCallback = (direction: inputMethod.Direction) => { console.log(`Succeeded in subscribing moveCursor, direction: ${direction}`); }; inputMethodController.off('moveCursor', onMoveCursorCallback); inputMethodController.off('moveCursor'); ``` ### on('handleExtendAction')10+ on(type: 'handleExtendAction', callback: (action: ExtendAction) => void): void 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 | | -------- | ------ | ---- | -------- | | type | string | Yes | Listening type. The value is fixed at **'handleExtendAction'**.| | callback | callback: (action: [ExtendAction](#extendaction10)) => void | Yes | Callback used to return the extended action type.
The 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](errorcode-inputmethod-framework.md) and [Universal Error Codes](../errorcode-universal.md). | ID| Error Message | | -------- | -------------------------------------- | | 401 | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | | 12800009 | input method client detached. | **Example** ```ts try { inputMethodController.on('handleExtendAction', (action: inputMethod.ExtendAction) => { console.log(`Succeeded in subscribing handleExtendAction, action: ${action}`); }); } catch(err) { console.error(`Failed to subscribe handleExtendAction: ${JSON.stringify(err)}`); } ``` ### off('handleExtendAction')10+ off(type: 'handleExtendAction', callback?: (action: ExtendAction) => void): void Disables 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 | | ------ | ------ | ---- | ------- | | type | string | Yes | Listening type. The value is fixed at **'handleExtendAction'**.| | callback | (action: [ExtendAction](#extendaction10)) => void | No| Callback used for disable listening, which must be the same as that passed by the **on** API.
If this parameter is not specified, listening will be disabled for all callbacks corresponding to the specified type.| **Example** ```ts try { let onHandleExtendActionCallback = (action: inputMethod.ExtendAction) => { console.log(`Succeeded in subscribing handleExtendAction, action: ${action}`); }; inputMethodController.off('handleExtendAction', onHandleExtendActionCallback); inputMethodController.off('handleExtendAction'); } catch(err) { console.error(`Failed to subscribe handleExtendAction: ${JSON.stringify(err)}`); } ``` ### on('selectByRange')10+ on(type: 'selectByRange', callback: Callback<Range>): void 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 is fixed at **'selectByRange'**.| | callback | Callback<[Range](#range10)> | Yes | Callback used to return the range of the text to be selected.
The application needs to select the text based on the range returned in the callback.| **Error codes** For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). | ID| Error Message | | -------- | ------------------------------------------------------- | | 401 | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | **Example** ```ts try { inputMethodController.on('selectByRange', (range: inputMethod.Range) => { console.log(`Succeeded in subscribing selectByRange: start: ${range.start} , end: ${range.end}`); }); } catch(err) { console.error(`Failed to subscribe selectByRange: ${JSON.stringify(err)}`); } ``` ### off('selectByRange')10+ off(type: 'selectByRange', callback?: Callback<Range>): void Disables 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 is fixed at **'selectByRange'**.| | callback | Callback<[Range](#range10)> | No | Callback used for disable listening, which must be the same as that passed by the **on** API.
If this parameter is not specified, listening will be disabled for all callbacks corresponding to the specified type.| **Example** ```ts try { let onSelectByRangeCallback = (range: inputMethod.Range) => { console.log(`Succeeded in subscribing selectByRange, start: ${range.start} , end: ${range.end}`); }; inputMethodController.off('selectByRange', onSelectByRangeCallback); inputMethodController.off('selectByRange'); } catch(err) { console.error(`Failed to subscribe selectByRange: ${JSON.stringify(err)}`); } ``` ### on('selectByMovement')10+ on(type: 'selectByMovement', callback: Callback<Movement>): void Enables listening for the select-by-cursor-movement 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 is fixed at **'selectByMovement'**.| | callback | Callback<[Movement](#movement10)> | Yes | Callback used to return the direction in which the cursor moves.
The application needs to select the text based on the direction returned in the callback.| **Error codes** For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). | ID| Error Message | | -------- | ------------------------------------------------------- | | 401 | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | **Example** ```ts try { inputMethodController.on('selectByMovement', (movement: inputMethod.Movement) => { console.log('Succeeded in subscribing selectByMovement: direction: ' + movement.direction); }); } catch(err) { console.error(`Failed to subscribe selectByMovement: ${JSON.stringify(err)}`); } ``` ### off('selectByMovement')10+ off(type: 'selectByMovement', callback?: Callback<Movement>): void Disables listening for the select-by-cursor-movement 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 is fixed at **'selectByMovement'**.| | callback | Callback<[Movement](#movement10)> | No | Callback used for disable listening, which must be the same as that passed by the **on** API.
If this parameter is not specified, listening will be disabled for all callbacks corresponding to the specified type.| **Example** ```ts try { let onSelectByMovementCallback = (movement: inputMethod.Movement) => { console.log(`Succeeded in subscribing selectByMovement, movement.direction: ${movement.direction}`); }; inputMethodController.off('selectByMovement', onSelectByMovementCallback); inputMethodController.off('selectByMovement'); } catch(err) { console.error(`Failed to unsubscribing selectByMovement: ${JSON.stringify(err)}`); } ``` ### on('getLeftTextOfCursor')10+ on(type: 'getLeftTextOfCursor', callback: (length: number) => string): void Enables listening for the event of obtaining the length of text deleted leftward. 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 is fixed at **'getLeftTextOfCursor'**.| | callback | (length: number) => string | Yes | Callback used to obtain the text of the specified length deleted leftward.| **Error codes** For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md) and [Universal Error Codes](../errorcode-universal.md). | ID| Error Message | | -------- | -------------------------------------- | | 401 | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | | 12800009 | input method client detached. | **Example** ```ts try { inputMethodController.on('getLeftTextOfCursor', (length: number) => { console.info(`Succeeded in subscribing getLeftTextOfCursor, length: ${length}`); let text:string = ""; return text; }); } catch(err) { console.error(`Failed to unsubscribing getLeftTextOfCursor. err: ${JSON.stringify(err)}`); } ``` ### off('getLeftTextOfCursor')10+ off(type: 'getLeftTextOfCursor', callback?: (length: number) => string): void Disables listening for the event of obtaining the length of text deleted leftward. 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 is fixed at **'getLeftTextOfCursor'**.| | callback | (length: number) => string | No | Callback used for disable listening, which must be the same as that passed by the **on** API.
If this parameter is not specified, listening will be disabled for all callbacks corresponding to the specified type.| **Example** ```ts try { let getLeftTextOfCursorCallback = (length: number) => { console.info(`Succeeded in unsubscribing getLeftTextOfCursor, length: ${length}`); let text:string = ""; return text; }; inputMethodController.off('getLeftTextOfCursor', getLeftTextOfCursorCallback); inputMethodController.off('getLeftTextOfCursor'); } catch(err) { console.error(`Failed to unsubscribing getLeftTextOfCursor. err: ${JSON.stringify(err)}`); } ``` ### on('getRightTextOfCursor')10+ on(type: 'getRightTextOfCursor', callback: (length: number) => string): void Enables listening for the event of obtaining the length of text deleted rightward. 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 is fixed at **'getRightTextOfCursor'**.| | callback | (length: number) => string | Yes | Callback used to obtain the text of the specified length deleted rightward.| **Error codes** For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md) and [Universal Error Codes](../errorcode-universal.md). | ID| Error Message | | -------- | -------------------------------------- | | 401 | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | | 12800009 | input method client detached. | **Example** ```ts try { inputMethodController.on('getRightTextOfCursor', (length: number) => { console.info(`Succeeded in subscribing getRightTextOfCursor, length: ${length}`); let text:string = ""; return text; }); } catch(err) { console.error(`Failed to subscribe getRightTextOfCursor. err: ${JSON.stringify(err)}`); } ``` ### off('getRightTextOfCursor')10+ off(type: 'getRightTextOfCursor', callback?: (length: number) => string): void Disables listening for the event of obtaining the length of text deleted rightward. 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 is fixed at **'getRightTextOfCursor'**.| | callback | (length: number) => string | No |Callback used for disable listening, which must be the same as that passed by the **on** API.
If this parameter is not specified, listening will be disabled for all callbacks corresponding to the specified type.| **Example** ```ts try { let getRightTextOfCursorCallback = (length: number) => { console.info(`Succeeded in unsubscribing getRightTextOfCursor, length: ${length}`); let text:string = ""; return text; }; inputMethodController.off('getRightTextOfCursor', getRightTextOfCursorCallback); inputMethodController.off('getRightTextOfCursor'); } catch(err) { console.error(`Failed to unsubscribing getRightTextOfCursor. err: ${JSON.stringify(err)}`); } ``` ### on('getTextIndexAtCursor')10+ on(type: 'getTextIndexAtCursor', callback: () => number): void Enables listening for the event of obtaining the index of text at the cursor. 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 is fixed at **'getTextIndexAtCursor'**.| | callback | () => number | Yes | Callback used to obtain the index of text at the cursor.| **Error codes** For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md) and [Universal Error Codes](../errorcode-universal.md). | ID| Error Message | | -------- | -------------------------------------- | | 401 | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | | 12800009 | input method client detached. | **Example** ```ts try { inputMethodController.on('getTextIndexAtCursor', () => { console.info(`Succeeded in subscribing getTextIndexAtCursor.`); let index:number = 0; return index; }); } catch(err) { console.error(`Failed to subscribe getTextIndexAtCursor. err: ${JSON.stringify(err)}`); } ``` ### off('getTextIndexAtCursor')10+ off(type: 'getTextIndexAtCursor', callback?: () => number): void Disables listening for the event of obtaining the index of text at the cursor. 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 is fixed at **'getTextIndexAtCursor'**.| | callback | () => number | No | Callback used for disable listening, which must be the same as that passed by the **on** API.
If this parameter is not specified, listening will be disabled for all callbacks corresponding to the specified type.| **Example** ```ts try { let getTextIndexAtCursorCallback = () => { console.info(`Succeeded in unsubscribing getTextIndexAtCursor.`); let index:number = 0; return index; }; inputMethodController.off('getTextIndexAtCursor', getTextIndexAtCursorCallback); inputMethodController.off('getTextIndexAtCursor'); } catch(err) { console.error(`Failed to unsubscribing getTextIndexAtCursor. err: ${JSON.stringify(err)}`); } ``` ## InputMethodSetting8+ In the following API examples, you must first use [getSetting](#inputmethodgetsetting9) to obtain an **InputMethodSetting** instance, and then call the APIs using the obtained instance. ### on('imeChange')9+ on(type: 'imeChange', callback: (inputMethodProperty: InputMethodProperty, inputMethodSubtype: InputMethodSubtype) => void): void Enables listening for the input method and subtype change 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 is fixed at **'imeChange'**.| | callback | (inputMethodProperty: [InputMethodProperty](#inputmethodproperty8), inputMethodSubtype: [InputMethodSubtype](./js-apis-inputmethod-subtype.md#inputmethodsubtype)) => void | Yes| Callback used to return the input method attributes and subtype.| **Example** ```ts import { InputMethodSubtype } from '@kit.IMEKit'; try { inputMethodSetting.on('imeChange', (inputMethodProperty: inputMethod.InputMethodProperty, inputMethodSubtype: InputMethodSubtype) => { console.log('Succeeded in subscribing imeChange: inputMethodProperty: ' + JSON.stringify(inputMethodProperty) + " , inputMethodSubtype: " + JSON.stringify(inputMethodSubtype)); }); } catch(err) { console.error(`Failed to unsubscribing inputMethodProperty. err: ${JSON.stringify(err)}`); } ``` ### off('imeChange')9+ off(type: 'imeChange', callback?: (inputMethodProperty: InputMethodProperty, inputMethodSubtype: InputMethodSubtype) => void): void Disables listening for the input method and subtype change 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 is fixed at **'imeChange'**.| | callback | (inputMethodProperty: [InputMethodProperty](#inputmethodproperty8), inputMethodSubtype: [InputMethodSubtype](./js-apis-inputmethod-subtype.md#inputmethodsubtype)) => void | No| Callback used to return the input method attributes and subtype.| **Example** ```ts inputMethodSetting.off('imeChange'); ``` ### listInputMethodSubtype9+ listInputMethodSubtype(inputMethodProperty: InputMethodProperty, callback: AsyncCallback<Array<InputMethodSubtype>>): void Obtains all subtypes of a specified 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.| | callback | AsyncCallback<Array<[InputMethodSubtype](./js-apis-inputmethod-subtype.md#inputmethodsubtype)>> | Yes| Callback used to return all subtypes of the specified input method.| **Error codes** For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md) and [Universal Error Codes](../errorcode-universal.md). | ID| Error Message | | -------- | -------------------------------------- | | 401 | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | | 12800001 | bundle manager error. | | 12800008 | input method manager service error. | **Example** ```ts import { InputMethodSubtype } from '@kit.IMEKit'; import { BusinessError } from '@kit.BasicServicesKit'; let inputMethodProperty: inputMethod.InputMethodProperty = { name: 'com.example.kikakeyboard', id: 'propertyId', packageName: 'com.example.kikakeyboard', methodId: 'propertyId', } let inputMethodSetting = inputMethod.getSetting(); try { inputMethodSetting.listInputMethodSubtype(inputMethodProperty, (err: BusinessError, data: Array) => { 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)}`); } ``` ### listInputMethodSubtype9+ listInputMethodSubtype(inputMethodProperty: InputMethodProperty): Promise<Array<InputMethodSubtype>> Obtains all subtypes of a specified input method. This API uses a promise to return the result. **System capability**: SystemCapability.MiscServices.InputMethodFramework **Parameters** | Name | Type | Mandatory| Description | | -------- | -------------------------------------------------- | ---- | ---------------------- | | inputMethodProperty | [InputMethodProperty](#inputmethodproperty8)| Yes| Input method.| **Return value** | Type | Description | | ----------------------------------------------------------- | ---------------------- | | Promise> | Promise used to return all subtypes of the specified input method.| **Error codes** For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md) and [Universal Error Codes](../errorcode-universal.md). | ID| Error Message | | -------- | -------------------------------------- | | 401 | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | | 12800001 | bundle manager error. | | 12800008 | input method manager service error. | **Example** ```ts import { InputMethodSubtype } from '@kit.IMEKit'; import { BusinessError } from '@kit.BasicServicesKit'; let inputMethodProperty: inputMethod.InputMethodProperty = { name: 'com.example.kikakeyboard', id: 'propertyId', packageName: 'com.example.kikakeyboard', methodId: 'propertyId', } let inputMethodSetting = inputMethod.getSetting(); try { inputMethodSetting.listInputMethodSubtype(inputMethodProperty).then((data: Array) => { console.log('Succeeded in listing inputMethodSubtype.'); }).catch((err: BusinessError) => { console.error(`Failed to listInputMethodSubtype: ${JSON.stringify(err)}`); }) } catch(err) { console.error(`Failed to listInputMethodSubtype: ${JSON.stringify(err)}`); } ``` ### listCurrentInputMethodSubtype9+ listCurrentInputMethodSubtype(callback: AsyncCallback<Array<InputMethodSubtype>>): void Obtains all subtypes of this input method. This API uses an asynchronous callback to return the result. **System capability**: SystemCapability.MiscServices.InputMethodFramework **Parameters** | Name | Type | Mandatory| Description | | -------- | -------------------------------------------------- | ---- | ---------------------- | | callback | AsyncCallback<Array<[InputMethodSubtype](./js-apis-inputmethod-subtype.md#inputmethodsubtype)>> | Yes | Callback used to return all subtypes of the current input method.| **Error codes** For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md) and [Universal Error Codes](../errorcode-universal.md). | ID| Error Message | | -------- | -------------------------------------- | | 12800001 | bundle manager error. | | 12800008 | input method manager service error. | **Example** ```ts import { InputMethodSubtype } from '@kit.IMEKit'; import { BusinessError } from '@kit.BasicServicesKit'; let inputMethodSetting = inputMethod.getSetting(); try { inputMethodSetting.listCurrentInputMethodSubtype((err: BusinessError, data: Array) => { 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)}`); } ``` ### listCurrentInputMethodSubtype9+ listCurrentInputMethodSubtype(): Promise<Array<InputMethodSubtype>> Obtains all subtypes of this input method. This API uses a promise to return the result. **System capability**: SystemCapability.MiscServices.InputMethodFramework **Return value** | Type | Description | | ----------------------------------------------------------- | ---------------------- | | Promise> | Promise used to return all subtypes of the current input method.| **Error codes** For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md) and [Universal Error Codes](../errorcode-universal.md). | ID| Error Message | | -------- | -------------------------------------- | | 12800001 | bundle manager error. | | 12800008 | input method manager service error. | **Example** ```ts import { InputMethodSubtype } from '@kit.IMEKit'; import { BusinessError } from '@kit.BasicServicesKit'; let inputMethodSetting = inputMethod.getSetting(); try { inputMethodSetting.listCurrentInputMethodSubtype().then((data: Array) => { console.log('Succeeded in listing currentInputMethodSubtype.'); }).catch((err: BusinessError) => { console.error(`Failed to listCurrentInputMethodSubtype: ${JSON.stringify(err)}`); }) } catch(err) { console.error(`Failed to listCurrentInputMethodSubtype: ${JSON.stringify(err)}`); } ``` ### getInputMethods9+ getInputMethods(enable: boolean, callback: AsyncCallback<Array<InputMethodProperty>>): void Obtains a list of activated or deactivated input methods. This API uses an asynchronous callback to return the result. > **NOTE** > > An activated input method refers to an input method that is enabled. The default input method is enabled by default. Other input methods can be enabled or disabled as needed. > > The list of activated input methods includes the default input method and enabled input methods. The list of deactivated input methods includes all installed input methods except the enabled ones. **System capability**: SystemCapability.MiscServices.InputMethodFramework **Parameters** | Name | Type | Mandatory| Description | | -------- | --------------------------------------------------- | ---- | ----------------------------- | | enable | boolean | Yes |Whether to return a list of activated input methods. The value **true** means to return a list of activated input methods, and **false** means to return a list of deactivated input methods.| | callback | AsyncCallback<Array<[InputMethodProperty](#inputmethodproperty8)>> | Yes | Callback used to return a list of activated or deactivated input methods.| **Error codes** For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md) and [Universal Error Codes](../errorcode-universal.md). | ID| Error Message | | -------- | ----------------------------------- | | 401 | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | | 12800001 | bundle manager error. | | 12800008 | input method manager service error. | **Example** ```ts import { BusinessError } from '@kit.BasicServicesKit'; try { inputMethodSetting.getInputMethods(true, (err: BusinessError, data: Array) => { 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)}`); } ``` ### getInputMethods9+ getInputMethods(enable: boolean): Promise<Array<InputMethodProperty>> Obtains a list of activated or deactivated input methods. This API uses a promise to return the result. > **NOTE** > > An activated input method refers to an input method that is enabled. The default input method is enabled by default. Other input methods can be enabled or disabled as needed. > > The list of activated input methods includes the default input method and enabled input methods. The list of deactivated input methods includes all installed input methods except the enabled ones. **System capability**: SystemCapability.MiscServices.InputMethodFramework **Parameters** | Name| Type | Mandatory| Description | | ------ | ------- | ---- | ----------------------- | | enable | boolean | Yes |Whether to return a list of activated input methods. The value **true** means to return a list of activated input methods, and **false** means to return a list of deactivated input methods.| **Return value** | Type | Description | | ------------------------------------------------------------ | ------------------------------------------ | | Promise\> | Promise used to return a list of activated or deactivated input methods.| **Error codes** For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md) and [Universal Error Codes](../errorcode-universal.md). | ID| Error Message | | -------- | ----------------------------------- | | 401 | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | | 12800001 | bundle manager error. | | 12800008 | input method manager service error. | **Example** ```ts import { BusinessError } from '@kit.BasicServicesKit'; try { inputMethodSetting.getInputMethods(true).then((data: Array) => { console.log('Succeeded in getting inputMethods.'); }).catch((err: BusinessError) => { console.error(`Failed to getInputMethods: ${JSON.stringify(err)}`); }) } catch(err) { console.error(`Failed to getInputMethods: ${JSON.stringify(err)}`); } ``` ### getInputMethodsSync11+ getInputMethodsSync(enable: boolean): Array<InputMethodProperty> Obtains a list of activated or deactivated input methods. This API returns the result synchronously. > **NOTE** > > An activated input method refers to an input method that is enabled. The default input method is enabled by default. Other input methods can be enabled or disabled as needed. > > The list of activated input methods includes the default input method and enabled input methods. The list of deactivated input methods includes all installed input methods except the enabled ones. **System capability**: SystemCapability.MiscServices.InputMethodFramework **Parameters** | Name| Type | Mandatory| Description | | ------ | ------- | ---- | ----------------------- | | enable | boolean | Yes |Whether to return a list of activated input methods. The value **true** means to return a list of activated input methods, and **false** means to return a list of deactivated input methods.| **Return value** | Type | Description | | ---------------------------------------------------- | ----------------------------- | | Array\<[InputMethodProperty](#inputmethodproperty8)> | List of activated or deactivated input methods.| **Error codes** For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md) and [Universal Error Codes](../errorcode-universal.md). | ID| Error Message | | -------- | -------------------------------------- | | 401 | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | | 12800001 | bundle manager error. | | 12800008 |input method manager service error. | **Example** ```ts try { let imeProp = inputMethodSetting.getInputMethodsSync(true); } catch(err) { console.error(`Failed to getInputMethods: ${JSON.stringify(err)}`); } ``` ### getAllInputMethods11+ getAllInputMethods(callback: AsyncCallback<Array<InputMethodProperty>>): void Obtains a list of all input methods. This API uses an asynchronous callback to return the result. **System capability**: SystemCapability.MiscServices.InputMethodFramework **Parameters** | Name | Type | Mandatory| Description | | -------- | ------------------------------------------------------------ | ---- | ------------------------------ | | callback | AsyncCallback<Array<[InputMethodProperty](#inputmethodproperty8)>> | Yes | Callback used to return a list of all input methods.| **Error codes** For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md) and [Universal Error Codes](../errorcode-universal.md). | ID| Error Message | | -------- | ----------------------------------- | | 12800001 | bundle manager error. | | 12800008 | input method manager service error. | **Example** ```ts import { BusinessError } from '@kit.BasicServicesKit'; try { inputMethodSetting.getAllInputMethods((err: BusinessError, data: Array) => { if (err) { console.error(`Failed to getAllInputMethods: ${JSON.stringify(err)}`); return; } console.log('Succeeded in getting all inputMethods.'); }); } catch (err) { console.error(`Failed to getAllInputMethods: ${JSON.stringify(err)}`); } ``` ### getAllInputMethods11+ getAllInputMethods(): Promise<Array<InputMethodProperty>> Obtains a list of all input methods. This API uses a promise to return the result. **System capability**: SystemCapability.MiscServices.InputMethodFramework **Return value** | Type | Description | | ------------------------------------------------------------ | --------------------------------- | | Promise\> | Promise used to return a list of all input methods.| **Error codes** For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md) and [Universal Error Codes](../errorcode-universal.md). | ID| Error Message | | -------- | ----------------------------------- | | 12800001 | bundle manager error. | | 12800008 | input method manager service error. | **Example** ```ts import { BusinessError } from '@kit.BasicServicesKit'; inputMethodSetting.getAllInputMethods().then((data: Array) => { console.log('Succeeded in getting all inputMethods.'); }).catch((err: BusinessError) => { console.error(`Failed to getAllInputMethods: ${JSON.stringify(err)}`); }) ``` ### getAllInputMethodsSync11+ getAllInputMethodsSync(): Array<InputMethodProperty> Obtains a list of all input methods. This API returns the result synchronously. **System capability**: SystemCapability.MiscServices.InputMethodFramework **Return value** | Type | Description | | ---------------------------------------------------- | ------------------ | | Array\<[InputMethodProperty](#inputmethodproperty8)> | List of all input methods.| **Error codes** For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md). | ID| Error Message | | -------- | ----------------------------------- | | 12800001 | bundle manager error. | | 12800008 | input method manager service error. | **Example** ```ts try { let imeProp = inputMethodSetting.getAllInputMethodsSync(); } catch(err) { console.error(`Failed to getAllInputMethodsSync: ${JSON.stringify(err)}`); } ``` ### showOptionalInputMethods9+ showOptionalInputMethods(callback: AsyncCallback<boolean>): void Displays a dialog box for selecting an 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.| **Error codes** For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md). | ID| Error Message | | -------- | -------------------------------------- | | 12800008 | input method manager service error. | **Example** ```ts import { BusinessError } from '@kit.BasicServicesKit'; try { inputMethodSetting.showOptionalInputMethods((err: BusinessError, data: boolean) => { 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)}`); } ``` ### showOptionalInputMethods9+ showOptionalInputMethods(): Promise<boolean> Displays a dialog box for selecting an input method. This API uses a promise to return the result. **System capability**: SystemCapability.MiscServices.InputMethodFramework **Return value** | Type| Description| | -------- | -------- | | Promise<boolean> | Promise 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](errorcode-inputmethod-framework.md). | ID| Error Message | | -------- | -------------------------------------- | | 12800008 | input method manager service error. | **Example** ```ts import { BusinessError } from '@kit.BasicServicesKit'; inputMethodSetting.showOptionalInputMethods().then((data: boolean) => { console.log('Succeeded in showing optionalInputMethods.'); }).catch((err: BusinessError) => { console.error(`Failed to showOptionalInputMethods: ${JSON.stringify(err)}`); }) ``` ### listInputMethod(deprecated) listInputMethod(callback: AsyncCallback<Array<InputMethodProperty>>): void Obtains a list of installed input methods. 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 [getInputMethods](#getinputmethods9) instead. **System capability**: SystemCapability.MiscServices.InputMethodFramework **Parameters** | Name | Type | Mandatory| Description | | -------- | -------------------------------------------------- | ---- | ---------------------- | | callback | AsyncCallback<Array<[InputMethodProperty](#inputmethodproperty8)>> | Yes | Callback used to return the list of installed input methods.| **Example** ```ts import { BusinessError } from '@kit.BasicServicesKit'; inputMethodSetting.listInputMethod((err: BusinessError, data: Array) => { if (err) { console.error(`Failed to listInputMethod: ${JSON.stringify(err)}`); return; } console.log('Succeeded in listing inputMethod.'); }); ``` ### listInputMethod(deprecated) listInputMethod(): Promise<Array<InputMethodProperty>> Obtains a list of installed input methods. 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 [getInputMethods](#getinputmethods9-1) instead. **System capability**: SystemCapability.MiscServices.InputMethodFramework **Return value** | Type | Description | | ----------------------------------------------------------- | ---------------------- | | Promise> | Promise used to return the list of installed input methods.| **Example** ```ts import { BusinessError } from '@kit.BasicServicesKit'; inputMethodSetting.listInputMethod().then((data: Array) => { console.log('Succeeded in listing inputMethod.'); }).catch((err: BusinessError) => { console.error(`Failed to listInputMethod: ${JSON.stringify(err)}`); }) ``` ### displayOptionalInputMethod(deprecated) displayOptionalInputMethod(callback: AsyncCallback<void>): void Displays a dialog box for selecting an input method. 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 [showOptionalInputMethods()](#showoptionalinputmethods9) instead. **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.| **Example** ```ts import { BusinessError } from '@kit.BasicServicesKit'; inputMethodSetting.displayOptionalInputMethod((err: BusinessError) => { if (err) { console.error(`Failed to displayOptionalInputMethod: ${JSON.stringify(err)}`); return; } console.log('Succeeded in displaying optionalInputMethod.'); }); ``` ### displayOptionalInputMethod(deprecated) displayOptionalInputMethod(): Promise<void> Displays a dialog box for selecting an input method. 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 [showOptionalInputMethods()](#showoptionalinputmethods9-1) instead. **System capability**: SystemCapability.MiscServices.InputMethodFramework **Return value** | Type| Description| | -------- | -------- | | Promise<void> | Promise that returns no value.| **Example** ```ts import { BusinessError } from '@kit.BasicServicesKit'; inputMethodSetting.displayOptionalInputMethod().then(() => { console.log('Succeeded in displaying optionalInputMethod.'); }).catch((err: BusinessError) => { console.error(`Failed to displayOptionalInputMethod: ${JSON.stringify(err)}`); }) ```