# @ohos.inputMethod (Input Method Framework) The **inputMethod** module provides an input method framework, which can be used to hide the keyboard, obtain the list of installed input methods, display the dialog box for input method selection, and more. > **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 ```js import inputMethod from '@ohos.inputMethod'; ``` ## Constants8+ Provides the constants. **System capability**: SystemCapability.MiscServices.InputMethodFramework | Name| Type| Value| Description| | -------- | -------- | -------- | -------- | | MAX_TYPE_NUM | number | 128 | Maximum number of supported input methods.| ## InputMethodProperty8+ Describes the input method application attributes. **System capability**: SystemCapability.MiscServices.InputMethodFramework | Name| Type| Readable| Writable| Description| | -------- | -------- | -------- | -------- | -------- | | name9+ | string | Yes| No| Internal name of the input method. Mandatory.| | id9+ | string | Yes| No| Unique ID of the input method. Mandatory.| | label9+ | string | Yes| No| External display name of the input method. Optional.| | icon9+ | string | Yes| No| Icon of the input method. Optional.| | iconId9+ | number | Yes| No| Icon ID of the input method. Optional.| | extra9+ | object | Yes| Yes| Extra information about the input method. Mandatory.| | packageName(deprecated) | string | Yes| No| Name of the input method package. Mandatory.
**NOTE**
This API is supported since API version 8 and deprecated since API version 9. You are advised to use **name**.| | methodId(deprecated) | string | Yes| No| Unique ID of the input method. Mandatory.
**NOTE**
This API is supported since API version 8 and deprecated since API version 9. You are advised to use **id**.| ## inputMethod.getController9+ getController(): InputMethodController Obtains an **[InputMethodController](#inputmethodcontroller)** instance. **System capability**: SystemCapability.MiscServices.InputMethodFramework **Return value** | Type | Description | | ----------------------------------------------- | ------------------------ | | [InputMethodController](#inputmethodcontroller) | Current **InputMethodController** instance.| **Error codes** For details about the error codes, see [Input Method Framework Error Codes](../errorcodes/errorcode-inputmethod-framework.md). | Error Code ID| Error Message | | -------- | ------------------------------ | | 12800006 | Input method controller error. | **Example** ```js let inputMethodController = inputMethod.getController(); ``` ## inputMethod.getSetting9+ getSetting(): InputMethodSetting Obtains an **[InputMethodSetting](#inputmethodsetting8)** instance. **System capability**: SystemCapability.MiscServices.InputMethodFramework **Return value** | Type | Description | | ----------------------------------------- | ---------------------------- | | [InputMethodSetting](#inputmethodsetting8) | Current **InputMethodSetting** instance.| **Error codes** For details about the error codes, see [Input Method Framework Error Codes](../errorcodes/errorcode-inputmethod-framework.md). | Error Code ID| Error Message | | -------- | -------------------------------------- | | 12800007 | Input method settings extension error. | **Example** ```js 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. **Required permissions**: ohos.permission.CONNECT_IME_ABILITY (available only to system applications) **System capability**: SystemCapability.MiscServices.InputMethodFramework **Parameters** | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | | target | [InputMethodProperty](#inputmethodproperty8) | Yes| Input method to switch to.| | callback | AsyncCallback<boolean> | Yes| Callback used to return the result. If the operation is successful, **err** is **undefined** and **data** is **true**. Otherwise, **err** is an error object.| **Error codes** For details about the error codes, see [Input Method Framework Error Codes](../errorcodes/errorcode-inputmethod-framework.md). | Error Code ID| Error Message | | -------- | -------------------------------------- | | 12800005 | Configuration persisting error. | | 12800008 | Input method manager service error. | **Example** ```js let im = inputMethod.getCurrentInputMethod(); let prop = { packageName: im.packageName, methodId: im.methodId, name: im.packageName, id: im.methodId, extra: {} } try{ inputMethod.switchInputMethod(prop, (err, result) => { if (err !== undefined) { console.error('Failed to switchInputMethod: ' + JSON.stringify(err)); return; } if (result) { console.info('Succeeded in switching inputmethod.'); } else { console.error('Failed to switchInputMethod.'); } }); } catch(err) { console.error('Failed to switchInputMethod: ' + JSON.stringify(err)); } ``` ## inputMethod.switchInputMethod9+ switchInputMethod(target: InputMethodProperty): Promise<boolean> Switches to another input method. This API uses a promise to return the result. **Required permissions**: ohos.permission.CONNECT_IME_ABILITY (available only to system applications) **System capability**: SystemCapability.MiscServices.InputMethodFramework **Parameters** | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | |target | [InputMethodProperty](#inputmethodproperty8)| Yes| Input method to switch to.| **Return value** | Type | Description | | ----------------------------------------- | ---------------------------- | | Promise\ | Promise used to return the result. The value **true** means that the switching is successful, and **false** means the opposite.| **Error codes** For details about the error codes, see [Input Method Framework Error Codes](../errorcodes/errorcode-inputmethod-framework.md). | Error Code ID| Error Message | | -------- | -------------------------------------- | | 12800005 | Configuration persisting error. | | 12800008 | Input method manager service error. | **Example** ```js let im = inputMethod.getCurrentInputMethod(); let prop = { packageName: im.packageName, methodId: im.methodId, name: im.packageName, id: im.methodId, extra: {} } try { inputMethod.switchInputMethod(prop).then((result) => { if (result) { console.info('Succeeded in switching inputmethod.'); } else { console.error('Failed to switchInputMethod.'); } }).catch((err) => { console.error('Failed to switchInputMethod: ' + JSON.stringify(err)); }) } catch(err) { console.error('Failed to switchInputMethod: ' + JSON.stringify(err)); } ``` ## inputMethod.getCurrentInputMethod9+ getCurrentInputMethod(): InputMethodProperty Obtains the current input method. This API synchronously returns the **InputmethodProperty** instance of the current input method. **System capability**: SystemCapability.MiscServices.InputMethodFramework **Return value** | Type | Description | | -------------------------------------------- | ------------------------ | | [InputMethodProperty](#inputmethodproperty8) | **InputmethodProperty** instance of the current input method.| **Example** ```js let currentIme = inputMethod.getCurrentInputMethod(); ``` ## inputMethod.switchCurrentInputMethodSubtype9+ switchCurrentInputMethodSubtype(target: InputMethodSubtype, callback: AsyncCallback\): void Switches to another subtype of the current input method. This API uses an asynchronous callback to return the result. **Required permissions**: ohos.permission.CONNECT_IME_ABILITY (available only to system applications) **System capability**: SystemCapability.MiscServices.InputMethodFramework **Parameters** | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | | target | [InputMethodSubtype](./js-apis-inputmethod-subtype.md#inputmethodsubtype)| Yes| Input method subtype to switch to.| | callback | AsyncCallback<boolean> | Yes| Callback used to return the result. If the operation is successful, **err** is **undefined** and **data** is **true**. Otherwise, **err** is an error object.| **Error codes** For details about the error codes, see [Input Method Framework Error Codes](../errorcodes/errorcode-inputmethod-framework.md). | Error Code ID| Error Message | | -------- | -------------------------------------- | | 12800005 | Configuration persisting error. | | 12800008 | Input method manager service error. | **Example** ```js try { inputMethod.switchCurrentInputMethodSubtype({ id: "com.example.kikakeyboard", label: "ServiceExtAbility", name: "", mode: "upper", locale: "", language: "", icon: "", iconId: 0, extra: {} }, (err, result) => { if (err !== undefined) { console.error('Failed to switchCurrentInputMethodSubtype: ' + JSON.stringify(err)); return; } if (result) { console.info('Succeeded in switching currentInputMethodSubtype.'); } else { console.error('Failed to switchCurrentInputMethodSubtype'); } }); } catch(err) { console.error('Failed to switchCurrentInputMethodSubtype: ' + JSON.stringify(err)); } ``` ## inputMethod.switchCurrentInputMethodSubtype9+ switchCurrentInputMethodSubtype(target: InputMethodSubtype): Promise<boolean> Switches to another subtype of the current input method. This API uses a promise to return the result. **Required permissions**: ohos.permission.CONNECT_IME_ABILITY (available only to system applications) **System capability**: SystemCapability.MiscServices.InputMethodFramework **Parameters** | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | |target | [InputMethodSubtype](./js-apis-inputmethod-subtype.md#inputmethodsubtype)| Yes| Input method subtype to switch to.| **Return value** | Type | Description | | ----------------------------------------- | ---------------------------- | | Promise\ | Promise used to return the result. The value **true** means that the switching is successful, and **false** means the opposite.| **Error codes** For details about the error codes, see [Input Method Framework Error Codes](../errorcodes/errorcode-inputmethod-framework.md). | Error Code ID| Error Message | | -------- | -------------------------------------- | | 12800005 | Configuration persisting error. | | 12800008 | Input method manager service error. | **Example** ```js try { inputMethod.switchCurrentInputMethodSubtype({ id: "com.example.kikakeyboard", label: "ServiceExtAbility", name: "", mode: "upper", locale: "", language: "", icon: "", iconId: 0, extra: {} }).then((result) => { if (result) { console.info('Succeeded in switching currentInputMethodSubtype.'); } else { console.error('Failed to switchCurrentInputMethodSubtype.'); } }).catch((err) => { console.error('Failed to switchCurrentInputMethodSubtype: ' + JSON.stringify(err)); }) } catch(err) { console.error('Failed to switchCurrentInputMethodSubtype: ' + JSON.stringify(err)); } ``` ## 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** ```js 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. **Required permissions**: ohos.permission.CONNECT_IME_ABILITY (available only to system applications) **System capability**: SystemCapability.MiscServices.InputMethodFramework **Parameters** | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | |inputMethodProperty | [InputMethodProperty](#inputmethodproperty8)| Yes| Input method to switch to.| |inputMethodSubtype | [InputMethodSubtype](./js-apis-inputmethod-subtype.md#inputmethodsubtype)| Yes| Input method subtype to switch to.| | callback | AsyncCallback<boolean> | Yes| Callback used to return the result. If the operation is successful, **err** is **undefined** and **data** is **true**. Otherwise, **err** is an error object.| **Error codes** For details about the error codes, see [Input Method Framework Error Codes](../errorcodes/errorcode-inputmethod-framework.md). | Error Code ID| Error Message | | -------- | -------------------------------------- | | 12800005 | Configuration persisting error. | | 12800008 | Input method manager service error. | **Example** ```js let im = inputMethod.getCurrentInputMethod(); let inputMethodProperty = { packageName: im.packageName, methodId: im.methodId, name: im.packageName, id: im.methodId, extra: {} } try { inputMethod.switchCurrentInputMethodAndSubtype(inputMethodProperty, { id: "com.example.kikakeyboard", label: "ServiceExtAbility", name: "", mode: "upper", locale: "", language: "", icon: "", iconId: 0, extra: {} }, (err,result) => { if (err !== undefined) { console.error('Failed to switchCurrentInputMethodAndSubtype: ' + JSON.stringify(err)); return; } if (result) { console.info('Succeeded in switching currentInputMethodAndSubtype.'); } else { console.error('Failed to switchCurrentInputMethodAndSubtype.'); } }); } catch (err) { console.error('Failed to switchCurrentInputMethodAndSubtype: ' + JSON.stringify(err)); } ``` ## inputMethod.switchCurrentInputMethodAndSubtype9+ switchCurrentInputMethodAndSubtype(inputMethodProperty: InputMethodProperty, inputMethodSubtype: InputMethodSubtype): Promise<boolean> Switches to a specified subtype of a specified input method. This API uses a promise to return the result. **Required permissions**: ohos.permission.CONNECT_IME_ABILITY (available only to system applications) **System capability**: SystemCapability.MiscServices.InputMethodFramework **Parameters** | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | |inputMethodProperty | [InputMethodProperty](#inputmethodproperty8)| Yes| Input method to switch to.| |inputMethodSubtype | [InputMethodSubtype](./js-apis-inputmethod-subtype.md#inputmethodsubtype)| Yes| Input method subtype to switch to.| **Return value** | Type | Description | | ----------------------------------------- | ---------------------------- | | Promise\ | Promise used to return the result. The value **true** means that the switching is successful, and **false** means the opposite.| **Error codes** For details about the error codes, see [Input Method Framework Error Codes](../errorcodes/errorcode-inputmethod-framework.md). | Error Code ID| Error Message | | -------- | -------------------------------------- | | 12800005 | Configuration persisting error. | | 12800008 | Input method manager service error. | **Example** ```js let im = inputMethod.getCurrentInputMethod(); let inputMethodProperty = { packageName: im.packageName, methodId: im.methodId, name: im.packageName, id: im.methodId, extra: {} } try { inputMethod.switchCurrentInputMethodAndSubtype(inputMethodProperty, { id: im.packageName, label: im.methodId, name: "", mode: "upper", locale: "", language: "", icon: "", iconId: 0, extra: {} }).then((result) => { if (result) { console.info('Succeeded in switching currentInputMethodAndSubtype.'); } else { console.error('Failed to switchCurrentInputMethodAndSubtype.'); } }).catch((err) => { console.error('Failed to switchCurrentInputMethodAndSubtype: ' + JSON.stringify(err)); }) } catch(err) { console.error('Failed to switchCurrentInputMethodAndSubtype: ' + JSON.stringify(err)); } ``` ## inputMethod.getInputMethodController(deprecated) getInputMethodController(): InputMethodController Obtains an **[InputMethodController](#inputmethodcontroller)** instance. > **NOTE** > > This API is supported since API version 6 and deprecated since API version 9. You are advised to use [getController()](#inputmethodgetcontroller9). **System capability**: SystemCapability.MiscServices.InputMethodFramework **Return value** | Type | Description | | ----------------------------------------------- | ------------------------ | | [InputMethodController](#inputmethodcontroller) | Current **InputMethodController** instance.| **Example** ```js let inputMethodController = inputMethod.getInputMethodController(); ``` ## inputMethod.getInputMethodSetting(deprecated) getInputMethodSetting(): InputMethodSetting Obtains an **[InputMethodSetting](#inputmethodsetting8)** instance. > **NOTE** > > This API is supported since API version 6 and deprecated since API version 9. You are advised to use [getSetting()](#inputmethodgetsetting9). **System capability**: SystemCapability.MiscServices.InputMethodFramework **Return value** | Type | Description | | ----------------------------------------- | ---------------------------- | | [InputMethodSetting](#inputmethodsetting8) | Current **InputMethodSetting** instance.| **Example** ```js let inputMethodSetting = inputMethod.getInputMethodSetting(); ``` ## InputMethodController In the following API examples, you must first use [getController](#inputmethodgetcontroller9) to obtain an **InputMethodController** instance, and then call the APIs using the obtained instance. ### stopInputSession9+ stopInputSession(callback: AsyncCallback<boolean>): void Ends this input session. The invoking of this API takes effect only after the input session is enabled by clicking the text box. This API uses an asynchronous callback to return the result. **System capability**: SystemCapability.MiscServices.InputMethodFramework **Parameters** | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | | callback | AsyncCallback<boolean> | Yes| Callback used to return the result. If the operation is successful, **err** is **undefined** and **data** is **true**. Otherwise, **err** is an error object.| **Error codes** For details about the error codes, see [Input Method Framework Error Codes](../errorcodes/errorcode-inputmethod-framework.md). | Error Code ID| Error Message | | -------- | -------------------------------------- | | 12800003 | Input method client error. | | 12800008 | Input method manager service error. | **Example** ```js try { inputMethodController.stopInputSession((error, result) => { if (error !== undefined) { console.error('Failed to stopInputSession: ' + JSON.stringify(error)); return; } if (result) { console.info('Succeeded in stopping inputSession.'); } else { console.error('Failed to stopInputSession.'); } }); } catch(error) { console.error('Failed to stopInputSession: ' + JSON.stringify(error)); } ``` ### stopInputSession9+ stopInputSession(): Promise<boolean> Ends this input session. The invoking of this API takes effect only after the input session is enabled by clicking the text box. This API uses a promise to return the result. **System capability**: SystemCapability.MiscServices.InputMethodFramework **Return value** | Type| Description| | -------- | -------- | | Promise<boolean> | Promise used to return the result. The value **true** means that the ending is successful, and **false** means the opposite.| **Error codes** For details about the error codes, see [Input Method Framework Error Codes](../errorcodes/errorcode-inputmethod-framework.md). | Error Code ID| Error Message | | -------- | -------------------------------------- | | 12800003 | Input method client error. | | 12800008 | Input method manager service error. | **Example** ```js try { inputMethodController.stopInputSession().then((result) => { if (result) { console.info('Succeeded in stopping inputSession.'); } else { console.error('Failed to stopInputSession.'); } }).catch((err) => { console.error('Failed to stopInputSession: ' + JSON.stringify(err)); }) } catch(err) { console.error('Failed to stopInputSession: ' + JSON.stringify(err)); } ``` ### showSoftKeyboard9+ showSoftKeyboard(callback: AsyncCallback<void>): void Shows this soft keyboard. This API must be used with the input text box and works only when the input text box is activated. This API uses an asynchronous callback to return the result. **Required permissions**: ohos.permission.CONNECT_IME_ABILITY (available only to system applications) **System capability**: SystemCapability.MiscServices.InputMethodFramework **Parameters** | Name | Type | Mandatory| Description | | -------- | ------------------------- | ---- | ---------- | | callback | AsyncCallback<void> | Yes | Callback used to return the result. If the operation is successful, **err** is **undefined**. Otherwise, **err** is an error object.| **Error codes** For details about the error codes, see [Input Method Framework Error Codes](../errorcodes/errorcode-inputmethod-framework.md). | Error Code ID| Error Message | | -------- | -------------------------------------- | | 12800003 | Input method client error. | | 12800008 | Input method manager service error. | **Example** ```js inputMethodController.showSoftKeyboard((err) => { if (err === undefined) { console.info('Succeeded in showing softKeyboard.'); } else { console.error('Failed to showSoftKeyboard: ' + JSON.stringify(err)); } }) ``` ### showSoftKeyboard9+ showSoftKeyboard(): Promise<void> Shows this soft keyboard. This API must be used with the input text box and works only when the input text box is activated. This API uses a promise to return the result. **Required permissions**: ohos.permission.CONNECT_IME_ABILITY (available only to system applications) **System capability**: SystemCapability.MiscServices.InputMethodFramework **Return value** | Type | Description | | ------------------- | ------------------------- | | Promise<void> | Promise that returns no value.| **Error codes** For details about the error codes, see [Input Method Framework Error Codes](../errorcodes/errorcode-inputmethod-framework.md). | Error Code ID| Error Message | | -------- | -------------------------------------- | | 12800003 | Input method client error. | | 12800008 | Input method manager service error. | **Example** ```js inputMethodController.showSoftKeyboard().then(() => { console.log('Succeeded in showing softKeyboard.'); }).catch((err) => { console.error('Failed to showSoftKeyboard: ' + JSON.stringify(err)); }); ``` ### hideSoftKeyboard9+ hideSoftKeyboard(callback: AsyncCallback<void>): void Hides this soft keyboard. This API must be used with the input text box and works only when the input text box is activated. This API uses an asynchronous callback to return the result. **Required permissions**: ohos.permission.CONNECT_IME_ABILITY (available only to system applications) **System capability**: SystemCapability.MiscServices.InputMethodFramework **Parameters** | Name | Type | Mandatory| Description | | -------- | ------------------------- | ---- | ---------- | | callback | AsyncCallback<void> | Yes | Callback used to return the result. If the operation is successful, **err** is **undefined**. Otherwise, **err** is an error object.| **Error codes** For details about the error codes, see [Input Method Framework Error Codes](../errorcodes/errorcode-inputmethod-framework.md). | Error Code ID| Error Message | | -------- | -------------------------------------- | | 12800003 | Input method client error. | | 12800008 | Input method manager service error. | **Example** ```js inputMethodController.hideSoftKeyboard((err) => { if (err === undefined) { console.info('Succeeded in hiding softKeyboard.'); } else { console.error('Failed to hideSoftKeyboard: ' + JSON.stringify(err)); } }) ``` ### hideSoftKeyboard9+ hideSoftKeyboard(): Promise<void> Hides this soft keyboard. This API must be used with the input text box and works only when the input text box is activated. This API uses a promise to return the result. **Required permissions**: ohos.permission.CONNECT_IME_ABILITY (available only to system applications) **System capability**: SystemCapability.MiscServices.InputMethodFramework **Return value** | Type | Description | | ------------------- | ------------------------- | | Promise<void> | Promise that returns no value.| **Error codes** For details about the error codes, see [Input Method Framework Error Codes](../errorcodes/errorcode-inputmethod-framework.md). | Error Code ID| Error Message | | -------- | -------------------------------------- | | 12800003 | Input method client error. | | 12800008 | Input method manager service error. | **Example** ```js inputMethodController.hideSoftKeyboard().then(() => { console.log('Succeeded in hiding softKeyboard.'); }).catch((err) => { console.error('Failed to hideSoftKeyboard: ' + JSON.stringify(err)); }); ``` ### stopInput(deprecated) stopInput(callback: AsyncCallback<boolean>): void Ends this input session. The invoking of this API takes effect only after the input session is enabled by clicking the text box. This API uses an asynchronous callback to return the result. > **NOTE** > > This API is supported since API version 6 and deprecated since API version 9. You are advised to use [stopInputSession()](#stopinputsession9). **System capability**: SystemCapability.MiscServices.InputMethodFramework **Parameters** | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | | callback | AsyncCallback<boolean> | Yes| Callback used to return the result. If the operation is successful, **err** is **undefined** and **data** is **true**. Otherwise, **err** is an error object.| **Example** ```js inputMethodController.stopInput((error, result) => { if (error !== undefined) { console.error('Failed to stopInput: ' + JSON.stringify(error)); return; } if (result) { console.info('Succeeded in stopping input.'); } else { console.error('Failed to stopInput.'); } }); ``` ### stopInput(deprecated) stopInput(): Promise<boolean> Ends this input session. The invoking of this API takes effect only after the input session is enabled by clicking the text box. This API uses a promise to return the result. > **NOTE** > > This API is supported since API version 6 and deprecated since API version 9. You are advised to use [stopInputSession()](#stopinputsession9). **System capability**: SystemCapability.MiscServices.InputMethodFramework **Return value** | Type| Description| | -------- | -------- | | Promise<boolean> | Promise used to return the result. The value **true** means that the hiding is successful, and **false** means the opposite.| **Example** ```js inputMethodController.stopInput().then((result) => { if (result) { console.info('Succeeded in stopping input.'); } else { console.error('Failed to stopInput.'); } }).catch((err) => { console.error('Failed to stopInput: ' + err); }) ``` ### on('selectByRange')10+ on(type: 'selectByRange', callback: Callback<Range>): void Enables listening for the selection-by-range event. This API uses an asynchronous callback to return the result. **System capability**: SystemCapability.MiscServices.InputMethodFramework **Parameters** | Name | Type | Mandatory| Description | | -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | | type | string | Yes | Listening type.
The value **selectByRange** indicates the selection-by-range event.| | callback | Callback<[Range](./js-apis-inputmethod-InputMethodCommon.md#range)> | Yes | Callback used to return the range of the text to be selected.
Your application needs to select the text in the returned range in the text box.| **Example** ```js inputMethodController.on('selectByRange', (range) => { console.info('Succeeded in subscribing selectByRange: start: ' + range.start + " , end: " + range.end); }); ``` ### off('selectByRange')10+ off(type: 'selectByRange'): void Disables listening for the selection-by-range event. **System capability**: SystemCapability.MiscServices.InputMethodFramework **Parameters** | Name| Type | Mandatory| Description | | ------ | ------ | ---- | ------------------------------------------------------------ | | type | string | Yes | Listening type.
The value **selectByRange** indicates the selection-by-range event.| **Example** ```js inputMethodController.off('selectByRange'); ``` ### on('selectByMovement')10+ on(type: 'selectByMovement', callback: Callback<Movement>): void Enables listening for the selection-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 **selectByMovement** indicates the selection-by-cursor-movement event.| | callback | Callback<[Movement](./js-apis-inputmethod-InputMethodCommon.md#movement)> | Yes | Callback used to return the range of the text to be selected.
Your application needs to select the text in the returned range in the text box.| **Example** ```js inputMethodController.on('selectByMovement', (movement) => { console.info('Succeeded in subscribing selectByMovement: direction: ' + movement.direction); }); ``` ### off('selectByMovement')10+ off(type: 'selectByMovement'): void Disables listening for the selection-by-cursor-movement event. **System capability**: SystemCapability.MiscServices.InputMethodFramework **Parameters** | Name| Type | Mandatory| Description | | ------ | ------ | ---- | ------------------------------------------------------------ | | type | string | Yes | Listening type.
The value **selectByMovement** indicates the selection-by-cursor-movement event.| **Example** ```js inputMethodController.off('selectByMovement'); ``` ## 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 **'imeChange'** indicates the input method and subtype change event.| | 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** ```js inputMethodSetting.on('imeChange', (inputMethodProperty, inputMethodSubtype) => { console.info('Succeeded in subscribing imeChange: inputMethodProperty: ' + JSON.stringify(inputMethodProperty) + " , inputMethodSubtype: " + JSON.stringify(inputMethodSubtype)); }); ``` ### 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 **'imeChange'** indicates the input method and subtype change event.| | 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** ```js 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| Yes| Input method to which the subtypes belong.| | 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](../errorcodes/errorcode-inputmethod-framework.md). | Error Code ID| Error Message | | -------- | -------------------------------------- | | 12800001 | Package manager error. | | 12800008 | Input method manager service error. | **Example** ```js let inputMethodProperty = { packageName: 'com.example.kikakeyboard', methodId: 'com.example.kikakeyboard', name: 'com.example.kikakeyboard', id: 'com.example.kikakeyboard', extra:{} } try { inputMethodSetting.listInputMethodSubtype(inputMethodProperty, (err,data) => { if (err !== undefined) { 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| Yes| Input method to which the subtypes belong.| **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](../errorcodes/errorcode-inputmethod-framework.md). | Error Code ID| Error Message | | -------- | -------------------------------------- | | 12800001 | Package manager error. | | 12800008 | Input method manager service error. | **Example** ```js let inputMethodProperty = { packageName: 'com.example.kikakeyboard', methodId: 'com.example.kikakeyboard', name: 'com.example.kikakeyboard', id: 'com.example.kikakeyboard', extra:{} } try { inputMethodSetting.listInputMethodSubtype(inputMethodProperty).then((data) => { console.info('Succeeded in listing inputMethodSubtype.'); }).catch((err) => { 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](../errorcodes/errorcode-inputmethod-framework.md). | Error Code ID| Error Message | | -------- | -------------------------------------- | | 12800001 | Package manager error. | | 12800008 | Input method manager service error. | **Example** ```js try { inputMethodSetting.listCurrentInputMethodSubtype((err, data) => { if (err !== undefined) { console.error('Failed to listCurrentInputMethodSubtype: ' + JSON.stringify(err)); return; } console.log('Succeeded in listing currentInputMethodSubtype.'); }); } 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](../errorcodes/errorcode-inputmethod-framework.md). | Error Code ID| Error Message | | -------- | -------------------------------------- | | 12800001 | Package manager error. | | 12800008 | Input method manager service error. | **Example** ```js try { inputMethodSetting.listCurrentInputMethodSubtype().then((data) => { console.info('Succeeded in listing currentInputMethodSubtype.'); }).catch((err) => { console.error('Failed to listCurrentInputMethodSubtype: ' + JSON.stringify(err)); }) } 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. In the current version, an activated input method is the input method in use, and a deactivated one is any of the installed input methods except the one in use. This API uses an asynchronous callback to return the result. **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](../errorcodes/errorcode-inputmethod-framework.md). | Error Code ID| Error Message | | -------- | -------------------------------------- | | 12800001 | Package manager error. | | 12800008 | Input method manager service error. | **Example** ```js try { inputMethodSetting.getInputMethods(true, (err,data) => { if (err !== undefined) { console.error('Failed to getInputMethods: ' + JSON.stringify(err)); return; } console.log('Succeeded in getting inputMethods.'); }); } 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. In the current version, an activated input method is the input method in use, and a deactivated one is any of the installed input methods except the one in use. This API uses a promise to return the result. **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.| **Error codes** For details about the error codes, see [Input Method Framework Error Codes](../errorcodes/errorcode-inputmethod-framework.md). | Error Code ID| Error Message | | -------- | -------------------------------------- | | 12800001 | Package manager error. | | 12800008 | Input method manager service error. | **Return value** | Type | Description | | ------------------------------------------------------------ | ----------------------------- | | Promise> | Promise used to return a list of activated or deactivated input methods.| **Example** ```js try { inputMethodSetting.getInputMethods(true).then((data) => { console.info('Succeeded in getting inputMethods.'); }).catch((err) => { console.error('Failed to getInputMethods: ' + JSON.stringify(err)); }) } catch(err) { console.error('Failed to getInputMethods: ' + 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](../errorcodes/errorcode-inputmethod-framework.md). | Error Code ID| Error Message | | -------- | -------------------------------------- | | 12800008 | Input method manager service error. | **Example** ```js try { inputMethodSetting.showOptionalInputMethods((err, data) => { if (err !== undefined) { console.error('Failed to showOptionalInputMethods: ' + JSON.stringify(err)); return; } console.info('Succeeded in showing optionalInputMethods.'); }); } 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. 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](../errorcodes/errorcode-inputmethod-framework.md). | Error Code ID| Error Message | | -------- | -------------------------------------- | | 12800008 | Input method manager service error. | **Example** ```js inputMethodSetting.showOptionalInputMethods().then((data) => { console.info('Succeeded in showing optionalInputMethods.'); }).catch((err) => { 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). **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** ```js inputMethodSetting.listInputMethod((err,data) => { if (err !== undefined) { 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). **System capability**: SystemCapability.MiscServices.InputMethodFramework **Return value** | Type | Description | | ----------------------------------------------------------- | ---------------------- | | Promise> | Promise used to return the list of installed input methods.| **Example** ```js inputMethodSetting.listInputMethod().then((data) => { console.info('Succeeded in listing inputMethod.'); }).catch((err) => { 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). **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** ```js inputMethodSetting.displayOptionalInputMethod((err) => { if (err !== undefined) { console.error('Failed to displayOptionalInputMethod: ' + JSON.stringify(err)); return; } console.info('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). **System capability**: SystemCapability.MiscServices.InputMethodFramework **Return value** | Type| Description| | -------- | -------- | | Promise<void> | Promise that returns no value.| **Example** ```js inputMethodSetting.displayOptionalInputMethod().then(() => { console.info('Succeeded in displaying optionalInputMethod.'); }).catch((err) => { console.error('Failed to displayOptionalInputMethod: ' + JSON.stringify(err)); }) ```