未验证 提交 d5d9428f 编写于 作者: O openharmony_ci 提交者: Gitee

!13141 翻译完成 12510+12379+12457

Merge pull request !13141 from ester.zhou/C2-0103
# @ohos.inputmethodsubtype
The **inputMethodSubtype** 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.|
# Input Method Framework # @ohos.inputmethod
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.
...@@ -9,20 +9,19 @@ The **inputMethod** module provides an input method framework, which can be used ...@@ -9,20 +9,19 @@ The **inputMethod** module provides an input method framework, which can be used
## Modules to Import ## Modules to Import
``` ```js
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. Mandatory.|
| methodId | string | Yes| No| Ability name.| | id<sup>9+</sup> | string | Yes| No| Unique ID of the input method. Mandatory.|
| label<sup>9+</sup> | string | Yes| No| External display name of the input method. Optional.|
| icon<sup>9+</sup> | string | Yes| No| Icon of the input method. Optional.|
| iconId<sup>9+</sup> | number | Yes| No| Icon ID of the input method. Optional.|
| extra<sup>9+</sup> | object | Yes| Yes| Extra information about the input method. Mandatory.|
| packageName<sup>(deprecated)</sup> | string | Yes| No| Name of the input method package. Mandatory.<br>**NOTE**<br>This API is supported since API version 8 and deprecated since API version 9. You are advised to use **name**.|
| methodId<sup>(deprecated)</sup> | string | Yes| No| Unique ID of the input method. Mandatory.<br>**NOTE**<br>This API is supported since API version 8 and deprecated since API version 9. You are advised to use **id**.|
## 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 (available only to system applications)
**System capability**: SystemCapability.MiscServices.InputMethodFramework **System capability**: SystemCapability.MiscServices.InputMethodFramework
...@@ -87,29 +110,51 @@ Switches to another input method. This API can be used only in the stage model. ...@@ -87,29 +110,51 @@ 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 manager service error. |
**Example** **Example**
```js ```js
inputMethod.switchInputMethod({packageName:'com.example.kikakeyboard', methodId:'com.example.kikakeyboard'} ,(err,result) => { let im = inputMethod.getCurrentInputMethod();
if (err) { let prop = {
console.error('switchInputMethod err: ' + JSON.stringify(err)); packageName: im.packageName,
methodId: im.methodId,
name: im.packageName,
id: im.methodId,
extra: {}
}
try{
inputMethod.switchInputMethod(prop, (err, result) => {
if (err !== undefined) {
console.error('Failed to switchInputMethod: ' + JSON.stringify(err));
return; return;
} }
if (result) { if (result) {
console.info('Success to switchInputMethod.(callback)'); console.info('Succeeded in switching inputmethod.');
} else { } else {
console.error('Failed to switchInputMethod.(callback)'); console.error('Failed to switchInputMethod.');
} }
}); });
} catch(err) {
console.error('Failed to switchInputMethod: ' + 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 (available only to system applications)
**System capability**: SystemCapability.MiscServices.InputMethodFramework **System capability**: SystemCapability.MiscServices.InputMethodFramework
...@@ -117,28 +162,49 @@ Switches to another input method. This API can be used only in the stage model. ...@@ -117,28 +162,49 @@ 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 manager service error. |
**Example**
```js ```js
inputMethod.switchInputMethod({packageName:'com.example.kikakeyboard', methodId:'com.example.kikakeyboard'}).then((result) => { let im = inputMethod.getCurrentInputMethod();
let prop = {
packageName: im.packageName,
methodId: im.methodId,
name: im.packageName,
id: im.methodId,
extra: {}
}
try {
inputMethod.switchInputMethod(prop).then((result) => {
if (result) { if (result) {
console.info('Success to switchInputMethod.(promise)'); console.info('Succeeded in switching inputmethod.');
} 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('Failed to switchInputMethod: ' + JSON.stringify(err));
}) })
} catch(err) {
console.error('Failed to switchInputMethod: ' + JSON.stringify(err));
}
``` ```
## inputMethod.getCurrentInputMethod<sup>9+</sup> ## inputMethod.getCurrentInputMethod<sup>9+</sup>
getCurrentInputMethod(): InputMethodProperty getCurrentInputMethod(): InputMethodProperty
...@@ -151,24 +217,339 @@ Obtains the current input method. This API synchronously returns the **Inputmeth ...@@ -151,24 +217,339 @@ 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**
```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 (available only to system applications)
**System capability**: SystemCapability.MiscServices.InputMethodFramework
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| target | [InputMethodSubtype](./js-apis-inputmethod-subtype.md#inputmethodsubtype)| Yes| Input method subtype to switch to.|
| callback | AsyncCallback&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 manager service error. |
**Example**
```js
try {
inputMethod.switchCurrentInputMethodSubtype({
id: "com.example.kikakeyboard",
label: "ServiceExtAbility",
name: "",
mode: "upper",
locale: "",
language: "",
icon: "",
iconId: 0,
extra: {}
}, (err, result) => {
if (err !== undefined) {
console.error('Failed to switchCurrentInputMethodSubtype: ' + JSON.stringify(err));
return;
}
if (result) {
console.info('Succeeded in switching currentInputMethodSubtype.');
} else {
console.error('Failed to switchCurrentInputMethodSubtype');
}
});
} catch(err) {
console.error('Failed to switchCurrentInputMethodSubtype: ' + JSON.stringify(err));
}
```
## inputMethod.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 (available only to system applications)
**System capability**: SystemCapability.MiscServices.InputMethodFramework
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
|target | [InputMethodSubtype](./js-apis-inputmethod-subtype.md#inputmethodsubtype)| Yes| Input method subtype to switch to.|
**Return value**
| Type | Description |
| ----------------------------------------- | ---------------------------- |
| Promise\<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 manager service error. |
**Example**
```js
try {
inputMethod.switchCurrentInputMethodSubtype({
id: "com.example.kikakeyboard",
label: "ServiceExtAbility",
name: "",
mode: "upper",
locale: "",
language: "",
icon: "",
iconId: 0,
extra: {}
}).then((result) => {
if (result) {
console.info('Succeeded in switching currentInputMethodSubtype.');
} else {
console.error('Failed to switchCurrentInputMethodSubtype.');
}
}).catch((err) => {
console.error('Failed to switchCurrentInputMethodSubtype: ' + JSON.stringify(err));
})
} catch(err) {
console.error('Failed to switchCurrentInputMethodSubtype: ' + JSON.stringify(err));
}
```
## inputMethod.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 (available only to system applications)
**System capability**: SystemCapability.MiscServices.InputMethodFramework
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
|inputMethodProperty | [InputMethodProperty](#inputmethodproperty8)| Yes| Input method to switch to.|
|inputMethodSubtype | [InputMethodSubtype](./js-apis-inputmethod-subtype.md#inputmethodsubtype)| Yes| Input method subtype to switch to.|
| callback | AsyncCallback&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 manager service error. |
**Example**
```js
let im = inputMethod.getCurrentInputMethod();
let inputMethodProperty = {
packageName: im.packageName,
methodId: im.methodId,
name: im.packageName,
id: im.methodId,
extra: {}
}
try {
inputMethod.switchCurrentInputMethodAndSubtype(inputMethodProperty, {
id: "com.example.kikakeyboard",
label: "ServiceExtAbility",
name: "",
mode: "upper",
locale: "",
language: "",
icon: "",
iconId: 0,
extra: {}
}, (err,result) => {
if (err !== undefined) {
console.error('Failed to switchCurrentInputMethodAndSubtype: ' + JSON.stringify(err));
return;
}
if (result) {
console.info('Succeeded in switching currentInputMethodAndSubtype.');
} else {
console.error('Failed to switchCurrentInputMethodAndSubtype.');
}
});
} catch (err) {
console.error('Failed to switchCurrentInputMethodAndSubtype: ' + JSON.stringify(err));
}
```
## inputMethod.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 (available only to system applications)
**System capability**: SystemCapability.MiscServices.InputMethodFramework
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
|inputMethodProperty | [InputMethodProperty](#inputmethodproperty8)| Yes| Input method to switch to.|
|inputMethodSubtype | [InputMethodSubtype](./js-apis-inputmethod-subtype.md#inputmethodsubtype)| Yes| Input method subtype to switch to.|
**Return value**
| Type | Description |
| ----------------------------------------- | ---------------------------- |
| Promise\<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 manager service error. |
**Example**
```js
let im = inputMethod.getCurrentInputMethod();
let inputMethodProperty = {
packageName: im.packageName,
methodId: im.methodId,
name: im.packageName,
id: im.methodId,
extra: {}
}
try {
inputMethod.switchCurrentInputMethodAndSubtype(inputMethodProperty, {
id: im.packageName,
label: im.methodId,
name: "",
mode: "upper",
locale: "",
language: "",
icon: "",
iconId: 0,
extra: {}
}).then((result) => {
if (result) {
console.info('Succeeded in switching currentInputMethodAndSubtype.');
} else {
console.error('Failed to switchCurrentInputMethodAndSubtype.');
}
}).catch((err) => {
console.error('Failed to switchCurrentInputMethodAndSubtype: ' + JSON.stringify(err));
})
} catch(err) {
console.error('Failed to switchCurrentInputMethodAndSubtype: ' + JSON.stringify(err));
}
```
## inputMethod.getInputMethodController<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** **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 ```js
var currentIme = inputMethod.getCurrentInputMethod(); 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 +557,42 @@ Hides the keyboard. This API uses an asynchronous callback to return the result. ...@@ -176,29 +557,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 manager service error. |
**Example** **Example**
```js ```js
InputMethodController.stopInput((error, result) => { try {
if (error) { inputMethodController.stopInputSession((error, result) => {
console.error('failed to stopInput because: ' + JSON.stringify(error)); if (error !== undefined) {
console.error('Failed to stopInputSession: ' + JSON.stringify(error));
return; return;
} }
if (result) { if (result) {
console.info('Success to stopInput.(callback)'); console.info('Succeeded in stopping inputSession.');
} else { } else {
console.error('Failed to stopInput.(callback)'); console.error('Failed to stopInputSession.');
} }
}); });
} catch(error) {
console.error('Failed to stopInputSession: ' + 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 +600,42 @@ Hides the keyboard. This API uses a promise to return the result. If any paramet ...@@ -206,28 +600,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 manager service 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('Succeeded in stopping inputSession.');
} 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('Failed to stopInputSession: ' + JSON.stringify(err));
}) })
} catch(err) {
console.error('Failed to stopInputSession: ' + 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 (available only to system applications)
**System capability**: SystemCapability.MiscServices.InputMethodFramework **System capability**: SystemCapability.MiscServices.InputMethodFramework
...@@ -235,26 +643,36 @@ Shows this soft keyboard. This API uses an asynchronous callback to return the r ...@@ -235,26 +643,36 @@ 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 manager service error. |
**Example** **Example**
```js ```js
InputMethodController.showSoftKeyboard((err) => { inputMethodController.showSoftKeyboard((err) => {
if (err === undefined) { if (err === undefined) {
console.info('showSoftKeyboard success'); console.info('Succeeded in showing softKeyboard.');
} else { } else {
console.error('showSoftKeyboard failed because : ' + JSON.stringify(err)); console.error('Failed to showSoftKeyboard: ' + JSON.stringify(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 (available only to system applications)
**System capability**: SystemCapability.MiscServices.InputMethodFramework **System capability**: SystemCapability.MiscServices.InputMethodFramework
...@@ -264,21 +682,32 @@ Shows this soft keyboard. This API uses a promise to return the result. If any p ...@@ -264,21 +682,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 manager service error. |
**Example** **Example**
```js ```js
InputMethodController.showSoftKeyboard().then(async (err) => { inputMethodController.showSoftKeyboard().then(() => {
console.log('showSoftKeyboard success'); console.log('Succeeded in showing softKeyboard.');
}).catch((err) => { }).catch((err) => {
console.error('showSoftKeyboard promise err: ' + JSON.stringify(err)); console.error('Failed to showSoftKeyboard: ' + 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 (available only to system applications)
**System capability**: SystemCapability.MiscServices.InputMethodFramework **System capability**: SystemCapability.MiscServices.InputMethodFramework
...@@ -286,26 +715,36 @@ Hides this soft keyboard. This API uses an asynchronous callback to return the r ...@@ -286,26 +715,36 @@ 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 manager service error. |
**Example** **Example**
```js ```js
InputMethodController.hideSoftKeyboard((err) => { inputMethodController.hideSoftKeyboard((err) => {
if (err === undefined) { if (err === undefined) {
console.info('hideSoftKeyboard success'); console.info('Succeeded in hiding softKeyboard.');
} else { } else {
console.error('hideSoftKeyboard failed because : ' + JSON.stringify(err)); console.error('Failed to hideSoftKeyboard: ' + JSON.stringify(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 (available only to system applications)
**System capability**: SystemCapability.MiscServices.InputMethodFramework **System capability**: SystemCapability.MiscServices.InputMethodFramework
...@@ -315,25 +754,317 @@ Hides this soft keyboard. This API uses a promise to return the result. If any p ...@@ -315,25 +754,317 @@ 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 manager service error. |
**Example** **Example**
```js ```js
InputMethodController.hideSoftKeyboard().then(async (err) => { inputMethodController.hideSoftKeyboard().then(() => {
console.log('hideSoftKeyboard success'); console.log('Succeeded in hiding softKeyboard.');
}).catch((err) => { }).catch((err) => {
console.error('hideSoftKeyboard promise err: ' + JSON.stringify(err)); console.error('Failed to hideSoftKeyboard: ' + 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 !== undefined) {
console.error('Failed to stopInput: ' + JSON.stringify(error));
return;
}
if (result) {
console.info('Succeeded in stopping input.');
} else {
console.error('Failed to stopInput.');
}
});
```
### stopInput<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('Succeeded in stopping input.');
} else {
console.error('Failed to stopInput.');
}
}).catch((err) => {
console.error('Failed to stopInput: ' + 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**
### listInputMethod<sup>9+</sup> | 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>
listInputMethod(enable: boolean, callback: AsyncCallback&lt;Array&lt;InputMethodProperty&gt;&gt;): void listInputMethodSubtype(inputMethodProperty: InputMethodProperty, callback: AsyncCallback&lt;Array&lt;InputMethodSubtype&gt;&gt;): void
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. 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 manager service error. |
**Example**
```js
let inputMethodProperty = {
packageName: 'com.example.kikakeyboard',
methodId: 'com.example.kikakeyboard',
name: 'com.example.kikakeyboard',
id: 'com.example.kikakeyboard',
extra:{}
}
try {
inputMethodSetting.listInputMethodSubtype(inputMethodProperty, (err,data) => {
if (err !== undefined) {
console.error('Failed to listInputMethodSubtype: ' + JSON.stringify(err));
return;
}
console.log('Succeeded in listing inputMethodSubtype.');
});
} catch (err) {
console.error('Failed to listInputMethodSubtype: ' + JSON.stringify(err));
}
```
### 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 manager service error. |
**Example**
```js
let inputMethodProperty = {
packageName: 'com.example.kikakeyboard',
methodId: 'com.example.kikakeyboard',
name: 'com.example.kikakeyboard',
id: 'com.example.kikakeyboard',
extra:{}
}
try {
inputMethodSetting.listInputMethodSubtype(inputMethodProperty).then((data) => {
console.info('Succeeded in listing inputMethodSubtype.');
}).catch((err) => {
console.error('Failed to listInputMethodSubtype: ' + JSON.stringify(err));
})
} catch(err) {
console.error('Failed to listInputMethodSubtype: ' + JSON.stringify(err));
}
```
### listCurrentInputMethodSubtype<sup>9+</sup>
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 manager service error. |
**Example**
```js
try {
inputMethodSetting.listCurrentInputMethodSubtype((err, data) => {
if (err !== undefined) {
console.error('Failed to listCurrentInputMethodSubtype: ' + JSON.stringify(err));
return;
}
console.log('Succeeded in listing currentInputMethodSubtype.');
});
} catch(err) {
console.error('Failed to listCurrentInputMethodSubtype: ' + JSON.stringify(err));
}
```
### 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 manager service error. |
**Example**
```js
try {
inputMethodSetting.listCurrentInputMethodSubtype().then((data) => {
console.info('Succeeded in listing currentInputMethodSubtype.');
}).catch((err) => {
console.error('Failed to listCurrentInputMethodSubtype: ' + JSON.stringify(err));
})
} catch(err) {
console.error('Failed to listCurrentInputMethodSubtype: ' + JSON.stringify(err));
}
```
### 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 +1073,38 @@ Obtains a list of activated or deactivated input methods. This API uses an async ...@@ -342,25 +1073,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 manager service error. |
**Example** **Example**
```js ```js
InputMethodSetting.listInputMethod(true, (err,data) => { try {
if (err) { inputMethodSetting.getInputMethods(true, (err,data) => {
console.error('listInputMethod failed because: ' + JSON.stringify(err)); if (err !== undefined) {
console.error('Failed to getInputMethods: ' + JSON.stringify(err));
return; return;
} }
console.log('listInputMethod success'); console.log('Succeeded in getting inputMethods.');
}); });
} catch (err) {
console.error('Failed to getInputMethods: ' + 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 +1114,15 @@ Obtains a list of activated or deactivated input methods. This API uses a promis ...@@ -370,6 +1114,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 manager service error. |
**Return value** **Return value**
| Type | Description | | Type | Description |
...@@ -379,18 +1132,100 @@ Obtains a list of activated or deactivated input methods. This API uses a promis ...@@ -379,18 +1132,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('Succeeded in getting inputMethods.');
}).catch((err) => {
console.error('Failed to getInputMethods: ' + JSON.stringify(err));
})
} catch(err) {
console.error('Failed to getInputMethods: ' + 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 (available only to system applications)
**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 manager service error. |
**Example**
```js
try {
inputMethodSetting.showOptionalInputMethods((err, data) => {
if (err !== undefined) {
console.error('Failed to showOptionalInputMethods: ' + JSON.stringify(err));
return;
}
console.info('Succeeded in showing optionalInputMethods.');
});
} catch (err) {
console.error('Failed to showOptionalInputMethods: ' + JSON.stringify(err));
}
```
### 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 (available only to system applications)
**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 manager service error. |
**Example**
```js
inputMethodSetting.showOptionalInputMethods().then((data) => {
console.info('Succeeded in showing optionalInputMethods.');
}).catch((err) => { }).catch((err) => {
console.error('listInputMethod promise err: ' + err); console.error('Failed to showOptionalInputMethods: ' + JSON.stringify(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,25 +1233,29 @@ Obtains a list of installed input methods. This API uses an asynchronous callbac ...@@ -398,25 +1233,29 @@ 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 !== undefined) {
console.error('listInputMethod failed because: ' + JSON.stringify(err)); console.error('Failed to listInputMethod: ' + JSON.stringify(err));
return; return;
} }
console.log('listInputMethod success'); console.log('Succeeded in listing inputMethod.');
}); });
``` ```
### 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 +1268,22 @@ Obtains a list of installed input methods. This API uses a promise to return the ...@@ -429,18 +1268,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('Succeeded in listing inputMethod.');
}).catch((err) => { }).catch((err) => {
console.error('listInputMethod promise err: ' + err); console.error('Failed to listInputMethod: ' + 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,27 +1291,31 @@ Displays a dialog box for selecting an input method. This API uses an asynchrono ...@@ -448,27 +1291,31 @@ 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 !== undefined) {
console.error('displayOptionalInputMethod failed because: ' + JSON.stringify(err)); console.error('Failed to displayOptionalInputMethod: ' + JSON.stringify(err));
return; return;
} }
console.info('displayOptionalInputMethod success'); console.info('Succeeded in displaying optionalInputMethod.');
}); });
``` ```
### 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.
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. > **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 **System capability**: SystemCapability.MiscServices.InputMethodFramework
**Return value** **Return value**
...@@ -479,9 +1326,9 @@ InputMethodSetting.displayOptionalInputMethod((err) => { ...@@ -479,9 +1326,9 @@ InputMethodSetting.displayOptionalInputMethod((err) => {
**Example** **Example**
```js ```js
InputMethodSetting.displayOptionalInputMethod().then(() => { inputMethodSetting.displayOptionalInputMethod().then(() => {
console.info('displayOptionalInputMethod success.(promise)'); console.info('Succeeded in displaying optionalInputMethod.');
}).catch((err) => { }).catch((err) => {
console.error('displayOptionalInputMethod promise err: ' + err); console.error('Failed to displayOptionalInputMethod: ' + JSON.stringify(err));
}) })
``` ```
# Input Method Engine # @ohos.inputmethodengine
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, textClient) => {
KeyboardController = kbController; let keyboardController = kbController;
TextInputClient = textInputClient; let textInputClient = textClient;
}); });
``` ```
### 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,119 @@ Cancels listening for the input method binding event. An exception is thrown in ...@@ -132,24 +180,119 @@ 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** **Example**
```js ```js
InputMethodEngine.off('inputStart', (kbController, textInputClient) => { inputMethodEngine.getInputMethodEngine().on('keyboardShow', () => {
console.log('delete inputStart notification.'); 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');
inputMethodEngine.getInputMethodEngine().off('keyboardHide');
```
## 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, client) => {
let keyboardController = kbController;
let inputClient = client;
});
```
### 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**
```js
inputMethodEngine.getInputMethodAbility().off('inputStart');
```
### 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 +300,22 @@ Listens for the input method stop event. This API uses a callback to return the ...@@ -157,22 +300,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 +323,22 @@ Cancels listening for the input method stop event. This API uses a callback to r ...@@ -180,22 +323,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 +346,22 @@ Listens for the window invocation setting event. This API uses a callback to ret ...@@ -203,22 +346,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 +369,22 @@ Cancels listening for the window invocation setting event. This API uses a callb ...@@ -226,22 +369,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 a keyboard event. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.MiscServices.InputMethodFramework **System capability**: SystemCapability.MiscServices.InputMethodFramework
...@@ -249,25 +392,25 @@ Listens for an input method event. This API requires two parameters, the first o ...@@ -249,25 +392,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 a keyboard event. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.MiscServices.InputMethodFramework **System capability**: SystemCapability.MiscServices.InputMethodFramework
...@@ -275,30 +418,75 @@ Cancels listening for an input method event. An exception is thrown in the follo ...@@ -275,30 +418,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>
## KeyboardDelegate<a name="KeyboardDelegate"></a> off(type: 'setSubtype', callback?: (inputMethodSubtype: InputMethodSubtype) => void): void
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. 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
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 +494,71 @@ Listens for a hard keyboard even. This API uses a callback to return the key inf ...@@ -306,75 +494,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 +567,24 @@ KeyboardDelegate.on('cursorContextChange', (x, y, height) => { ...@@ -383,24 +567,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 +592,21 @@ KeyboardDelegate.off('cursorContextChange', (x, y, height) => { ...@@ -408,21 +592,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 +618,21 @@ KeyboardDelegate.on('selectionChange', (oldBegin, oldEnd, newBegin, newEnd) => { ...@@ -434,21 +618,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,21 +642,21 @@ KeyboardDelegate.off('selectionChange', (oldBegin, oldEnd, newBegin, newEnd) => ...@@ -458,21 +642,21 @@ 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
**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 | 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 +665,34 @@ KeyboardDelegate.on('textChange', (text) => { ...@@ -481,34 +665,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 +700,33 @@ Hides the keyboard. This API uses an asynchronous callback to return the result. ...@@ -516,26 +700,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('Failed to hide keyboard: ' + JSON.stringify(err));
return; return;
} }
console.log('hideKeyboard callback.'); console.log('Succeeded in hiding keyboard.');
}); });
``` ```
### 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 +736,182 @@ Hides the keyboard. This API uses a promise to return the result. If any paramet ...@@ -545,88 +736,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('Succeeded in hiding keyboard.');
console.info('hideKeyboard promise.'); }).catch((err) => {
}).catch((err) => { console.info('Failed to hide keyboard: ' + 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('Failed to hide Keyboard: ' + JSON.stringify(err));
console.error('getForward callback result---err: ' + err.msg);
return; return;
} }
console.log('getForward callback result---text: ' + text); console.log('Succeeded in hiding keyboard.');
}); });
``` ```
### 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('Succeeded in hiding keyboard.');
await TextInputClient.getForward(length).then((text) => { }).catch((err) => {
console.info('getForward promise result---res: ' + text); console.info('Failed to hide Keyboard: ' + 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 !== undefined) {
console.error('Failed to sendKeyFunction: ' + JSON.stringify(err));
return;
}
if (result) {
console.info('Succeeded in sending key function. ');
} else {
console.error('Failed to sendKeyFunction. ');
}
}); });
} 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('Succeeded in sending key function. ');
} else {
console.error('Failed to sendKeyFunction. ');
} }
``` }).catch((err) => {
console.error('Failed to sendKeyFunction:' + JSON.stringify(err));
});
} catch (err) {
console.error('Failed to sendKeyFunction: ' + JSON.stringify(err));
}
```
### 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 +920,39 @@ Obtains the specific-length text after the cursor. This API uses an asynchronous ...@@ -635,26 +920,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 !== undefined) {
console.error('Failed to getForward: ' + JSON.stringify(err));
return; return;
} }
console.log('getBackward callback result---text: ' + text); console.log('Succeeded in getting forward, text: ' + text);
}); });
``` } catch (err) {
console.error('Failed to getForward: ' + 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 +966,37 @@ Obtains the specific-length text after the cursor. This API uses a promise to re ...@@ -668,26 +966,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('Succeeded in getting forward, text: ' + text);
}).catch((err) => { }).catch((err) => {
console.error('getBackward promise err: ' + err.msg); console.error('Failed to getForward: ' + JSON.stringify(err));
}); });
} } catch (err) {
``` console.error('Failed to getForward: ' + 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 +1005,221 @@ Deletes the fixed-length text before the cursor. This API uses an asynchronous c ...@@ -696,165 +1005,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 !== undefined) {
console.error('Failed to getForward: ' + JSON.stringify(err));
return; return;
} }
if (result) { console.log('Succeeded in getting backward, text: ' + text);
console.info('Success to deleteForward.(callback) ');
} else {
console.error('Failed to deleteForward.(callback) ');
}
}); });
``` } catch (err) {
### deleteForward console.error('Failed to getForward: ' + JSON.stringify(err));
}
```
deleteForward(length:number): Promise&lt;boolean&gt; ### getBackward<sup>9+</sup>
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. getBackward(length:number): Promise&lt;string&gt;
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('Succeeded in getting backward, text: ' + 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('Failed to getForward: ' + JSON.stringify(err));
}); });
} catch (err) {
console.error('Failed to getForward: ' + 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 !== undefined) {
console.error('Failed to delete forward: ' + JSON.stringify(err));
return; return;
} }
if (result) { if (result) {
console.info('Success to deleteBackward.(callback) '); console.info('Succeeded in deleting forward. ');
} else { } else {
console.error('Failed to deleteBackward.(callback) '); console.error('Failed to delete forward: ' + JSON.stringify(err));
} }
}); });
} catch (err) {
console.error('Failed to delete forward: ' + 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('Succeeded in deleting forward. ');
} else { } else {
console.error('Failed to deleteBackward.(promise) '); console.error('Failed to delete Forward. ');
} }
}).catch((err) => { }).catch((err) => {
console.error('deleteBackward promise err: ' + err.msg); console.error('Failed to delete Forward: ' + JSON.stringify(err));
}); });
} catch (err) {
console.error('Failed to delete Forward: ' + JSON.stringify(err));
} }
``` ```
### sendKeyFunction
sendKeyFunction(action:number, callback: AsyncCallback&lt;boolean&gt;): void ### deleteBackward<sup>9+</sup>
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. 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.
**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 !== undefined) {
console.error('Failed to delete Backward: ' + JSON.stringify(err));
return; return;
} }
if (result) { if (result) {
console.info('Success to sendKeyFunction.(callback) '); console.info('Succeeded in deleting backward. ');
} else { } else {
console.error('Failed to sendKeyFunction.(callback) '); console.error('Failed to delete Backward: ' + JSON.stringify(err));
} }
}); });
} 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 +1227,43 @@ Sets the Enter key to send the text to its target. This API uses a promise to re ...@@ -862,35 +1227,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('Succeeded in deleting backward. ');
} 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('Failed to deleteBackward: ' + 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 +1272,38 @@ Inserts text. This API uses an asynchronous callback to return the result. If th ...@@ -899,29 +1272,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 !== undefined) {
console.error('insertText callback result---err: ' + err.msg); console.error('Failed to insertText: ' + JSON.stringify(err));
return; return;
} }
if (result) { if (result) {
console.info('Success to insertText.(callback) '); console.info('Succeeded in inserting text. ');
} 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 +1317,40 @@ Inserts text. This API uses a promise to return the result. If the required para ...@@ -935,29 +1317,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('Succeeded in inserting text. ');
} 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('Failed to insertText: ' + JSON.stringify(err));
}); });
} } catch (err) {
``` console.error('Failed to insertText: ' + 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 +1358,34 @@ Obtains the attribute of the edit box. This API uses an asynchronous callback to ...@@ -965,26 +1358,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 !== undefined) {
console.error('getEditorAttribute callback result---err: ' + err.msg); console.error('Failed to getEditorAttribute: ' + 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 +1393,32 @@ Obtains the attribute of the edit box. This API uses a promise to return the res ...@@ -992,26 +1393,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('Failed to getEditorAttribute: ' + 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 +1427,37 @@ Moves the cursor. This API uses an asynchronous callback to return the result. I ...@@ -1020,24 +1427,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_UP, (err) => {
console.error('moveCursor callback result---err: ' + err.msg); if (err !== undefined) {
console.error('Failed to moveCursor: ' + JSON.stringify(err));
return; return;
} }
}); console.info('Succeeded in moving cursor.');
});
} catch (err) {
console.error('Failed to moveCursor: ' + 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 +1473,31 @@ Moves the cursor. This API uses a promise to return the result. If the required ...@@ -1053,21 +1473,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('Succeeded in moving cursor.');
}).catch((err) => { }).catch((err) => {
console.error('moveCursor success err: ' + err.msg); console.error('Failed to moveCursor: ' + JSON.stringify(err));
}); });
} catch (err) {
console.log('Failed to moveCursor: ' + 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 +1506,7 @@ Describes the attribute of the edit box. ...@@ -1076,7 +1506,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 +1516,502 @@ Describes the attribute of a key. ...@@ -1086,3 +1516,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('Failed to getForward: ' + JSON.stringify(err));
return;
}
console.log('Succeeded in getting forward, 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('Succeeded in getting forward, text: ' + text);
}).catch((err) => {
console.error('Failed to getForward: ' + 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('Failed to getBackward: ' + JSON.stringify(err));
return;
}
console.log('Succeeded in getting borward, 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('Succeeded in getting backward: ' + JSON.stringify(text));
}).catch((err) => {
console.error('Failed to getBackward: ' + 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('Failed to deleteForward: ' + JSON.stringify(err));
return;
}
if (result) {
console.info('Succeeded in deleting forward. ');
} 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('Succeeded in deleting forward. ');
} else {
console.error('Failed to delete forward. ');
}
}).catch((err) => {
console.error('Failed to delete forward: ' + 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('Failed to delete backward: ' + JSON.stringify(err));
return;
}
if (result) {
console.info('Succeeded in deleting backward. ');
} 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('Succeeded in deleting backward. ');
} else {
console.error('Failed to deleteBackward. ');
}
}).catch((err) => {
console.error('Failed to deleteBackward: ' + 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('Failed to sendKeyFunction: ' + JSON.stringify(err));
return;
}
if (result) {
console.info('Succeeded in sending key function. ');
} 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('Succeeded in sending key function. ');
} else {
console.error('Failed to sendKeyFunction. ');
}
}).catch((err) => {
console.error('Failed to sendKeyFunction:' + 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('Failed to insertText: ' + JSON.stringify(err));
return;
}
if (result) {
console.info('Succeeded in inserting text. ');
} 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('Succeeded in inserting text. ');
} else {
console.error('Failed to insertText. ');
}
}).catch((err) => {
console.error('Failed to insertText: ' + 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('Failed to getEditorAttribute: ' + 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('Failed to getEditorAttribute: ' + JSON.stringify(err));
});
```
...@@ -23,7 +23,7 @@ Slider(options?: {value?: number, min?: number, max?: number, step?: number, sty ...@@ -23,7 +23,7 @@ Slider(options?: {value?: number, min?: number, max?: number, step?: number, sty
| value | number | No| Current progress.<br>Default value: **0**| | value | number | No| Current progress.<br>Default value: **0**|
| min | number | No| Minimum value.<br>Default value: **0**| | min | number | No| Minimum value.<br>Default value: **0**|
| max | number | No| Maximum value.<br>Default value: **100**| | max | number | No| Maximum value.<br>Default value: **100**|
| step | number | No| Step of the slider.<br>Default value: **1**| | step | number | No| Step of the slider.<br>Default value: **1**<br>Value range: [0.01, max]|
| style | SliderStyle | No| Style of the slider thumb and track.<br>Default value: **SliderStyle.OutSet**| | style | SliderStyle | No| Style of the slider thumb and track.<br>Default value: **SliderStyle.OutSet**|
| direction<sup>8+</sup> | [Axis](ts-appendix-enums.md#axis) | No| Whether the slider moves horizontally or vertically.<br>Default value: **Axis.Horizontal**| | direction<sup>8+</sup> | [Axis](ts-appendix-enums.md#axis) | No| Whether the slider moves horizontally or vertically.<br>Default value: **Axis.Horizontal**|
| reverse<sup>8+</sup> | boolean | No| Whether the slider values are reversed. By default, the values increase from left to right for a horizontal slider and from top to bottom for a vertical slider.<br>Default value: **false**| | reverse<sup>8+</sup> | boolean | No| Whether the slider values are reversed. By default, the values increase from left to right for a horizontal slider and from top to bottom for a vertical slider.<br>Default value: **false**|
...@@ -46,7 +46,7 @@ Except touch target attributes, the universal attributes are supported. ...@@ -46,7 +46,7 @@ Except touch target attributes, the universal attributes are supported.
| trackColor | [ResourceColor](ts-types.md#resourcecolor) | Background color of the slider.| | trackColor | [ResourceColor](ts-types.md#resourcecolor) | Background color of the slider.|
| selectedColor | [ResourceColor](ts-types.md#resourcecolor) | Color of the selected part of the slider track.| | selectedColor | [ResourceColor](ts-types.md#resourcecolor) | Color of the selected part of the slider track.|
| showSteps | boolean | Whether to display the current step.<br>Default value: **false**| | showSteps | boolean | Whether to display the current step.<br>Default value: **false**|
| showTips | boolean | Whether to display a bubble to indicate the percentage when the user drags the slider.<br>Default value: **false** | | showTips | boolean | Whether to display a bubble to indicate the percentage when the user drags the slider.<br>Default value: **false**|
| trackThickness | [Length](ts-types.md#length) | Track thickness of the slider.| | trackThickness | [Length](ts-types.md#length) | Track thickness of the slider.|
...@@ -223,4 +223,4 @@ struct SliderExample { ...@@ -223,4 +223,4 @@ struct SliderExample {
} }
``` ```
![en-us_image_0000001211898492](figures/en-us_image_0000001211898492.gif) ![en-us_image_0000001179613854](figures/en-us_image_0000001179613854.gif)
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册