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.
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**
> **NOTE**
>
>
...
@@ -33,10 +33,11 @@ Describes the input method application attributes.
...
@@ -33,10 +33,11 @@ Describes the input method application attributes.
| name<sup>9+</sup> | string | Yes| No| Internal name of the input method. Mandatory.|
| name<sup>9+</sup> | string | Yes| No| Internal name of the input method. Mandatory.|
| id<sup>9+</sup> | string | Yes| No| Unique ID of the input method. Mandatory.|
| id<sup>9+</sup> | string | Yes| No| Unique ID of the input method. Mandatory.|
| label<sup>9+</sup> | string | Yes| No| External display name of the input method. Optional.|
| label<sup>9+</sup> | string | Yes| No| External name of the input method. Optional.|
| labelId<sup>10+</sup> | string | Yes| No| External ID of the input method. Optional.|
| icon<sup>9+</sup> | string | Yes| No| Icon of the input method. Optional.|
| icon<sup>9+</sup> | string | Yes| No| Icon of the input method. Optional.|
| iconId<sup>9+</sup> | number | Yes| No| Icon ID of the input method. Optional.|
| iconId<sup>9+</sup> | number | Yes| No| Icon ID of the input method. Optional.|
| extra<sup>9+</sup> | object | Yes| Yes| Extra information about the input method. Mandatory.|
| extra<sup>9+</sup> | object | Yes| Yes| Extra information about the input method. Optional.<br>**NOTE**<br>This parameter is optional since API version 10.|
| packageName<sup>(deprecated)</sup> | string | Yes| No| Name of the input method package. Mandatory.<br>**NOTE**<br>This API is supported since API version 8 and deprecated since API version 9. You are advised to use **name**.|
| packageName<sup>(deprecated)</sup> | string | Yes| No| Name of the input method package. Mandatory.<br>**NOTE**<br>This API is supported since API version 8 and deprecated since API version 9. You are advised to use **name**.|
| methodId<sup>(deprecated)</sup> | string | Yes| No| Unique ID of the input method. Mandatory.<br>**NOTE**<br>This API is supported since API version 8 and deprecated since API version 9. You are advised to use **id**.|
| methodId<sup>(deprecated)</sup> | string | Yes| No| Unique ID of the input method. Mandatory.<br>**NOTE**<br>This API is supported since API version 8 and deprecated since API version 9. You are advised to use **id**.|
Switches to another subtype of the current input method. This API uses an asynchronous callback to return the result.
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)
**Required permissions**: ohos.permission.CONNECT_IME_ABILITY (available only to system applications)<br>**NOTE**<br>Since API version 10, this permission is not required if the caller is the current 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.|
| 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**
**Error codes**
...
@@ -256,9 +257,9 @@ For details about the error codes, see [Input Method Framework Error Codes](../e
...
@@ -256,9 +257,9 @@ For details about the error codes, see [Input Method Framework Error Codes](../e
Switches to another subtype of the current input method. This API uses a promise to return the result.
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)
**Required permissions**: ohos.permission.CONNECT_IME_ABILITY (available only to system applications)<br>**NOTE**<br>Since API version 10, this permission is not required if the caller is the current input method.
| [InputMethodSubtype](./js-apis-inputmethod-subtype.md#inputmethodsubtype) | Current input method subtype.|
| [InputMethodSubtype](./js-apis-inputmethod-subtype.md) | Current input method subtype.|
**Example**
**Example**
...
@@ -375,7 +376,7 @@ Switches to a specified subtype of a specified input method. This API uses an as
...
@@ -375,7 +376,7 @@ Switches to a specified subtype of a specified input method. This API uses an as
| Name| Type| Mandatory| Description|
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| -------- | -------- | -------- | -------- |
|inputMethodProperty | [InputMethodProperty](#inputmethodproperty8)| Yes| Input method to switch to.|
|inputMethodProperty | [InputMethodProperty](#inputmethodproperty8)| Yes| Input method to switch to.|
|inputMethodSubtype | [InputMethodSubtype](./js-apis-inputmethod-subtype.md#inputmethodsubtype)| Yes| Input method subtype to switch to.|
|inputMethodSubtype | [InputMethodSubtype](./js-apis-inputmethod-subtype.md)| Yes| Input method subtype to switch to.|
| callback | AsyncCallback<boolean> | Yes| Callback used to return the result. If the operation is successful, **err** is **undefined** and **data** is **true**. Otherwise, **err** is an error object.|
| 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**
**Error codes**
...
@@ -391,25 +392,9 @@ For details about the error codes, see [Input Method Framework Error Codes](../e
...
@@ -391,25 +392,9 @@ For details about the error codes, see [Input Method Framework Error Codes](../e
| type | string | Yes | Listening type.<br>The value **selectByMovement** indicates the selection-by-cursor-movement event.|
| type | string | Yes | Listening type.<br>The value **selectByMovement** indicates the select-by-cursor-movement event.|
| callback | Callback<[Movement](./js-apis-inputmethod-InputMethodCommon.md#movement)> | Yes | Callback used to return the range of the text to be selected.<br>Your application needs to select the text in the returned range in the text box.|
| callback | Callback<[Movement](./js-apis-inputmethod-InputMethodCommon.md#movement)> | Yes | Callback used to return the range of the text to be selected.<br>Your application needs to select the text in the returned range in the text box.|
| inputMethodProperty | InputMethodProperty| Yes| Input method to which the subtypes belong.|
| 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.|
| callback | AsyncCallback<Array<[InputMethodSubtype](./js-apis-inputmethod-subtype.md)>> | Yes| Callback used to return all subtypes of the specified input method.|
**Error codes**
**Error codes**
...
@@ -1038,7 +1007,7 @@ Obtains all subtypes of a specified input method. This API uses a promise to ret
...
@@ -1038,7 +1007,7 @@ Obtains all subtypes of a specified input method. This API uses a promise to ret
| Promise<Array<[InputMethodSubtype](./js-apis-inputmethod-subtype.md#inputmethodsubtype)>> | Promise used to return all subtypes of the specified input method.|
| Promise<Array<[InputMethodSubtype](./js-apis-inputmethod-subtype.md)>> | Promise used to return all subtypes of the specified input method.|
**Error codes**
**Error codes**
...
@@ -1082,7 +1051,7 @@ Obtains all subtypes of this input method. This API uses an asynchronous callbac
...
@@ -1082,7 +1051,7 @@ Obtains all subtypes of this input method. This API uses an asynchronous callbac
| callback | AsyncCallback<Array<[InputMethodSubtype](./js-apis-inputmethod-subtype.md#inputmethodsubtype)>> | Yes | Callback used to return all subtypes of the current input method.|
| callback | AsyncCallback<Array<[InputMethodSubtype](./js-apis-inputmethod-subtype.md)>> | Yes | Callback used to return all subtypes of the current input method.|
**Error codes**
**Error codes**
...
@@ -1121,7 +1090,7 @@ Obtains all subtypes of this input method. This API uses a promise to return the
...
@@ -1121,7 +1090,7 @@ Obtains all subtypes of this input method. This API uses a promise to return the
| Promise<Array<[InputMethodSubtype](./js-apis-inputmethod-subtype.md#inputmethodsubtype)>> | Promise used to return all subtypes of the current input method.|
| Promise<Array<[InputMethodSubtype](./js-apis-inputmethod-subtype.md)>> | Promise used to return all subtypes of the current input method.|
The **inputMethodEngine** module streamlines the interactions between input methods and applications. By calling APIs of this module, applications can be bound to input method services to accept text input, request the keyboard to display or hide, listen for the input method status, and much more.
The **inputMethodEngine** module is oriented to input method applications (including system and third-party input method applications). With the APIs of this module, input method applications are able to create soft keyboard windows, insert or delete characters, select text, and listen for physical keyboard events.
> **NOTE**
> **NOTE**
>
>
...
@@ -56,15 +56,15 @@ Provides the constant values of function keys, edit boxes, and the cursor.
...
@@ -56,15 +56,15 @@ Provides the constant values of function keys, edit boxes, and the cursor.
getInputMethodAbility(): InputMethodAbility
getInputMethodAbility(): InputMethodAbility
Obtains an **InputMethodEngine** instance.
Obtains an [InputMethodAbility](#inputmethodability) instance for the input method. The input method can use the obtained instance to subscribe to a soft keyboard display/hide request event, create/destroy an input method panel, and the like.
@@ -76,15 +76,15 @@ let InputMethodAbility = inputMethodEngine.getInputMethodAbility();
...
@@ -76,15 +76,15 @@ let InputMethodAbility = inputMethodEngine.getInputMethodAbility();
getKeyboardDelegate(): KeyboardDelegate
getKeyboardDelegate(): KeyboardDelegate
Obtains a **KeyboardDelegate** instance.
Obtains a [KeyboardDelegate](#keyboarddelegate) instance for the input method. The input method can use the obtained instance to subscribe to a physical keyboard event, text selection change event, and more.
@@ -96,7 +96,7 @@ let KeyboardDelegate = inputMethodEngine.getKeyboardDelegate();
...
@@ -96,7 +96,7 @@ let KeyboardDelegate = inputMethodEngine.getKeyboardDelegate();
getInputMethodEngine(): InputMethodEngine
getInputMethodEngine(): InputMethodEngine
Obtains an **InputMethodEngine** instance.
Obtains an [InputMethodEngine](#inputmethodengine-1) instance for the input method. The input method can use the obtained instance to subscribe to a soft keyboard display/hide request event.
> **NOTE**
> **NOTE**
>
>
...
@@ -106,9 +106,9 @@ Obtains an **InputMethodEngine** instance.
...
@@ -106,9 +106,9 @@ Obtains an **InputMethodEngine** instance.
@@ -120,7 +120,7 @@ let InputMethodEngine = inputMethodEngine.getInputMethodEngine();
...
@@ -120,7 +120,7 @@ let InputMethodEngine = inputMethodEngine.getInputMethodEngine();
createKeyboardDelegate(): KeyboardDelegate
createKeyboardDelegate(): KeyboardDelegate
Obtains a **KeyboardDelegate** instance.
Obtains a [KeyboardDelegate](#keyboarddelegate) instance for the input method. The input method can use the obtained instance to subscribe to a physical keyboard event, text selection change event, and more.
> **NOTE**
> **NOTE**
>
>
...
@@ -130,9 +130,9 @@ Obtains a **KeyboardDelegate** instance.
...
@@ -130,9 +130,9 @@ Obtains a **KeyboardDelegate** instance.
| type | string | Yes | Listening type.<br>The value **'inputStart'** indicates the input method binding event.|
| type | string | Yes | Listening type.<br>The value **'inputStart'** indicates the input method binding event.|
| callback | (kbController: [KeyboardController](#keyboardcontroller), textInputClient: [TextInputClient](#textinputclient)) => void | Yes| Callback used to return the **KeyboardController** and **TextInputClient** instances.|
| callback | (kbController: [KeyboardController](#keyboardcontroller), textInputClient: [TextInputClient](#textinputclientdeprecated)) => void | Yes| Callback used to return the **KeyboardController** and **TextInputClient** instances.|
**Example**
**Example**
...
@@ -181,7 +181,7 @@ Cancels listening for the input method binding event.
...
@@ -181,7 +181,7 @@ Cancels listening for the input method binding event.
| type | string | Yes | Listening type.<br>The value **'inputStart'** indicates the input method binding event.|
| type | string | Yes | Listening type.<br>The value **'inputStart'** indicates the input method binding event.|
| callback | (kbController: [KeyboardController](#keyboardcontroller), textInputClient: [TextInputClient](#textinputclient)) => void | No| Callback used to return the **KeyboardController** and **TextInputClient** instances.|
| callback | (kbController: [KeyboardController](#keyboardcontroller), textInputClient: [TextInputClient](#textinputclientdeprecated)) => void | No| Callback used to return the **KeyboardController** and **TextInputClient** instances.|
Creates an input method panel. This API can be called only by input method applications and system applications with the system_core permission. Only one SOFT_KEYBOARD panel and one STATUS_BAR panel can be created for a single input method application. This API uses an asynchronous callback to return the result.
| ctx | [BaseContext](./js-apis-inner-application-baseContext.md) | Yes | Context of the current input method.|
| info | [PanelInfo](#panelinfo10) | Yes | Information about the input method panel.|
| callback | AsyncCallback\<[Panel](#panel10)> | Yes | Callback used to return the result. If the operation is successful, the created input method panel is returned. |
Creates an input method panel. This API can be called only by input method applications and system applications with the system_core permission. Only one SOFT_KEYBOARD panel and one STATUS_BAR panel can be created for a single input method application. This API uses a promise to return the result.
| ctx | [BaseContext](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/reference/apis/js-apis-inner-application-baseContext.md) | Yes | Context of the current input method.|
| info | [PanelInfo](#panelinfo10) | Yes | Information about the input method panel.|
| callback | AsyncCallback\<void> | Yes | Callback used to return the result. If the operation is successful, **err** is **undefined**. Otherwise, **err** is an error object. |
console.log('Failed to destroy panel, err: '+JSON.stringify(err));
});
}catch(err){
console.log('Failed to destroy panel, err: '+JSON.stringify(err));
}
```
## KeyboardDelegate
## KeyboardDelegate
In the following API examples, you must first use **[getKeyboardDelegate](#inputmethodenginegetkeyboarddelegate9)** to obtain a **KeyboardDelegate** instance, and then call the APIs using the obtained instance.
In the following API examples, you must first use **[getKeyboardDelegate](#inputmethodenginegetkeyboarddelegate9)** to obtain a **KeyboardDelegate** instance, and then call the APIs using the obtained instance.
In the following API examples, you must first use **[createPanel](#createpanel10)** to obtain a **Panel** instance, and then call the APIs using the obtained instance.
| path | string | Yes | Path of the page from which the content will be loaded.|
| 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
try{
panel.setUiContent('pages/page2/page2',(err)=>{
if(err){
console.error('Failed to set the content. err:'+JSON.stringify(err));
return;
}
console.info('Succeeded in setting the content.');
});
}catch(exception){
console.error('Failed to set the content. err:'+JSON.stringify(exception));
}
```
### setUiContent<sup>10+</sup>
setUiContent(path: string): Promise\<void>
Loads content from a page to this panel. This API uses a promise to return the result.
| path | string | Yes | Path of the page from which the content will be loaded.|
| storage | [LocalStorage](../../quick-start/arkts-state-mgmt-application-level.md#localstorage) | Yes | Storage unit that provides storage for mutable and immutable state variables in the application.|
| callback | AsyncCallback\<void> | Yes | Callback used to return the result. If the operation is successful, **err** is **undefined**. Otherwise, **err** is an error object.|
| path | string | Yes | Path of the page from which the content will be loaded.|
| storage | [LocalStorage](../../quick-start/arkts-state-mgmt-application-level.md#localstorage) | Yes | Storage unit that provides storage for mutable and immutable state variables in the application.|
**Return value**
| Type | Description |
| ------- | ------------------------------ |
| Promise\<void> | Promise that returns no value. |
| width | number | Yes | Target width of the panel, in pixels.|
| height | number | Yes | Target height of the panel, in pixels.|
| 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
try{
panel.resize(500,1000,(err)=>{
if(err){
console.error('Failed to change the panel size. Cause:'+JSON.stringify(err));
return;
}
console.info('Succeeded in changing the panel size.');
});
}catch(exception){
console.error('Failed to change the panel size. Cause:'+JSON.stringify(exception));
| x | number | Yes | Distance to move along the x-axis, in px. A positive value indicates moving rightwards.|
| y | number | Yes | Distance to move along the y-axis, in pixels. A positive value indicates moving downwards.|
| 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
try{
panel.moveTo(300,300,(err)=>{
if(err){
console.error('Failed to move the panel. err:'+JSON.stringify(err));
return;
}
console.info('Succeeded in moving the panel.');
});
}catch(exception){
console.error('Failed to move the panel. err:'+JSON.stringify(exception));
}
```
### moveTo<sup>10+</sup>
moveTo(x: number, y: number): Promise\<void>
Moves this panel to the specified position. This API uses a promise to return the result.
This API does not work on panels in the FLG_FIXED state.
| 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
panel.show((err)=>{
if(err){
console.error('Failed to show the panel. Cause: '+JSON.stringify(err));
return;
}
console.info('Succeeded in showing the panel.');
});
```
### show<sup>10+</sup>
show(): Promise\<void>
Displays this panel. This API uses a promise to return the result.
| 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
panel.hide((err)=>{
if(err){
console.error('Failed to hide the panel. Cause: '+JSON.stringify(err));
return;
}
console.info('Succeeded in hiding the panel.');
});
```
### hide<sup>10+</sup>
hide(): Promise\<void>
Hides this panel. This API uses a promise to return the result.
| type | 'show'\|'hide' | Yes| Listening type.<br>- The value **'show'** indicates the panel display event.<br>- The value **'hide'** indicates the panel hiding event.|
| callback | () => void | Yes | Callback used to return the result.|
| type | 'show'/'hide' | Yes| Listening type.<br>- The value **'show'** indicates the panel display event.<br>- The value **'hide'** indicates the panel hiding event.|
| callback | () => void | No | Callback used to return the result.|
**Example**
```js
panel.off('show');
```
### changeFlag<sup>10+</sup>
changeFlag(flag: PanelFlag): void
Changes the panel state type. This API only works for SOFT_KEYBOARD panels.
In the following API examples, you must first use **[on('inputStart')](#oninputstart9)** to obtain a **KeyboardController** instance, and then call the APIs using the obtained instance.
In the following API examples, you must first use **[on('inputStart')](#oninputstart9)** to obtain a **KeyboardController** instance, and then call the APIs using the obtained instance.
...
@@ -1752,6 +2381,39 @@ Describes the attribute of a key.
...
@@ -1752,6 +2381,39 @@ Describes the attribute of a key.
| keyCode | number | Yes | No | Key value.|
| keyCode | number | Yes | No | Key value.|
| keyAction | number | Yes | No | Key status.|
| keyAction | number | Yes | No | Key status.|
## PanelFlag<sup>10+</sup>
Enumerates the state types of the input method panel.
## @ohos.InputMethodSubtype Change of name, label, and id
Changed the **name**, **label**, and **id** attributes since API version 9.
**Change Impact**
Applications must be adapted to the following changes.
| Name| Before Change| After Change|
| -------- | -------- | -------- |
| label | (1) Value: ID of the input method subtype.| (1) Value: Label of the input method subtype.|
| name | (1) Description: Name of the input method subtype. (2) Value: Label of the input method subtype.| (1) Description: Bundle name of the input method; (2) Value: Bundle name of the input method.|
| id | (1) Value: Bundle name of the input method.| (1) Value: ID of the input method subtype.|
**Adaptation Guide**
Update the code to adapt to the preceding changes.
## @ohos.InputMethodSubtype Change of name, label, and id
Changed the **name**, **label**, and **id** attributes since API version 9.
**Change Impact**
Applications must be adapted to the following changes.
| Name| Before Change| After Change|
| -------- | -------- | -------- |
| label | (1) Value: ID of the input method subtype.| (1) Value: Label of the input method subtype.|
| name | (1) Description: Name of the input method subtype. (2) Value: Label of the input method subtype.| (1) Description: Bundle name of the input method; (2) Value: Bundle name of the input method.|
| id | (1) Value: Bundle name of the input method.| (1) Value: ID of the input method subtype.|
**Adaptation Guide**
Update the code to adapt to the preceding changes.