提交 534b4b73 编写于 作者: E ester.zhou

Add and update docs (12035)

Signed-off-by: Nester.zhou <ester.zhou@huawei.com>
上级 89466409
# InputMethodExtensionAbility # InputMethodExtensionAbility
The **InputMethodExtensionAbility** module provides the **InputMethodExtensionAbility** and **InputMethodExtensionContext** APIs that you can implement to develop input methods and manage their lifecycles. The **InputMethodExtensionAbility** module provides APIs for developing input methods and managing their lifecycles.
> **NOTE** > **NOTE**
> >
> The initial APIs of this module are supported since API version 9. Newly added APIs will be marked with a superscript to indicate their earliest API version. > The initial APIs of this module are supported since API version 9. Newly added APIs will be marked with a superscript to indicate their earliest API version.
> The APIs of this module can be used only in the stage model.
## Modules to Import ## Modules to Import
``` ```js
import InputMethodExtensionAbility from '@ohos.inputmethodextensionability'; import InputMethodExtensionAbility from '@ohos.inputmethodextensionability';
``` ```
...@@ -21,10 +20,9 @@ import InputMethodExtensionAbility from '@ohos.inputmethodextensionability'; ...@@ -21,10 +20,9 @@ import InputMethodExtensionAbility from '@ohos.inputmethodextensionability';
| -------- | -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- | -------- |
| context | [InputMethodExtensionContext](js-apis-inputmethod-extension-context.md) | Yes| No| Context of the **InputMethodExtension**, which is inherited from **ExtensionContext**.| | context | [InputMethodExtensionContext](js-apis-inputmethod-extension-context.md) | Yes| No| Context of the **InputMethodExtension**, which is inherited from **ExtensionContext**.|
## InputMethodExtensionAbility.onCreate
## InputMethodExtensionAbility.onCreate() onCreate(want: Want): void
onCreate(want: Want): void;
Called when the **InputMethodExtension** ability is started to implement initialization. Called when the **InputMethodExtension** ability is started to implement initialization.
...@@ -32,24 +30,23 @@ Called when the **InputMethodExtension** ability is started to implement initial ...@@ -32,24 +30,23 @@ Called when the **InputMethodExtension** ability is started to implement initial
**Parameters** **Parameters**
| Name| Type| Mandatory| Description| | Name| Type | Mandatory| Description |
| -------- | -------- | -------- | -------- | | ------ | ----------- | ---- | ------------------------------- |
| want | [Want](js-apis-application-Want.md) | Yes| Information related to the **InputMethodExtension** ability, including the ability name and bundle name. | | want | [Want](js-apis-app-ability-want.md) | Yes | Information related to the **InputMethodExtension** ability, including the ability name and bundle name.|
**Example** **Example**
```js ```js
class InputMethodExt extends InputMethodExtensionAbility { class InputMethodExt extends InputMethodExtensionAbility {
onCreate(want) { onCreate(want) {
console.log('onCreate, want:' + want.abilityName); console.log('onCreate, want:' + want.abilityName);
} }
} }
``` ```
## InputMethodExtensionAbility.onDestroy() ## InputMethodExtensionAbility.onDestroy
onDestroy(): void; onDestroy(): void
Called when this **InputMethodExtension** ability is destroyed to clear resources. Called when this **InputMethodExtension** ability is destroyed to clear resources.
...@@ -57,10 +54,10 @@ Called when this **InputMethodExtension** ability is destroyed to clear resource ...@@ -57,10 +54,10 @@ Called when this **InputMethodExtension** ability is destroyed to clear resource
**Example** **Example**
```js ```js
class InputMethodExt extends InputMethodExtensionAbility { class InputMethodExt extends InputMethodExtensionAbility {
onDestroy() { onDestroy() {
console.log('onDestroy'); console.log('onDestroy');
} }
} }
``` ```
...@@ -6,8 +6,7 @@ You can use the APIs of this module to start, terminate, connect, and disconnect ...@@ -6,8 +6,7 @@ You can use the APIs of this module to start, terminate, connect, and disconnect
> **NOTE** > **NOTE**
> >
> The initial APIs of this module are supported since API version 9. Newly added APIs will be marked with a superscript to indicate their earliest API version. >The initial APIs of this module are supported since API version 9. Newly added APIs will be marked with a superscript to indicate their earliest API version.
> The APIs of this module can be used only in the stage model.
## Modules to Import ## Modules to Import
...@@ -20,112 +19,17 @@ import InputMethodExtensionContext from '@ohos.inputmethodextensioncontext'; ...@@ -20,112 +19,17 @@ import InputMethodExtensionContext from '@ohos.inputmethodextensioncontext';
Before using the **InputMethodExtensionContext** module, you must define a child class that inherits from **InputMethodExtensionAbility**. Before using the **InputMethodExtensionContext** module, you must define a child class that inherits from **InputMethodExtensionAbility**.
```js ```js
import InputMethodExtensionAbility from '@ohos.inputmethodextensionability'; import InputMethodExtensionAbility from '@ohos.inputmethodextensionability';
class MainAbility extends InputMethodExtensionAbility { class MainAbility extends InputMethodExtensionAbility {
onCreate() { onCreate() {
let context = this.context; let context = this.context;
} }
} }
``` ```
## InputMethodExtensionContext.startAbility ## InputMethodExtensionContext.destroy
startAbility(want: Want, callback: AsyncCallback&lt;void&gt;): void;
Starts an ability with the **want** parameter. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.MiscServices.InputMethodFramework
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| want | [Want](js-apis-application-Want.md) | Yes| Information about the target ability, such as the ability name and bundle name.|
| callback | AsyncCallback&lt;void&gt; | Yes| Callback used to return the result.|
**Example**
```js
let want = {
'bundleName': 'com.example.myapp',
'abilityName': 'MyAbility'
};
this.context.startAbility(want, (err) => {
console.log('startAbility result:' + JSON.stringify(err));
});
```
## InputMethodExtensionContext.startAbility
startAbility(want: Want, options?: StartOptions): Promise\<void>; destroy(callback: AsyncCallback\<void>): void
Starts an ability with the mandatory **want** and optional **options** parameters. This API uses a promise to return the result.
**System capability**: SystemCapability.MiscServices.InputMethodFramework
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| want | [Want](js-apis-application-Want.md) | Yes| Information about the target ability, such as the ability name and bundle name.|
| options | [StartOptions](js-apis-application-StartOptions.md) | No| Parameters used for starting the ability.|
**Return value**
| Type| Description|
| -------- | -------- |
| Promise&lt;void&gt; | Promise used to return the result.|
**Example**
```js
let want = {
'bundleName': 'com.example.myapp',
'abilityName': 'MyAbility'
};
this.context.startAbility(want).then((data) => {
console.log('success:' + JSON.stringify(data));
}).catch((error) => {
console.log('failed:' + JSON.stringify(error));
});
```
## InputMethodExtensionContext.startAbility
startAbility(want: Want, options: StartOptions, callback: AsyncCallback&lt;void&gt;): void
Starts an ability with the **want** and **options** parameters. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.MiscServices.InputMethodFramework
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| want | [Want](js-apis-application-Want.md) | Yes| Information about the target ability.|
| options | [StartOptions](js-apis-application-StartOptions.md) | Yes| Parameters used for starting the ability.|
| callback | AsyncCallback&lt;void&gt; | Yes| Callback used to return the result.|
**Example**
```js
var want = {
'deviceId': '',
'bundleName': 'com.extreme.test',
'abilityName': 'MainAbility'
};
var options = {
windowMode: 0,
};
this.context.startAbility(want, options, (error) => {
console.log('error.code = ' + error.code)
})
```
## InputMethodExtensionContext.terminateSelf
terminateSelf(callback: AsyncCallback&lt;void&gt;): void;
Terminates this ability. This API uses an asynchronous callback to return the result. Terminates this ability. This API uses an asynchronous callback to return the result.
...@@ -134,20 +38,20 @@ Terminates this ability. This API uses an asynchronous callback to return the re ...@@ -134,20 +38,20 @@ Terminates this ability. This API uses an asynchronous callback to return the re
**Parameters** **Parameters**
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| -------- | ------------------------- | ---- | -------------------------------------- | | -------- | -------------------- | ---- | ------------------------------------------------------------ |
| callback | AsyncCallback&lt;void&gt; | Yes | Callback used 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** **Example**
```js ```js
this.context.terminateSelf((err) => { this.context.destroy((err) => {
console.log('terminateSelf result:' + JSON.stringify(err)); console.log('destroy result:' + JSON.stringify(err));
}); });
``` ```
## InputMethodExtensionContext.terminateSelf ## InputMethodExtensionContext.destroy
terminateSelf(): Promise&lt;void&gt;; destroy(): Promise<void&gt;
Terminates this ability. This API uses a promise to return the result. Terminates this ability. This API uses a promise to return the result.
...@@ -155,16 +59,16 @@ Terminates this ability. This API uses a promise to return the result. ...@@ -155,16 +59,16 @@ Terminates this ability. This API uses a promise to return the result.
**Return value** **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| Promise&lt;void&gt; | Promise used to return the result.| | Promise<void&gt; | Promise that returns no value.|
**Example** **Example**
```js ```js
this.context.terminateSelf().then((data) => { this.context.destroy().then((data) => {
console.log('success:' + JSON.stringify(data)); console.log('success:' + JSON.stringify(data));
}).catch((error) => { }).catch((error) => {
console.log('failed:' + JSON.stringify(error)); console.log('failed:' + JSON.stringify(error));
}); });
``` ```
# Input Method Subtype
The **inputMethodEngine** module provides APIs for managing the attributes of input method subtypes. Different attribute settings result in different subtypes.
> **NOTE**
>
>The initial APIs of this module are supported since API version 9. Newly added APIs will be marked with a superscript to indicate their earliest API version.
## Modules to Import
```
import inputMethodEngine from '@ohos.inputMethodSubtype';
```
## Attributes
**System capability**: SystemCapability.MiscServices.InputMethodFramework
| Name| Type| Readable| Writable| Mandatory| Description|
| -------- | -------- | -------- | -------- | -------- | -------- |
| label | string | Yes| No| No| Label of the input method subtype.|
| name | string | Yes| No| Yes| Name of the input method subtype.|
| id | string | Yes| No| Yes| ID of the input method subtype.|
| mode | string | Yes| No| No| Mode of the input method subtype, including **upper** (uppercase) and **lower** (lowercase).|
| locale | string | Yes| No| Yes| Locale of the input method subtype.|
| language | string | Yes| No| Yes| Language of the input method subtype.|
| icon | string | Yes| No| No| Icon of the input method subtype.|
| iconId | number | Yes| No| No| Icon ID of the input method subtype.|
| extra | object | Yes| Yes| Yes| Extra information of the input method subtype.|
...@@ -2,9 +2,9 @@ ...@@ -2,9 +2,9 @@
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 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** >**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. >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 ## Modules to Import
...@@ -13,16 +13,15 @@ The **inputMethod** module provides an input method framework, which can be used ...@@ -13,16 +13,15 @@ The **inputMethod** module provides an input method framework, which can be used
import inputMethod from '@ohos.inputmethod'; import inputMethod from '@ohos.inputmethod';
``` ```
## inputMethod<sup>8+</sup> ## Constants<sup>8+</sup>
Provides the constants. Provides the constants.
**System capability**: SystemCapability.MiscServices.InputMethodFramework **System capability**: SystemCapability.MiscServices.InputMethodFramework
| Name| Type| Readable| Writable| Description| | Name| Type| Value| Description|
| -------- | -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| MAX_TYPE_NUM | number | Yes| No| Maximum number of supported input methods.| | MAX_TYPE_NUM | number | 128 | Maximum number of supported input methods.|
## InputMethodProperty<sup>8+</sup> ## InputMethodProperty<sup>8+</sup>
...@@ -32,12 +31,18 @@ Describes the input method application attributes. ...@@ -32,12 +31,18 @@ Describes the input method application attributes.
| Name| Type| Readable| Writable| Description| | Name| Type| Readable| Writable| Description|
| -------- | -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- | -------- |
| packageName | string | Yes| No| Package name.| | name<sup>9+</sup> | string | Yes| No| Internal name of the input method.|
| methodId | string | Yes| No| Ability name.| | id<sup>9+</sup> | string | Yes| No| Unique ID of the input method.|
| label<sup>9+</sup> | string | Yes| No| External display name of the input method.|
| icon<sup>9+</sup> | string | Yes| No| Icon of the input method.|
| iconId<sup>9+</sup> | number | Yes| No| Icon ID of the input method.|
| extra<sup>9+</sup> | object | Yes| No| Extra information about the input method.|
| packageName<sup>(deprecated)</sup> | string | Yes| No| Name of the input method package.<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.<br>**NOTE**<br>This API is supported since API version 8 and deprecated since API version 9. You are advised to use **id**.|
## inputMethod.getInputMethodController ## inputMethod.getController<sup>9+</sup>
getInputMethodController(): InputMethodController getController(): InputMethodController
Obtains an **[InputMethodController](#inputmethodcontroller)** instance. Obtains an **[InputMethodController](#inputmethodcontroller)** instance.
...@@ -49,15 +54,23 @@ Obtains an **[InputMethodController](#inputmethodcontroller)** instance. ...@@ -49,15 +54,23 @@ Obtains an **[InputMethodController](#inputmethodcontroller)** instance.
| ----------------------------------------------- | ------------------------ | | ----------------------------------------------- | ------------------------ |
| [InputMethodController](#inputmethodcontroller) | Current **InputMethodController** instance.| | [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** **Example**
```js ```js
var InputMethodController = inputMethod.getInputMethodController(); let inputMethodController = inputMethod.getController();
``` ```
## inputMethod.getInputMethodSetting<sup>8+</sup> ## inputMethod.getSetting<sup>9+</sup>
getInputMethodSetting(): InputMethodSetting getSetting(): InputMethodSetting
Obtains an **[InputMethodSetting](#inputmethodsetting8)** instance. Obtains an **[InputMethodSetting](#inputmethodsetting8)** instance.
...@@ -69,17 +82,27 @@ Obtains an **[InputMethodSetting](#inputmethodsetting8)** instance. ...@@ -69,17 +82,27 @@ Obtains an **[InputMethodSetting](#inputmethodsetting8)** instance.
| ----------------------------------------- | ---------------------------- | | ----------------------------------------- | ---------------------------- |
| [InputMethodSetting](#inputmethodsetting8) | Current **InputMethodSetting** instance.| | [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** **Example**
```js ```js
var InputMethodSetting = inputMethod.getInputMethodSetting(); let inputMethodSetting = inputMethod.getSetting();
``` ```
## inputMethod.switchInputMethod<sup>9+</sup> ## inputMethod.switchInputMethod<sup>9+</sup>
switchInputMethod(target: InputMethodProperty, callback: AsyncCallback&lt;boolean&gt;): void switchInputMethod(target: InputMethodProperty, callback: AsyncCallback&lt;boolean&gt;): void
Switches to another input method. This API can be used only in the stage model. It uses an asynchronous callback to return the result. If the required two parameters are not passed in, an exception is thrown. Switches to another input method. This API uses an asynchronous callback to return the result.
**Required permissions**: ohos.permission.CONNECT_IME_ABILITY
**System capability**: SystemCapability.MiscServices.InputMethodFramework **System capability**: SystemCapability.MiscServices.InputMethodFramework
...@@ -87,14 +110,23 @@ Switches to another input method. This API can be used only in the stage model. ...@@ -87,14 +110,23 @@ Switches to another input method. This API can be used only in the stage model.
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
|target | [InputmethodProperty](#inputmethodproperty8) | Yes| Input method to switch to.| | target | [InputMethodProperty](#inputmethodproperty8) | Yes| Input method to switch to.|
| callback | AsyncCallback&lt;boolean&gt; | Yes| Callback used to return the execution result.| | callback | AsyncCallback&lt;boolean&gt; | 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 settings extension error. |
**Example** **Example**
```js ```js
inputMethod.switchInputMethod({packageName:'com.example.kikakeyboard', methodId:'com.example.kikakeyboard'} ,(err,result) => { try{
inputMethod.switchInputMethod({packageName:'com.example.kikakeyboard', methodId:'com.example.kikakeyboard', extra: {}}, (err, result) => {
if (err) { if (err) {
console.error('switchInputMethod err: ' + JSON.stringify(err)); console.error('switchInputMethod err: ' + JSON.stringify(err));
return; return;
...@@ -104,12 +136,17 @@ inputMethod.switchInputMethod({packageName:'com.example.kikakeyboard', methodId: ...@@ -104,12 +136,17 @@ inputMethod.switchInputMethod({packageName:'com.example.kikakeyboard', methodId:
} else { } else {
console.error('Failed to switchInputMethod.(callback)'); console.error('Failed to switchInputMethod.(callback)');
} }
}); });
} catch(err) {
console.error('switchInputMethod err: ' + JSON.stringify(err));
}
``` ```
## inputMethod.switchInputMethod<sup>9+</sup> ## inputMethod.switchInputMethod<sup>9+</sup>
switchInputMethod(target: InputMethodProperty): Promise&lt;boolean&gt; switchInputMethod(target: InputMethodProperty): Promise&lt;boolean&gt;
Switches to another input method. This API can be used only in the stage model. It uses a promise to return the result. If the required parameter is not passed in, an exception is thrown. Switches to another input method. This API uses a promise to return the result.
**Required permissions**: ohos.permission.CONNECT_IME_ABILITY
**System capability**: SystemCapability.MiscServices.InputMethodFramework **System capability**: SystemCapability.MiscServices.InputMethodFramework
...@@ -117,28 +154,41 @@ Switches to another input method. This API can be used only in the stage model. ...@@ -117,28 +154,41 @@ Switches to another input method. This API can be used only in the stage model.
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
|target | [InputmethodProperty](#inputmethodproperty8)| Yes| Input method to switch to.| |target | [InputMethodProperty](#inputmethodproperty8)| Yes| Input method to switch to.|
**Return value** **Return value**
| Type | Description | | Type | Description |
| ----------------------------------------- | ---------------------------- | | ----------------------------------------- | ---------------------------- |
| Promise\<boolean> | Promise used to return the execution result.| | Promise\<boolean> | Promise used to return the result. The value **true** means that the switching is successful, and **false** means the opposite.|
**Example** **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 settings extension error. |
**Example**
```js ```js
inputMethod.switchInputMethod({packageName:'com.example.kikakeyboard', methodId:'com.example.kikakeyboard'}).then((result) => { try {
inputMethod.switchInputMethod({packageName:'com.example.kikakeyboard', methodId:'com.example.kikakeyboard', extra: {}}).then((result) => {
if (result) { if (result) {
console.info('Success to switchInputMethod.(promise)'); console.info('Success to switchInputMethod.');
} else { } else {
console.error('Failed to switchInputMethod.(promise)'); console.error('Failed to switchInputMethod.');
} }
}).catch((err) => { }).catch((err) => {
console.error('switchInputMethod promise err: ' + err); console.error('switchInputMethod err: ' + JSON.stringify(err));
}) })
} catch(err) {
console.error('switchInputMethod err: ' + JSON.stringify(err));
}
``` ```
## inputMethod.getCurrentInputMethod<sup>9+</sup> ## inputMethod.getCurrentInputMethod<sup>9+</sup>
getCurrentInputMethod(): InputMethodProperty getCurrentInputMethod(): InputMethodProperty
...@@ -151,24 +201,337 @@ Obtains the current input method. This API synchronously returns the **Inputmeth ...@@ -151,24 +201,337 @@ Obtains the current input method. This API synchronously returns the **Inputmeth
| Type | Description | | Type | Description |
| -------------------------------------------- | ------------------------ | | -------------------------------------------- | ------------------------ |
| [InputmethodProperty](#inputmethodproperty8) | **InputmethodProperty** instance of the current input method.| | [InputMethodProperty](#inputmethodproperty8) | **InputmethodProperty** instance of the current input method.|
**Example** **Example**
```js
let currentIme = inputMethod.getCurrentInputMethod();
```
## inputMethod.switchCurrentInputMethodSubtype<sup>9+</sup>
switchCurrentInputMethodSubtype(target: InputMethodSubtype, callback: AsyncCallback\<boolean>): 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
**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&lt;boolean&gt; | 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 settings extension error. |
**Example**
```js ```js
var currentIme = inputMethod.getCurrentInputMethod(); let inputMethodSubtype = {
id: "com.example.kikakeyboard",
label: "ServiceExtAbility",
name: "",
mode: "upper",
locale: "",
language: "",
icon: "",
iconId: 0,
extra: {}
}
try {
inputMethod.switchCurrentInputMethodSubtype(inputMethodSubtype, (err, result) => {
if (err) {
console.error('switchCurrentInputMethodSubtype err: ' + JSON.stringify(err));
return;
}
if (result) {
console.info('Success to switchCurrentInputMethodSubtype.(callback)');
} else {
console.error('Failed to switchCurrentInputMethodSubtype.(callback)');
}
});
} catch(err) {
console.error('switchCurrentInputMethodSubtype err: ' + JSON.stringify(err));
}
```
## inputMethod.switchCurrentInputMethodSubtype<sup>9+</sup>
switchCurrentInputMethodSubtype(target: InputMethodSubtype): Promise&lt;boolean&gt;
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
**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\<boolean> | 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 settings extension error. |
**Example**
```js
let inputMethodSubtype = {
id: "com.example.kikakeyboard",
label: "ServiceExtAbility",
name: "",
mode: "upper",
locale: "",
language: "",
icon: "",
iconId: 0,
extra: {}
}
try {
inputMethod.switchCurrentInputMethodSubtype(inputMethodSubtype).then((result) => {
if (result) {
console.info('Success to switchCurrentInputMethodSubtype.');
} else {
console.error('Failed to switchCurrentInputMethodSubtype.');
}
}).catch((err) => {
console.error('switchCurrentInputMethodSubtype err: ' + JSON.stringify(err));
})
} catch(err) {
console.error('switchCurrentInputMethodSubtype err: ' + JSON.stringify(err));
}
```
## inputMethod.getCurrentInputMethodSubtype<sup>9+</sup>
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.switchCurrentInputMethodAndSubtype<sup>9+</sup>
switchCurrentInputMethodAndSubtype(inputMethodProperty: InputMethodProperty, inputMethodSubtype: InputMethodSubtype, callback: AsyncCallback\<boolean>): 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
**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&lt;boolean&gt; | 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 settings extension error. |
**Example**
```js
let inputMethodProperty = {
packageName: "com.example.kikakeyboard",
methodId: "ServiceExtAbility",
extra: {}
}
let inputMethodSubProperty = {
id: "com.example.kikakeyboard",
label: "ServiceExtAbility",
name: "",
mode: "upper",
locale: "",
language: "",
icon: "",
iconId: 0,
extra: {}
}
try {
inputMethod.switchCurrentInputMethodAndSubtype(inputMethodProperty, inputMethodSubProperty, (err,result) => {
if (err) {
console.error('switchCurrentInputMethodAndSubtype err: ' + JSON.stringify(err));
return;
}
if (result) {
console.info('Success to switchCurrentInputMethodAndSubtype.(callback)');
} else {
console.error('Failed to switchCurrentInputMethodAndSubtype.(callback)');
}
});
} catch (err) {
console.error('switchCurrentInputMethodAndSubtype err: ' + JSON.stringify(err));
}
```
## inputMethod.switchCurrentInputMethodAndSubtype<sup>9+</sup>
switchCurrentInputMethodAndSubtype(inputMethodProperty: InputMethodProperty, inputMethodSubtype: InputMethodSubtype): Promise&lt;boolean&gt;
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
**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\<boolean> | 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 settings extension error. |
**Example**
```js
let inputMethodProperty = {
packageName: "com.example.kikakeyboard",
methodId: "ServiceExtAbility",
extra: {}
}
let inputMethodSubProperty = {
id: "com.example.kikakeyboard",
label: "ServiceExtAbility",
name: "",
mode: "upper",
locale: "",
language: "",
icon: "",
iconId: 0,
extra: {}
}
try {
inputMethod.switchCurrentInputMethodAndSubtype(inputMethodProperty, inputMethodSubProperty).then((result) => {
if (result) {
console.info('Success to switchCurrentInputMethodAndSubtype.');
} else {
console.error('Failed to switchCurrentInputMethodAndSubtype.');
}
}).catch((err) => {
console.error('switchCurrentInputMethodAndSubtype err: ' + err);
})
} catch(err) {
console.error('switchCurrentInputMethodAndSubtype err: ' + err);
}
```
## inputMethod.getInputMethodController<sup>(deprecated)</sup>
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<sup>(deprecated)</sup>
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 ## InputMethodController
In the following API examples, you must first use **[getInputMethodController](#inputmethodgetinputmethodcontroller)** to obtain an **InputMethodController** instance, and then call the APIs using the obtained instance. 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.
### stopInput ### stopInputSession<sup>9+</sup>
stopInput(callback: AsyncCallback&lt;boolean&gt;): void stopInputSession(callback: AsyncCallback&lt;boolean&gt;): void
Hides the keyboard. This API uses an asynchronous callback to return the result. If the required parameter is not passed in, an exception is thrown. 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 **System capability**: SystemCapability.MiscServices.InputMethodFramework
...@@ -176,29 +539,42 @@ Hides the keyboard. This API uses an asynchronous callback to return the result. ...@@ -176,29 +539,42 @@ Hides the keyboard. This API uses an asynchronous callback to return the result.
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| callback | AsyncCallback&lt;boolean&gt; | Yes| Callback used to return whether the keyboard is successfully hidden.| | callback | AsyncCallback&lt;boolean&gt; | 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 settings extension error. |
**Example** **Example**
```js ```js
InputMethodController.stopInput((error, result) => { try {
inputMethodController.stopInputSession((error, result) => {
if (error) { if (error) {
console.error('failed to stopInput because: ' + JSON.stringify(error)); console.error('stopInputSession err: ' + JSON.stringify(error));
return; return;
} }
if (result) { if (result) {
console.info('Success to stopInput.(callback)'); console.info('Success to stopInputSession.(callback)');
} else { } else {
console.error('Failed to stopInput.(callback)'); console.error('Failed to stopInputSession.(callback)');
} }
}); });
} catch(error) {
console.error('stopInputSession err: ' + JSON.stringify(error));
}
``` ```
### stopInput ### stopInputSession<sup>9+</sup>
stopInput(): Promise&lt;boolean&gt; stopInputSession(): Promise&lt;boolean&gt;
Hides the keyboard. This API uses a promise to return the result. If any parameter is passed in, an exception is thrown. 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 **System capability**: SystemCapability.MiscServices.InputMethodFramework
...@@ -206,28 +582,42 @@ Hides the keyboard. This API uses a promise to return the result. If any paramet ...@@ -206,28 +582,42 @@ Hides the keyboard. This API uses a promise to return the result. If any paramet
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| Promise&lt;boolean&gt; | Promise used to return whether the keyboard is successfully hidden.| | Promise&lt;boolean&gt; | Promise used to return the result. The value **true** means that the ending is successful, and **false** means the opposite.|
**Example** **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 settings extension error. |
**Example**
```js ```js
InputMethodController.stopInput().then((result) => { try {
inputMethodController.stopInputSession().then((result) => {
if (result) { if (result) {
console.info('Success to stopInput.(promise)'); console.info('Success to stopInputSession.');
} else { } else {
console.error('Failed to stopInput.(promise)'); console.error('Failed to stopInputSession.');
} }
}).catch((err) => { }).catch((err) => {
console.error('stopInput promise err: ' + err); console.error('stopInputSession err: ' + JSON.stringify(err));
}) })
} catch(err) {
console.error('stopInputSession err: ' + JSON.stringify(err));
}
``` ```
### showSoftKeyboard<sup>9+</sup> ### ### showSoftKeyboard<sup>9+</sup>
showSoftKeyboard(callback: AsyncCallback&lt;void&gt;): void showSoftKeyboard(callback: AsyncCallback&lt;void&gt;): void
Shows this soft keyboard. This API uses an asynchronous callback to return the result. If the required parameter is not passed in, an exception is thrown. 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
**System capability**: SystemCapability.MiscServices.InputMethodFramework **System capability**: SystemCapability.MiscServices.InputMethodFramework
...@@ -235,12 +625,21 @@ Shows this soft keyboard. This API uses an asynchronous callback to return the r ...@@ -235,12 +625,21 @@ Shows this soft keyboard. This API uses an asynchronous callback to return the r
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| -------- | ------------------------- | ---- | ---------- | | -------- | ------------------------- | ---- | ---------- |
| callback | AsyncCallback&lt;void&gt; | Yes | Callback used to return the execution result.| | callback | AsyncCallback&lt;void&gt; | 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 settings extension error. |
**Example** **Example**
```js ```js
InputMethodController.showSoftKeyboard((err) => { inputMethodController.showSoftKeyboard((err) => {
if (err === undefined) { if (err === undefined) {
console.info('showSoftKeyboard success'); console.info('showSoftKeyboard success');
} else { } else {
...@@ -249,12 +648,13 @@ InputMethodController.showSoftKeyboard((err) => { ...@@ -249,12 +648,13 @@ InputMethodController.showSoftKeyboard((err) => {
}) })
``` ```
### showSoftKeyboard<sup>9+</sup>
### showSoftKeyboard<sup>9+</sup> ###
showSoftKeyboard(): Promise&lt;void&gt; showSoftKeyboard(): Promise&lt;void&gt;
Shows this soft keyboard. This API uses a promise to return the result. If any parameter is passed in, an exception is thrown. 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
**System capability**: SystemCapability.MiscServices.InputMethodFramework **System capability**: SystemCapability.MiscServices.InputMethodFramework
...@@ -264,21 +664,32 @@ Shows this soft keyboard. This API uses a promise to return the result. If any p ...@@ -264,21 +664,32 @@ Shows this soft keyboard. This API uses a promise to return the result. If any p
| ------------------- | ------------------------- | | ------------------- | ------------------------- |
| Promise&lt;void&gt; | Promise that returns no value.| | Promise&lt;void&gt; | 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 settings extension error. |
**Example** **Example**
```js ```js
InputMethodController.showSoftKeyboard().then(async (err) => { inputMethodController.showSoftKeyboard().then(async (err) => {
console.log('showSoftKeyboard success'); console.log('showSoftKeyboard success');
}).catch((err) => { }).catch((err) => {
console.error('showSoftKeyboard promise err: ' + JSON.stringify(err)); console.error('showSoftKeyboard err: ' + JSON.stringify(err));
}); });
``` ```
### hideSoftKeyboard<sup>9+</sup> ### ### hideSoftKeyboard<sup>9+</sup>
hideSoftKeyboard(callback: AsyncCallback&lt;void&gt;): void hideSoftKeyboard(callback: AsyncCallback&lt;void&gt;): void
Hides this soft keyboard. This API uses an asynchronous callback to return the result. If the required parameter is not passed in, an exception is thrown. 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
**System capability**: SystemCapability.MiscServices.InputMethodFramework **System capability**: SystemCapability.MiscServices.InputMethodFramework
...@@ -286,12 +697,21 @@ Hides this soft keyboard. This API uses an asynchronous callback to return the r ...@@ -286,12 +697,21 @@ Hides this soft keyboard. This API uses an asynchronous callback to return the r
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| -------- | ------------------------- | ---- | ---------- | | -------- | ------------------------- | ---- | ---------- |
| callback | AsyncCallback&lt;void&gt; | Yes | Callback used to return the execution result.| | callback | AsyncCallback&lt;void&gt; | 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 settings extension error. |
**Example** **Example**
```js ```js
InputMethodController.hideSoftKeyboard((err) => { inputMethodController.hideSoftKeyboard((err) => {
if (err === undefined) { if (err === undefined) {
console.info('hideSoftKeyboard success'); console.info('hideSoftKeyboard success');
} else { } else {
...@@ -300,12 +720,13 @@ InputMethodController.hideSoftKeyboard((err) => { ...@@ -300,12 +720,13 @@ InputMethodController.hideSoftKeyboard((err) => {
}) })
``` ```
### hideSoftKeyboard<sup>9+</sup>
### hideSoftKeyboard<sup>9+</sup> ###
hideSoftKeyboard(): Promise&lt;void&gt; hideSoftKeyboard(): Promise&lt;void&gt;
Hides this soft keyboard. This API uses a promise to return the result. If any parameter is passed in, an exception is thrown. 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
**System capability**: SystemCapability.MiscServices.InputMethodFramework **System capability**: SystemCapability.MiscServices.InputMethodFramework
...@@ -315,25 +736,313 @@ Hides this soft keyboard. This API uses a promise to return the result. If any p ...@@ -315,25 +736,313 @@ Hides this soft keyboard. This API uses a promise to return the result. If any p
| ------------------- | ------------------------- | | ------------------- | ------------------------- |
| Promise&lt;void&gt; | Promise that returns no value.| | Promise&lt;void&gt; | 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 settings extension error. |
**Example** **Example**
```js ```js
InputMethodController.hideSoftKeyboard().then(async (err) => { inputMethodController.hideSoftKeyboard().then(async (err) => {
console.log('hideSoftKeyboard success'); console.log('hideSoftKeyboard success');
}).catch((err) => { }).catch((err) => {
console.error('hideSoftKeyboard promise err: ' + JSON.stringify(err)); console.error('hideSoftKeyboard err: ' + JSON.stringify(err));
}); });
``` ```
### stopInput<sup>(deprecated)</sup>
stopInput(callback: AsyncCallback&lt;boolean&gt;): 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&lt;boolean&gt; | 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) {
console.error('failed to stopInput because: ' + JSON.stringify(error));
return;
}
if (result) {
console.info('Success to stopInput.(callback)');
} else {
console.error('Failed to stopInput.(callback)');
}
});
```
### stopInput<sup>(deprecated)</sup>
stopInput(): Promise&lt;boolean&gt;
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&lt;boolean&gt; | 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('Success to stopInput.');
} else {
console.error('Failed to stopInput.');
}
}).catch((err) => {
console.error('stopInput err: ' + err);
})
```
## InputMethodSetting<sup>8+</sup> ## InputMethodSetting<sup>8+</sup>
In the following API examples, you must first use **[getInputMethodSetting](#inputmethodgetinputmethodcontroller)** to obtain an **InputMethodSetting** instance, and then call the APIs using the obtained instance. 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')<sup>9+</sup>
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.<br>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')<sup>9+</sup>
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.<br>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');
```
### listInputMethodSubtype<sup>9+</sup>
listInputMethodSubtype(inputMethodProperty: InputMethodProperty, callback: AsyncCallback&lt;Array&lt;InputMethodSubtype&gt;&gt;): 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&lt;Array<[InputMethodSubtype](./js-apis-inputmethod-subtype.md#inputmethodsubtype)>&gt; | 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 settings extension error. |
**Example**
```js
let inputMethodProperty = {
packageName:'com.example.kikakeyboard',
methodId:'com.example.kikakeyboard',
extra:{}
}
try {
inputMethodSetting.listInputMethodSubtype(inputMethodProperty, (err,data) => {
if (err) {
console.error('listInputMethodSubtype failed: ' + JSON.stringify(err));
return;
}
console.log('listInputMethodSubtype success');
});
} catch (err) {
console.error('listInputMethodSubtype failed: ' + JSON.stringify(err));
}
```
### listInputMethodSubtype<sup>9+</sup>
listInputMethodSubtype(inputMethodProperty: InputMethodProperty): Promise&lt;Array&lt;InputMethodSubtype&gt;&gt;
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<Array<[InputMethodSubtype](./js-apis-inputmethod-subtype.md#inputmethodsubtype)>> | 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 settings extension error. |
### listInputMethod<sup>9+</sup> **Example**
```js
let inputMethodProperty = {
packageName:'com.example.kikakeyboard',
methodId:'com.example.kikakeyboard',
extra:{}
}
try {
inputMethodSetting.listInputMethodSubtype(inputMethodProperty).then((data) => {
console.info('listInputMethodSubtype success');
}).catch((err) => {
console.error('listInputMethodSubtype err: ' + JSON.stringify(err));
})
} catch(err) {
console.error('listInputMethodSubtype err: ' + JSON.stringify(err));
}
```
listInputMethod(enable: boolean, callback: AsyncCallback&lt;Array&lt;InputMethodProperty&gt;&gt;): void ### listCurrentInputMethodSubtype<sup>9+</sup>
Obtains a list of activated or deactivated input methods. This API uses an asynchronous callback to return the result. If the required two parameters are not passed in, an exception is thrown. listCurrentInputMethodSubtype(callback: AsyncCallback&lt;Array&lt;InputMethodSubtype&gt;&gt;): 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&lt;Array<[InputMethodSubtype](./js-apis-inputmethod-subtype.md#inputmethodsubtype)>&gt; | 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 settings extension error. |
**Example**
```js
try {
inputMethodSetting.listCurrentInputMethodSubtype((err, data) => {
if (err) {
console.error('listCurrentInputMethodSubtype failed: ' + JSON.stringify(err));
return;
}
console.log('listCurrentInputMethodSubtype success');
});
} catch(err) {
console.error('listCurrentInputMethodSubtype err: ' + JSON.stringify(err));
}
```
### listCurrentInputMethodSubtype<sup>9+</sup>
listCurrentInputMethodSubtype(): Promise&lt;Array&lt;InputMethodSubtype&gt;&gt;
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<Array<[InputMethodSubtype](./js-apis-inputmethod-subtype.md#inputmethodsubtype)>> | 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 settings extension error. |
**Example**
```js
try {
inputMethodSetting.listCurrentInputMethodSubtype().then((data) => {
console.info('listCurrentInputMethodSubtype success');
}).catch((err) => {
console.error('listCurrentInputMethodSubtype err: ' + err);
})
} catch(err) {
console.error('listCurrentInputMethodSubtype err: ' + JSON.stringify(err));
}
```
### getInputMethods<sup>9+</sup>
getInputMethods(enable: boolean, callback: AsyncCallback&lt;Array&lt;InputMethodProperty&gt;&gt;): 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 **System capability**: SystemCapability.MiscServices.InputMethodFramework
...@@ -342,25 +1051,38 @@ Obtains a list of activated or deactivated input methods. This API uses an async ...@@ -342,25 +1051,38 @@ Obtains a list of activated or deactivated input methods. This API uses an async
| Name | Type | Mandatory| Description | | 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. | | 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 | Array<[InputMethodProperty](#inputmethodproperty8)> | Yes | Callback used to return a list of activated or deactivated input methods.| | callback | AsyncCallback&lt;Array<[InputMethodProperty](#inputmethodproperty8)>&gt; | 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 settings extension error. |
**Example** **Example**
```js ```js
InputMethodSetting.listInputMethod(true, (err,data) => { try {
inputMethodSetting.getInputMethods(true, (err,data) => {
if (err) { if (err) {
console.error('listInputMethod failed because: ' + JSON.stringify(err)); console.error('getInputMethods failed: ' + JSON.stringify(err));
return; return;
} }
console.log('listInputMethod success'); console.log('getInputMethods success');
}); });
} catch (err) {
console.error('getInputMethods failed: ' + JSON.stringify(err));
}
``` ```
### listInputMethod<sup>9+</sup> ### getInputMethods<sup>9+</sup>
listInputMethod(enable: boolean): Promise&lt;Array&lt;InputMethodProperty&gt;&gt; getInputMethods(enable: boolean): Promise&lt;Array&lt;InputMethodProperty&gt;&gt;
Obtains a list of activated or deactivated input methods. This API uses a promise to return the result. If any parameter is passed in, an exception is thrown. 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 **System capability**: SystemCapability.MiscServices.InputMethodFramework
...@@ -370,6 +1092,15 @@ Obtains a list of activated or deactivated input methods. This API uses a promis ...@@ -370,6 +1092,15 @@ Obtains a list of activated or deactivated input methods. This API uses a promis
| ------ | ------- | ---- | ----------------------- | | ------ | ------- | ---- | ----------------------- |
| 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.| | 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 settings extension error. |
**Return value** **Return value**
| Type | Description | | Type | Description |
...@@ -379,18 +1110,100 @@ Obtains a list of activated or deactivated input methods. This API uses a promis ...@@ -379,18 +1110,100 @@ Obtains a list of activated or deactivated input methods. This API uses a promis
**Example** **Example**
```js ```js
InputMethodSetting.listInputMethod(true).then((data) => { try {
console.info('listInputMethod success'); inputMethodSetting.getInputMethods(true).then((data) => {
console.info('getInputMethods success');
}).catch((err) => {
console.error('getInputMethods err: ' + JSON.stringify(err));
})
} catch(err) {
console.error('getInputMethods err: ' + JSON.stringify(err));
}
```
### showOptionalInputMethods<sup>9+</sup>
showOptionalInputMethods(callback: AsyncCallback&lt;boolean&gt;): void
Displays a dialog box for selecting an input method. This API uses an asynchronous callback to return the result.
**Required permissions**: ohos.permission.CONNECT_IME_ABILITY
**System capability**: SystemCapability.MiscServices.InputMethodFramework
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| callback | AsyncCallback&lt;boolean&gt; | 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 settings extension error. |
**Example**
```js
try {
inputMethodSetting.showOptionalInputMethods((err, data) => {
if (err) {
console.error('showOptionalInputMethods failed: ' + JSON.stringify(err));
return;
}
console.info('showOptionalInputMethods success');
});
} catch (err) {
console.error('showOptionalInputMethods failed: ' + JSON.stringify(err));
}
```
### showOptionalInputMethods<sup>9+</sup>
showOptionalInputMethods(): Promise&lt;boolean&gt;
Displays a dialog box for selecting an input method. This API uses a promise to return the result.
**Required permissions**: ohos.permission.CONNECT_IME_ABILITY
**System capability**: SystemCapability.MiscServices.InputMethodFramework
**Return value**
| Type| Description|
| -------- | -------- |
| Promise&lt;boolean&gt; | 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 settings extension error. |
**Example**
```js
inputMethodSetting.showOptionalInputMethods().then((data) => {
console.info('displayOptionalInputMethod success.');
}).catch((err) => { }).catch((err) => {
console.error('listInputMethod promise err: ' + err); console.error('displayOptionalInputMethod err: ' + err);
}) })
``` ```
### listInputMethod ### listInputMethod<sup>(deprecated)</sup>
listInputMethod(callback: AsyncCallback&lt;Array&lt;InputMethodProperty&gt;&gt;): void listInputMethod(callback: AsyncCallback&lt;Array&lt;InputMethodProperty&gt;&gt;): void
Obtains a list of installed input methods. This API uses an asynchronous callback to return the result. If the required parameter is not passed in, an exception is thrown. 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 **System capability**: SystemCapability.MiscServices.InputMethodFramework
...@@ -398,12 +1211,12 @@ Obtains a list of installed input methods. This API uses an asynchronous callbac ...@@ -398,12 +1211,12 @@ Obtains a list of installed input methods. This API uses an asynchronous callbac
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| -------- | -------------------------------------------------- | ---- | ---------------------- | | -------- | -------------------------------------------------- | ---- | ---------------------- |
| callback | Array<[InputMethodProperty](#inputmethodproperty8)> | Yes | Callback used to return the list of installed input methods.| | callback | AsyncCallback&lt;Array<[InputMethodProperty](#inputmethodproperty8)>&gt; | Yes | Callback used to return the list of installed input methods.|
**Example** **Example**
```js ```js
InputMethodSetting.listInputMethod((err,data) => { inputMethodSetting.listInputMethod((err,data) => {
if (err) { if (err) {
console.error('listInputMethod failed because: ' + JSON.stringify(err)); console.error('listInputMethod failed because: ' + JSON.stringify(err));
return; return;
...@@ -412,11 +1225,15 @@ InputMethodSetting.listInputMethod((err,data) => { ...@@ -412,11 +1225,15 @@ InputMethodSetting.listInputMethod((err,data) => {
}); });
``` ```
### listInputMethod ### listInputMethod<sup>(deprecated)</sup>
listInputMethod(): Promise&lt;Array&lt;InputMethodProperty&gt;&gt; listInputMethod(): Promise&lt;Array&lt;InputMethodProperty&gt;&gt;
Obtains a list of installed input methods. This API uses a promise to return the result. If any parameter is passed in, an exception is thrown. 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 **System capability**: SystemCapability.MiscServices.InputMethodFramework
...@@ -429,18 +1246,22 @@ Obtains a list of installed input methods. This API uses a promise to return the ...@@ -429,18 +1246,22 @@ Obtains a list of installed input methods. This API uses a promise to return the
**Example** **Example**
```js ```js
InputMethodSetting.listInputMethod().then((data) => { inputMethodSetting.listInputMethod().then((data) => {
console.info('listInputMethod success'); console.info('listInputMethod success');
}).catch((err) => { }).catch((err) => {
console.error('listInputMethod promise err: ' + err); console.error('listInputMethod err: ' + JSON.stringify(err));
}) })
``` ```
### displayOptionalInputMethod ### displayOptionalInputMethod<sup>(deprecated)</sup>
displayOptionalInputMethod(callback: AsyncCallback&lt;void&gt;): void displayOptionalInputMethod(callback: AsyncCallback&lt;void&gt;): void
Displays a dialog box for selecting an input method. This API uses an asynchronous callback to return the result. If the required parameter is not passed in, an exception is thrown. 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 **System capability**: SystemCapability.MiscServices.InputMethodFramework
...@@ -448,12 +1269,12 @@ Displays a dialog box for selecting an input method. This API uses an asynchrono ...@@ -448,12 +1269,12 @@ Displays a dialog box for selecting an input method. This API uses an asynchrono
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| callback | AsyncCallback&lt;void&gt; | Yes| Callback used to return the execution result.| | callback | AsyncCallback&lt;void&gt; | Yes| Callback used to return the result. If the operation is successful, **err** is **undefined**. Otherwise, **err** is an error object. |
**Example** **Example**
```js ```js
InputMethodSetting.displayOptionalInputMethod((err) => { inputMethodSetting.displayOptionalInputMethod((err) => {
if (err) { if (err) {
console.error('displayOptionalInputMethod failed because: ' + JSON.stringify(err)); console.error('displayOptionalInputMethod failed because: ' + JSON.stringify(err));
return; return;
...@@ -462,13 +1283,17 @@ InputMethodSetting.displayOptionalInputMethod((err) => { ...@@ -462,13 +1283,17 @@ InputMethodSetting.displayOptionalInputMethod((err) => {
}); });
``` ```
### displayOptionalInputMethod ### displayOptionalInputMethod<sup>(deprecated)</sup>
displayOptionalInputMethod(): Promise&lt;void&gt; displayOptionalInputMethod(): Promise&lt;void&gt;
Displays a dialog box for selecting an input method. This API uses a promise to return the result. If any parameter is passed in, an exception is thrown. Displays a dialog box for selecting an input method. This API uses a promise to return the result.
**System capability**: SystemCapability.MiscServices.InputMethodFramework > **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** **Return value**
...@@ -479,9 +1304,9 @@ InputMethodSetting.displayOptionalInputMethod((err) => { ...@@ -479,9 +1304,9 @@ InputMethodSetting.displayOptionalInputMethod((err) => {
**Example** **Example**
```js ```js
InputMethodSetting.displayOptionalInputMethod().then(() => { inputMethodSetting.displayOptionalInputMethod().then(() => {
console.info('displayOptionalInputMethod success.(promise)'); console.info('displayOptionalInputMethod success');
}).catch((err) => { }).catch((err) => {
console.error('displayOptionalInputMethod promise err: ' + err); console.error('displayOptionalInputMethod err: ' + err);
}) })
``` ```
# Input Method Engine # Input Method Engine
The **inputMethodEngine** module streamlines the interaction between applications and input methods. By calling APIs of this module, applications can accept text input through the input methods, be bound to input method services, request the keyboard to display or hide, listen for the input method status, and much more. The **inputMethodEngine** module streamlines the interaction between input methods and applications. By calling APIs of this module, applications can be bound to input method services to accept text input through the input methods, request the keyboard to display or hide, listen for the input method status, and much more.
> **NOTE** > **NOTE**
> >
> The initial APIs of this module are supported since API version 8. Newly added APIs will be marked with a superscript to indicate their earliest API version. >The initial APIs of this module are supported since API version 8. Newly added APIs will be marked with a superscript to indicate their earliest API version.
## Modules to Import ## Modules to Import
...@@ -12,95 +12,143 @@ The **inputMethodEngine** module streamlines the interaction between application ...@@ -12,95 +12,143 @@ The **inputMethodEngine** module streamlines the interaction between application
import inputMethodEngine from '@ohos.inputmethodengine'; import inputMethodEngine from '@ohos.inputmethodengine';
``` ```
## inputMethodEngine ## Constants
Provides the constants. Provides the constant values of function keys, edit boxes, and the cursor.
**System capability**: SystemCapability.MiscServices.InputMethodFramework **System capability**: SystemCapability.MiscServices.InputMethodFramework
| Name| Type| Readable| Writable| Description| | Name| Type| Value| Description|
| -------- | -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| ENTER_KEY_TYPE_UNSPECIFIED | number | Yes| No| No function is specified for the Enter key.| | ENTER_KEY_TYPE_UNSPECIFIED | number | 0 | No function is specified for the Enter key.|
| ENTER_KEY_TYPE_GO | number | Yes| No| The Enter key takes the user to the target.| | ENTER_KEY_TYPE_GO | number | 2 | The Enter key takes the user to the target.|
| ENTER_KEY_TYPE_SEARCH | number | Yes| No| The Enter key takes the user to the results of their searching.| | ENTER_KEY_TYPE_SEARCH | number | 3 | The Enter key takes the user to the results of their searching.|
| ENTER_KEY_TYPE_SEND | number | Yes| No| The Enter key sends the text to its target.| | ENTER_KEY_TYPE_SEND | number | 4 | The Enter key sends the text to its target.|
| ENTER_KEY_TYPE_NEXT | number | Yes| No| The Enter key takes the user to the next field.| | ENTER_KEY_TYPE_NEXT | number | 5 | The Enter key takes the user to the next field.|
| ENTER_KEY_TYPE_DONE | number | Yes| No| The Enter key takes the user to the next line.| | ENTER_KEY_TYPE_DONE | number | 6 | The Enter key takes the user to the next line.|
| ENTER_KEY_TYPE_PREVIOUS | number | Yes| No| The Enter key takes the user to the previous field.| | ENTER_KEY_TYPE_PREVIOUS | number | 7 | The Enter key takes the user to the previous field.|
| PATTERN_NULL | number | Yes| No| Any type of edit box.| | PATTERN_NULL | number | -1 | Any type of edit box.|
| PATTERN_TEXT | number | Yes| No| Text edit box.| | PATTERN_TEXT | number | 0 | Text edit box.|
| PATTERN_NUMBER | number | Yes| No| Number edit box.| | PATTERN_NUMBER | number | 2 | Number edit box.|
| PATTERN_PHONE | number | Yes| No| Phone number edit box.| | PATTERN_PHONE | number | 3 | Phone number edit box.|
| PATTERN_DATETIME | number | Yes| No| Date edit box.| | PATTERN_DATETIME | number | 4 | Date edit box.|
| PATTERN_EMAIL | number | Yes| No| Email edit box.| | PATTERN_EMAIL | number | 5 | Email edit box.|
| PATTERN_URI | number | Yes| No| URI edit box.| | PATTERN_URI | number | 6 | URI edit box.|
| PATTERN_PASSWORD | number | Yes| No| Password edit box.| | PATTERN_PASSWORD | number | 7 | Password edit box.|
| OPTION_ASCII | number | Yes| No| ASCII values are allowed.| | OPTION_ASCII | number | 20 | ASCII values are allowed.|
| OPTION_NONE | number | Yes| No| No input attribute is specified.| | OPTION_NONE | number | 0 | No input attribute is specified.|
| OPTION_AUTO_CAP_CHARACTERS | number | Yes| No| Characters are allowed.| | OPTION_AUTO_CAP_CHARACTERS | number | 2 | Characters are allowed.|
| OPTION_AUTO_CAP_SENTENCES | number | Yes| No| Sentences are allowed.| | OPTION_AUTO_CAP_SENTENCES | number | 8 | Sentences are allowed.|
| OPTION_AUTO_WORDS | number | Yes| No| Words are allowed.| | OPTION_AUTO_WORDS | number | 4 | Words are allowed.|
| OPTION_MULTI_LINE | number | Yes| No| Multiple lines are allowed.| | OPTION_MULTI_LINE | number | 1 | Multiple lines are allowed.|
| OPTION_NO_FULLSCREEN | number | Yes| No| Half-screen style.| | OPTION_NO_FULLSCREEN | number | 10 | Half-screen style.|
| FLAG_SELECTING | number | Yes| No| The edit box is being selected.| | FLAG_SELECTING | number | 2 | The edit box is being selected.|
| FLAG_SINGLE_LINE | number | Yes| No| The edit box allows only single-line input.| | FLAG_SINGLE_LINE | number | 1 | The edit box allows only single-line input.|
| DISPLAY_MODE_PART | number | Yes| No| The edit box is displayed in half-screen mode.| | DISPLAY_MODE_PART | number | 0 | The edit box is displayed in half-screen mode.|
| DISPLAY_MODE_FULL | number | Yes| No| The edit box is displayed in full screen.| | DISPLAY_MODE_FULL | number | 1 | The edit box is displayed in full screen.|
| CURSOR_UP<sup>9+</sup> | number | Yes| No| The caret moves upward.| | CURSOR_UP<sup>9+</sup> | number | 1 | The caret moves upward.|
| CURSOR_DOWN<sup>9+</sup> | number | Yes| No| The caret moves downward.| | CURSOR_DOWN<sup>9+</sup> | number | 2 | The caret moves downward.|
| CURSOR_LEFT<sup>9+</sup> | number | Yes| No| The caret moves leftward.| | CURSOR_LEFT<sup>9+</sup> | number | 3 | The caret moves leftward.|
| CURSOR_RIGHT<sup>9+</sup> | number | Yes| No| The caret moves rightward.| | CURSOR_RIGHT<sup>9+</sup> | number | 4 | The caret moves rightward.|
| WINDOW_TYPE_INPUT_METHOD_FLOAT<sup>9+</sup> | number | Yes| No| The input method is displayed in a floating window.| | WINDOW_TYPE_INPUT_METHOD_FLOAT<sup>9+</sup> | number | 2105 | The input method is displayed in a floating window.|
## inputMethodEngine.getInputMethodEngine<a name="getInputMethodEngine"></a> ## inputMethodEngine.getInputMethodAbility<sup>9+</sup>
getInputMethodAbility(): InputMethodAbility
Obtains an **InputMethodEngine** instance.
**System capability**: SystemCapability.MiscServices.InputMethodFramework
**Return value**
| Type | Description |
| --------------------------------------- | ------------ |
| [InputMethodAbility](#inputmethodability) | **InputMethodEngine** instance obtained.|
**Example**
```js
let InputMethodAbility = inputMethodEngine.getInputMethodAbility();
```
## inputMethodEngine.getKeyboardDelegate<sup>9+</sup>
getKeyboardDelegate(): KeyboardDelegate
Obtains a **KeyboardDelegate** instance.
**System capability**: SystemCapability.MiscServices.InputMethodFramework
**Return value**
| Type | Description |
| ------------------------------------- | ---------------- |
| [KeyboardDelegate](#keyboarddelegate) | **KeyboardDelegate** instance obtained.|
**Example**
```js
let KeyboardDelegate = inputMethodEngine.getKeyboardDelegate();
```
## inputMethodEngine.getInputMethodEngine<sup>(deprecated)</sup>
getInputMethodEngine(): InputMethodEngine getInputMethodEngine(): InputMethodEngine
Obtains an **InputMethodEngine** instance. Obtains an **InputMethodEngine** instance.
> **NOTE**
>
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [getInputMethodAbility()](#inputmethodenginegetinputmethodability9).
**System capability**: SystemCapability.MiscServices.InputMethodFramework **System capability**: SystemCapability.MiscServices.InputMethodFramework
**Return value** **Return value**
| Type | Description | | Type | Description |
| --------------------------------------- | ------------ | | --------------------------------------- | ------------ |
| [InputMethodEngine](#InputMethodEngine) | **InputMethodEngine** instance obtained.| | [InputMethodEngine](#inputmethodengine-1) | **InputMethodEngine** instance obtained.|
**Example** **Example**
```js ```js
var InputMethodEngine = inputMethodEngine.getInputMethodEngine(); let InputMethodEngine = inputMethodEngine.getInputMethodEngine();
``` ```
## inputMethodEngine.createKeyboardDelegate<a name="createKeyboardDelegate"></a> ## inputMethodEngine.createKeyboardDelegate<sup>(deprecated)</sup>
createKeyboardDelegate(): KeyboardDelegate createKeyboardDelegate(): KeyboardDelegate
Obtains a **KeyboardDelegate** instance. Obtains a **KeyboardDelegate** instance.
> **NOTE**
>
>This API is supported since API version 8 and deprecated since API version 9. You are advised to use [getKeyboardDelegate()](#inputmethodenginegetkeyboarddelegate9).
**System capability**: SystemCapability.MiscServices.InputMethodFramework **System capability**: SystemCapability.MiscServices.InputMethodFramework
**Return value** **Return value**
| Type | Description | | Type | Description |
| ------------------------------------- | ---------------- | | ------------------------------------- | ---------------- |
| [KeyboardDelegate](#KeyboardDelegate) | **KeyboardDelegate** instance obtained.| | [KeyboardDelegate](#keyboarddelegate) | **KeyboardDelegate** instance obtained.|
**Example** **Example**
```js ```js
var KeyboardDelegate = inputMethodEngine.createKeyboardDelegate(); let KeyboardDelegate = inputMethodEngine.createKeyboardDelegate();
``` ```
## InputMethodEngine<a name="InputMethodEngine"></a> ## InputMethodEngine
In the following API examples, you must first use [getInputMethodEngine](#getInputMethodEngine) to obtain an **InputMethodEngine** instance, and then call the APIs using the obtained instance. In the following API examples, you must first use **[getInputMethodEngine](#inputmethodenginegetinputmethodenginedeprecated)** to obtain an **InputMethodEngine** instance, and then call the APIs using the obtained instance.
### on('inputStart')<a name="inputStart"></a> ### on('inputStart')
on(type: 'inputStart', callback: (kbController: KeyboardController, textInputClient: TextInputClient) => void): void on(type: 'inputStart', callback: (kbController: KeyboardController, textInputClient: TextInputClient) => void): void
Listens for the input method binding event. This API uses a callback to return the result. This API requires two parameters, the first one being napi_string and the second one being napi_function. If either of these parameters is not passed in, an exception is thrown. Enables listening for the input method binding event. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.MiscServices.InputMethodFramework **System capability**: SystemCapability.MiscServices.InputMethodFramework
...@@ -108,23 +156,23 @@ Listens for the input method binding event. This API uses a callback to return t ...@@ -108,23 +156,23 @@ Listens for the input method binding event. This API uses a callback to return t
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| -------- | ------------------------------- | ---- | ------------------------------------------------------------ | | -------- | ------------------------------- | ---- | ------------------------------------------------------------ |
| type | string | Yes | Listening type.<br>Set it to **'inputStart'**, which indicates listening for the input method binding event.| | type | string | Yes | Listening type.<br>The value **'inputStart'** indicates the input method binding event.|
| callback | [KeyboardController](#KeyboardController), [TextInputClient](#TextInputClient) | Yes| Callback used to return the result.| | callback | (kbController: [KeyboardController](#keyboardcontroller), textInputClient: [TextInputClient](#textinputclient)) => void | Yes| Callback used to return the **KeyboardController** and **TextInputClient** instances.|
**Example** **Example**
```js ```js
InputMethodEngine.on('inputStart', (kbController, textInputClient) => { inputMethodEngine.getInputMethodEngine().on('inputStart', (kbController, textInputClient) => {
KeyboardController = kbController; KeyboardController = kbController;
TextInputClient = textInputClient; TextInputClient = textInputClient;
}); });
``` ```
### off('inputStart') ### off('inputStart')
off(type: 'inputStart', callback?: (kbController: KeyboardController, textInputClient: TextInputClient) => void): void off(type: 'inputStart', callback?: (kbController: KeyboardController, textInputClient: TextInputClient) => void): void
Cancels listening for the input method binding event. An exception is thrown in the following cases: (1) No parameter is passed; (2) Only one parameter is passed in, and it is not napi_string; (2) Two parameters are passed in, and the first parameter is not napi_string or the second parameter is not napi_function. If only one parameter is passed in, all listeners of the specified type will be canceled. If two parameters are passed in, the current listener of the specified type will be canceled. Cancels listening for the input method binding event.
**System capability**: SystemCapability.MiscServices.InputMethodFramework **System capability**: SystemCapability.MiscServices.InputMethodFramework
...@@ -132,24 +180,125 @@ Cancels listening for the input method binding event. An exception is thrown in ...@@ -132,24 +180,125 @@ Cancels listening for the input method binding event. An exception is thrown in
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| -------- | -------------------- | ---- | ------------------------ | | -------- | -------------------- | ---- | ------------------------ |
| type | string | Yes | Listening type.<br>Set it to **'inputStart'**, which indicates listening for the input method binding event.| | type | string | Yes | Listening type.<br>The value **'inputStart'** indicates the input method binding event.|
| callback | [KeyboardController](#KeyboardController), [TextInputClient](#TextInputClient) | No| Callback used to return the result.| | callback | (kbController: [KeyboardController](#keyboardcontroller), textInputClient: [TextInputClient](#textinputclient)) => void | No| Callback used to return the **KeyboardController** and **TextInputClient** instances.|
**Example**
```js
inputMethodEngine.getInputMethodEngine().off('inputStart', (kbController, textInputClient) => {
console.log('delete inputStart notification.');
});
```
### on('keyboardShow'|'keyboardHide')
on(type: 'keyboardShow'|'keyboardHide', callback: () => void): void
Enables listening for a keyboard 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.<br>- The value **'keyboardShow'** indicates the keyboard display event.<br>- The value **'keyboardHide'** indicates the keyboard hiding event. |
| callback | () => void | Yes | Callback used to return the result. |
**Example**
```js
inputMethodEngine.getInputMethodEngine().on('keyboardShow', () => {
console.log('inputMethodEngine keyboardShow.');
});
inputMethodEngine.getInputMethodEngine().on('keyboardHide', () => {
console.log('inputMethodEngine keyboardHide.');
});
```
### off('keyboardShow'|'keyboardHide')
off(type: 'keyboardShow'|'keyboardHide', callback?: () => void): void
Disables listening for a keyboard 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.<br>- The value **'keyboardShow'** indicates the keyboard display event.<br>- The value **'keyboardHide'** indicates the keyboard hiding event. |
| callback | () => void | No | Callback used to return the result.|
**Example**
```js
inputMethodEngine.getInputMethodEngine().off('keyboardShow', () => {
console.log('inputMethodEngine delete keyboardShow notification.');
});
inputMethodEngine.getInputMethodEngine().off('keyboardHide', () => {
console.log('inputMethodEngine delete keyboardHide notification.');
});
```
## InputMethodAbility
In the following API examples, you must first use **[getInputMethodAbility](#inputmethodenginegetinputmethodability9)** to obtain an **InputMethodAbility** instance, and then call the APIs using the obtained instance.
### on('inputStart')<sup>9+</sup>
on(type: 'inputStart', callback: (kbController: KeyboardController, inputClient: InputClient) => void): void
Enables listening for the input method binding 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.<br>The value **'inputStart'** indicates the input method binding event.|
| callback | (kbController: [KeyboardController](#keyboardcontroller), inputClient: [InputClient](#inputclient9)) => void | Yes| Callback used to return the result.|
**Example**
```js
inputMethodEngine.getInputMethodAbility().on('inputStart', (kbController, inputClient) => {
KeyboardController = kbController;
InputClient = inputClient;
});
```
### off('inputStart')<sup>9+</sup>
off(type: 'inputStart', callback?: (kbController: KeyboardController, inputClient: InputClient) => void): void
Cancels listening for the input method binding 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.<br>The value **'inputStart'** indicates the input method binding event.|
| callback | (kbController: [KeyboardController](#keyboardcontroller), inputClient: [InputClient](#inputclient9)) => void | No| Callback used to return the result.|
**Example** **Example**
```js ```js
InputMethodEngine.off('inputStart', (kbController, textInputClient) => { inputMethodEngine.getInputMethodAbility().off('inputStart', (kbController, inputClient) => {
console.log('delete inputStart notification.'); console.log('delete inputStart notification.');
}); });
``` ```
### on('inputStop')<sup>9+</sup> ### on('inputStop')<sup>9+</sup>
on(type: 'inputStop', callback: () => void): void on(type: 'inputStop', callback: () => void): void
Listens for the input method stop event. This API uses a callback to return the result. Enables listening for the input method unbinding event. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.MiscServices.InputMethodFramework **System capability**: SystemCapability.MiscServices.InputMethodFramework
...@@ -157,22 +306,22 @@ Listens for the input method stop event. This API uses a callback to return the ...@@ -157,22 +306,22 @@ Listens for the input method stop event. This API uses a callback to return the
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| -------- | ------ | ---- | ------------------------------------------------------------ | | -------- | ------ | ---- | ------------------------------------------------------------ |
| type | string | Yes | Listening type.<br>Set it to **'inputStop'**, which indicates listening for the input method stop event.| | type | string | Yes | Listening type.<br>The value **'inputStop'** indicates the input method unbinding event.|
| callback | void | Yes | Callback used to return the result. | | callback | () => void | Yes | Callback used to return the result. |
**Example** **Example**
```js ```js
InputMethodEngine.getInputMethodEngine().on('inputStop', () => { inputMethodEngine.getInputMethodAbility().on('inputStop', () => {
console.log('inputMethodEngine inputStop'); console.log('inputMethodAbility inputStop');
}); });
``` ```
### off('inputStop')<sup>9+</sup> ### off('inputStop')<sup>9+</sup>
off(type: 'inputStop', callback: () => void): void off(type: 'inputStop', callback: () => void): void
Cancels listening for the input method stop event. This API uses a callback to return the result. Cancels listening for the input method stop event. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.MiscServices.InputMethodFramework **System capability**: SystemCapability.MiscServices.InputMethodFramework
...@@ -180,22 +329,22 @@ Cancels listening for the input method stop event. This API uses a callback to r ...@@ -180,22 +329,22 @@ Cancels listening for the input method stop event. This API uses a callback to r
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| -------- | ------ | ---- | ------------------------------------------------------------ | | -------- | ------ | ---- | ------------------------------------------------------------ |
| type | string | Yes | Listening type.<br>Set it to **'inputStop'**, which indicates listening for the input method stop event.| | type | string | Yes | Listening type.<br>The value **'inputStop'** indicates the input method unbinding event.|
| callback | void | Yes | Callback used to return the result. | | callback | () => void | Yes | Callback used to return the result. |
**Example** **Example**
```js ```js
InputMethodEngine.getInputMethodEngine().off('inputStop', () => { inputMethodEngine.getInputMethodAbility().off('inputStop', () => {
console.log('inputMethodEngine delete inputStop notification.'); console.log('inputMethodAbility delete inputStop notification.');
}); });
``` ```
### on('setCallingWindow')<sup>9+</sup> ### on('setCallingWindow')<sup>9+</sup>
on(type: 'setCallingWindow', callback: (wid:number) => void): void on(type: 'setCallingWindow', callback: (wid: number) => void): void
Listens for the window invocation setting event. This API uses a callback to return the result. Enables listening for the window invocation setting event. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.MiscServices.InputMethodFramework **System capability**: SystemCapability.MiscServices.InputMethodFramework
...@@ -203,22 +352,22 @@ Listens for the window invocation setting event. This API uses a callback to ret ...@@ -203,22 +352,22 @@ Listens for the window invocation setting event. This API uses a callback to ret
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| -------- | ------ | ---- | ------------------------------------------------------------ | | -------- | ------ | ---- | ------------------------------------------------------------ |
| type | string | Yes | Listening type.<br>Set it to **'setCallingWindow'**, which indicates listening for the window invocation setting event.| | type | string | Yes | Listening type.<br>The value **'setCallingWindow'** indicates the window invocation setting event.|
| callback | number | Yes | Window ID of the caller. | | callback | (wid: number) => void | Yes | Callback used to return the window ID of the caller. |
**Example** **Example**
```js ```js
InputMethodEngine.getInputMethodEngine().on('setCallingWindow', (wid) => { inputMethodEngine.getInputMethodAbility().on('setCallingWindow', (wid) => {
console.log('inputMethodEngine setCallingWindow'); console.log('inputMethodAbility setCallingWindow');
}); });
``` ```
### off('setCallingWindow')<sup>9+</sup> ### off('setCallingWindow')<sup>9+</sup>
off(type: 'setCallingWindow', callback: (wid:number) => void): void off(type: 'setCallingWindow', callback: (wid:number) => void): void
Cancels listening for the window invocation setting event. This API uses a callback to return the result. Disables listening for the window invocation setting event. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.MiscServices.InputMethodFramework **System capability**: SystemCapability.MiscServices.InputMethodFramework
...@@ -226,22 +375,22 @@ Cancels listening for the window invocation setting event. This API uses a callb ...@@ -226,22 +375,22 @@ Cancels listening for the window invocation setting event. This API uses a callb
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| -------- | ------ | ---- | ------------------------------------------------------------ | | -------- | ------ | ---- | ------------------------------------------------------------ |
| type | string | Yes | Listening type.<br>Set it to **'setCallingWindow'**, which indicates listening for the window invocation setting event.| | type | string | Yes | Listening type.<br>The value **'setCallingWindow'** indicates the window invocation setting event.|
| callback | number | Yes | Window ID of the caller. | | callback | (wid:number) => void | Yes | Callback used to return the window ID of the caller. |
**Example** **Example**
```js ```js
InputMethodEngine.getInputMethodEngine().off('setCallingWindow', () => { inputMethodEngine.getInputMethodAbility().off('setCallingWindow', () => {
console.log('inputMethodEngine delete setCallingWindow notification.'); console.log('inputMethodAbility delete setCallingWindow notification.');
}); });
``` ```
### on('keyboardShow'|'keyboardHide') ### on('keyboardShow'|'keyboardHide')<sup>9+</sup>
on(type: 'keyboardShow'|'keyboardHide', callback: () => void): void on(type: 'keyboardShow'|'keyboardHide', callback: () => void): void
Listens for an input method event. This API requires two parameters, the first one being napi_string and the second one being napi_function. If either of these parameters is not passed in, an exception is thrown. Enables listening for an input method event. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.MiscServices.InputMethodFramework **System capability**: SystemCapability.MiscServices.InputMethodFramework
...@@ -249,25 +398,25 @@ Listens for an input method event. This API requires two parameters, the first o ...@@ -249,25 +398,25 @@ Listens for an input method event. This API requires two parameters, the first o
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| -------- | ------ | ---- | ------------------------------------------------------------ | | -------- | ------ | ---- | ------------------------------------------------------------ |
| type | string | Yes | Listening type.<br>- The value **'keyboardShow'** means to listen for displaying of the keyboard.<br>- The value **'keyboardHide'** means to listen for hiding of the keyboard. | | type | string | Yes | Listening type.<br>- The value **'keyboardShow'** indicates the keyboard display event.<br>- The value **'keyboardHide'** indicates the keyboard hiding event. |
| callback | void | No | Callback used to return the result. | | callback | () => void | Yes | Callback used to return the result. |
**Example** **Example**
```js ```js
InputMethodEngine.on('keyboardShow', () => { inputMethodEngine.getInputMethodAbility().on('keyboardShow', () => {
console.log('inputMethodEngine keyboardShow.'); console.log('InputMethodAbility keyboardShow.');
}); });
InputMethodEngine.on('keyboardHide', () => { inputMethodEngine.getInputMethodAbility().on('keyboardHide', () => {
console.log('inputMethodEngine keyboardHide.'); console.log('InputMethodAbility keyboardHide.');
}); });
``` ```
### off('keyboardShow'|'keyboardHide') ### off('keyboardShow'|'keyboardHide')<sup>9+</sup>
off(type: 'keyboardShow'|'keyboardHide', callback?: () => void): void off(type: 'keyboardShow'|'keyboardHide', callback?: () => void): void
Cancels listening for an input method event. An exception is thrown in the following cases: (1) No parameter is passed; (2) Only one parameter is passed in, and it is not napi_string; (2) Two parameters are passed in, and the first parameter is not napi_string or the second parameter is not napi_function. If only one parameter is passed in, all listeners of the specified type will be canceled. If two parameters are passed in, the current listener of the specified type will be canceled. Disables listening for an input method event. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.MiscServices.InputMethodFramework **System capability**: SystemCapability.MiscServices.InputMethodFramework
...@@ -275,30 +424,75 @@ Cancels listening for an input method event. An exception is thrown in the follo ...@@ -275,30 +424,75 @@ Cancels listening for an input method event. An exception is thrown in the follo
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| -------- | ------ | ---- | ------------------------------------------------------------ | | -------- | ------ | ---- | ------------------------------------------------------------ |
| type | string | Yes | Listening type.<br>- The value **'keyboardShow'** means to listen for displaying of the keyboard.<br>- The value **'keyboardHide'** means to listen for hiding of the keyboard.| | type | string | Yes | Listening type.<br>The value **'keyboardShow'** indicates the keyboard display event.<br>The value **'keyboardHide'** indicates the keyboard hiding event.|
| callback | void | No | Callback used to return the result. | | callback | () => void | No | Callback used to return the result. |
**Example** **Example**
```js ```js
InputMethodEngine.off('keyboardShow', () => { inputMethodEngine.getInputMethodAbility().off('keyboardShow', () => {
console.log('inputMethodEngine delete keyboardShow notification.'); console.log('InputMethodAbility delete keyboardShow notification.');
}); });
InputMethodEngine.off('keyboardHide', () => { inputMethodEngine.getInputMethodAbility().off('keyboardHide', () => {
console.log('inputMethodEngine delete keyboardHide notification.'); console.log('InputMethodAbility delete keyboardHide notification.');
}); });
``` ```
### on('setSubtype')<sup>9+</sup>
on(type: 'setSubtype', callback: (inputMethodSubtype: InputMethodSubtype) => void): void
Enables listening for the input method subtype setting 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.<br>The value **'setSubtype'** indicates the input method subtype setting event.|
| callback | (inputMethodSubtype: [InputMethodSubtype](js-apis-inputmethod-subtype.md)) => void | Yes | Callback used to return the input method subtype. |
**Example**
```js
inputMethodEngine.getInputMethodAbility().on('setSubtype', (inputMethodSubtype) => {
console.log('InputMethodAbility setSubtype.');
});
```
### off('setSubtype')<sup>9+</sup>
off(type: 'setSubtype', callback?: (inputMethodSubtype: InputMethodSubtype) => void): void
Disables listening for the input method subtype setting 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.<br>The value **'setSubtype'** indicates the input method subtype setting event.|
| callback | (inputMethodSubtype: [InputMethodSubtype](js-apis-inputmethod-subtype.md)) => void | No | Callback used to return the input method subtype. |
**Example**
```js
inputMethodEngine.getInputMethodAbility().off('setSubtype', () => {
console.log('InputMethodAbility delete setSubtype notification.');
});
```
## KeyboardDelegate<a name="KeyboardDelegate"></a> ## KeyboardDelegate
In the following API examples, you must first use [createKeyboardDelegate](#createKeyboardDelegate) 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.
### on('keyDown'|'keyUp') ### on('keyDown'|'keyUp')
on(type: 'keyDown'|'keyUp', callback: (event: KeyEvent) => boolean): void on(type: 'keyDown'|'keyUp', callback: (event: KeyEvent) => boolean): void
Listens for a hard keyboard even. This API uses a callback to return the key information. This API requires two parameters, the first one being napi_string and the second one being napi_function. If either of these parameters is not passed in, an exception is thrown. Enables listening for a keyboard event. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.MiscServices.InputMethodFramework **System capability**: SystemCapability.MiscServices.InputMethodFramework
...@@ -306,75 +500,71 @@ Listens for a hard keyboard even. This API uses a callback to return the key inf ...@@ -306,75 +500,71 @@ Listens for a hard keyboard even. This API uses a callback to return the key inf
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| -------- | ------------------------------- | ---- | ------------------------------------------------------------ | | -------- | ------------------------------- | ---- | ------------------------------------------------------------ |
| type | string | Yes | Listening type.<br>- The value **'keyDown'** means to listen for pressing of a key.<br>- The value **'keyUp'** means to listen for releasing of a key.| | type | string | Yes | Listening type.<br>The value **'keyDown'** indicates the keydown event.<br>The value **'keyUp'** indicates the keyup event.|
| callback | [KeyEvent](#KeyEvent) | Yes| Callback used to return the key information.| | callback | (event: [KeyEvent](#keyevent)) => boolean | Yes| Callback used to return the key information.|
**Example** **Example**
```js ```js
KeyboardDelegate.on('keyUp', (keyEvent) => { inputMethodEngine.getKeyboardDelegate().on('keyUp', (keyEvent) => {
console.info('inputMethodEngine keyCode.(keyUp):' + JSON.stringify(keyEvent.keyCode)); console.info('inputMethodEngine keyCode.(keyUp):' + JSON.stringify(keyEvent.keyCode));
console.info('inputMethodEngine keyAction.(keyUp):' + JSON.stringify(keyEvent.keyAction)); console.info('inputMethodEngine keyAction.(keyUp):' + JSON.stringify(keyEvent.keyAction));
return true; return true;
}); });
KeyboardDelegate.on('keyDown', (keyEvent) => { inputMethodEngine.getKeyboardDelegate().on('keyDown', (keyEvent) => {
console.info('inputMethodEngine keyCode.(keyDown):' + JSON.stringify(keyEvent.keyCode)); console.info('inputMethodEngine keyCode.(keyDown):' + JSON.stringify(keyEvent.keyCode));
console.info('inputMethodEngine keyAction.(keyDown):' + JSON.stringify(keyEvent.keyAction)); console.info('inputMethodEngine keyAction.(keyDown):' + JSON.stringify(keyEvent.keyAction));
return true; return true;
}); });
``` ```
### off('keyDown'|'keyUp') ### off('keyDown'|'keyUp')
off(type: 'keyDown'|'keyUp', callback?: (event: KeyEvent) => boolean): void off(type: 'keyDown'|'keyUp', callback?: (event: KeyEvent) => boolean): void
Cancels listening for a hard keyboard even. An exception is thrown in the following cases: (1) No parameter is passed; (2) Only one parameter is passed in, and it is not napi_string; (2) Two parameters are passed in, and the first parameter is not napi_string or the second parameter is not napi_function. If only one parameter is passed in, all listeners of the specified type will be canceled. If two parameters are passed in, the current listener of the specified type will be canceled. Disables listening for a keyboard event. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.MiscServices.InputMethodFramework **System capability**: SystemCapability.MiscServices.InputMethodFramework
**Parameters** **Parameters**
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| -------- | --------------------- | ---- | ------------------------------------------------------------ | | -------- | ----------------------------------------- | ---- | ------------------------------------------------------------ |
| type | string | Yes | Listening type.<br>- The value **'keyDown'** means to listen for pressing of a key.<br>- The value **'keyUp'** means to listen for releasing of a key.| | type | string | Yes | Listening type.<br>The value **'keyDown'** indicates the keydown event.<br>The value **'keyUp'** indicates the keyup event.|
| callback | [KeyEvent](#KeyEvent) | No | Callback used to return the key information. | | callback | (event: [KeyEvent](#keyevent)) => boolean | No | Callback used to return the key information. |
**Example** **Example**
```js ```js
KeyboardDelegate.off('keyUp', (keyEvent) => { inputMethodEngine.getKeyboardDelegate().off('keyUp', (keyEvent) => {
console.log('delete keyUp notification.'); console.log('delete keyUp notification.');
return true; return true;
}); });
KeyboardDelegate.off('keyDown', (keyEvent) => { inputMethodEngine.getKeyboardDelegate().off('keyDown', (keyEvent) => {
console.log('delete keyDown notification.'); console.log('delete keyDown notification.');
return true; return true;
}); });
``` ```
### on('cursorContextChange') ### on('cursorContextChange')
on(type: 'cursorContextChange', callback: (x: number, y:number, height:number) => void): void on(type: 'cursorContextChange', callback: (x: number, y:number, height:number) => void): void
Listens for cursor context changes. This API uses a callback to return the cursor information. This API requires two parameters, the first one being napi_string and the second one being napi_function. If either of these parameters is not passed in, an exception is thrown. Enables listening for the cursor change event. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.MiscServices.InputMethodFramework **System capability**: SystemCapability.MiscServices.InputMethodFramework
**Parameters** **Parameters**
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| -------- | ------ | ---- | ------------------------------------------------------------ | | -------- | ---------------------------------------------- | ---- | ------------------------------------------------------------ |
| type | string | Yes | Listening type.<br>Set it to **'cursorContextChange'**, which indicates listening for cursor context changes.| | type | string | Yes | Listening type.<br>The value **'cursorContextChange'** indicates the cursor change event.|
| callback | number | Yes | Callback used to return the cursor information. | | callback | (x: number, y: number, height: number) => void | Yes | Callback used to return the cursor information.<br>- **x**: x coordinate of the top of the cursor.<br>- **y**: x coordinate of the bottom of the cursor.<br>- **height**: height of the cursor.|
**Example**
**Example**
```js ```js
KeyboardDelegate.on('cursorContextChange', (x, y, height) => { inputMethodEngine.getKeyboardDelegate().on('cursorContextChange', (x, y, height) => {
console.log('inputMethodEngine cursorContextChange x:' + x); console.log('inputMethodEngine cursorContextChange x:' + x);
console.log('inputMethodEngine cursorContextChange y:' + y); console.log('inputMethodEngine cursorContextChange y:' + y);
console.log('inputMethodEngine cursorContextChange height:' + height); console.log('inputMethodEngine cursorContextChange height:' + height);
...@@ -383,24 +573,24 @@ KeyboardDelegate.on('cursorContextChange', (x, y, height) => { ...@@ -383,24 +573,24 @@ KeyboardDelegate.on('cursorContextChange', (x, y, height) => {
### off('cursorContextChange') ### off('cursorContextChange')
off(type: 'cursorContextChange', callback?: (x: number, y:number, height:number) => void): void off(type: 'cursorContextChange', callback?: (x: number, y: number, height: number) => void): void
Cancels listening for cursor context changes. An exception is thrown in the following cases: (1) No parameter is passed; (2) Only one parameter is passed in, and it is not napi_string; (2) Two parameters are passed in, and the first parameter is not napi_string or the second parameter is not napi_function. If only one parameter is passed in, all listeners of the specified type will be canceled. If two parameters are passed in, the current listener of the specified type will be canceled. Cancels listening for cursor context changes. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.MiscServices.InputMethodFramework **System capability**: SystemCapability.MiscServices.InputMethodFramework
**Parameters** **Parameters**
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| -------- | ------ | ---- | ------------------------------------------------------------ | | -------- | -------------------------------------------- | ---- | ------------------------------------------------------------ |
| type | string | Yes | Listening type.<br>Set it to **'cursorContextChange'**, which indicates listening for cursor context changes.| | type | string | Yes | Listening type.<br>The value **'cursorContextChange'** indicates the cursor change event.|
| callback | number | No | Callback used to return the cursor information. | | callback | (x: number, y:number, height:number) => void | No | Callback used to return the cursor information.<br>- **x**: x coordinate of the top of the cursor.<br>- **y**: x coordinate of the bottom of the cursor.<br>- **height**: height of the cursor.<br>|
**Example** **Example**
```js ```js
KeyboardDelegate.off('cursorContextChange', (x, y, height) => { inputMethodEngine.getKeyboardDelegate().off('cursorContextChange', (x, y, height) => {
console.log('delete cursorContextChange notification.'); console.log('delete cursorContextChange notification.');
}); });
``` ```
...@@ -408,21 +598,21 @@ KeyboardDelegate.off('cursorContextChange', (x, y, height) => { ...@@ -408,21 +598,21 @@ KeyboardDelegate.off('cursorContextChange', (x, y, height) => {
on(type: 'selectionChange', callback: (oldBegin: number, oldEnd: number, newBegin: number, newEnd: number) => void): void on(type: 'selectionChange', callback: (oldBegin: number, oldEnd: number, newBegin: number, newEnd: number) => void): void
Listens for text selection changes. This API uses a callback to return the text selection information. This API requires two parameters, the first one being napi_string and the second one being napi_function. If either of these parameters is not passed in, an exception is thrown. Enables listening for the text selection change event. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.MiscServices.InputMethodFramework **System capability**: SystemCapability.MiscServices.InputMethodFramework
**Parameters** **Parameters**
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| -------- | ------ | ---- | ------------------------------------------------------------ | | -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
| type | string | Yes | Listening type.<br>Set it to **'selectionChange'**, which indicates listening for text selection changes.| | type | string | Yes | Listening type.<br>The value **'selectionChange'** indicates the text selection change event.|
| callback | number | Yes | Callback used to return the text selection information. | | callback | (oldBegin: number, oldEnd: number, newBegin: number, newEnd: number) => void | Yes | Callback used to return the text selection information.<br>- **oldBegin**: start of the selected text before the change.<br>- **oldEnd**: end of the selected text before the change.<br>- **newBegin**: start of the selected text after the change.<br>- **newEnd**: end of the selected text after the change.|
**Example** **Example**
```js ```js
KeyboardDelegate.on('selectionChange', (oldBegin, oldEnd, newBegin, newEnd) => { inputMethodEngine.getKeyboardDelegate().on('selectionChange', (oldBegin, oldEnd, newBegin, newEnd) => {
console.log('inputMethodEngine beforeEach selectionChange oldBegin:' + oldBegin); console.log('inputMethodEngine beforeEach selectionChange oldBegin:' + oldBegin);
console.log('inputMethodEngine beforeEach selectionChange oldEnd:' + oldEnd); console.log('inputMethodEngine beforeEach selectionChange oldEnd:' + oldEnd);
console.log('inputMethodEngine beforeEach selectionChange newBegin:' + newBegin); console.log('inputMethodEngine beforeEach selectionChange newBegin:' + newBegin);
...@@ -434,21 +624,21 @@ KeyboardDelegate.on('selectionChange', (oldBegin, oldEnd, newBegin, newEnd) => { ...@@ -434,21 +624,21 @@ KeyboardDelegate.on('selectionChange', (oldBegin, oldEnd, newBegin, newEnd) => {
off(type: 'selectionChange', callback?: (oldBegin: number, oldEnd: number, newBegin: number, newEnd: number) => void): void off(type: 'selectionChange', callback?: (oldBegin: number, oldEnd: number, newBegin: number, newEnd: number) => void): void
Cancels listening for text selection changes. An exception is thrown in the following cases: (1) No parameter is passed; (2) Only one parameter is passed in, and it is not napi_string; (2) Two parameters are passed in, and the first parameter is not napi_string or the second parameter is not napi_function. If only one parameter is passed in, all listeners of the specified type will be canceled. If two parameters are passed in, the current listener of the specified type will be canceled. Cancels listening for text selection changes. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.MiscServices.InputMethodFramework **System capability**: SystemCapability.MiscServices.InputMethodFramework
**Parameters** **Parameters**
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| -------- | ------ | ---- | ------------------------------------------------------------ | | -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
| type | string | Yes | Listening type.<br>Set it to **'selectionChange'**, which indicates listening for text selection changes.| | type | string | Yes | Listening type.<br>The value **'selectionChange'** indicates the text selection change event.|
| callback | number | No | Callback used to return the text selection information. | | callback | (oldBegin: number, oldEnd: number, newBegin: number, newEnd: number) => void | No | Callback used to return the text selection information.<br>- **oldBegin**: start of the selected text before the change.<br>- **oldEnd**: end of the selected text before the change.<br>- **newBegin**: start of the selected text after the change.<br>- **newEnd**: end of the selected text after the change.<br>|
**Example** **Example**
```js ```js
KeyboardDelegate.off('selectionChange', (oldBegin, oldEnd, newBegin, newEnd) => { inputMethodEngine.getKeyboardDelegate().off('selectionChange', (oldBegin, oldEnd, newBegin, newEnd) => {
console.log('delete selectionChange notification.'); console.log('delete selectionChange notification.');
}); });
``` ```
...@@ -458,7 +648,7 @@ KeyboardDelegate.off('selectionChange', (oldBegin, oldEnd, newBegin, newEnd) => ...@@ -458,7 +648,7 @@ KeyboardDelegate.off('selectionChange', (oldBegin, oldEnd, newBegin, newEnd) =>
on(type: 'textChange', callback: (text: string) => void): void on(type: 'textChange', callback: (text: string) => void): void
Listens for text changes. This API uses a callback to return the current text content. This API requires two parameters, the first one being napi_string and the second one being napi_function. If either of these parameters is not passed in, an exception is thrown. Enables listening for the text change event. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.MiscServices.InputMethodFramework **System capability**: SystemCapability.MiscServices.InputMethodFramework
...@@ -466,13 +656,13 @@ Listens for text changes. This API uses a callback to return the current text co ...@@ -466,13 +656,13 @@ Listens for text changes. This API uses a callback to return the current text co
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| -------- | ------ | ---- | ------------------------------------------------------------ | | -------- | ------ | ---- | ------------------------------------------------------------ |
| type | string | Yes | Listening type.<br>Set it to **'textChange'**, which indicates listening for text changes.| | type | string | Yes | Listening type.<br>The value **'textChange'** indicates the text change event.|
| callback | string | Yes | Callback used to return the current text content. | | callback | (text: string) => void | Yes | Callback used to return the text content. |
**Example** **Example**
```js ```js
KeyboardDelegate.on('textChange', (text) => { inputMethodEngine.getKeyboardDelegate().on('textChange', (text) => {
console.log('inputMethodEngine textChange. text:' + text); console.log('inputMethodEngine textChange. text:' + text);
}); });
``` ```
...@@ -481,34 +671,34 @@ KeyboardDelegate.on('textChange', (text) => { ...@@ -481,34 +671,34 @@ KeyboardDelegate.on('textChange', (text) => {
off(type: 'textChange', callback?: (text: string) => void): void off(type: 'textChange', callback?: (text: string) => void): void
Cancels listening for text changes. An exception is thrown in the following cases: (1) No parameter is passed; (2) Only one parameter is passed in, and it is not napi_string; (2) Two parameters are passed in, and the first parameter is not napi_string or the second parameter is not napi_function. If only one parameter is passed in, all listeners of the specified type will be canceled. If two parameters are passed in, the current listener of the specified type will be canceled. Cancels listening for text changes. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.MiscServices.InputMethodFramework **System capability**: SystemCapability.MiscServices.InputMethodFramework
**Parameters** **Parameters**
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| -------- | ------ | ---- | ------------------------------------------------------------ | | -------- | ------ | ---- | ------------------------------------------------------------ |
| type | string | Yes | Listening type.<br>Set it to **'textChange'**, which indicates listening for text changes.| | type | string | Yes | Listening type.<br>The value **'textChange'** indicates the text change event.|
| callback | string | No | Callback used to return the current text content. | | callback | (text: string) => void | No | Callback used to return the text content.|
**Example** **Example**
```js ```js
keyboardDelegate.off('textChange', (text) => { inputMethodEngine.getKeyboardDelegate().off('textChange', (text) => {
console.log('delete textChange notification. text:' + text); console.log('delete textChange notification. text:' + text);
}); });
``` ```
## KeyboardController<a name="KeyboardController"></a> ## KeyboardController
In the following API examples, you must first use [inputStart](#inputStart) 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.
### hideKeyboard ### hide<sup>9+</sup>
hideKeyboard(callback: AsyncCallback&lt;void&gt;): void hide(callback: AsyncCallback&lt;void&gt;): void
Hides the keyboard. This API uses an asynchronous callback to return the result. If the required parameter is not passed in, an exception is thrown. Hides the keyboard. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.MiscServices.InputMethodFramework **System capability**: SystemCapability.MiscServices.InputMethodFramework
...@@ -516,26 +706,33 @@ Hides the keyboard. This API uses an asynchronous callback to return the result. ...@@ -516,26 +706,33 @@ Hides the keyboard. This API uses an asynchronous callback to return the result.
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| -------- | ---------------------- | ---- | -------- | | -------- | ---------------------- | ---- | -------- |
| callback | AsyncCallback&lt;void> | No | Callback used to return the result.| | callback | AsyncCallback&lt;void> | Yes | Callback used to return the result. If the operation is successful, **err** is **undefined**. Otherwise, **err** is an error object.|
**Example** **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. |
**Example**
```js ```js
KeyboardController.hideKeyboard((err) => { KeyboardController.hide((err) => {
if (err === undefined) { if (err === undefined) {
console.error('hideKeyboard callback result---err: ' + err.msg); console.error('hide err: ' + JSON.stringify(err));
return; return;
} }
console.log('hideKeyboard callback.'); console.log('hide success.');
}); });
``` ```
### hideKeyboard ### hide<sup>9+</sup>
hideKeyboard(): Promise&lt;void&gt; hide(): Promise&lt;void&gt;
Hides the keyboard. This API uses a promise to return the result. If any parameter is passed in, an exception is thrown. Hides the keyboard. This API uses a promise to return the result.
**System capability**: SystemCapability.MiscServices.InputMethodFramework **System capability**: SystemCapability.MiscServices.InputMethodFramework
...@@ -545,88 +742,182 @@ Hides the keyboard. This API uses a promise to return the result. If any paramet ...@@ -545,88 +742,182 @@ Hides the keyboard. This API uses a promise to return the result. If any paramet
| ---------------- | ------------------------- | | ---------------- | ------------------------- |
| Promise&lt;void> | Promise that returns no value.| | Promise&lt;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. |
**Example** **Example**
```js ```js
async function InputMethodEngine() { KeyboardController.hide().then(() => {
await KeyboardController.hideKeyboard().then(() => { console.info('hide success.');
console.info('hideKeyboard promise.'); }).catch((err) => {
}).catch((err) => { console.info('hide err: ' + JSON.stringify(err));
console.info('hideKeyboard promise err: ' + err.msg); });
});
}
``` ```
## TextInputClient<a name="TextInputClient"></a> ### hideKeyboard<sup>(deprecated)</sup>
In the following API examples, you must first use [inputStart](#inputStart) to obtain a **TextInputClient** instance, and then call the APIs using the obtained instance. hideKeyboard(callback: AsyncCallback&lt;void&gt;): void
### getForward
getForward(length:number, callback: AsyncCallback&lt;string&gt;): void Hides the keyboard. This API uses an asynchronous callback to return the result.
Obtains the specific-length text before the cursor. This API uses an asynchronous callback to return the result. If the required two parameters are not passed in, an exception is thrown. > **NOTE**
>
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [hide](#hide9).
**System capability**: SystemCapability.MiscServices.InputMethodFramework **System capability**: SystemCapability.MiscServices.InputMethodFramework
**Parameters** **Parameters**
| Name| Type| Mandatory| Description| | Name | Type | Mandatory| Description |
| -------- | -------- | -------- | -------- | | -------- | ---------------------- | ---- | -------- |
| length | number | Yes| Text length.| | callback | AsyncCallback&lt;void> | Yes | Callback used to return the result. If the operation is successful, **err** is **undefined**. Otherwise, **err** is an error object.|
| callback | AsyncCallback&lt;string&gt; | Yes| Callback used to return the text.|
**Example** **Example**
```js ```js
var length = 1; KeyboardController.hideKeyboard((err) => {
TextInputClient.getForward(length, (err, text) => {
if (err === undefined) { if (err === undefined) {
console.error('getForward callback result---err: ' + err.msg); console.error('hideKeyboard err: ' + JSON.stringify(err));
return; return;
} }
console.log('getForward callback result---text: ' + text); console.log('hideKeyboard success.');
}); });
``` ```
### getForward
getForward(length:number): Promise&lt;string&gt; ### hideKeyboard<sup>(deprecated)</sup>
Obtains the specific-length text before the cursor. This API uses a promise to return the result. If the required parameter is not passed in, an exception is thrown. hideKeyboard(): Promise&lt;void&gt;
**System capability**: SystemCapability.MiscServices.InputMethodFramework Hides the keyboard. This API uses a promise to return the result.
**Parameters** > **NOTE**
>
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [hide](#hide9-1).
| Name| Type| Mandatory| Description| **System capability**: SystemCapability.MiscServices.InputMethodFramework
| -------- | -------- | -------- | -------- |
| length | number | Yes| Text length.|
**Return value** **Return value**
| Type | Description | | Type | Description |
| ------------------------------- | ------------------------------------------------------------ | | ---------------- | ------------------------- |
| Promise&lt;string&gt; | Promise used to return the text. | | Promise&lt;void> | Promise that returns no value.|
**Example** **Example**
```js ```js
async function InputMethodEngine() { KeyboardController.hideKeyboard().then(() => {
var length = 1; console.info('hideKeyboard success.');
await TextInputClient.getForward(length).then((text) => { }).catch((err) => {
console.info('getForward promise result---res: ' + text); console.info('hideKeyboard err: ' + JSON.stringify(err));
}).catch((err) => { });
console.error('getForward promise err: ' + err.msg); ```
## InputClient<sup>9+</sup>
In the following API examples, you must first use **[on('inputStart')](#oninputstart9)** to obtain an **InputClient** instance, and then call the APIs using the obtained instance.
### sendKeyFunction<sup>9+</sup>
sendKeyFunction(action:number, callback: AsyncCallback&lt;boolean&gt;): void
Sends the function key. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.MiscServices.InputMethodFramework
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| action | number | Yes| Action of the function key.<br>**0**: invalid key.<br>**1**: confirm key (Enter key).|
| callback | AsyncCallback&lt;boolean&gt; | 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. |
**Example**
```js
let action = 1;
try {
InputClient.sendKeyFunction(action, (err, result) => {
if (err) {
console.error('sendKeyFunction err: ' + JSON.stringify(err));
return;
}
if (result) {
console.info('Success to sendKeyFunction. ');
} else {
console.error('Failed to sendKeyFunction. ');
}
}); });
} catch (err) {
console.error('sendKeyFunction err: ' + JSON.stringify(err));
}
```
### sendKeyFunction<sup>9+</sup>
sendKeyFunction(action: number): Promise&lt;boolean&gt;
Sends the function key. This API uses a promise to return the result.
**System capability**: SystemCapability.MiscServices.InputMethodFramework
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| action | number | Yes| Action of the function key.<br>**0**: invalid key.<br>**1**: confirm key (Enter key).|
**Return value**
| Type | Description |
| ------------------------------- | ------------------------------------------------------------ |
| Promise&lt;boolean&gt; | 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 |
| -------- | -------------------------- |
| 12800003 | Input method client error. |
**Example**
```js
let action = 1;
try {
InputClient.sendKeyFunction(action).then((result) => {
if (result) {
console.info('Success to sendKeyFunction. ');
} else {
console.error('Failed to sendKeyFunction. ');
} }
``` }).catch((err) => {
console.error('sendKeyFunction err:' + JSON.stringify(err));
});
} catch (err) {
console.error('sendKeyFunction err: ' + JSON.stringify(err));
}
```
### getBackward ### getForward<sup>9+</sup>
getBackward(length:number, callback: AsyncCallback&lt;string&gt;): void getForward(length:number, callback: AsyncCallback&lt;string&gt;): void
Obtains the specific-length text after the cursor. This API uses an asynchronous callback to return the result. If the required two parameters are not passed in, an exception is thrown. Obtains the specific-length text before the cursor. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.MiscServices.InputMethodFramework **System capability**: SystemCapability.MiscServices.InputMethodFramework
...@@ -635,26 +926,39 @@ Obtains the specific-length text after the cursor. This API uses an asynchronous ...@@ -635,26 +926,39 @@ Obtains the specific-length text after the cursor. This API uses an asynchronous
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| length | number | Yes| Text length.| | length | number | Yes| Text length.|
| callback | AsyncCallback&lt;string&gt; | Yes| Callback used to return the text.| | callback | AsyncCallback&lt;string&gt; | Yes| Callback used to return the result. If the operation is successful, **err** is **undefined** and **data** is the obtained text. Otherwise, **err** is an error object.|
**Error codes**
For details about the error codes, see [Input Method Framework Error Codes](../errorcodes/errorcode-inputmethod-framework.md).
| Error Code ID| Error Message |
| -------- | ------------------------------ |
| 12800003 | Input method client error. |
| 12800006 | Input method controller error. |
**Example** **Example**
```js ```js
var length = 1; let length = 1;
TextInputClient.getBackward(length, (err, text) => { try {
if (err === undefined) { InputClient.getForward(length, (err, text) => {
console.error('getBackward callback result---err: ' + err.msg); if (err) {
console.error('getForward err: ' + JSON.stringify(err));
return; return;
} }
console.log('getBackward callback result---text: ' + text); console.log('getForward result: ' + text);
}); });
``` } catch (err) {
console.error('getForward err: ' + JSON.stringify(err));
}
```
### getBackward ### getForward<sup>9+</sup>
getBackward(length:number): Promise&lt;string&gt; getForward(length:number): Promise&lt;string&gt;
Obtains the specific-length text after the cursor. This API uses a promise to return the result. If the required parameter is not passed in, an exception is thrown. Obtains the specific-length text before the cursor. This API uses a promise to return the result.
**System capability**: SystemCapability.MiscServices.InputMethodFramework **System capability**: SystemCapability.MiscServices.InputMethodFramework
...@@ -668,26 +972,37 @@ Obtains the specific-length text after the cursor. This API uses a promise to re ...@@ -668,26 +972,37 @@ Obtains the specific-length text after the cursor. This API uses a promise to re
| Type | Description | | Type | Description |
| ------------------------------- | ------------------------------------------------------------ | | ------------------------------- | ------------------------------------------------------------ |
| Promise&lt;string&gt; | Promise used to return the text. | | Promise&lt;string&gt; | Promise used to return the specific-length text before the cursor. |
**Error codes**
For details about the error codes, see [Input Method Framework Error Codes](../errorcodes/errorcode-inputmethod-framework.md).
| Error Code ID| Error Message |
| -------- | ------------------------------ |
| 12800003 | Input method client error. |
| 12800006 | Input method controller error. |
**Example** **Example**
```js ```js
async function InputMethodEngine() { let length = 1;
var length = 1; try {
await TextInputClient.getBackward(length).then((text) => { InputClient.getForward(length).then((text) => {
console.info('getBackward promise result---res: ' + text); console.info('getForward resul: ' + text);
}).catch((err) => { }).catch((err) => {
console.error('getBackward promise err: ' + err.msg); console.error('getForward err: ' + JSON.stringify(err));
}); });
} } catch (err) {
``` console.error('getForward err: ' + JSON.stringify(err));
}
```
### deleteForward ### getBackward<sup>9+</sup>
deleteForward(length:number, callback: AsyncCallback&lt;boolean&gt;): void getBackward(length:number, callback: AsyncCallback&lt;string&gt;): void
Deletes the fixed-length text before the cursor. This API uses an asynchronous callback to return the result. If the required two parameters are not passed in, an exception is thrown. Obtains the specific-length text after the cursor. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.MiscServices.InputMethodFramework **System capability**: SystemCapability.MiscServices.InputMethodFramework
...@@ -696,165 +1011,221 @@ Deletes the fixed-length text before the cursor. This API uses an asynchronous c ...@@ -696,165 +1011,221 @@ Deletes the fixed-length text before the cursor. This API uses an asynchronous c
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| length | number | Yes| Text length.| | length | number | Yes| Text length.|
| callback | AsyncCallback&lt;boolean&gt; | Yes| Callback used to return the result.| | callback | AsyncCallback&lt;string&gt; | Yes| Callback used to return the result. If the operation is successful, **err** is **undefined** and **data** is the obtained text. Otherwise, **err** is an error object.|
**Error codes**
For details about the error codes, see [Input Method Framework Error Codes](../errorcodes/errorcode-inputmethod-framework.md).
| Error Code ID| Error Message |
| -------- | ------------------------------ |
| 12800003 | Input method client error. |
| 12800006 | Input method controller error. |
**Example** **Example**
```js ```js
var length = 1; let length = 1;
TextInputClient.deleteForward(length, (err, result) => { try {
if (err === undefined) { InputClient.getBackward(length, (err, text) => {
console.error('deleteForward callback result---err: ' + err.msg); if (err) {
console.error('getBackward result: ' + JSON.stringify(err));
return; return;
} }
if (result) { console.log('getBackward result---text: ' + text);
console.info('Success to deleteForward.(callback) ');
} else {
console.error('Failed to deleteForward.(callback) ');
}
}); });
``` } catch (err) {
### deleteForward console.error('getBackward result: ' + JSON.stringify(err));
}
```
deleteForward(length:number): Promise&lt;boolean&gt; ### getBackward<sup>9+</sup>
getBackward(length:number): Promise&lt;string&gt;
Deletes the fixed-length text before the cursor. This API uses a promise to return the result. If the required parameter is not passed in, an exception is thrown. Obtains the specific-length text after the cursor. This API uses a promise to return the result.
**System capability**: SystemCapability.MiscServices.InputMethodFramework **System capability**: SystemCapability.MiscServices.InputMethodFramework
**Parameters** **Parameters**
| Name| Type | Mandatory| Description | | Name| Type| Mandatory| Description|
| ------ | ------ | ---- | ---------- | | -------- | -------- | -------- | -------- |
| length | number | Yes | Text length.| | length | number | Yes| Text length.|
**Return value** **Return value**
| Type | Description | | Type | Description |
| ---------------------- | -------------- | | ------------------------------- | ------------------------------------------------------------ |
| Promise&lt;boolean&gt; | Promise used to return the result.| | Promise&lt;string&gt; | Promise used to return the specific-length text after the cursor. |
**Error codes**
For details about the error codes, see [Input Method Framework Error Codes](../errorcodes/errorcode-inputmethod-framework.md).
| Error Code ID| Error Message |
| -------- | ------------------------------ |
| 12800003 | Input method client error. |
| 12800006 | Input method controller error. |
**Example** **Example**
```js ```js
async function InputMethodEngine() { let length = 1;
var length = 1; try {
await TextInputClient.deleteForward(length).then((result) => { InputClient.getBackward(length).then((text) => {
if (result) { console.info('getBackward result: ' + text);
console.info('Success to deleteForward.(promise) ');
} else {
console.error('Failed to deleteForward.(promise) ');
}
}).catch((err) => { }).catch((err) => {
console.error('deleteForward promise err: ' + err.msg); console.error('getBackward err: ' + JSON.stringify(err));
}); });
} catch (err) {
console.error('getBackward err: ' + JSON.stringify(err));
} }
``` ```
### deleteBackward ### deleteForward<sup>9+</sup>
deleteBackward(length:number, callback: AsyncCallback&lt;boolean&gt;): void deleteForward(length:number, callback: AsyncCallback&lt;boolean&gt;): void
Deletes the fixed-length text after the cursor. This API uses an asynchronous callback to return the result. If the required two parameters are not passed in, an exception is thrown. Deletes the fixed-length text before the cursor. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.MiscServices.InputMethodFramework **System capability**: SystemCapability.MiscServices.InputMethodFramework
**Parameters** **Parameters**
| Name | Type | Mandatory| Description | | Name| Type| Mandatory| Description|
| -------- | ---------------------------- | ---- | -------------- | | -------- | -------- | -------- | -------- |
| length | number | Yes | Text length. | | length | number | Yes| Text length.|
| callback | AsyncCallback&lt;boolean&gt; | Yes | Callback used to return the result.| | callback | AsyncCallback&lt;boolean&gt; | 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** **Error codes**
For details about the error codes, see [Input Method Framework Error Codes](../errorcodes/errorcode-inputmethod-framework.md).
| Error Code ID| Error Message |
| -------- | -------------------------- |
| 12800002 | Input method engine error. |
| 12800003 | Input method client error. |
**Example**
```js ```js
var length = 1; let length = 1;
TextInputClient.deleteBackward(length, (err, result) => { try {
if (err === undefined) { InputClient.deleteForward(length, (err, result) => {
console.error('deleteBackward callback result---err: ' + err.msg); if (err) {
console.error('deleteForward result: ' + JSON.stringify(err));
return; return;
} }
if (result) { if (result) {
console.info('Success to deleteBackward.(callback) '); console.info('Success to deleteForward. ');
} else { } else {
console.error('Failed to deleteBackward.(callback) '); console.error('Failed to deleteForward. ');
} }
}); });
} catch (err) {
console.error('deleteForward result: ' + JSON.stringify(err));
}
``` ```
### deleteBackward ### deleteForward<sup>9+</sup>
deleteBackward(length:number): Promise&lt;boolean&gt; deleteForward(length:number): Promise&lt;boolean&gt;
Deletes the fixed-length text after the cursor. This API uses an asynchronous callback to return the result. If the required two parameters are not passed in, an exception is thrown. Deletes the fixed-length text before the cursor. This API uses a promise to return the result.
**System capability**: SystemCapability.MiscServices.InputMethodFramework **System capability**: SystemCapability.MiscServices.InputMethodFramework
**Parameters** **Parameters**
| Name| Type| Mandatory| Description| | Name| Type | Mandatory| Description |
| -------- | -------- | -------- | -------- | | ------ | ------ | ---- | ---------- |
| length | number | Yes| Text length.| | length | number | Yes | Text length.|
**Return value** **Return value**
| Type | Description | | Type | Description |
| ------------------------------- | ------------------------------------------------------------ | | ---------------------- | -------------- |
| Promise&lt;boolean&gt; | Promise used to return the result. | | Promise&lt;boolean&gt; | 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 |
| -------- | -------------------------- |
| 12800002 | Input method engine error. |
| 12800003 | Input method client error. |
**Example** **Example**
```js ```js
async function InputMethodEngine() { let length = 1;
var length = 1; try {
await TextInputClient.deleteBackward(length).then((result) => { InputClient.deleteForward(length).then((result) => {
if (result) { if (result) {
console.info('Success to deleteBackward.(promise) '); console.info('Success to deleteForward. ');
} else { } else {
console.error('Failed to deleteBackward.(promise) '); console.error('Failed to deleteForward. ');
} }
}).catch((err) => { }).catch((err) => {
console.error('deleteBackward promise err: ' + err.msg); console.error('deleteForward err: ' + JSON.stringify(err));
}); });
} catch (err) {
console.error('deleteForward err: ' + JSON.stringify(err));
} }
``` ```
### sendKeyFunction
sendKeyFunction(action:number, callback: AsyncCallback&lt;boolean&gt;): void ### deleteBackward<sup>9+</sup>
deleteBackward(length:number, callback: AsyncCallback&lt;boolean&gt;): void
Sets the Enter key to send the text to its target. This API uses an asynchronous callback to return the result. If the required two parameters are not passed in, an exception is thrown. Deletes the fixed-length text after the cursor. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.MiscServices.InputMethodFramework **System capability**: SystemCapability.MiscServices.InputMethodFramework
**Parameters** **Parameters**
| Name| Type| Mandatory| Description| | Name | Type | Mandatory| Description |
| -------- | -------- | -------- | -------- | | -------- | ---------------------------- | ---- | -------------- |
| action | number | Yes| Edit box attribute.| | length | number | Yes | Text length. |
| callback | AsyncCallback&lt;boolean&gt; | Yes| Callback used to return the result.| | callback | AsyncCallback&lt;boolean&gt; | 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** **Error codes**
For details about the error codes, see [Input Method Framework Error Codes](../errorcodes/errorcode-inputmethod-framework.md).
| Error Code ID| Error Message |
| -------- | -------------------------- |
| 12800002 | Input method engine error. |
| 12800003 | Input method client error. |
**Example**
```js ```js
TextInputClient.sendKeyFunction(keyFunction, (err, result) => { let length = 1;
if (err === undefined) { try {
console.error('sendKeyFunction callback result---err: ' + err.msg); InputClient.deleteBackward(length, (err, result) => {
if (err) {
console.error('deleteBackward err: ' + JSON.stringify(err));
return; return;
} }
if (result) { if (result) {
console.info('Success to sendKeyFunction.(callback) '); console.info('Success to deleteBackward. ');
} else { } else {
console.error('Failed to sendKeyFunction.(callback) '); console.error('Failed to deleteBackward. ');
} }
}); });
} catch (err) {
console.error('deleteBackward err: ' + JSON.stringify(err));
}
``` ```
### sendKeyFunction ### deleteBackward<sup>9+</sup>
sendKeyFunction(action:number): Promise&lt;boolean&gt; deleteBackward(length:number): Promise&lt;boolean&gt;
Sets the Enter key to send the text to its target. This API uses a promise to return the result. If the required parameter is not passed in, an exception is thrown. Deletes the fixed-length text after the cursor. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.MiscServices.InputMethodFramework **System capability**: SystemCapability.MiscServices.InputMethodFramework
...@@ -862,35 +1233,43 @@ Sets the Enter key to send the text to its target. This API uses a promise to re ...@@ -862,35 +1233,43 @@ Sets the Enter key to send the text to its target. This API uses a promise to re
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| action | number | Yes| Edit box attribute.| | length | number | Yes| Text length.|
**Return value** **Return value**
| Type | Description | | Type | Description |
| ------------------------------- | ------------------------------------------------------------ | | ------------------------------- | ------------------------------------------------------------ |
| Promise&lt;boolean&gt; | Promise used to return the result. | | Promise&lt;boolean&gt; | Promise used to return the result. The value **true** means that the deletion 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 |
| -------- | -------------------------- |
| 12800002 | Input method engine error. |
| 12800003 | Input method client error. |
**Example** **Example**
```js ```js
async function InputMethodEngine() { let length = 1;
await client.sendKeyFunction(keyFunction).then((result) => { InputClient.deleteBackward(length).then((result) => {
if (result) { if (result) {
console.info('Success to sendKeyFunction.(promise) '); console.info('Success to deleteBackward. ');
} else { } else {
console.error('Failed to sendKeyFunction.(promise) '); console.error('Failed to deleteBackward. ');
}
}).catch((err) => {
console.error('sendKeyFunction promise err:' + err.msg);
});
} }
``` }).catch((err) => {
console.error('deleteBackward err: ' + JSON.stringify(err));
});
```
### insertText ### insertText<sup>9+</sup>
insertText(text:string, callback: AsyncCallback&lt;boolean&gt;): void insertText(text:string, callback: AsyncCallback&lt;boolean&gt;): void
Inserts text. This API uses an asynchronous callback to return the result. If the required two parameters are not passed in, an exception is thrown. Inserts text. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.MiscServices.InputMethodFramework **System capability**: SystemCapability.MiscServices.InputMethodFramework
...@@ -899,29 +1278,38 @@ Inserts text. This API uses an asynchronous callback to return the result. If th ...@@ -899,29 +1278,38 @@ Inserts text. This API uses an asynchronous callback to return the result. If th
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| text | string | Yes| Text to insert.| | text | string | Yes| Text to insert.|
| callback | AsyncCallback&lt;boolean&gt; | Yes| Callback used to return the result.| | callback | AsyncCallback&lt;boolean&gt; | 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 |
| -------- | -------------------------- |
| 12800002 | Input method engine error. |
| 12800003 | Input method client error. |
**Example** **Example**
```js ```js
TextInputClient.insertText('test', (err, result) => { InputClient.insertText('test', (err, result) => {
if (err === undefined) { if (err) {
console.error('insertText callback result---err: ' + err.msg); console.error('insertText err: ' + JSON.stringify(err));
return; return;
} }
if (result) { if (result) {
console.info('Success to insertText.(callback) '); console.info('Success to insertText. ');
} else { } else {
console.error('Failed to insertText.(callback) '); console.error('Failed to insertText. ');
} }
}); });
``` ```
### insertText ### insertText<sup>9+</sup>
insertText(text:string): Promise&lt;boolean&gt; insertText(text:string): Promise&lt;boolean&gt;
Inserts text. This API uses a promise to return the result. If the required parameter is not passed in, an exception is thrown. Inserts text. This API uses a promise to return the result.
**System capability**: SystemCapability.MiscServices.InputMethodFramework **System capability**: SystemCapability.MiscServices.InputMethodFramework
...@@ -935,29 +1323,40 @@ Inserts text. This API uses a promise to return the result. If the required para ...@@ -935,29 +1323,40 @@ Inserts text. This API uses a promise to return the result. If the required para
| Type | Description | | Type | Description |
| ------------------------------- | ------------------------------------------------------------ | | ------------------------------- | ------------------------------------------------------------ |
| Promise&lt;boolean&gt; | Promise used to return the result. | | Promise&lt;boolean&gt; | Promise used to return the result. The value **true** means that the insertion 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 |
| -------- | -------------------------- |
| 12800002 | Input method engine error. |
| 12800003 | Input method client error. |
**Example** **Example**
```js ```js
async function InputMethodEngine() { try {
await TextInputClient.insertText('test').then((result) => { InputClient.insertText('test').then((result) => {
if (result) { if (result) {
console.info('Success to insertText.(promise) '); console.info('Success to insertText. ');
} else { } else {
console.error('Failed to insertText.(promise) '); console.error('Failed to insertText. ');
} }
}).catch((err) => { }).catch((err) => {
console.error('insertText promise err: ' + err.msg); console.error('insertText err: ' + JSON.stringify(err));
}); });
} } catch (err) {
``` console.error('insertText err: ' + JSON.stringify(err));
}
```
### getEditorAttribute ### getEditorAttribute<sup>9+</sup>
getEditorAttribute(callback: AsyncCallback&lt;EditorAttribute&gt;): void getEditorAttribute(callback: AsyncCallback&lt;EditorAttribute&gt;): void
Obtains the attribute of the edit box. This API uses an asynchronous callback to return the result. If the required parameter is not passed in, an exception is thrown. Obtains the attribute of the edit box. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.MiscServices.InputMethodFramework **System capability**: SystemCapability.MiscServices.InputMethodFramework
...@@ -965,26 +1364,34 @@ Obtains the attribute of the edit box. This API uses an asynchronous callback to ...@@ -965,26 +1364,34 @@ Obtains the attribute of the edit box. This API uses an asynchronous callback to
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| ------------------------------- | ------------------------------------------------------------ | ------------------------------------------------------------ | ------------------------------------------------------------ | | ------------------------------- | ------------------------------------------------------------ | ------------------------------------------------------------ | ------------------------------------------------------------ |
| callback | AsyncCallback&lt;[EditorAttribute](#EditorAttribute)&gt; | Yes| Attribute of the edit box. | | callback | AsyncCallback&lt;[EditorAttribute](#editorattribute)&gt; | Yes| Callback used to return the result. If the operation is successful, **err** is **undefined** and **data** is the attribute of the edit box. Otherwise, **err** is an error object.|
**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. |
**Example** **Example**
```js ```js
TextInputClient.getEditorAttribute((err, editorAttribute) => { InputClient.getEditorAttribute((err, editorAttribute) => {
if (err === undefined) { if (err) {
console.error('getEditorAttribute callback result---err: ' + err.msg); console.error('getEditorAttribute err: ' + JSON.stringify(err));
return; return;
} }
console.log('editorAttribute.inputPattern(callback): ' + JSON.stringify(editorAttribute.inputPattern)); console.log('editorAttribute.inputPattern: ' + JSON.stringify(editorAttribute.inputPattern));
console.log('editorAttribute.enterKeyType(callback): ' + JSON.stringify(editorAttribute.enterKeyType)); console.log('editorAttribute.enterKeyType: ' + JSON.stringify(editorAttribute.enterKeyType));
}); });
``` ```
### getEditorAttribute ### getEditorAttribute<sup>9+</sup>
getEditorAttribute(): Promise&lt;EditorAttribute&gt; getEditorAttribute(): Promise&lt;EditorAttribute&gt;
Obtains the attribute of the edit box. This API uses a promise to return the result. If any parameter is passed in, an exception is thrown. Obtains the attribute of the edit box. This API uses a promise to return the result.
**System capability**: SystemCapability.MiscServices.InputMethodFramework **System capability**: SystemCapability.MiscServices.InputMethodFramework
...@@ -992,26 +1399,32 @@ Obtains the attribute of the edit box. This API uses a promise to return the res ...@@ -992,26 +1399,32 @@ Obtains the attribute of the edit box. This API uses a promise to return the res
| Type | Description | | Type | Description |
| ------------------------------- | ------------------------------------------------------------ | | ------------------------------- | ------------------------------------------------------------ |
| Promise&lt;[EditorAttribute](#EditorAttribute)&gt; | Promise used to return the attribute of the edit box. | | Promise&lt;[EditorAttribute](#editorattribute)&gt; | Promise used to return the attribute of the edit box. |
**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. |
**Example** **Example**
```js ```js
async function InputMethodEngine() { InputClient.getEditorAttribute().then((editorAttribute) => {
await TextInputClient.getEditorAttribute().then((editorAttribute) => { console.info('editorAttribute.inputPattern: ' + JSON.stringify(editorAttribute.inputPattern));
console.info('editorAttribute.inputPattern(promise): ' + JSON.stringify(editorAttribute.inputPattern)); console.info('editorAttribute.enterKeyType: ' + JSON.stringify(editorAttribute.enterKeyType));
console.info('editorAttribute.enterKeyType(promise): ' + JSON.stringify(editorAttribute.enterKeyType)); }).catch((err) => {
}).catch((err) => { console.error('getEditorAttribute err: ' + JSON.stringify(err));
console.error('getEditorAttribute promise err: ' + err.msg); });
}); ```
}
```
### moveCursor<sup>9+</sup> ### moveCursor<sup>9+</sup>
moveCursor(direction: number, callback: AsyncCallback&lt;void&gt;): void moveCursor(direction: number, callback: AsyncCallback&lt;void&gt;): void
Moves the cursor. This API uses an asynchronous callback to return the result. If the required parameter is not passed in, an exception is thrown. Moves the cursor. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.MiscServices.InputMethodFramework **System capability**: SystemCapability.MiscServices.InputMethodFramework
...@@ -1020,24 +1433,37 @@ Moves the cursor. This API uses an asynchronous callback to return the result. I ...@@ -1020,24 +1433,37 @@ Moves the cursor. This API uses an asynchronous callback to return the result. I
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| --------- | ------------------------- | ---- | -------------- | | --------- | ------------------------- | ---- | -------------- |
| direction | number | Yes | Direction in which the cursor moves.| | direction | number | Yes | Direction in which the cursor moves.|
| callback | AsyncCallback&lt;void&gt; | Yes | Callback used to return the result. | | callback | AsyncCallback&lt;void&gt; | 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. |
**Example** **Example**
```js ```js
TextInputClient.moveCursor(inputMethodEngine.CURSOR_xxx, (err) => { try {
if (err === undefined) { InputClient.moveCursor(inputMethodEngine.CURSOR_xxx, (err) => {
console.error('moveCursor callback result---err: ' + err.msg); if (err) {
console.error('moveCursor err: ' + JSON.stringify(err));
return; return;
} }
}); console.info('moveCursor success');
});
} catch (err) {
console.error('moveCursor err: ' + JSON.stringify(err));
}
``` ```
### moveCursor<sup>9+</sup> ### moveCursor<sup>9+</sup>
moveCursor(direction: number): Promise&lt;void&gt; moveCursor(direction: number): Promise&lt;void&gt;
Moves the cursor. This API uses a promise to return the result. If the required parameter is not passed in, an exception is thrown. Moves the cursor. This API uses a promise to return the result.
**System capability**: SystemCapability.MiscServices.InputMethodFramework **System capability**: SystemCapability.MiscServices.InputMethodFramework
...@@ -1053,21 +1479,31 @@ Moves the cursor. This API uses a promise to return the result. If the required ...@@ -1053,21 +1479,31 @@ Moves the cursor. This API uses a promise to return the result. If the required
| ------------------- | ------------------------- | | ------------------- | ------------------------- |
| Promise&lt;void&gt; | Promise that returns no value.| | Promise&lt;void&gt; | 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. |
**Example** **Example**
```js ```js
async function InputMethodEngine() { try {
await TextInputClient.moveCursor(inputMethodEngine.CURSOR_xxx).then(async (err) => { InputClient.moveCursor(inputMethodEngine.CURSOR_UP).then(() => {
console.log('moveCursor success'); console.log('moveCursor success');
}).catch((err) => { }).catch((err) => {
console.error('moveCursor success err: ' + err.msg); console.error('moveCursor success err: ' + JSON.stringify(err));
}); });
} catch (err) {
console.log('moveCursor err: ' + JSON.stringify(err));
} }
``` ```
## EditorAttribute<a name="EditorAttribute"></a> ## EditorAttribute
Describes the attribute of the edit box. Attribute of the edit box.
**System capability**: SystemCapability.MiscServices.InputMethodFramework **System capability**: SystemCapability.MiscServices.InputMethodFramework
...@@ -1076,7 +1512,7 @@ Describes the attribute of the edit box. ...@@ -1076,7 +1512,7 @@ Describes the attribute of the edit box.
| enterKeyType | number | Yes | No | Function attribute of the edit box.| | enterKeyType | number | Yes | No | Function attribute of the edit box.|
| inputPattern | number | Yes | No | Text attribute of the edit box.| | inputPattern | number | Yes | No | Text attribute of the edit box.|
## KeyEvent<a name="KeyEvent"></a> ## KeyEvent
Describes the attribute of a key. Describes the attribute of a key.
...@@ -1086,3 +1522,502 @@ Describes the attribute of a key. ...@@ -1086,3 +1522,502 @@ 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.|
## TextInputClient<sup>(deprecated)</sup>
> **NOTE**
>
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [InputClient](#inputclient9).
In the following API examples, you must first use **[on('inputStart')](#oninputstart)** to obtain a **TextInputClient** instance, and then call the APIs using the obtained instance.
### getForward<sup>(deprecated)</sup>
getForward(length:number, callback: AsyncCallback&lt;string&gt;): void
Obtains the specific-length text before the cursor. 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 [getForward](#getforward9).
**System capability**: SystemCapability.MiscServices.InputMethodFramework
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| length | number | Yes| Text length.|
| callback | AsyncCallback&lt;string&gt; | Yes| Callback used to return the result. If the operation is successful, **err** is **undefined** and **data** is the obtained text. Otherwise, **err** is an error object.|
**Example**
```js
let length = 1;
TextInputClient.getForward(length, (err, text) => {
if (err === undefined) {
console.error('getForward err: ' + JSON.stringify(err));
return;
}
console.log('getForward result---text: ' + text);
});
```
### getForward<sup>(deprecated)</sup>
getForward(length:number): Promise&lt;string&gt;
Obtains the specific-length text before the cursor. This API uses a promise to return the result.
> **NOTE**
>
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [getForward](#getforward9).
**System capability**: SystemCapability.MiscServices.InputMethodFramework
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| length | number | Yes| Text length.|
**Return value**
| Type | Description |
| ------------------------------- | ------------------------------------------------------------ |
| Promise&lt;string&gt; | Promise used to return the specific-length text before the cursor. |
**Example**
```js
let length = 1;
TextInputClient.getForward(length).then((text) => {
console.info('getForward result: ' + JSON.stringify(text));
}).catch((err) => {
console.error('getForward err: ' + JSON.stringify(err));
});
```
### getBackward<sup>(deprecated)</sup>
getBackward(length:number, callback: AsyncCallback&lt;string&gt;): void
Obtains the specific-length text after the cursor. 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 [getBackward](#getbackward9).
**System capability**: SystemCapability.MiscServices.InputMethodFramework
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| length | number | Yes| Text length.|
| callback | AsyncCallback&lt;string&gt; | Yes| Callback used to return the result. If the operation is successful, **err** is **undefined** and **data** is the obtained text. Otherwise, **err** is an error object.|
**Example**
```js
let length = 1;
TextInputClient.getBackward(length, (err, text) => {
if (err === undefined) {
console.error('getBackward err: ' + JSON.stringify(err));
return;
}
console.log('getBackward result---text: ' + text);
});
```
### getBackward<sup>(deprecated)</sup>
getBackward(length:number): Promise&lt;string&gt;
Obtains the specific-length text after the cursor. This API uses a promise to return the result.
> **NOTE**
>
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [getBackward](#getbackward9).
**System capability**: SystemCapability.MiscServices.InputMethodFramework
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| length | number | Yes| Text length.|
**Return value**
| Type | Description |
| ------------------------------- | ------------------------------------------------------------ |
| Promise&lt;string&gt; | Promise used to return the specific-length text after the cursor. |
**Example**
```js
let length = 1;
TextInputClient.getBackward(length).then((text) => {
console.info('getBackward result: ' + JSON.stringify(text));
}).catch((err) => {
console.error('getBackward err: ' + JSON.stringify(err));
});
```
### deleteForward<sup>(deprecated)</sup>
deleteForward(length:number, callback: AsyncCallback&lt;boolean&gt;): void
Deletes the fixed-length text before the cursor. 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 [deleteForward](#deleteforward9).
**System capability**: SystemCapability.MiscServices.InputMethodFramework
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| length | number | Yes| Text length.|
| callback | AsyncCallback&lt;boolean&gt; | 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
let length = 1;
TextInputClient.deleteForward(length, (err, result) => {
if (err === undefined) {
console.error('deleteForward err: ' + JSON.stringify(err));
return;
}
if (result) {
console.info('Success to deleteForward. ');
} else {
console.error('Failed to deleteForward. ');
}
});
```
### deleteForward<sup>(deprecated)</sup>
deleteForward(length:number): Promise&lt;boolean&gt;
Deletes the fixed-length text before the cursor. This API uses a promise to return the result.
> **NOTE**
>
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [deleteForward](#deleteforward9).
**System capability**: SystemCapability.MiscServices.InputMethodFramework
**Parameters**
| Name| Type | Mandatory| Description |
| ------ | ------ | ---- | ---------- |
| length | number | Yes | Text length.|
**Return value**
| Type | Description |
| ---------------------- | -------------- |
| Promise&lt;boolean&gt; | Promise used to return the result. The value **true** means that the deletion is successful, and **false** means the opposite.|
**Example**
```js
let length = 1;
TextInputClient.deleteForward(length).then((result) => {
if (result) {
console.info('Succeed in deleting forward. ');
} else {
console.error('Failed to delete forward. ');
}
}).catch((err) => {
console.error('Failed to delete forward err: ' + JSON.stringify(err));
});
```
### deleteBackward<sup>(deprecated)</sup>
deleteBackward(length:number, callback: AsyncCallback&lt;boolean&gt;): void
Deletes the fixed-length text after the cursor. 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 [deleteBackward](#deletebackward9).
**System capability**: SystemCapability.MiscServices.InputMethodFramework
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ---------------------------- | ---- | -------------- |
| length | number | Yes | Text length. |
| callback | AsyncCallback&lt;boolean&gt; | 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
let length = 1;
TextInputClient.deleteBackward(length, (err, result) => {
if (err === undefined) {
console.error('deleteBackward err: ' + JSON.stringify(err));
return;
}
if (result) {
console.info('Success to deleteBackward. ');
} else {
console.error('Failed to deleteBackward. ');
}
});
```
### deleteBackward<sup>(deprecated)</sup>
deleteBackward(length:number): Promise&lt;boolean&gt;
Deletes the fixed-length text after the cursor. 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 [deleteBackward](#deletebackward9).
**System capability**: SystemCapability.MiscServices.InputMethodFramework
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| length | number | Yes| Text length.|
**Return value**
| Type | Description |
| ------------------------------- | ------------------------------------------------------------ |
| Promise&lt;boolean&gt; | Promise used to return the result. The value **true** means that the deletion is successful, and **false** means the opposite.|
**Example**
```js
let length = 1;
TextInputClient.deleteBackward(length).then((result) => {
if (result) {
console.info('Success to deleteBackward. ');
} else {
console.error('Failed to deleteBackward. ');
}
}).catch((err) => {
console.error('deleteBackward err: ' + JSON.stringify(err));
});
```
### sendKeyFunction<sup>(deprecated)</sup>
sendKeyFunction(action: number, callback: AsyncCallback&lt;boolean&gt;): void
Sends the function key. 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 [sendKeyFunction](#sendkeyfunction9).
**System capability**: SystemCapability.MiscServices.InputMethodFramework
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| action | number | Yes| Action of the function key.<br>**0**: invalid key.<br>**1**: confirm key (Enter key).|
| callback | AsyncCallback&lt;boolean&gt; | 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
let action = 1;
TextInputClient.sendKeyFunction(action, (err, result) => {
if (err === undefined) {
console.error('sendKeyFunction err: ' + JSON.stringify(err));
return;
}
if (result) {
console.info('Success to sendKeyFunction. ');
} else {
console.error('Failed to sendKeyFunction. ');
}
});
```
### sendKeyFunction<sup>(deprecated)</sup>
sendKeyFunction(action: number): Promise&lt;boolean&gt;
Sends the function key. This API uses a promise to return the result.
> **NOTE**
>
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [sendKeyFunction](#sendkeyfunction9).
**System capability**: SystemCapability.MiscServices.InputMethodFramework
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| action | number | Yes| Action of the function key.<br>**0**: invalid key.<br>**1**: confirm key (Enter key).|
**Return value**
| Type | Description |
| ------------------------------- | ------------------------------------------------------------ |
| Promise&lt;boolean&gt; | Promise used to return the result. The value **true** means that the setting is successful, and **false** means the opposite.|
**Example**
```js
let action = 1;
TextInputClient.sendKeyFunction(action).then((result) => {
if (result) {
console.info('Success to sendKeyFunction. ');
} else {
console.error('Failed to sendKeyFunction. ');
}
}).catch((err) => {
console.error('sendKeyFunction err:' + JSON.stringify(err));
});
```
### insertText<sup>(deprecated)</sup>
insertText(text:string, callback: AsyncCallback&lt;boolean&gt;): void
Inserts text. This API uses an asynchronous callback to return the result.
> **NOTE**
>
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [insertText](#inserttext9).
**System capability**: SystemCapability.MiscServices.InputMethodFramework
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| text | string | Yes| Text to insert.|
| callback | AsyncCallback&lt;boolean&gt; | 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
TextInputClient.insertText('test', (err, result) => {
if (err === undefined) {
console.error('insertText err: ' + JSON.stringify(err));
return;
}
if (result) {
console.info('Success to insertText. ');
} else {
console.error('Failed to insertText. ');
}
});
```
### insertText<sup>(deprecated)</sup>
insertText(text:string): Promise&lt;boolean&gt;
Inserts text. This API uses a promise to return the result.
> **NOTE**
>
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [insertText](#inserttext9).
**System capability**: SystemCapability.MiscServices.InputMethodFramework
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| text | string | Yes| Text to insert.|
**Return value**
| Type | Description |
| ------------------------------- | ------------------------------------------------------------ |
| Promise&lt;boolean&gt; | Promise used to return the result. The value **true** means that the insertion is successful, and **false** means the opposite.|
**Example**
```js
TextInputClient.insertText('test').then((result) => {
if (result) {
console.info('Success to insertText. ');
} else {
console.error('Failed to insertText. ');
}
}).catch((err) => {
console.error('insertText err: ' + JSON.stringify(err));
});
```
### getEditorAttribute<sup>(deprecated)</sup>
getEditorAttribute(callback: AsyncCallback&lt;EditorAttribute&gt;): void
Obtains the attribute of the edit box. 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 [getEditorAttribute](#geteditorattribute9).
**System capability**: SystemCapability.MiscServices.InputMethodFramework
**Parameters**
| Name | Type | Mandatory | Description |
| ------------------------------- | ------------------------------------------------------------ | ------------------------------------------------------------ | ------------------------------------------------------------ |
| callback | AsyncCallback&lt;[EditorAttribute](#editorattribute)&gt; | Yes| Callback used to return the result. If the operation is successful, **err** is **undefined** and **data** is the attribute of the edit box. Otherwise, **err** is an error object.|
**Example**
```js
TextInputClient.getEditorAttribute((err, editorAttribute) => {
if (err === undefined) {
console.error('getEditorAttribute err: ' + JSON.stringify(err));
return;
}
console.log('editorAttribute.inputPattern: ' + JSON.stringify(editorAttribute.inputPattern));
console.log('editorAttribute.enterKeyType: ' + JSON.stringify(editorAttribute.enterKeyType));
});
```
### getEditorAttribute<sup>(deprecated)</sup>
getEditorAttribute(): Promise&lt;EditorAttribute&gt;
Obtains the attribute of the edit box. 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 [getEditorAttribute](#geteditorattribute9).
**System capability**: SystemCapability.MiscServices.InputMethodFramework
**Return value**
| Type | Description |
| ------------------------------- | ------------------------------------------------------------ |
| Promise&lt;[EditorAttribute](#editorattribute)&gt; | Promise used to return the attribute of the edit box. |
**Example**
```js
TextInputClient.getEditorAttribute().then((editorAttribute) => {
console.info('editorAttribute.inputPattern: ' + JSON.stringify(editorAttribute.inputPattern));
console.info('editorAttribute.enterKeyType: ' + JSON.stringify(editorAttribute.enterKeyType));
}).catch((err) => {
console.error('getEditorAttribute err: ' + JSON.stringify(err));
});
```
# Input Method Framework Error Codes
## 12800001 Package Manager Error
**Error Message**
Package manager error.
**Description**
This error code is reported when an API of the package manager, such as **getInputMethods** and **listCurrentInputMethodSubtype**, fails to be invoked to obtain information.
**Possible Causes**
The package manager is not working correctly.
**Solution**
None
## 12800002 Input Method Engine Error
**Error Message**
Input method engine error.
**Description**
This error code is reported when an input method API fails to be invoked.
**Possible Causes**
The input method process is suspended.
**Solution**
Check whether the input method process is running properly. For example, click the input text box in an appliccation and check whether the input keyboard is displayed.
## 12800003 Input Method Client Error
**Error Message**
Input method client error.
**Description**
This error code is reported when the API for showing or hiding the keyboard fails to be invoked by a third-party application.
**Possible Causes**
The input method is disconnected from the third-party application due to a service error with the application.
**Solution**
Bind the input method to the third-party application again: Close the background process of the third-party application, start the application again, and touch an input text box. If the keyboard is displayed properly, the issue is resolved.
## 12800004 Key Event Processing Error
**Error Message**
Key event processing error.
**Description**
This error code is reported when a key event error occurs.
**Possible Causes**
An exception occurs during key event distribution, consumption, or listening.
**Solution**
None
## 12800005 Configuration Persistence Error
**Error Message**
Configuration persisting error.
**Description**
This error code is reported when the configuration fails to be saved during input method switching.
**Possible Causes**
An exception occurs with the system parameter configuration module.
**Solution**
Run the **hdc shell param get persist.sys.default_ime** command to check the default input method parameters. If the parameters are displayed, the system parameter configuration module is working properly. In this case, restart the device and try again.
## 12800006 Input Method Controller Error
**Error Message**
Input method controller error.
**Description**
This error code is reported when the input method controller fails to be obtained.
**Possible Causes**
An error occurs during invoking of the **getCotroller** API.
**Solution**
None
## 12800007 Input Method Setter Error
**Error Message**
Input method settings extension error.
**Description**
This error code is reported when an **InputMethodSetting** instance fails to be obtained.
**Possible Causes**
An error occurs during invoking of the **getSetting** API.
**Solution**
None
## 12800008 Input Method Manager Service Error
**Error Message**
Input method manager service error.
**Description**
This error code is reported when an API of the [input method framework](../apis/js-apis-inputmethod.md) fails to be invoked.
**Possible Causes**
The input method manager service fails to be obtained.
**Solution**
Run the **ps -A|grep inputmethod** command to check for the process ID of the input method service. If the process ID is found, the service is working properly.
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册