提交 20724e50 编写于 作者: M ma-shaoyin

Signed-off-by: ma-shaoyin <mashaoyin1@huawei.com>

 Changes to be committed:
上级 6ec41313
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
> **说明:** > **说明:**
> >
> 本模块首批接口从 API version 8 开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 >本模块首批接口从API version 8开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
## 导入模块 ## 导入模块
...@@ -19,7 +19,7 @@ import inputMethodEngine from '@ohos.inputMethodEngine'; ...@@ -19,7 +19,7 @@ import inputMethodEngine from '@ohos.inputMethodEngine';
**系统能力:** SystemCapability.MiscServices.InputMethodFramework **系统能力:** SystemCapability.MiscServices.InputMethodFramework
| 名称 | 类型 | 值 | 说明 | | 名称 | 类型 | 值 | 说明 |
| ------------------------------------------- | ------ | ---- | ------------------------ | | -------- | -------- | -------- | -------- |
| ENTER_KEY_TYPE_UNSPECIFIED | number | 0 | 无功能键。 | | ENTER_KEY_TYPE_UNSPECIFIED | number | 0 | 无功能键。 |
| ENTER_KEY_TYPE_GO | number | 2 | “前往”功能键。 | | ENTER_KEY_TYPE_GO | number | 2 | “前往”功能键。 |
| ENTER_KEY_TYPE_SEARCH | number | 3 | “搜索”功能键。 | | ENTER_KEY_TYPE_SEARCH | number | 3 | “搜索”功能键。 |
...@@ -35,7 +35,7 @@ import inputMethodEngine from '@ohos.inputMethodEngine'; ...@@ -35,7 +35,7 @@ import inputMethodEngine from '@ohos.inputMethodEngine';
| PATTERN_EMAIL | number | 5 | 邮件编辑框。 | | PATTERN_EMAIL | number | 5 | 邮件编辑框。 |
| PATTERN_URI | number | 6 | 超链接编辑框。 | | PATTERN_URI | number | 6 | 超链接编辑框。 |
| PATTERN_PASSWORD | number | 7 | 密码编辑框。 | | PATTERN_PASSWORD | number | 7 | 密码编辑框。 |
| OPTION_ASCII | number | 20 | 允许输入 ASCII 值。 | | OPTION_ASCII | number | 20 | 允许输入ASCII值。 |
| OPTION_NONE | number | 0 | 不指定编辑框输入属性。 | | OPTION_NONE | number | 0 | 不指定编辑框输入属性。 |
| OPTION_AUTO_CAP_CHARACTERS | number | 2 | 允许输入字符。 | | OPTION_AUTO_CAP_CHARACTERS | number | 2 | 允许输入字符。 |
| OPTION_AUTO_CAP_SENTENCES | number | 8 | 允许输入句子。 | | OPTION_AUTO_CAP_SENTENCES | number | 8 | 允许输入句子。 |
...@@ -100,7 +100,7 @@ getInputMethodEngine(): InputMethodEngine ...@@ -100,7 +100,7 @@ getInputMethodEngine(): InputMethodEngine
> **说明:** > **说明:**
> >
> 从 API version 8 开始支持,API version 9 开始废弃,建议使用[getInputMethodAbility()](#inputmethodenginegetinputmethodability9)替代。 > 从API version 8开始支持,API version 9开始废弃,建议使用[getInputMethodAbility()](#inputmethodenginegetinputmethodability9)替代。
**系统能力:** SystemCapability.MiscServices.InputMethodFramework **系统能力:** SystemCapability.MiscServices.InputMethodFramework
...@@ -124,7 +124,7 @@ createKeyboardDelegate(): KeyboardDelegate ...@@ -124,7 +124,7 @@ createKeyboardDelegate(): KeyboardDelegate
> **说明:** > **说明:**
> >
> 从 API version 8 开始支持,API version 9 开始废弃,建议使用[getKeyboardDelegate()](#inputmethodenginegetkeyboarddelegate9)替代。 >从API version 8开始支持,API version 9开始废弃,建议使用[getKeyboardDelegate()](#inputmethodenginegetkeyboarddelegate9)替代。
**系统能力:** SystemCapability.MiscServices.InputMethodFramework **系统能力:** SystemCapability.MiscServices.InputMethodFramework
...@@ -142,32 +142,30 @@ let keyboardDelegate = inputMethodEngine.createKeyboardDelegate(); ...@@ -142,32 +142,30 @@ let keyboardDelegate = inputMethodEngine.createKeyboardDelegate();
## InputMethodEngine ## InputMethodEngine
下列 API 均需使用[getInputMethodEngine](#inputmethodenginegetinputmethodenginedeprecated)获取到 InputMethodEngine 实例后,通过实例调用。 下列API均需使用[getInputMethodEngine](#inputmethodenginegetinputmethodenginedeprecated)获取到InputMethodEngine实例后,通过实例调用。
### on('inputStart') ### on('inputStart')
on(type: 'inputStart', callback: (kbController: KeyboardController, textInputClient: TextInputClient) => void): void on(type: 'inputStart', callback: (kbController: KeyboardController, textInputClient: TextInputClient) => void): void
订阅输入法绑定成功事件。使用 callback 异步回调。 订阅输入法绑定成功事件。使用callback异步回调。
**系统能力:** SystemCapability.MiscServices.InputMethodFramework **系统能力:** SystemCapability.MiscServices.InputMethodFramework
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| -------- | ----------------------------------------------------------------------------------------------------------------------- | ---- | ----------------------------------------------------------------------- | | -------- | ------------------------------- | ---- | ------------------------------------------------------------ |
| type | string | 是 | 设置监听类型,固定取值为'inputStart'。 | | type | string | 是 | 设置监听类型,固定取值为'inputStart'。 |
| callback | (kbController: [KeyboardController](#keyboardcontroller), textInputClient: [TextInputClient](#textinputclient)) => void | 是 | 回调函数,返回订阅输入法的 KeyboardController 和 TextInputClient 实例。 | | callback | (kbController: [KeyboardController](#keyboardcontroller), textInputClient: [TextInputClient](#textinputclient)) => void | 是 | 回调函数,返回订阅输入法的KeyboardController和TextInputClient实例。 |
**示例:** **示例:**
```js ```js
inputMethodEngine inputMethodEngine.getInputMethodEngine().on('inputStart', (kbController, textClient) => {
.getInputMethodEngine()
.on("inputStart", (kbController, textClient) => {
let keyboardController = kbController; let keyboardController = kbController;
let textInputClient = textClient; let textInputClient = textClient;
}); });
``` ```
### off('inputStart') ### off('inputStart')
...@@ -181,43 +179,41 @@ off(type: 'inputStart', callback?: (kbController: KeyboardController, textInputC ...@@ -181,43 +179,41 @@ off(type: 'inputStart', callback?: (kbController: KeyboardController, textInputC
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| -------- | ----------------------------------------------------------------------------------------------------------------------- | ---- | -------------------------------------------------------------------- | | -------- | -------------------- | ---- | ------------------------ |
| type | string | 是 | 设置监听类型,固定取值为'inputStart'。 | | type | string | 是 | 设置监听类型,固定取值为'inputStart'。 |
| callback | (kbController: [KeyboardController](#keyboardcontroller), textInputClient: [TextInputClient](#textinputclient)) => void | 否 | 取消订阅的回调函数。参数不填写时,取消订阅 type 对应的所有回调事件。 | | callback | (kbController: [KeyboardController](#keyboardcontroller), textInputClient: [TextInputClient](#textinputclient)) => void | 否 | 取消订阅的回调函数。参数不填写时,取消订阅type对应的所有回调事件。|
**示例:** **示例:**
```js ```js
inputMethodEngine inputMethodEngine.getInputMethodEngine().off('inputStart', (kbController, textInputClient) => {
.getInputMethodEngine() console.log('delete inputStart notification.');
.off("inputStart", (kbController, textInputClient) => { });
console.log("delete inputStart notification.");
});
``` ```
### on('keyboardShow'|'keyboardHide') ### on('keyboardShow'|'keyboardHide')
on(type: 'keyboardShow'|'keyboardHide', callback: () => void): void on(type: 'keyboardShow'|'keyboardHide', callback: () => void): void
订阅输入法软键盘显示或隐藏事件。使用 callback 异步回调。 订阅输入法软键盘显示或隐藏事件。使用callback异步回调。
**系统能力:** SystemCapability.MiscServices.InputMethodFramework **系统能力:** SystemCapability.MiscServices.InputMethodFramework
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| -------- | ---------- | ---- | -------------------------------------------------------------------------------------------------- | | -------- | ------ | ---- | ------------------------------------------------------------ |
| type | string | 是 | 设置监听类型。<br/>-'keyboardShow'表示显示输入法软键盘。<br/>-'keyboardHide'表示隐藏输入法软键盘。 | | type | string | 是 | 设置监听类型。<br/>-'keyboardShow'表示显示输入法软键盘。<br/>-'keyboardHide'表示隐藏输入法软键盘。 |
| callback | () => void | 是 | 回调函数。 | | callback | () => void | 是 | 回调函数。 |
**示例:** **示例:**
```js ```js
inputMethodEngine.getInputMethodEngine().on("keyboardShow", () => { inputMethodEngine.getInputMethodEngine().on('keyboardShow', () => {
console.log("inputMethodEngine keyboardShow."); console.log('inputMethodEngine keyboardShow.');
}); });
inputMethodEngine.getInputMethodEngine().on("keyboardHide", () => { inputMethodEngine.getInputMethodEngine().on('keyboardHide', () => {
console.log("inputMethodEngine keyboardHide."); console.log('inputMethodEngine keyboardHide.');
}); });
``` ```
...@@ -225,95 +221,93 @@ inputMethodEngine.getInputMethodEngine().on("keyboardHide", () => { ...@@ -225,95 +221,93 @@ inputMethodEngine.getInputMethodEngine().on("keyboardHide", () => {
off(type: 'keyboardShow'|'keyboardHide', callback?: () => void): void off(type: 'keyboardShow'|'keyboardHide', callback?: () => void): void
取消订阅输入法软键盘显示或隐藏事件。使用 callback 异步回调。 取消订阅输入法软键盘显示或隐藏事件。使用callback异步回调。
**系统能力:** SystemCapability.MiscServices.InputMethodFramework **系统能力:** SystemCapability.MiscServices.InputMethodFramework
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| -------- | ---------- | ---- | ------------------------------------------------------------------------------------------------------------------ | | -------- | ------ | ---- | ------------------------------------------------------------ |
| type | string | 是 | 要取消监听的输入法软键盘类型。<br/>-'keyboardShow'表示显示输入法软键盘。<br/>-'keyboardHide'表示隐藏输入法软键盘。 | | type | string | 是 | 要取消监听的输入法软键盘类型。<br/>-'keyboardShow'表示显示输入法软键盘。<br/>-'keyboardHide'表示隐藏输入法软键盘。|
| callback | () => void | 否 | 取消订阅的回调函数。参数不填写时,取消订阅 type 对应的所有回调事件。 | | callback | () => void | 否 | 取消订阅的回调函数。参数不填写时,取消订阅type对应的所有回调事件。 |
**示例:** **示例:**
```js ```js
inputMethodEngine.getInputMethodEngine().off("keyboardShow"); inputMethodEngine.getInputMethodEngine().off('keyboardShow');
inputMethodEngine.getInputMethodEngine().off("keyboardHide"); inputMethodEngine.getInputMethodEngine().off('keyboardHide');
``` ```
## InputMethodAbility ## InputMethodAbility
下列 API 均需使用[getInputMethodAbility](#inputmethodenginegetinputmethodability9)获取到 InputMethodAbility 实例后,通过实例调用。 下列API均需使用[getInputMethodAbility](#inputmethodenginegetinputmethodability9)获取到InputMethodAbility实例后,通过实例调用。
### on('inputStart')<sup>9+</sup> ### on('inputStart')<sup>9+</sup>
on(type: 'inputStart', callback: (kbController: KeyboardController, inputClient: InputClient) => void): void on(type: 'inputStart', callback: (kbController: KeyboardController, inputClient: InputClient) => void): void
订阅输入法绑定成功事件。使用 callback 异步回调。 订阅输入法绑定成功事件。使用callback异步回调。
**系统能力:** SystemCapability.MiscServices.InputMethodFramework **系统能力:** SystemCapability.MiscServices.InputMethodFramework
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| -------- | ------------------------------------------------------------------------------------------------------------ | ---- | -------------------------------------- | | -------- | ------------------------------- | ---- | ------------------------------------------------------------ |
| type | string | 是 | 设置监听类型,固定取值为'inputStart'。 | | type | string | 是 | 设置监听类型,固定取值为'inputStart'。 |
| callback | (kbController: [KeyboardController](#keyboardcontroller), inputClient: [InputClient](#inputclient9)) => void | 是 | 回调函数,返回输入法操作相关实例。 | | callback | (kbController: [KeyboardController](#keyboardcontroller), inputClient: [InputClient](#inputclient9)) => void | 是 | 回调函数,返回输入法操作相关实例。 |
**示例:** **示例:**
```js ```js
inputMethodEngine inputMethodEngine.getInputMethodAbility().on('inputStart', (kbController, client) => {
.getInputMethodAbility()
.on("inputStart", (kbController, client) => {
let keyboardController = kbController; let keyboardController = kbController;
let inputClient = client; let inputClient = client;
}); });
``` ```
### off('inputStart')<sup>9+</sup> ### off('inputStart')<sup>9+</sup>
off(type: 'inputStart', callback?: (kbController: KeyboardController, inputClient: InputClient) => void): void off(type: 'inputStart', callback?: (kbController: KeyboardController, inputClient: InputClient) => void): void
取消订阅输入法绑定成功事件。使用 callback 异步回调。 取消订阅输入法绑定成功事件。使用callback异步回调。
**系统能力:** SystemCapability.MiscServices.InputMethodFramework **系统能力:** SystemCapability.MiscServices.InputMethodFramework
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| -------- | ------------------------------------------------------------------------------------------------------------ | ---- | -------------------------------------------------------------------- | | -------- | -------------------- | ---- | ------------------------ |
| type | string | 是 | 设置监听类型,固定取值为'inputStart'。 | | type | string | 是 | 设置监听类型,固定取值为'inputStart'。 |
| callback | (kbController: [KeyboardController](#keyboardcontroller), inputClient: [InputClient](#inputclient9)) => void | 否 | 取消订阅的回调函数。参数不填写时,取消订阅 type 对应的所有回调事件。 | | callback | (kbController: [KeyboardController](#keyboardcontroller), inputClient: [InputClient](#inputclient9)) => void | 否 | 取消订阅的回调函数。参数不填写时,取消订阅type对应的所有回调事件。|
**示例:** **示例:**
```js ```js
inputMethodEngine.getInputMethodAbility().off("inputStart"); 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
订阅停止输入法应用事件。使用 callback 异步回调。 订阅停止输入法应用事件。使用callback异步回调。
**系统能力:** SystemCapability.MiscServices.InputMethodFramework **系统能力:** SystemCapability.MiscServices.InputMethodFramework
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| -------- | ---------- | ---- | ------------------------------------- | | -------- | ------ | ---- | ------------------------------------------------------------ |
| type | string | 是 | 设置监听类型,固定取值为'inputStop'。 | | type | string | 是 | 设置监听类型,固定取值为'inputStop'。 |
| callback | () => void | 是 | 回调函数。 | | callback | () => void | 是 | 回调函数。 |
**示例:** **示例:**
```js ```js
inputMethodEngine.getInputMethodAbility().on("inputStop", () => { inputMethodEngine.getInputMethodAbility().on('inputStop', () => {
console.log("inputMethodAbility inputStop"); console.log('inputMethodAbility inputStop');
}); });
``` ```
...@@ -321,22 +315,22 @@ inputMethodEngine.getInputMethodAbility().on("inputStop", () => { ...@@ -321,22 +315,22 @@ inputMethodEngine.getInputMethodAbility().on("inputStop", () => {
off(type: 'inputStop', callback: () => void): void off(type: 'inputStop', callback: () => void): void
取消订阅停止输入法应用事件。使用 callback 异步回调。 取消订阅停止输入法应用事件。使用callback异步回调。
**系统能力:** SystemCapability.MiscServices.InputMethodFramework **系统能力:** SystemCapability.MiscServices.InputMethodFramework
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| -------- | ---------- | ---- | -------------------------------------------------------------------- | | -------- | ------ | ---- | ------------------------------------------------------------ |
| type | string | 是 | 设置监听类型,固定取值为'inputStop'。 | | type | string | 是 | 设置监听类型,固定取值为'inputStop'。 |
| callback | () => void | 是 | 取消订阅的回调函数。参数不填写时,取消订阅 type 对应的所有回调事件。 | | callback | () => void | 是 | 取消订阅的回调函数。参数不填写时,取消订阅type对应的所有回调事件。 |
**示例:** **示例:**
```js ```js
inputMethodEngine.getInputMethodAbility().off("inputStop", () => { inputMethodEngine.getInputMethodAbility().off('inputStop', () => {
console.log("inputMethodAbility delete inputStop notification."); console.log('inputMethodAbility delete inputStop notification.');
}); });
``` ```
...@@ -344,22 +338,22 @@ inputMethodEngine.getInputMethodAbility().off("inputStop", () => { ...@@ -344,22 +338,22 @@ inputMethodEngine.getInputMethodAbility().off("inputStop", () => {
on(type: 'setCallingWindow', callback: (wid: number) => void): void on(type: 'setCallingWindow', callback: (wid: number) => void): void
订阅设置调用窗口事件。使用 callback 异步回调。 订阅设置调用窗口事件。使用callback异步回调。
**系统能力:** SystemCapability.MiscServices.InputMethodFramework **系统能力:** SystemCapability.MiscServices.InputMethodFramework
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| -------- | --------------------- | ---- | -------------------------------------------- | | -------- | ------ | ---- | ------------------------------------------------------------ |
| type | string | 是 | 设置监听类型,固定取值为'setCallingWindow'。 | | type | string | 是 | 设置监听类型,固定取值为'setCallingWindow'。 |
| callback | (wid: number) => void | 是 | 回调函数,返回调用方窗口的 Id。 | | callback | (wid: number) => void | 是 | 回调函数,返回调用方窗口的Id。 |
**示例:** **示例:**
```js ```js
inputMethodEngine.getInputMethodAbility().on("setCallingWindow", (wid) => { inputMethodEngine.getInputMethodAbility().on('setCallingWindow', (wid) => {
console.log("inputMethodAbility setCallingWindow"); console.log('inputMethodAbility setCallingWindow');
}); });
``` ```
...@@ -367,22 +361,22 @@ inputMethodEngine.getInputMethodAbility().on("setCallingWindow", (wid) => { ...@@ -367,22 +361,22 @@ inputMethodEngine.getInputMethodAbility().on("setCallingWindow", (wid) => {
off(type: 'setCallingWindow', callback: (wid:number) => void): void off(type: 'setCallingWindow', callback: (wid:number) => void): void
取消订阅设置调用窗口事件。使用 callback 异步回调。 取消订阅设置调用窗口事件。使用callback异步回调。
**系统能力:** SystemCapability.MiscServices.InputMethodFramework **系统能力:** SystemCapability.MiscServices.InputMethodFramework
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| -------- | -------------------- | ---- | -------------------------------------------------------------------- | | -------- | ------ | ---- | ------------------------------------------------------------ |
| type | string | 是 | 设置监听类型,固定取值为'setCallingWindow'。 | | type | string | 是 | 设置监听类型,固定取值为'setCallingWindow'。|
| callback | (wid:number) => void | 是 | 取消订阅的回调函数。参数不填写时,取消订阅 type 对应的所有回调事件。 | | callback | (wid:number) => void | 是 | 取消订阅的回调函数。参数不填写时,取消订阅type对应的所有回调事件。 |
**示例:** **示例:**
```js ```js
inputMethodEngine.getInputMethodAbility().off("setCallingWindow", (wid) => { inputMethodEngine.getInputMethodAbility().off('setCallingWindow', (wid) => {
console.log("inputMethodAbility delete setCallingWindow notification."); console.log('inputMethodAbility delete setCallingWindow notification.');
}); });
``` ```
...@@ -390,25 +384,25 @@ inputMethodEngine.getInputMethodAbility().off("setCallingWindow", (wid) => { ...@@ -390,25 +384,25 @@ inputMethodEngine.getInputMethodAbility().off("setCallingWindow", (wid) => {
on(type: 'keyboardShow'|'keyboardHide', callback: () => void): void on(type: 'keyboardShow'|'keyboardHide', callback: () => void): void
订阅输入法软键盘显示或隐藏事件。使用 callback 异步回调。 订阅输入法软键盘显示或隐藏事件。使用callback异步回调。
**系统能力:** SystemCapability.MiscServices.InputMethodFramework **系统能力:** SystemCapability.MiscServices.InputMethodFramework
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| -------- | ---------- | ---- | ---------------------------------------------------------------------------------------------------- | | -------- | ------ | ---- | ------------------------------------------------------------ |
| type | string | 是 | 设置监听类型。<br/>- 'keyboardShow'表示显示输入法软键盘。<br/>- 'keyboardHide'表示隐藏输入法软键盘。 | | type | string | 是 | 设置监听类型。<br/>- 'keyboardShow'表示显示输入法软键盘。<br/>- 'keyboardHide'表示隐藏输入法软键盘。 |
| callback | () => void | 是 | 回调函数。 | | callback | () => void | 是 | 回调函数。 |
**示例:** **示例:**
```js ```js
inputMethodEngine.getInputMethodAbility().on("keyboardShow", () => { inputMethodEngine.getInputMethodAbility().on('keyboardShow', () => {
console.log("InputMethodAbility keyboardShow."); console.log('InputMethodAbility keyboardShow.');
}); });
inputMethodEngine.getInputMethodAbility().on("keyboardHide", () => { inputMethodEngine.getInputMethodAbility().on('keyboardHide', () => {
console.log("InputMethodAbility keyboardHide."); console.log('InputMethodAbility keyboardHide.');
}); });
``` ```
...@@ -416,25 +410,25 @@ inputMethodEngine.getInputMethodAbility().on("keyboardHide", () => { ...@@ -416,25 +410,25 @@ inputMethodEngine.getInputMethodAbility().on("keyboardHide", () => {
off(type: 'keyboardShow'|'keyboardHide', callback?: () => void): void off(type: 'keyboardShow'|'keyboardHide', callback?: () => void): void
取消订阅输入法事件。使用 callback 异步回调。 取消订阅输入法事件。使用callback异步回调。
**系统能力:** SystemCapability.MiscServices.InputMethodFramework **系统能力:** SystemCapability.MiscServices.InputMethodFramework
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| -------- | ---------- | ---- | ------------------------------------------------------------------------------------ | | -------- | ------ | ---- | ------------------------------------------------------------ |
| type | string | 是 | 设置监听类型。<br/>- 'keyboardShow'表示显示键盘。<br/>- 'keyboardHide'表示隐藏键盘。 | | type | string | 是 | 设置监听类型。<br/>- 'keyboardShow'表示显示键盘。<br/>- 'keyboardHide'表示隐藏键盘。 |
| callback | () => void | 否 | 回调函数。 | | callback | () => void | 否 | 回调函数。 |
**示例:** **示例:**
```js ```js
inputMethodEngine.getInputMethodAbility().off("keyboardShow", () => { inputMethodEngine.getInputMethodAbility().off('keyboardShow', () => {
console.log("InputMethodAbility delete keyboardShow notification."); console.log('InputMethodAbility delete keyboardShow notification.');
}); });
inputMethodEngine.getInputMethodAbility().off("keyboardHide", () => { inputMethodEngine.getInputMethodAbility().off('keyboardHide', () => {
console.log("InputMethodAbility delete keyboardHide notification."); console.log('InputMethodAbility delete keyboardHide notification.');
}); });
``` ```
...@@ -442,47 +436,45 @@ inputMethodEngine.getInputMethodAbility().off("keyboardHide", () => { ...@@ -442,47 +436,45 @@ inputMethodEngine.getInputMethodAbility().off("keyboardHide", () => {
on(type: 'setSubtype', callback: (inputMethodSubtype: InputMethodSubtype) => void): void on(type: 'setSubtype', callback: (inputMethodSubtype: InputMethodSubtype) => void): void
订阅设置输入法子类型事件。使用 callback 异步回调。 订阅设置输入法子类型事件。使用callback异步回调。
**系统能力:** SystemCapability.MiscServices.InputMethodFramework **系统能力:** SystemCapability.MiscServices.InputMethodFramework
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| -------- | ---------------------------------------------------------------------------------- | ---- | -------------------------------------- | | -------- | --- | ---- | --- |
| type | string | 是 | 设置监听类型,固定取值为'setSubtype'。 | | type | string | 是 | 设置监听类型,固定取值为'setSubtype'。 |
| callback | (inputMethodSubtype: [InputMethodSubtype](js-apis-inputmethod-subtype.md)) => void | 是 | 回调函数,返回设置的输入法子类型。 | | callback | (inputMethodSubtype: [InputMethodSubtype](js-apis-inputmethod-subtype.md)) => void | 是 | 回调函数,返回设置的输入法子类型。 |
**示例:** **示例:**
```js ```js
inputMethodEngine inputMethodEngine.getInputMethodAbility().on('setSubtype', (inputMethodSubtype) => {
.getInputMethodAbility() console.log('InputMethodAbility setSubtype.');
.on("setSubtype", (inputMethodSubtype) => { });
console.log("InputMethodAbility setSubtype.");
});
``` ```
### off('setSubtype')<sup>9+</sup> ### off('setSubtype')<sup>9+</sup>
off(type: 'setSubtype', callback?: (inputMethodSubtype: InputMethodSubtype) => void): void off(type: 'setSubtype', callback?: (inputMethodSubtype: InputMethodSubtype) => void): void
取消订阅输入法软键盘显示或隐藏事件。使用 callback 异步回调。 取消订阅输入法软键盘显示或隐藏事件。使用callback异步回调。
**系统能力:** SystemCapability.MiscServices.InputMethodFramework **系统能力:** SystemCapability.MiscServices.InputMethodFramework
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| -------- | ---------------------------------------------------------------------------------- | ---- | -------------------------------------------------------------------- | | ------- | ----- | ---- | ---- |
| type | string | 是 | 设置监听类型,固定取值为'setSubtype'。 | | type | string | 是 | 设置监听类型,固定取值为'setSubtype'。 |
| callback | (inputMethodSubtype: [InputMethodSubtype](js-apis-inputmethod-subtype.md)) => void | 否 | 取消订阅的回调函数。参数不填写时,取消订阅 type 对应的所有回调事件。 | | callback | (inputMethodSubtype: [InputMethodSubtype](js-apis-inputmethod-subtype.md)) => void | 否 | 取消订阅的回调函数。参数不填写时,取消订阅type对应的所有回调事件。 |
**示例:** **示例:**
```js ```js
inputMethodEngine.getInputMethodAbility().off("setSubtype", () => { inputMethodEngine.getInputMethodAbility().off('setSubtype', () => {
console.log("InputMethodAbility delete setSubtype notification."); console.log('InputMethodAbility delete setSubtype notification.');
}); });
``` ```
...@@ -490,22 +482,22 @@ inputMethodEngine.getInputMethodAbility().off("setSubtype", () => { ...@@ -490,22 +482,22 @@ inputMethodEngine.getInputMethodAbility().off("setSubtype", () => {
createPanel(ctx: BaseContext, info: PanelInfo, callback: AsyncCallback\<Panel>): void createPanel(ctx: BaseContext, info: PanelInfo, callback: AsyncCallback\<Panel>): void
创建输入法面板,仅支持输入法应用调用。使用 callback 异步回调。<br>单个输入法应用仅允许创建一个[软键盘类型](#paneltype10)[状态栏类型](#paneltype10)的面板。 创建输入法面板,仅支持输入法应用调用。使用callback异步回调。<br>单个输入法应用仅允许创建一个[软键盘类型](#paneltype10)[状态栏类型](#paneltype10)的面板。
**系统能力:** SystemCapability.MiscServices.InputMethodFramework **系统能力:** SystemCapability.MiscServices.InputMethodFramework
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| -------- | ------------------------------------------------------- | ---- | -------------------------------------------------------------- | | ------- | ----------- | ---- | ------------------------ |
| ctx | [BaseContext](js-apis-inner-application-baseContext.md) | 是 | 当前输入法应用上下文信息。 | | ctx | [BaseContext](js-apis-inner-application-baseContext.md) | 是 | 当前输入法应用上下文信息。 |
| info | [PanelInfo](#panelinfo10) | 是 | 输入法应用信息。 | | info | [PanelInfo](#panelinfo10) | 是 | 输入法应用信息。 |
| callback | AsyncCallback\<[Panel](#panel10)> | 是 | 回调函数。当输入法面板创建成功,返回当前创建的输入法面板对象。 | | callback | AsyncCallback\<[Panel](#panel10)> | 是 | 回调函数。当输入法面板创建成功,返回当前创建的输入法面板对象。 |
**错误码:** **错误码:**
| 错误码 ID | 错误信息 | | 错误码ID | 错误信息 |
| --------- | ------------------------------ | | ---------- | ----------------------------- |
| 12800004 | not an input method extension. | | 12800004 | not an input method extension. |
**示例:** **示例:**
...@@ -513,19 +505,17 @@ createPanel(ctx: BaseContext, info: PanelInfo, callback: AsyncCallback\<Panel>): ...@@ -513,19 +505,17 @@ createPanel(ctx: BaseContext, info: PanelInfo, callback: AsyncCallback\<Panel>):
```js ```js
let panelInfo: inputMethodEngine.PanelInfo = { let panelInfo: inputMethodEngine.PanelInfo = {
type: inputMethodEngine.PanelType.SOFT_KEYBOARD, type: inputMethodEngine.PanelType.SOFT_KEYBOARD,
flag: inputMethodEngine.PanelFlag.FLG_FIXED, flag: inputMethodEngine.PanelFlag.FLG_FIXED
}; }
try { try {
inputMethodEngine inputMethodEngine.getInputMethodAbility().createPanel(this.context, panelInfo, (err, panel) => {
.getInputMethodAbility()
.createPanel(this.context, panelInfo, (err, panel) => {
if (err) { if (err) {
console.error(`Failed to createPanel: ${JSON.stringify(err)}`); console.error(`Failed to createPanel: ${JSON.stringify(err)}`);
return; return;
} }
console.log("Succeed in creating panel."); console.log('Succeed in creating panel.');
}); })
} catch (err) { } catch(err) {
console.error(`Failed to createPanel: ${JSON.stringify(err)}`); console.error(`Failed to createPanel: ${JSON.stringify(err)}`);
} }
``` ```
...@@ -534,14 +524,14 @@ try { ...@@ -534,14 +524,14 @@ try {
createPanel(ctx: BaseContext, info: PanelInfo): Promise\<Panel> createPanel(ctx: BaseContext, info: PanelInfo): Promise\<Panel>
创建输入法面板,仅支持输入法应用调用。使用 promise 异步回调。<br>单个输入法应用仅允许创建一个[软键盘类型](#paneltype10)[状态栏类型](#paneltype10)的面板。 创建输入法面板,仅支持输入法应用调用。使用promise异步回调。<br>单个输入法应用仅允许创建一个[软键盘类型](#paneltype10)[状态栏类型](#paneltype10)的面板。
**系统能力:** SystemCapability.MiscServices.InputMethodFramework **系统能力:** SystemCapability.MiscServices.InputMethodFramework
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| ------ | ------------------------------------------------------- | ---- | -------------------------- | | ------- | ----------- | ---- | ------------------------ |
| ctx | [BaseContext](js-apis-inner-application-baseContext.md) | 是 | 当前输入法应用上下文信息。 | | ctx | [BaseContext](js-apis-inner-application-baseContext.md) | 是 | 当前输入法应用上下文信息。 |
| info | [PanelInfo](#panelinfo10) | 是 | 输入法面板信息。 | | info | [PanelInfo](#panelinfo10) | 是 | 输入法面板信息。 |
...@@ -552,8 +542,8 @@ createPanel(ctx: BaseContext, info: PanelInfo): Promise\<Panel> ...@@ -552,8 +542,8 @@ createPanel(ctx: BaseContext, info: PanelInfo): Promise\<Panel>
**错误码:** **错误码:**
| 错误码 ID | 错误信息 | | 错误码ID | 错误信息 |
| --------- | ------------------------------ | | ---------- | ----------------------------- |
| 12800004 | not an input method extension. | | 12800004 | not an input method extension. |
**示例:** **示例:**
...@@ -561,67 +551,59 @@ createPanel(ctx: BaseContext, info: PanelInfo): Promise\<Panel> ...@@ -561,67 +551,59 @@ createPanel(ctx: BaseContext, info: PanelInfo): Promise\<Panel>
```js ```js
let panelInfo: inputMethodEngine.PanelInfo = { let panelInfo: inputMethodEngine.PanelInfo = {
type: inputMethodEngine.PanelType.SOFT_KEYBOARD, type: inputMethodEngine.PanelType.SOFT_KEYBOARD,
flag: inputMethodEngine.PanelFlag.FLG_FIXED, flag: inputMethodEngine.PanelFlag.FLG_FIXED
}; }
inputMethodEngine inputMethodEngine.getInputMethodAbility().createPanel(this.context, panelInfo).then((panel) => {
.getInputMethodAbility() console.log('Succeed in creating panel.');
.createPanel(this.context, panelInfo) }).catch((err) => {
.then((panel) => {
console.log("Succeed in creating panel.");
})
.catch((err) => {
console.error(`Failed to create panel: ${JSON.stringify(err)}`); console.error(`Failed to create panel: ${JSON.stringify(err)}`);
}); })
``` ```
### destroyPanel<sup>10+</sup> ### destroyPanel<sup>10+</sup>
destroyPanel(panel: Panel, callback: AsyncCallback\<void>): void; destroyPanel(panel: Panel, callback: AsyncCallback\<void>): void;
销毁输入法面板。使用 callback 异步回调。 销毁输入法面板。使用callback异步回调。
**系统能力:** SystemCapability.MiscServices.InputMethodFramework **系统能力:** SystemCapability.MiscServices.InputMethodFramework
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| -------- | -------------------- | ---- | ------------------------------------------------------------------ | | ------- | ----------- | ---- | ------------------------ |
| panel | [Panel](#panel10) | 是 | 要销毁的面板对象。 | | panel | [Panel](#panel10) | 是 | 要销毁的面板对象。 |
| callback | AsyncCallback\<void> | 是 | 回调函数。当输入法面板销毁成功,err 为 undefined,否则为错误对象。 | | callback | AsyncCallback\<void> | 是 | 回调函数。当输入法面板销毁成功,err为undefined,否则为错误对象。 |
**示例:** **示例:**
```js ```js
let panelInfo: inputMethodEngine.PanelInfo = { let panelInfo: inputMethodEngine.PanelInfo = {
type: inputMethodEngine.PanelType.SOFT_KEYBOARD, type: inputMethodEngine.PanelType.SOFT_KEYBOARD,
flag: inputMethodEngine.PanelFlag.FLG_FIXED, flag: inputMethodEngine.PanelFlag.FLG_FIXED
}; }
try { try {
inputMethodEngine inputMethodEngine.getInputMethodAbility().createPanel(this.context, panelInfo, (err, panel) => {
.getInputMethodAbility()
.createPanel(this.context, panelInfo, (err, panel) => {
if (err) { if (err) {
console.error(`Failed to create panel: ${JSON.stringify(err)}`); console.error(`Failed to create panel: ${JSON.stringify(err)}`);
return; return;
} }
globalThis.inputMethodPanel = panel; globalThis.inputMethodPanel = panel;
console.log("Succeed in creating panel."); console.log('Succeed in creating panel.');
}); })
} catch (err) { } catch(err) {
console.error(`Failed to create panel: ${JSON.stringify(err)}`); console.error(`Failed to create panel: ${JSON.stringify(err)}`);
} }
try { try {
inputMethodEngine inputMethodEngine.getInputMethodAbility().destroyPanel(globalThis.inputMethodPanel, (err) => {
.getInputMethodAbility() if(err !== undefined) {
.destroyPanel(globalThis.inputMethodPanel, (err) => {
if (err !== undefined) {
console.error(`Failed to destroy panel: ${JSON.stringify(err)}`); console.error(`Failed to destroy panel: ${JSON.stringify(err)}`);
return; return;
} }
console.log("Succeed in destroying panel."); console.log('Succeed in destroying panel.');
}); })
} catch (err) { } catch(err) {
console.error(`Failed to destroy panel: ${JSON.stringify(err)}`); console.error(`Failed to destroy panel: ${JSON.stringify(err)}`);
} }
``` ```
...@@ -630,51 +612,45 @@ try { ...@@ -630,51 +612,45 @@ try {
destroyPanel(panel: Panel): Promise\<void>; destroyPanel(panel: Panel): Promise\<void>;
销毁输入法面板。使用 promise 异步回调。 销毁输入法面板。使用promise异步回调。
**系统能力:** SystemCapability.MiscServices.InputMethodFramework **系统能力:** SystemCapability.MiscServices.InputMethodFramework
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| ------ | ----------------- | ---- | ------------------ | | ---------| ----------- | ---- | ------------------------ |
| panel | [Panel](#panel10) | 是 | 要销毁的面板对象。 | | panel | [Panel](#panel10) | 是 | 要销毁的面板对象。 |
**返回值:** **返回值:**
| 类型 | 说明 | | 类型 | 说明 |
| ------- | -------------------------------------------------------------------- | | ------- | -------------------------------------------------------------------- |
| Promise\<void> | 无返回结果的 Promise 对象。| | Promise\<void> | 无返回结果的Promise对象。|
**示例:** **示例:**
```js ```js
let panelInfo: inputMethodEngine.PanelInfo = { let panelInfo: inputMethodEngine.PanelInfo = {
type: inputMethodEngine.PanelType.SOFT_KEYBOARD, type: inputMethodEngine.PanelType.SOFT_KEYBOARD,
flag: inputMethodEngine.PanelFlag.FLG_FIXED, flag: inputMethodEngine.PanelFlag.FLG_FIXED
}; }
try { try {
inputMethodEngine inputMethodEngine.getInputMethodAbility().createPanel(this.context, panelInfo, (err, panel) => {
.getInputMethodAbility()
.createPanel(this.context, panelInfo, (err, panel) => {
if (err) { if (err) {
console.error(`Failed to create panel: ${JSON.stringify(err)}`); console.error(`Failed to create panel: ${JSON.stringify(err)}`);
return; return;
} }
globalThis.inputMethodPanel = panel; globalThis.inputMethodPanel = panel;
console.log("Succeed in creating panel."); console.log('Succeed in creating panel.');
}); })
} catch (err) { } catch(err) {
console.error(`Failed to create panel: ${JSON.stringify(err)}`); console.error(`Failed to create panel: ${JSON.stringify(err)}`);
} }
try { try {
inputMethodEngine inputMethodEngine.getInputMethodAbility().destroyPanel(globalThis.inputMethodPanel).then(() => {
.getInputMethodAbility() console.log('Succeed in destroying panel.');
.destroyPanel(globalThis.inputMethodPanel) }).catch((err) => {
.then(() => {
console.log("Succeed in destroying panel.");
})
.catch((err) => {
console.error(`Failed to destroy panel: ${JSON.stringify(err)}`); console.error(`Failed to destroy panel: ${JSON.stringify(err)}`);
}); });
} catch (err) { } catch (err) {
...@@ -684,43 +660,34 @@ try { ...@@ -684,43 +660,34 @@ try {
## KeyboardDelegate ## KeyboardDelegate
下列 API 均需使用[getKeyboardDelegate](#inputmethodenginegetkeyboarddelegate9)获取到 KeyboardDelegate 实例后,通过实例调用。 下列API均需使用[getKeyboardDelegate](#inputmethodenginegetkeyboarddelegate9)获取到KeyboardDelegate实例后,通过实例调用。
### on('keyDown'|'keyUp') ### on('keyDown'|'keyUp')
on(type: 'keyDown'|'keyUp', callback: (event: KeyEvent) => boolean): void on(type: 'keyDown'|'keyUp', callback: (event: KeyEvent) => boolean): void
订阅硬键盘(即物理键盘)上物理按键的按下或抬起事件。使用 callback 异步回调。 订阅硬键盘(即物理键盘)上物理按键的按下或抬起事件。使用callback异步回调。
**系统能力:** SystemCapability.MiscServices.InputMethodFramework **系统能力:** SystemCapability.MiscServices.InputMethodFramework
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| -------- | ----------------------------------------- | ---- | ------------------------------------------------------------------------ | | -------- | ------------------------------- | ---- | ------------------------------------------------------------ |
| type | string | 是 | 设置监听类型。<br/>- 'keyDown'表示键盘按下。<br/>- 'keyUp'表示键盘抬起。 | | type | string | 是 | 设置监听类型。<br/>- 'keyDown'表示键盘按下。<br/>- 'keyUp'表示键盘抬起。 |
| callback | (event: [KeyEvent](#keyevent)) => boolean | 是 | 回调函数,返回按键信息。 | | callback | (event: [KeyEvent](#keyevent)) => boolean | 是 | 回调函数,返回按键信息。 |
**示例:** **示例:**
```js ```js
inputMethodEngine.getKeyboardDelegate().on("keyUp", (keyEvent) => { inputMethodEngine.getKeyboardDelegate().on('keyUp', (keyEvent) => {
console.log( console.log('inputMethodEngine keyCode.(keyUp):' + JSON.stringify(keyEvent.keyCode));
"inputMethodEngine keyCode.(keyUp):" + JSON.stringify(keyEvent.keyCode) console.log('inputMethodEngine keyAction.(keyUp):' + JSON.stringify(keyEvent.keyAction));
);
console.log(
"inputMethodEngine keyAction.(keyUp):" + JSON.stringify(keyEvent.keyAction)
);
return true; return true;
}); });
inputMethodEngine.getKeyboardDelegate().on("keyDown", (keyEvent) => { inputMethodEngine.getKeyboardDelegate().on('keyDown', (keyEvent) => {
console.log( console.log('inputMethodEngine keyCode.(keyDown):' + JSON.stringify(keyEvent.keyCode));
"inputMethodEngine keyCode.(keyDown):" + JSON.stringify(keyEvent.keyCode) console.log('inputMethodEngine keyAction.(keyDown):' + JSON.stringify(keyEvent.keyAction));
);
console.log(
"inputMethodEngine keyAction.(keyDown):" +
JSON.stringify(keyEvent.keyAction)
);
return true; return true;
}); });
``` ```
...@@ -729,26 +696,26 @@ inputMethodEngine.getKeyboardDelegate().on("keyDown", (keyEvent) => { ...@@ -729,26 +696,26 @@ inputMethodEngine.getKeyboardDelegate().on("keyDown", (keyEvent) => {
off(type: 'keyDown'|'keyUp', callback?: (event: KeyEvent) => boolean): void off(type: 'keyDown'|'keyUp', callback?: (event: KeyEvent) => boolean): void
取消订阅硬键盘(即物理键盘)上物理按键的按下或抬起事件。使用 callback 异步回调。 取消订阅硬键盘(即物理键盘)上物理按键的按下或抬起事件。使用callback异步回调。
**系统能力:** SystemCapability.MiscServices.InputMethodFramework **系统能力:** SystemCapability.MiscServices.InputMethodFramework
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| -------- | ----------------------------------------- | ---- | ------------------------------------------------------------------------ | | -------- | ------- | ---- | ----- |
| type | string | 是 | 设置监听类型。<br/>- 'keyDown'表示键盘按下。<br/>- 'keyUp'表示键盘抬起。 | | type | string | 是 | 设置监听类型。<br/>- 'keyDown'表示键盘按下。<br/>- 'keyUp'表示键盘抬起。 |
| callback | (event: [KeyEvent](#keyevent)) => boolean | 否 | 取消订阅的回调函数。参数不填写时,取消订阅 type 对应的所有回调事件。 | | callback | (event: [KeyEvent](#keyevent)) => boolean | 否 | 取消订阅的回调函数。参数不填写时,取消订阅type对应的所有回调事件。 |
**示例:** **示例:**
```js ```js
inputMethodEngine.getKeyboardDelegate().off("keyUp", (keyEvent) => { inputMethodEngine.getKeyboardDelegate().off('keyUp', (keyEvent) => {
console.log("delete keyUp notification."); console.log('delete keyUp notification.');
return true; return true;
}); });
inputMethodEngine.getKeyboardDelegate().off("keyDown", (keyEvent) => { inputMethodEngine.getKeyboardDelegate().off('keyDown', (keyEvent) => {
console.log("delete keyDown notification."); console.log('delete keyDown notification.');
return true; return true;
}); });
``` ```
...@@ -757,30 +724,24 @@ inputMethodEngine.getKeyboardDelegate().off("keyDown", (keyEvent) => { ...@@ -757,30 +724,24 @@ inputMethodEngine.getKeyboardDelegate().off("keyDown", (keyEvent) => {
on(type: 'keyEvent', callback: (event: InputKeyEvent) => boolean): void on(type: 'keyEvent', callback: (event: InputKeyEvent) => boolean): void
订阅硬键盘(即物理键盘)事件。使用 callback 异步回调。 订阅硬键盘(即物理键盘)事件。使用callback异步回调。
**系统能力:** SystemCapability.MiscServices.InputMethodFramework **系统能力:** SystemCapability.MiscServices.InputMethodFramework
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | ---- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | -------- | -------- | ---- | ------------------------------------------------------------ |
| type | string | 是 | 设置监听类型,固定取值为'keyEvent'。 | | type | string | 是 | 设置监听类型,固定取值为'keyEvent'。 |
| callback | function | 是 | 回调函数,入参为按键事件信息,返回值类型为布尔类型。<br/>-&nbsp;入参按键事件信息的数据类型为[InputKeyEvent](js-apis-keyevent.md#KeyEvent)。<br/>-&nbsp;若按键事件被事件订阅者消费,则 callback 应返回 true,否则返回 false。 | | callback | function | 是 | 回调函数,入参为按键事件信息,返回值类型为布尔类型。<br/>-&nbsp;入参按键事件信息的数据类型为[InputKeyEvent](js-apis-keyevent.md#KeyEvent)。<br/>-&nbsp;若按键事件被事件订阅者消费,则callback应返回true,否则返回false。|
**示例:** **示例:**
```js ```js
inputMethodEngine.getKeyboardDelegate().on("keyEvent", (keyEvent) => { inputMethodEngine.getKeyboardDelegate().on('keyEvent', (keyEvent) => {
console.log( console.log('inputMethodEngine keyEvent.action:' + JSON.stringify(keyEvent.action));
"inputMethodEngine keyEvent.action:" + JSON.stringify(keyEvent.action) console.log('inputMethodEngine keyEvent.key.code:' + JSON.stringify(keyEvent.key.code));
); console.log('inputMethodEngine keyEvent.ctrlKey:' + JSON.stringify(keyEvent.ctrlKey));
console.log(
"inputMethodEngine keyEvent.key.code:" + JSON.stringify(keyEvent.key.code)
);
console.log(
"inputMethodEngine keyEvent.ctrlKey:" + JSON.stringify(keyEvent.ctrlKey)
);
return true; return true;
}); });
``` ```
...@@ -789,160 +750,145 @@ inputMethodEngine.getKeyboardDelegate().on("keyEvent", (keyEvent) => { ...@@ -789,160 +750,145 @@ inputMethodEngine.getKeyboardDelegate().on("keyEvent", (keyEvent) => {
off(type: 'keyEvent', callback?: (event: InputKeyEvent) => boolean): void off(type: 'keyEvent', callback?: (event: InputKeyEvent) => boolean): void
取消订阅硬键盘(即物理键盘)事件。使用 callback 异步回调。 取消订阅硬键盘(即物理键盘)事件。使用callback异步回调。
**系统能力:** SystemCapability.MiscServices.InputMethodFramework **系统能力:** SystemCapability.MiscServices.InputMethodFramework
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | ---- | -------------------------------------------------------------------- | | -------- | -------- | ---- | ------------------------------------------------------------ |
| type | string | 是 | 设置监听类型,固定取值为'keyEvent'。 | | type | string | 是 | 设置监听类型,固定取值为'keyEvent'。 |
| callback | function | 否 | 取消订阅的回调函数。参数不填写时,取消订阅 type 对应的所有回调事件。 | | callback | function | 否 | 取消订阅的回调函数。参数不填写时,取消订阅type对应的所有回调事件。|
**示例:** **示例:**
```js ```js
inputMethodEngine.getKeyboardDelegate().off("keyEvent", (keyEvent) => { inputMethodEngine.getKeyboardDelegate().off('keyEvent', (keyEvent) => {
console.log("This is a callback function which will be deregistered."); console.log('This is a callback function which will be deregistered.');
return true; return true;
}); });
inputMethodEngine.getKeyboardDelegate().off("keyEvent"); inputMethodEngine.getKeyboardDelegate().off('keyEvent');
``` ```
### 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
订阅光标变化事件。使用 callback 异步回调。 订阅光标变化事件。使用callback异步回调。
**系统能力:** SystemCapability.MiscServices.InputMethodFramework **系统能力:** SystemCapability.MiscServices.InputMethodFramework
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| -------- | ---------------------------------------------- | ---- | --------------------------------------------------------------------------------------------------------- | | -------- | ---- | ---- | ----- |
| type | string | 是 | 光标变化事件,固定取值为'cursorContextChange'。 | | type | string | 是 | 光标变化事件,固定取值为'cursorContextChange'。 |
| callback | (x: number, y: number, height: number) => void | 是 | 回调函数,返回光标信息。<br/>-x 为光标上端的的 x 坐标值,y 为光标上端的 y 坐标值,height 为光标的高度值。 | | callback | (x: number, y: number, height: number) => void | 是 | 回调函数,返回光标信息。<br/>-x为光标上端的的x坐标值,y为光标上端的y坐标值,height为光标的高度值。 |
**示例:** **示例:**
```js ```js
inputMethodEngine inputMethodEngine.getKeyboardDelegate().on('cursorContextChange', (x, y, height) => {
.getKeyboardDelegate() console.log('inputMethodEngine cursorContextChange x:' + x);
.on("cursorContextChange", (x, y, height) => { console.log('inputMethodEngine cursorContextChange y:' + y);
console.log("inputMethodEngine cursorContextChange x:" + x); console.log('inputMethodEngine cursorContextChange height:' + height);
console.log("inputMethodEngine cursorContextChange y:" + y); });
console.log("inputMethodEngine cursorContextChange height:" + 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
取消订阅光标变化事件。使用 callback 异步回调。 取消订阅光标变化事件。使用callback异步回调。
**系统能力:** SystemCapability.MiscServices.InputMethodFramework **系统能力:** SystemCapability.MiscServices.InputMethodFramework
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| -------- | -------------------------------------------- | ---- | -------------------------------------------------------------------- | | -------- | ---- | ---- | ------ |
| type | string | 是 | 光标变化事件,固定取值为'cursorContextChange' | | type | string | 是 | 光标变化事件,固定取值为'cursorContextChange' |
| callback | (x: number, y:number, height:number) => void | 否 | 取消订阅的回调函数。参数不填写时,取消订阅 type 对应的所有回调事件。 | | callback | (x: number, y:number, height:number) => void | 否 | 取消订阅的回调函数。参数不填写时,取消订阅type对应的所有回调事件。 |
**示例:**
**示例:**
```js ```js
inputMethodEngine inputMethodEngine.getKeyboardDelegate().off('cursorContextChange', (x, y, height) => {
.getKeyboardDelegate() console.log('delete cursorContextChange notification.');
.off("cursorContextChange", (x, y, height) => { });
console.log("delete cursorContextChange notification.");
});
``` ```
### on('selectionChange') ### on('selectionChange')
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
订阅文本选择范围变化事件。使用 callback 异步回调。 订阅文本选择范围变化事件。使用callback异步回调。
**系统能力:** SystemCapability.MiscServices.InputMethodFramework **系统能力:** SystemCapability.MiscServices.InputMethodFramework
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| -------- | ---------------------------------------------------------------------------- | ---- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | -------- | ----- | ---- | ---- |
| type | string | 是 | 文本选择变化事件,固定取值为'selectionChange'。 | | type | string | 是 | 文本选择变化事件,固定取值为'selectionChange'。 |
| callback | (oldBegin: number, oldEnd: number, newBegin: number, newEnd: number) => void | 是 | 回调函数,返回文本选择信息。<br/>- oldBegin 为变化前被选中文本的起始下标,oldEnd 为变化前被选中文本的终止下标。<br/>- newBegin 为变化后被选中文本的起始下标,newEnd 为变化后被选中文本的终止下标。 | | callback | (oldBegin: number, oldEnd: number, newBegin: number, newEnd: number) => void | 是 | 回调函数,返回文本选择信息。<br/>- oldBegin为变化前被选中文本的起始下标,oldEnd为变化前被选中文本的终止下标。<br/>- newBegin为变化后被选中文本的起始下标,newEnd为变化后被选中文本的终止下标。|
**示例:** **示例:**
```js ```js
inputMethodEngine inputMethodEngine.getKeyboardDelegate().on('selectionChange', (oldBegin, oldEnd, newBegin, newEnd) => {
.getKeyboardDelegate() console.log('inputMethodEngine beforeEach selectionChange oldBegin:' + oldBegin);
.on("selectionChange", (oldBegin, oldEnd, newBegin, newEnd) => { console.log('inputMethodEngine beforeEach selectionChange oldEnd:' + oldEnd);
console.log( console.log('inputMethodEngine beforeEach selectionChange newBegin:' + newBegin);
"inputMethodEngine beforeEach selectionChange oldBegin:" + oldBegin console.log('inputMethodEngine beforeEach selectionChange newEnd:' + newEnd);
); });
console.log(
"inputMethodEngine beforeEach selectionChange oldEnd:" + oldEnd
);
console.log(
"inputMethodEngine beforeEach selectionChange newBegin:" + newBegin
);
console.log(
"inputMethodEngine beforeEach selectionChange newEnd:" + newEnd
);
});
``` ```
### off('selectionChange') ### off('selectionChange')
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
取消订阅文本选择范围变化事件。使用 callback 异步回调。 取消订阅文本选择范围变化事件。使用callback异步回调。
**系统能力:** SystemCapability.MiscServices.InputMethodFramework **系统能力:** SystemCapability.MiscServices.InputMethodFramework
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| -------- | ---------------------------------------------------------------------------- | ---- | -------------------------------------------------------------------- | | -------- | ------- | ---- | ------- |
| type | string | 是 | 文本选择变化事件,固定取值为'selectionChange'。 | | type | string | 是 | 文本选择变化事件,固定取值为'selectionChange'。 |
| callback | (oldBegin: number, oldEnd: number, newBegin: number, newEnd: number) => void | 否 | 取消订阅的回调函数。参数不填写时,取消订阅 type 对应的所有回调事件。 | | callback | (oldBegin: number, oldEnd: number, newBegin: number, newEnd: number) => void | 否 | 取消订阅的回调函数。参数不填写时,取消订阅type对应的所有回调事件。|
**示例:** **示例:**
```js ```js
inputMethodEngine inputMethodEngine.getKeyboardDelegate().off('selectionChange', (oldBegin, oldEnd, newBegin, newEnd) => {
.getKeyboardDelegate() console.log('delete selectionChange notification.');
.off("selectionChange", (oldBegin, oldEnd, newBegin, newEnd) => { });
console.log("delete selectionChange notification.");
});
``` ```
### on('textChange') ### on('textChange')
on(type: 'textChange', callback: (text: string) => void): void on(type: 'textChange', callback: (text: string) => void): void
订阅文本内容变化事件。使用 callback 异步回调。 订阅文本内容变化事件。使用callback异步回调。
**系统能力:** SystemCapability.MiscServices.InputMethodFramework **系统能力:** SystemCapability.MiscServices.InputMethodFramework
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| -------- | ---------------------- | ---- | -------------------------------------- | | -------- | ------ | ---- | ------------------------------------------------------------ |
| type | string | 是 | 文本变化事件,固定取值为'textChange'。 | | type | string | 是 | 文本变化事件,固定取值为'textChange'。 |
| callback | (text: string) => void | 是 | 回调函数,返回订阅的文本内容。 | | callback | (text: string) => void | 是 | 回调函数,返回订阅的文本内容。|
**示例:** **示例:**
```js ```js
inputMethodEngine.getKeyboardDelegate().on("textChange", (text) => { inputMethodEngine.getKeyboardDelegate().on('textChange', (text) => {
console.log("inputMethodEngine textChange. text:" + text); console.log('inputMethodEngine textChange. text:' + text);
}); });
``` ```
...@@ -950,22 +896,22 @@ inputMethodEngine.getKeyboardDelegate().on("textChange", (text) => { ...@@ -950,22 +896,22 @@ inputMethodEngine.getKeyboardDelegate().on("textChange", (text) => {
off(type: 'textChange', callback?: (text: string) => void): void off(type: 'textChange', callback?: (text: string) => void): void
取消订阅文本内容变化事件。使用 callback 异步回调。 取消订阅文本内容变化事件。使用callback异步回调。
**系统能力:** SystemCapability.MiscServices.InputMethodFramework **系统能力:** SystemCapability.MiscServices.InputMethodFramework
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| -------- | ---------------------- | ---- | -------------------------------------------------------------------- | | -------- | ------ | ---- | ------------------------------------------------------------ |
| type | string | 是 | 文本变化事件,固定取值为'textChange'。 | | type | string | 是 | 文本变化事件,固定取值为'textChange'。 |
| callback | (text: string) => void | 否 | 取消订阅的回调函数。参数不填写时,取消订阅 type 对应的所有回调事件。 | | callback | (text: string) => void | 否 | 取消订阅的回调函数。参数不填写时,取消订阅type对应的所有回调事件。|
**示例:** **示例:**
```js ```js
inputMethodEngine.getKeyboardDelegate().off("textChange", (text) => { inputMethodEngine.getKeyboardDelegate().off('textChange', (text) => {
console.log("delete textChange notification. text:" + text); console.log('delete textChange notification. text:' + text);
}); });
``` ```
...@@ -973,24 +919,22 @@ inputMethodEngine.getKeyboardDelegate().off("textChange", (text) => { ...@@ -973,24 +919,22 @@ inputMethodEngine.getKeyboardDelegate().off("textChange", (text) => {
on(type: 'editorAttributeChanged', callback: (attr: EditorAttribute) => void): void on(type: 'editorAttributeChanged', callback: (attr: EditorAttribute) => void): void
订阅编辑框属性变化事件。使用 callback 异步回调。 订阅编辑框属性变化事件。使用callback异步回调。
**系统能力:** SystemCapability.MiscServices.InputMethodFramework **系统能力:** SystemCapability.MiscServices.InputMethodFramework
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| -------- | ------------------------------- | ---- | -------------------------------------------------- | | -------- | ------ | ---- | ------------------------------------------------------------ |
| type | string | 是 | 文本变化事件,固定取值为'editorAttributeChanged'。 | | type | string | 是 | 文本变化事件,固定取值为'editorAttributeChanged'。 |
| callback | (attr: EditorAttribute) => void | 是 | 回调函数,返回变化的编辑框属性。 | | callback | (attr: EditorAttribute) => void | 是 | 回调函数,返回变化的编辑框属性。|
**示例:** **示例:**
```js ```js
inputMethodEngine.getKeyboardDelegate().on("editorAttributeChanged", (attr) => { inputMethodEngine.getKeyboardDelegate().on('editorAttributeChanged', (attr) => {
console.log( console.log(`Succeeded in receiving attribute of editor, inputPattern = ${attr.inputPattern}, enterKeyType = ${attr.enterKeyType}`);
`Succeeded in receiving attribute of editor, inputPattern = ${attr.inputPattern}, enterKeyType = ${attr.enterKeyType}`
);
}); });
``` ```
...@@ -998,52 +942,52 @@ inputMethodEngine.getKeyboardDelegate().on("editorAttributeChanged", (attr) => { ...@@ -998,52 +942,52 @@ inputMethodEngine.getKeyboardDelegate().on("editorAttributeChanged", (attr) => {
off(type: 'editorAttributeChanged', callback?: (attr: EditorAttribute) => void): void off(type: 'editorAttributeChanged', callback?: (attr: EditorAttribute) => void): void
取消订阅编辑框属性变化事件。使用 callback 异步回调。 取消订阅编辑框属性变化事件。使用callback异步回调。
**系统能力:** SystemCapability.MiscServices.InputMethodFramework **系统能力:** SystemCapability.MiscServices.InputMethodFramework
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| -------- | ------------------------------- | ---- | ---------------------------------------------------------------------------- | | -------- | ------ | ---- | ------------------------------------------------------------ |
| type | string | 是 | 文本变化事件,固定取值为'editorAttributeChanged'。 | | type | string | 是 | 文本变化事件,固定取值为'editorAttributeChanged'。 |
| callback | (attr: EditorAttribute) => void | 否 | 所要取消订阅的回调处理函数。参数不填写时,取消订阅 type 对应的所有回调事件。 | | callback | (attr: EditorAttribute) => void | 否 | 所要取消订阅的回调处理函数。参数不填写时,取消订阅type对应的所有回调事件。 |
**示例:** **示例:**
```js ```js
inputMethodEngine.getKeyboardDelegate().off("editorAttributeChanged"); inputMethodEngine.getKeyboardDelegate().off('editorAttributeChanged');
``` ```
## Panel<sup>10+</sup> ## Panel<sup>10+</sup>
下列 API 均需使用[createPanel](#createpanel10)获取到 Panel 实例后,通过实例调用。 下列API均需使用[createPanel](#createpanel10)获取到Panel实例后,通过实例调用。
### setUiContent<sup>10+</sup> ### setUiContent<sup>10+</sup>
setUiContent(path: string, callback: AsyncCallback\<void>): void setUiContent(path: string, callback: AsyncCallback\<void>): void
为当前的输入法面板加载具体页面内容,使用 callback 异步回调。 为当前的输入法面板加载具体页面内容,使用callback异步回调。
**系统能力:** SystemCapability.MiscServices.InputMethodFramework **系统能力:** SystemCapability.MiscServices.InputMethodFramework
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| -------- | -------------------- | ---- | ------------------------------------------------------------------------- | | -------- | ---------------------- | ---- | -------- |
| path | string | 是 | 具体页面的路径。 | | path | string | 是 | 具体页面的路径。 |
| callback | AsyncCallback\<void> | 是 | 回调函数。当面板页面内容加载成功,err 为 undefined,否则 err 为错误对象。 | | callback | AsyncCallback\<void> | 是 | 回调函数。当面板页面内容加载成功,err为undefined,否则err为错误对象。 |
**示例:** **示例:**
```js ```js
try { try {
panel.setUiContent("pages/page2/page2", (err) => { panel.setUiContent('pages/page2/page2', (err) => {
if (err) { if (err) {
console.error(`Failed to setUiContent: ${JSON.stringify(err)}`); console.error(`Failed to setUiContent: ${JSON.stringify(err)}`);
return; return;
} }
console.log("Succeeded in setting the content."); console.log('Succeeded in setting the content.');
}); });
} catch (err) { } catch (err) {
console.error(`Failed to setUiContent: ${JSON.stringify(err)}`); console.error(`Failed to setUiContent: ${JSON.stringify(err)}`);
...@@ -1054,32 +998,30 @@ try { ...@@ -1054,32 +998,30 @@ try {
setUiContent(path: string): Promise\<void> setUiContent(path: string): Promise\<void>
为当前的输入法面板加载具体页面内容,使用 Promise 异步回调。 为当前的输入法面板加载具体页面内容,使用Promise异步回调。
**系统能力:** SystemCapability.MiscServices.InputMethodFramework **系统能力:** SystemCapability.MiscServices.InputMethodFramework
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| ------ | ------ | ---- | ---------------- | | -------- | ---------------------- | ---- | -------- |
| path | string | 是 | 具体页面的路径。 | | path | string | 是 | 具体页面的路径。 |
**返回值:** **返回值:**
| 类型 | 说明 | | 类型 | 说明 |
| -------------- | --------------------------- | | ------- | ------------------------------ |
| Promise\<void> | 无返回结果的 Promise 对象。 | | Promise\<void> | 无返回结果的Promise对象。 |
**示例:** **示例:**
```js ```js
try { try {
let promise = panel.setUiContent("pages/page2/page2"); let promise = panel.setUiContent('pages/page2/page2');
promise promise.then(() => {
.then(() => { console.log('Succeeded in setting the content.');
console.log("Succeeded in setting the content."); }).catch((err) =>{
})
.catch((err) => {
console.error(`Failed to setUiContent: ${JSON.stringify(err)}`); console.error(`Failed to setUiContent: ${JSON.stringify(err)}`);
}); });
} catch (err) { } catch (err) {
...@@ -1091,30 +1033,30 @@ try { ...@@ -1091,30 +1033,30 @@ try {
setUiContent(path: string, storage: LocalStorage, callback: AsyncCallback\<void>): void setUiContent(path: string, storage: LocalStorage, callback: AsyncCallback\<void>): void
为当前的输入法面板加载与 LocalStorage 相关联的具体页面内容,使用 callback 异步回调。 为当前的输入法面板加载与LocalStorage相关联的具体页面内容,使用callback异步回调。
**系统能力:** SystemCapability.MiscServices.InputMethodFramework **系统能力:** SystemCapability.MiscServices.InputMethodFramework
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| -------- | ---------------------------------------------------------------- | ---- | ------------------------------------------------------------------------- | | -------- | ---------------------- | ---- | -------- |
| path | string | 是 | LocalStorage 相关联的具体页面的路径。 | | path | string | 是 | LocalStorage相关联的具体页面的路径。 |
| storage | [LocalStorage](../arkui-ts/ts-state-management.md#localstorage9) | 是 | 存储单元,为应用程序范围内的可变和不可变状态属性提供存储。 | | storage | [LocalStorage](../arkui-ts/ts-state-management.md#localstorage9) | 是 | 存储单元,为应用程序范围内的可变和不可变状态属性提供存储。|
| callback | AsyncCallback\<void> | 是 | 回调函数。当面板页面内容加载成功,err 为 undefined,否则 err 为错误对象。 | | callback | AsyncCallback\<void> | 是 | 回调函数。当面板页面内容加载成功,err为undefined,否则err为错误对象。 |
**示例:** **示例:**
```js ```js
let storage = new LocalStorage(); let storage = new LocalStorage();
storage.setOrCreate("storageSimpleProp", 121); storage.setOrCreate('storageSimpleProp',121);
try { try {
panel.setUiContent("pages/page2/page2", storage, (err) => { panel.setUiContent('pages/page2/page2', storage, (err) => {
if (err) { if (err) {
console.error(`Failed to setUiContent: ${JSON.stringify(err)}`); console.error(`Failed to setUiContent: ${JSON.stringify(err)}`);
return; return;
} }
console.log("Succeeded in setting the content."); console.log('Succeeded in setting the content.');
}); });
} catch (err) { } catch (err) {
console.error(`Failed to setUiContent: ${JSON.stringify(err)}`); console.error(`Failed to setUiContent: ${JSON.stringify(err)}`);
...@@ -1125,35 +1067,33 @@ try { ...@@ -1125,35 +1067,33 @@ try {
setUiContent(path: string, storage: LocalStorage): Promise\<void> setUiContent(path: string, storage: LocalStorage): Promise\<void>
为当前面板加载与 LocalStorage 相关联的具体页面内容,使用 Promise 异步回调。 为当前面板加载与LocalStorage相关联的具体页面内容,使用Promise异步回调。
**系统能力:** SystemCapability.MiscServices.InputMethodFramework **系统能力:** SystemCapability.MiscServices.InputMethodFramework
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| ------- | ---------------------------------------------------------------- | ---- | ------------------------------------------------------------------ | | -------- | ---------------------- | ---- | -------- |
| path | string | 是 | 设置加载页面的路径。 | | path | string | 是 | 设置加载页面的路径。 |
| storage | [LocalStorage](../arkui-ts/ts-state-management.md#localstorage9) | 是 | 存储单元,为应用程序范围内的可变状态属性和非可变状态属性提供存储。 | | storage | [LocalStorage](../arkui-ts/ts-state-management.md#localstorage9) | 是 | 存储单元,为应用程序范围内的可变状态属性和非可变状态属性提供存储。|
**返回值:** **返回值:**
| 类型 | 说明 | | 类型 | 说明 |
| -------------- | --------------------------- | | ------- | ------------------------------ |
| Promise\<void> | 无返回结果的 Promise 对象。 | | Promise\<void> | 无返回结果的Promise对象。 |
**示例:** **示例:**
```js ```js
let storage = new LocalStorage(); let storage = new LocalStorage();
storage.setOrCreate("storageSimpleProp", 121); storage.setOrCreate('storageSimpleProp',121);
try { try {
let promise = panel.setUiContent("pages/page2/page2"); let promise = panel.setUiContent('pages/page2/page2');
promise promise.then(() => {
.then(() => { console.log('Succeeded in setting the content.');
console.log("Succeeded in setting the content."); }).catch((err) =>{
})
.catch((err) => {
console.error(`Failed to setUiContent: ${JSON.stringify(err)}`); console.error(`Failed to setUiContent: ${JSON.stringify(err)}`);
}); });
} catch (err) { } catch (err) {
...@@ -1165,21 +1105,21 @@ try { ...@@ -1165,21 +1105,21 @@ try {
resize(width: number, height: number, callback: AsyncCallback\<void>): void resize(width: number, height: number, callback: AsyncCallback\<void>): void
改变当前输入法面板的大小,使用 callback 异步回调。 改变当前输入法面板的大小,使用callback异步回调。
> **说明** > **说明**
> >
> 面板宽度不超出屏幕宽度,面板高度不高于屏幕高度的 0.6 倍。 > 面板宽度不超出屏幕宽度,面板高度不高于屏幕高度的0.6倍。
**系统能力:** SystemCapability.MiscServices.InputMethodFramework **系统能力:** SystemCapability.MiscServices.InputMethodFramework
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| -------- | -------------------- | ---- | --------------------------------------------------------------------- | | -------- | ---------------------- | ---- | -------- |
| width | number | 是 | 目标面板的宽度,单位为 px。 | | width | number | 是 | 目标面板的宽度,单位为px。|
| height | number | 是 | 目标面板的高度,单位为 px。 | | height | number | 是 | 目标面板的高度,单位为px。|
| callback | AsyncCallback\<void> | 是 | 回调函数。当面板大小改变成功,err 为 undefined,否则 err 为错误对象。 | | callback | AsyncCallback\<void> | 是 | 回调函数。当面板大小改变成功,err为undefined,否则err为错误对象。 |
**示例:** **示例:**
...@@ -1190,7 +1130,7 @@ try { ...@@ -1190,7 +1130,7 @@ try {
console.error(`Failed to resize panel: ${JSON.stringify(err)}`); console.error(`Failed to resize panel: ${JSON.stringify(err)}`);
return; return;
} }
console.log("Succeeded in changing the panel size."); console.log('Succeeded in changing the panel size.');
}); });
} catch (err) { } catch (err) {
console.error(`Failed to resize panel: ${JSON.stringify(err)}`); console.error(`Failed to resize panel: ${JSON.stringify(err)}`);
...@@ -1201,37 +1141,35 @@ try { ...@@ -1201,37 +1141,35 @@ try {
resize(width: number, height: number): Promise\<void>; resize(width: number, height: number): Promise\<void>;
改变当前输入法面板的大小,使用 Promise 异步回调。 改变当前输入法面板的大小,使用Promise异步回调。
> **说明** > **说明**
> >
> 面板宽度不超出屏幕宽度,面板高度不高于屏幕高度的 0.6 倍。 > 面板宽度不超出屏幕宽度,面板高度不高于屏幕高度的0.6倍。
**系统能力:** SystemCapability.MiscServices.InputMethodFramework **系统能力:** SystemCapability.MiscServices.InputMethodFramework
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| ------ | ------ | ---- | --------------------------- | | -------- | ---------------------- | ---- | -------- |
| width | number | 是 | 目标面板的宽度,单位为 px。 | | width | number | 是 | 目标面板的宽度,单位为px。|
| height | number | 是 | 目标面板的高度,单位为 px。 | | height | number | 是 | 目标面板的高度,单位为px。|
**返回值:** **返回值:**
| 类型 | 说明 | | 类型 | 说明 |
| -------------- | --------------------------- | | ------- | ------------------------------ |
| Promise\<void> | 无返回结果的 Promise 对象。 | | Promise\<void> | 无返回结果的Promise对象。 |
**示例:** **示例:**
```js ```js
try { try {
let promise = panel.resize(500, 1000); let promise = panel.resize(500, 1000);
promise promise.then(() => {
.then(() => { console.log('Succeeded in changing the panel size.');
console.log("Succeeded in changing the panel size."); }).catch((err) =>{
})
.catch((err) => {
console.error(`Failed to resize panel: ${JSON.stringify(err)}`); console.error(`Failed to resize panel: ${JSON.stringify(err)}`);
}); });
} catch (err) { } catch (err) {
...@@ -1243,28 +1181,28 @@ try { ...@@ -1243,28 +1181,28 @@ try {
moveTo(x: number, y: number, callback: AsyncCallback\<void>): void moveTo(x: number, y: number, callback: AsyncCallback\<void>): void
移动面板位置,使用 callback 异步回调。[面板状态](#panelflag10)为固定态时,不产生实际移动效果。 移动面板位置,使用callback异步回调。[面板状态](#panelflag10)为固定态时,不产生实际移动效果。
**系统能力:** SystemCapability.MiscServices.InputMethodFramework **系统能力:** SystemCapability.MiscServices.InputMethodFramework
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| -------- | -------------------- | ---- | --------------------------------------------------------------------- | | -------- | ---------------------- | ---- | -------- |
| x | number | 是 | x 轴方向移动的值,值大于 0 表示右移,单位为 px。 | | x | number | 是 | x轴方向移动的值,值大于0表示右移,单位为px。|
| y | number | 是 | y 轴方向移动的值,值大于 0 表示下移,单位为 px。 | | y | number | 是 | y轴方向移动的值,值大于0表示下移,单位为px。|
| callback | AsyncCallback\<void> | 是 | 回调函数。当面板位置移动成功,err 为 undefined,否则 err 为错误对象。 | | callback | AsyncCallback\<void> | 是 | 回调函数。当面板位置移动成功,err为undefined,否则err为错误对象。 |
**示例:** **示例:**
```js ```js
try { try {
panel.moveTo(300, 300, (err) => { panel.moveTo(300, 300, (err) =>{
if (err) { if (err) {
console.error(`Failed to move panel: ${JSON.stringify(err)}`); console.error(`Failed to move panel: ${JSON.stringify(err)}`);
return; return;
} }
console.log("Succeeded in moving the panel."); console.log('Succeeded in moving the panel.');
}); });
} catch (err) { } catch (err) {
console.error(`Failed to move panel: ${JSON.stringify(err)}`); console.error(`Failed to move panel: ${JSON.stringify(err)}`);
...@@ -1275,33 +1213,31 @@ try { ...@@ -1275,33 +1213,31 @@ try {
moveTo(x: number, y: number): Promise\<void> moveTo(x: number, y: number): Promise\<void>
移动面板位置,使用 promise 异步回调。[面板状态](#panelflag10)为固定态时,不产生实际移动效果。 移动面板位置,使用promise异步回调。[面板状态](#panelflag10)为固定态时,不产生实际移动效果。
**系统能力:** SystemCapability.MiscServices.InputMethodFramework **系统能力:** SystemCapability.MiscServices.InputMethodFramework
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| ------ | ------ | ---- | ------------------------------------------------ | | -------- | ---------------------- | ---- | -------- |
| x | number | 是 | x 轴方向移动的值,值大于 0 表示右移,单位为 px。 | | x | number | 是 |x轴方向移动的值,值大于0表示右移,单位为px。|
| y | number | 是 | y 轴方向移动的值,值大于 0 表示下移,单位为 px。 | | y | number | 是 |y轴方向移动的值,值大于0表示下移,单位为px。|
**返回值:** **返回值:**
| 类型 | 说明 | | 类型 | 说明 |
| -------------- | --------------------------- | | ------- | ------------------------------ |
| Promise\<void> | 无返回结果的 Promise 对象。 | | Promise\<void> | 无返回结果的Promise对象。 |
**示例:** **示例:**
```js ```js
try { try {
let promise = panel.moveTo(300, 300); let promise = panel.moveTo(300, 300);
promise promise.then(() => {
.then(() => { console.log('Succeeded in moving the panel.');
console.log("Succeeded in moving the panel."); }).catch((err) =>{
})
.catch((err) => {
console.error(`Failed to move panel: ${JSON.stringify(err)}`); console.error(`Failed to move panel: ${JSON.stringify(err)}`);
}); });
} catch (err) { } catch (err) {
...@@ -1313,15 +1249,15 @@ try { ...@@ -1313,15 +1249,15 @@ try {
show(callback: AsyncCallback\<void>): void show(callback: AsyncCallback\<void>): void
显示当前输入法面板,使用 callback 异步回调。 显示当前输入法面板,使用callback异步回调。
**系统能力:** SystemCapability.MiscServices.InputMethodFramework **系统能力:** SystemCapability.MiscServices.InputMethodFramework
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| -------- | -------------------- | ---- | ----------------------------------------------------------------- | | -------- | ---------------------- | ---- | -------- |
| callback | AsyncCallback\<void> | 是 | 回调函数。当面板显示成功,err 为 undefined,否则 err 为错误对象。 | | callback | AsyncCallback\<void> | 是 | 回调函数。当面板显示成功,err为undefined,否则err为错误对象。 |
**示例:** **示例:**
...@@ -1331,7 +1267,7 @@ panel.show((err) => { ...@@ -1331,7 +1267,7 @@ panel.show((err) => {
console.error(`Failed to show panel: ${JSON.stringify(err)}`); console.error(`Failed to show panel: ${JSON.stringify(err)}`);
return; return;
} }
console.log("Succeeded in showing the panel."); console.log('Succeeded in showing the panel.');
}); });
``` ```
...@@ -1339,42 +1275,40 @@ panel.show((err) => { ...@@ -1339,42 +1275,40 @@ panel.show((err) => {
show(): Promise\<void> show(): Promise\<void>
显示当前输入法面板,使用 promise 异步回调。 显示当前输入法面板,使用promise异步回调。
**系统能力:** SystemCapability.MiscServices.InputMethodFramework **系统能力:** SystemCapability.MiscServices.InputMethodFramework
**返回值:** **返回值:**
| 类型 | 说明 | | 类型 | 说明 |
| -------------- | --------------------------- | | ------- | ------------------------------ |
| Promise\<void> | 无返回结果的 Promise 对象。 | | Promise\<void> | 无返回结果的Promise对象。 |
**示例:** **示例:**
```js ```js
let promise = panel.show(); let promise = panel.show();
promise promise.then(() => {
.then(() => { console.log('Succeeded in showing the panel.');
console.log("Succeeded in showing the panel."); }).catch((err) =>{
})
.catch((err) => {
console.error(`Failed to show panel: ${JSON.stringify(err)}`); console.error(`Failed to show panel: ${JSON.stringify(err)}`);
}); });
``` ```
### hide<sup>10+</sup> ### hide<sup>10+</sup>
hide(callback: AsyncCallback\<void>): void hide(callback: AsyncCallback\<void>): void
隐藏当前输入法面板,使用 callback 异步回调。 隐藏当前输入法面板,使用callback异步回调。
**系统能力:** SystemCapability.MiscServices.InputMethodFramework **系统能力:** SystemCapability.MiscServices.InputMethodFramework
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| -------- | -------------------- | ---- | ----------------------------------------------------------------- | | -------- | ---------------------- | ---- | -------- |
| callback | AsyncCallback\<void> | 是 | 回调函数。当面板隐藏成功,err 为 undefined,否则 err 为错误对象。 | | callback | AsyncCallback\<void> | 是 | 回调函数。当面板隐藏成功,err为undefined,否则err为错误对象。 |
**示例:** **示例:**
...@@ -1384,7 +1318,7 @@ panel.hide((err) => { ...@@ -1384,7 +1318,7 @@ panel.hide((err) => {
console.error(`Failed to hide panel: ${JSON.stringify(err)}`); console.error(`Failed to hide panel: ${JSON.stringify(err)}`);
return; return;
} }
console.log("Succeeded in hiding the panel."); console.log('Succeeded in hiding the panel.');
}); });
``` ```
...@@ -1392,49 +1326,47 @@ panel.hide((err) => { ...@@ -1392,49 +1326,47 @@ panel.hide((err) => {
hide(): Promise\<void> hide(): Promise\<void>
隐藏当前输入法面板,使用 promise 异步回调。 隐藏当前输入法面板,使用promise异步回调。
**系统能力:** SystemCapability.MiscServices.InputMethodFramework **系统能力:** SystemCapability.MiscServices.InputMethodFramework
**返回值:** **返回值:**
| 类型 | 说明 | | 类型 | 说明 |
| -------------- | --------------------------- | | ------- | ------------------------------ |
| Promise\<void> | 无返回结果的 Promise 对象。 | | Promise\<void> | 无返回结果的Promise对象。 |
**示例:** **示例:**
```js ```js
let promise = panel.hide(); let promise = panel.hide();
promise promise.then(() => {
.then(() => { console.log('Succeeded in hiding the panel.');
console.log("Succeeded in hiding the panel."); }).catch((err) =>{
})
.catch((err) => {
console.error(`Failed to hide panel: ${JSON.stringify(err)}`); console.error(`Failed to hide panel: ${JSON.stringify(err)}`);
}); });
``` ```
### on('show')<sup>10+</sup> ### on('show')<sup>10+</sup>
on(type: 'show', callback: () => void): void on(type: 'show', callback: () => void): void
监听当前面板显示状态,使用 callback 异步回调。 监听当前面板显示状态,使用callback异步回调。
**系统能力:** SystemCapability.MiscServices.InputMethodFramework **系统能力:** SystemCapability.MiscServices.InputMethodFramework
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| -------- | ---------- | ---- | ------------------------------------------ | | -------- | ---------------------- | ---- | -------- |
| type | string | 是 | 监听当前面板的状态类型,固定取值为'show'。 | | type | string | 是 | 监听当前面板的状态类型,固定取值为'show'。 |
| callback | () => void | 是 | 回调函数。 | | callback | () => void | 是 | 回调函数。 |
**示例:** **示例:**
```js ```js
panel.on("show", () => { panel.on('show', () => {
console.log("Panel is showing."); console.log('Panel is showing.');
}); });
``` ```
...@@ -1442,22 +1374,22 @@ panel.on("show", () => { ...@@ -1442,22 +1374,22 @@ panel.on("show", () => {
on(type: 'hide', callback: () => void): void on(type: 'hide', callback: () => void): void
监听当前面板隐藏状态,使用 callback 异步回调。 监听当前面板隐藏状态,使用callback异步回调。
**系统能力:** SystemCapability.MiscServices.InputMethodFramework **系统能力:** SystemCapability.MiscServices.InputMethodFramework
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| -------- | ---------- | ---- | ------------------------------------------ | | -------- | ---------------------- | ---- | -------- |
| type | string | 是 | 监听当前面板的状态类型,固定取值为'hide'。 | | type | string | 是 | 监听当前面板的状态类型,固定取值为'hide'。 |
| callback | () => void | 是 | 回调函数。 | | callback | () => void | 是 | 回调函数。 |
**示例:** **示例:**
```js ```js
panel.on("hide", () => { panel.on('hide', () => {
console.log("Panel is hiding."); console.log('Panel is hiding.');
}); });
``` ```
...@@ -1465,42 +1397,42 @@ panel.on("hide", () => { ...@@ -1465,42 +1397,42 @@ panel.on("hide", () => {
off(type: 'show', callback?: () => void): void off(type: 'show', callback?: () => void): void
取消监听当前输入法面板的隐藏状态,使用 callback 异步回调。 取消监听当前输入法面板的隐藏状态,使用callback异步回调。
**系统能力:** SystemCapability.MiscServices.InputMethodFramework **系统能力:** SystemCapability.MiscServices.InputMethodFramework
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| -------- | ---------- | ---- | -------------------------------------------------------------------- | | -------- | ---------------------- | ---- | -------- |
| type | string | 是 | 取消监听当前面板的状态类型,固定取值为'show'。 | | type | string | 是 | 取消监听当前面板的状态类型,固定取值为'show'。 |
| callback | () => void | 否 | 取消订阅的回调函数。参数不填写时,取消订阅 type 对应的所有回调事件。 | | callback | () => void | 否 | 取消订阅的回调函数。参数不填写时,取消订阅type对应的所有回调事件。 |
**示例:** **示例:**
```js ```js
panel.off("show"); panel.off('show');
``` ```
### off('hide')<sup>10+</sup> ### off('hide')<sup>10+</sup>
off(type: 'hide', callback?: () => void): void off(type: 'hide', callback?: () => void): void
取消监听当前面板隐藏状态,使用 callback 异步回调。 取消监听当前面板隐藏状态,使用callback异步回调。
**系统能力:** SystemCapability.MiscServices.InputMethodFramework **系统能力:** SystemCapability.MiscServices.InputMethodFramework
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| -------- | ---------- | ---- | -------------------------------------------------------------------- | | -------- | ---------------------- | ---- | -------- |
| type | string | 是 | 要取消监听的当前面板状态类型,固定取值为'hide'。 | | type | string | 是 | 要取消监听的当前面板状态类型,固定取值为'hide'。 |
| callback | () => void | 否 | 取消订阅的回调函数。参数不填写时,取消订阅 type 对应的所有回调事件。 | | callback | () => void | 否 | 取消订阅的回调函数。参数不填写时,取消订阅type对应的所有回调事件。 |
**示例:** **示例:**
```js ```js
panel.off("hide"); panel.off('hide');
``` ```
### changeFlag<sup>10+</sup> ### changeFlag<sup>10+</sup>
...@@ -1514,7 +1446,7 @@ changeFlag(flag: PanelFlag): void ...@@ -1514,7 +1446,7 @@ changeFlag(flag: PanelFlag): void
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| ------ | ------------------------- | ---- | ------------------ | | -------- | ---------------------- | ---- | -------- |
| flag | [PanelFlag](#panelflag10) | 是 | 目标面板状态类型。 | | flag | [PanelFlag](#panelflag10) | 是 | 目标面板状态类型。 |
**示例:** **示例:**
...@@ -1526,28 +1458,28 @@ panel.changeFlag(panelFlag); ...@@ -1526,28 +1458,28 @@ panel.changeFlag(panelFlag);
## KeyboardController ## KeyboardController
下列 API 均需使用[on('inputStart')](#oninputstart9)获取到 KeyboardController 实例后,通过实例调用。 下列API均需使用[on('inputStart')](#oninputstart9)获取到KeyboardController实例后,通过实例调用。
### hide<sup>9+</sup> ### hide<sup>9+</sup>
hide(callback: AsyncCallback&lt;void&gt;): void hide(callback: AsyncCallback&lt;void&gt;): void
隐藏输入法。使用 callback 异步回调。 隐藏输入法。使用callback异步回调。
**系统能力:** SystemCapability.MiscServices.InputMethodFramework **系统能力:** SystemCapability.MiscServices.InputMethodFramework
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| -------- | ---------------------- | ---- | -------------------------------------------------------------- | | -------- | ---------------------- | ---- | -------- |
| callback | AsyncCallback&lt;void> | 是 | 回调函数。当输入法隐藏成功,errundefined,否则为错误对象。 | | callback | AsyncCallback&lt;void> | 是 | 回调函数。当输入法隐藏成功,errundefined,否则为错误对象。 |
**错误码:** **错误码:**
以下错误码的详细介绍请参见[输入法框架错误码](../errorcodes/errorcode-inputmethod-framework.md) 以下错误码的详细介绍请参见[输入法框架错误码](../errorcodes/errorcode-inputmethod-framework.md)
| 错误码 ID | 错误信息 | | 错误码ID | 错误信息 |
| --------- | -------------------------- | | -------- | -------------------------- |
| 12800003 | input method client error. | | 12800003 | input method client error. |
**示例:** **示例:**
...@@ -1558,7 +1490,7 @@ keyboardController.hide((err) => { ...@@ -1558,7 +1490,7 @@ keyboardController.hide((err) => {
console.error(`Failed to hide: ${JSON.stringify(err)}`); console.error(`Failed to hide: ${JSON.stringify(err)}`);
return; return;
} }
console.log("Succeeded in hiding keyboard."); console.log('Succeeded in hiding keyboard.');
}); });
``` ```
...@@ -1566,54 +1498,51 @@ keyboardController.hide((err) => { ...@@ -1566,54 +1498,51 @@ keyboardController.hide((err) => {
hide(): Promise&lt;void&gt; hide(): Promise&lt;void&gt;
隐藏输入法。使用 promise 异步回调。 隐藏输入法。使用promise异步回调。
**系统能力:** SystemCapability.MiscServices.InputMethodFramework **系统能力:** SystemCapability.MiscServices.InputMethodFramework
**返回值:** **返回值:**
| 类型 | 说明 | | 类型 | 说明 |
| ---------------- | --------------------------- | | ---------------- | ------------------------- |
| Promise&lt;void> | 无返回结果的 Promise 对象。 | | Promise&lt;void> | 无返回结果的Promise对象。 |
**错误码:** **错误码:**
以下错误码的详细介绍请参见[输入法框架错误码](../errorcodes/errorcode-inputmethod-framework.md) 以下错误码的详细介绍请参见[输入法框架错误码](../errorcodes/errorcode-inputmethod-framework.md)
| 错误码 ID | 错误信息 | | 错误码ID | 错误信息 |
| --------- | -------------------------- | | -------- | -------------------------- |
| 12800003 | input method client error. | | 12800003 | input method client error. |
**示例:** **示例:**
```js ```js
keyboardController keyboardController.hide().then(() => {
.hide() console.log('Succeeded in hiding keyboard.');
.then(() => { }).catch((err) => {
console.log("Succeeded in hiding keyboard.");
})
.catch((err) => {
console.log(`Failed to hide: ${JSON.stringify(err)}`); console.log(`Failed to hide: ${JSON.stringify(err)}`);
}); });
``` ```
### hideKeyboard<sup>(deprecated)</sup> ### hideKeyboard<sup>(deprecated)</sup>
hideKeyboard(callback: AsyncCallback&lt;void&gt;): void hideKeyboard(callback: AsyncCallback&lt;void&gt;): void
隐藏输入法。使用 callback 异步回调。 隐藏输入法。使用callback异步回调。
> **说明:** > **说明:**
> >
> 从 API version 8 开始支持,API version 9 开始废弃,建议使用[hide](#hide9)替代。 > 从API version 8开始支持,API version 9开始废弃,建议使用[hide](#hide9)替代。
**系统能力:** SystemCapability.MiscServices.InputMethodFramework **系统能力:** SystemCapability.MiscServices.InputMethodFramework
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| -------- | ---------------------- | ---- | -------------------------------------------------------------- | | -------- | ---------------------- | ---- | -------- |
| callback | AsyncCallback&lt;void> | 是 | 回调函数。当输入法隐藏成功,errundefined,否则为错误对象。 | | callback | AsyncCallback&lt;void> | 是 | 回调函数。当输入法隐藏成功,errundefined,否则为错误对象。 |
**示例:** **示例:**
...@@ -1623,7 +1552,7 @@ keyboardController.hideKeyboard((err) => { ...@@ -1623,7 +1552,7 @@ keyboardController.hideKeyboard((err) => {
console.error(`Failed to hideKeyboard: ${JSON.stringify(err)}`); console.error(`Failed to hideKeyboard: ${JSON.stringify(err)}`);
return; return;
} }
console.log("Succeeded in hiding keyboard."); console.log('Succeeded in hiding keyboard.');
}); });
``` ```
...@@ -1631,31 +1560,28 @@ keyboardController.hideKeyboard((err) => { ...@@ -1631,31 +1560,28 @@ keyboardController.hideKeyboard((err) => {
hideKeyboard(): Promise&lt;void&gt; hideKeyboard(): Promise&lt;void&gt;
隐藏输入法。使用 promise 异步回调。 隐藏输入法。使用promise异步回调。
> **说明:** > **说明:**
> >
> 从 API version 8 开始支持,API version 9 开始废弃,建议使用[hide](#hide9-1)替代。 > 从API version 8开始支持,API version 9开始废弃,建议使用[hide](#hide9-1)替代。
**系统能力:** SystemCapability.MiscServices.InputMethodFramework **系统能力:** SystemCapability.MiscServices.InputMethodFramework
**返回值:** **返回值:**
| 类型 | 说明 | | 类型 | 说明 |
| ---------------- | --------------------------- | | ---------------- | ------------------------- |
| Promise&lt;void> | 无返回结果的 Promise 对象。 | | Promise&lt;void> | 无返回结果的Promise对象。 |
**示例:** **示例:**
```js ```js
keyboardController keyboardController.hideKeyboard().then(() => {
.hideKeyboard() console.log('Succeeded in hiding keyboard.');
.then(() => { }).catch((err) => {
console.log("Succeeded in hiding keyboard.");
})
.catch((err) => {
console.log(`Failed to hideKeyboard: ${JSON.stringify(err)}`); console.log(`Failed to hideKeyboard: ${JSON.stringify(err)}`);
}); });
``` ```
## ExtendAction<sup>10+</sup> ## ExtendAction<sup>10+</sup>
...@@ -1664,12 +1590,12 @@ keyboardController ...@@ -1664,12 +1590,12 @@ keyboardController
**系统能力**: SystemCapability.MiscServices.InputMethodFramework **系统能力**: SystemCapability.MiscServices.InputMethodFramework
| 名称 | 值 | 说明 | | 名称 | 值 |说明 |
| ---------- | --- | ------ | | -------- | -------- |-------- |
| SELECT_ALL | 0 | 全选。 | | SELECT_ALL | 0 |全选。 |
| CUT | 3 | 剪切。 | | CUT | 3 |剪切。 |
| COPY | 4 | 复制。 | | COPY | 4 |复制。 |
| PASTE | 5 | 粘贴。 | | PASTE | 5 |粘贴。 |
## Direction<sup>10+</sup> ## Direction<sup>10+</sup>
...@@ -1677,12 +1603,12 @@ keyboardController ...@@ -1677,12 +1603,12 @@ keyboardController
**系统能力**: SystemCapability.MiscServices.InputMethodFramework **系统能力**: SystemCapability.MiscServices.InputMethodFramework
| 名称 | 值 | 说明 | | 名称 | 值 |说明 |
| ------------ | --- | ------ | | -------- | -------- |-------- |
| CURSOR_UP | 1 | 向上。 | | CURSOR_UP | 1 |向上。 |
| CURSOR_DOWN | 2 | 向下。 | | CURSOR_DOWN | 2 |向下。 |
| CURSOR_LEFT | 3 | 向左。 | | CURSOR_LEFT | 3 |向左。 |
| CURSOR_RIGHT | 4 | 向右。 | | CURSOR_RIGHT | 4 |向右。 |
## Range<sup>10+</sup> ## Range<sup>10+</sup>
...@@ -1691,9 +1617,9 @@ keyboardController ...@@ -1691,9 +1617,9 @@ keyboardController
**系统能力:** SystemCapability.MiscServices.InputMethodFramework **系统能力:** SystemCapability.MiscServices.InputMethodFramework
| 名称 | 类型 | 可读 | 可写 | 说明 | | 名称 | 类型 | 可读 | 可写 | 说明 |
| ----- | ------ | ---- | ---- | ---------------------------------- | | -------- | -------- | -------- | -------- | -------- |
| start | number | 是 | 是 | 选中文本的首字符在编辑框的索引值。 | | start | number | 是 | 是 | 选中文本的首字符在编辑框的索引值。|
| end | number | 是 | 是 | 选中文本的末字符在编辑框的索引值。 | | end | number | 是 | 是 | 选中文本的末字符在编辑框的索引值。|
## Movement<sup>10+</sup> ## Movement<sup>10+</sup>
...@@ -1702,37 +1628,37 @@ keyboardController ...@@ -1702,37 +1628,37 @@ keyboardController
**系统能力:** SystemCapability.MiscServices.InputMethodFramework **系统能力:** SystemCapability.MiscServices.InputMethodFramework
| 名称 | 类型 | 可读 | 可写 | 说明 | | 名称 | 类型 | 可读 | 可写 | 说明 |
| --------- | ------------------------- | ---- | ---- | ---------------------------- | | -------- | -------- | -------- | -------- | -------- |
| direction | [Direction](#direction10) | 是 | 是 | 选中文本时,光标的移动方向。 | | direction | [Direction](#direction10) | 是 | 是 | 选中文本时,光标的移动方向。|
## InputClient<sup>9+</sup> ## InputClient<sup>9+</sup>
下列 API 均需使用[on('inputStart')](#oninputstart9)获取到 InputClient 实例后,通过实例调用。 下列API均需使用[on('inputStart')](#oninputstart9)获取到InputClient实例后,通过实例调用。
### sendKeyFunction<sup>9+</sup> ### sendKeyFunction<sup>9+</sup>
sendKeyFunction(action:number, callback: AsyncCallback&lt;boolean&gt;): void sendKeyFunction(action:number, callback: AsyncCallback&lt;boolean&gt;): void
发送功能键。使用 callback 异步回调。 发送功能键。使用callback异步回调。
**系统能力:** SystemCapability.MiscServices.InputMethodFramework **系统能力:** SystemCapability.MiscServices.InputMethodFramework
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| -------- | ---------------------------- | ---- | ------------------------------------------------------------------------------------------ | | -------- | -------- | -------- | -------- |
| action | number | 是 | 功能键键值。<br/>- 当值为 0 时,表示无效按键。<br/>- 当值为 1 时,表示确认键(即回车键)。 | | action | number | 是 | 功能键键值。<br/>- 当值为0时,表示无效按键。<br/>- 当值为1时,表示确认键(即回车键)。 |
| callback | AsyncCallback&lt;boolean&gt; | 是 | 回调函数。当功能键发送成功,err 为 undefined,data 为 true;否则为错误对象。 | | callback | AsyncCallback&lt;boolean&gt; | 是 | 回调函数。当功能键发送成功,err为undefined,data为true;否则为错误对象。 |
**错误码:** **错误码:**
以下错误码的详细介绍请参见[输入法框架错误码](../errorcodes/errorcode-inputmethod-framework.md) 以下错误码的详细介绍请参见[输入法框架错误码](../errorcodes/errorcode-inputmethod-framework.md)
| 错误码 ID | 错误信息 | | 错误码ID | 错误信息 |
| --------- | -------------------------- | | -------- | -------------------------- |
| 12800003 | input method client error. | | 12800003 | input method client error. |
**示例:** **示例:**
```js ```js
let action = 1; let action = 1;
...@@ -1743,9 +1669,9 @@ try { ...@@ -1743,9 +1669,9 @@ try {
return; return;
} }
if (result) { if (result) {
console.log("Succeeded in sending key function."); console.log('Succeeded in sending key function.');
} else { } else {
console.error("Failed to sendKeyFunction."); console.error('Failed to sendKeyFunction.');
} }
}); });
} catch (err) { } catch (err) {
...@@ -1757,28 +1683,28 @@ try { ...@@ -1757,28 +1683,28 @@ try {
sendKeyFunction(action: number): Promise&lt;boolean&gt; sendKeyFunction(action: number): Promise&lt;boolean&gt;
发送功能键。使用 promise 异步回调。 发送功能键。使用promise异步回调。
**系统能力:** SystemCapability.MiscServices.InputMethodFramework **系统能力:** SystemCapability.MiscServices.InputMethodFramework
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| ------ | ------ | ---- | -------------------------------------------------------------------------------------- | | -------- | -------- | -------- | -------- |
| action | number | 是 | 功能键键值。<br/>当值为 0 时,表示无效按键;<br/>当值为 1 时,表示确认键(即回车键)。 | | action | number | 是 | 功能键键值。<br/>当值为0时,表示无效按键;<br/>当值为1时,表示确认键(即回车键)。 |
**返回值:** **返回值:**
| 类型 | 说明 | | 类型 | 说明 |
| ---------------------- | --------------------------------------------------------------------------- | | ------------------------------- | ------------------------------------------------------------ |
| Promise&lt;boolean&gt; | Promise 对象。返回 true 表示功能键发送成功;返回 false 表示功能键发送失败。 | | Promise&lt;boolean&gt; | Promise对象。返回true表示功能键发送成功;返回false表示功能键发送失败。|
**错误码:** **错误码:**
以下错误码的详细介绍请参见[输入法框架错误码](../errorcodes/errorcode-inputmethod-framework.md) 以下错误码的详细介绍请参见[输入法框架错误码](../errorcodes/errorcode-inputmethod-framework.md)
| 错误码 ID | 错误信息 | | 错误码ID | 错误信息 |
| --------- | -------------------------- | | -------- | -------------------------- |
| 12800003 | input method client error. | | 12800003 | input method client error. |
**示例:** **示例:**
...@@ -1786,16 +1712,13 @@ sendKeyFunction(action: number): Promise&lt;boolean&gt; ...@@ -1786,16 +1712,13 @@ sendKeyFunction(action: number): Promise&lt;boolean&gt;
```js ```js
let action = 1; let action = 1;
try { try {
inputClient inputClient.sendKeyFunction(action).then((result) => {
.sendKeyFunction(action)
.then((result) => {
if (result) { if (result) {
console.log("Succeeded in sending key function."); console.log('Succeeded in sending key function.');
} else { } else {
console.error("Failed to sendKeyFunction."); console.error('Failed to sendKeyFunction.');
} }
}) }).catch((err) => {
.catch((err) => {
console.error(`Failed to sendKeyFunction: ${JSON.stringify(err)}`); console.error(`Failed to sendKeyFunction: ${JSON.stringify(err)}`);
}); });
} catch (err) { } catch (err) {
...@@ -1807,23 +1730,23 @@ try { ...@@ -1807,23 +1730,23 @@ try {
getForward(length:number, callback: AsyncCallback&lt;string&gt;): void getForward(length:number, callback: AsyncCallback&lt;string&gt;): void
获取光标前固定长度的文本。使用 callback 异步回调。 获取光标前固定长度的文本。使用callback异步回调。
**系统能力:** SystemCapability.MiscServices.InputMethodFramework **系统能力:** SystemCapability.MiscServices.InputMethodFramework
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| -------- | --------------------------- | ---- | ------------------------------------------------------------------------------------------------- | | -------- | -------- | -------- | -------- |
| length | number | 是 | 文本长度。 | | length | number | 是 | 文本长度。 |
| callback | AsyncCallback&lt;string&gt; | 是 | 回调函数。当光标前固定长度的文本获取成功,err 为 undefined,data 为获取到的文本;否则为错误对象。 | | callback | AsyncCallback&lt;string&gt; | 是 | 回调函数。当光标前固定长度的文本获取成功,err为undefined,data为获取到的文本;否则为错误对象。 |
**错误码:** **错误码:**
以下错误码的详细介绍请参见[输入法框架错误码](../errorcodes/errorcode-inputmethod-framework.md) 以下错误码的详细介绍请参见[输入法框架错误码](../errorcodes/errorcode-inputmethod-framework.md)
| 错误码 ID | 错误信息 | | 错误码ID | 错误信息 |
| --------- | ------------------------------ | | -------- | ------------------------------ |
| 12800003 | input method client error. | | 12800003 | input method client error. |
| 12800006 | Input method controller error. | | 12800006 | Input method controller error. |
...@@ -1837,7 +1760,7 @@ try { ...@@ -1837,7 +1760,7 @@ try {
console.error(`Failed to getForward: ${JSON.stringify(err)}`); console.error(`Failed to getForward: ${JSON.stringify(err)}`);
return; return;
} }
console.log("Succeeded in getting forward, text: " + text); console.log('Succeeded in getting forward, text: ' + text);
}); });
} catch (err) { } catch (err) {
console.error(`Failed to getForward: ${JSON.stringify(err)}`); console.error(`Failed to getForward: ${JSON.stringify(err)}`);
...@@ -1848,28 +1771,28 @@ try { ...@@ -1848,28 +1771,28 @@ try {
getForward(length:number): Promise&lt;string&gt; getForward(length:number): Promise&lt;string&gt;
获取光标前固定长度的文本。使用 promise 异步回调。 获取光标前固定长度的文本。使用promise异步回调。
**系统能力:** SystemCapability.MiscServices.InputMethodFramework **系统能力:** SystemCapability.MiscServices.InputMethodFramework
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| ------ | ------ | ---- | ---------- | | -------- | -------- | -------- | -------- |
| length | number | 是 | 文本长度。 | | length | number | 是 | 文本长度。 |
**返回值:** **返回值:**
| 类型 | 说明 | | 类型 | 说明 |
| --------------------- | ---------------------------------------- | | ------------------------------- | ------------------------------------------------------------ |
| Promise&lt;string&gt; | Promise 对象,返回光标前固定长度的文本。 | | Promise&lt;string&gt; | Promise对象,返回光标前固定长度的文本。 |
**错误码:** **错误码:**
以下错误码的详细介绍请参见[输入法框架错误码](../errorcodes/errorcode-inputmethod-framework.md) 以下错误码的详细介绍请参见[输入法框架错误码](../errorcodes/errorcode-inputmethod-framework.md)
| 错误码 ID | 错误信息 | | 错误码ID | 错误信息 |
| --------- | ------------------------------ | | -------- | ------------------------------ |
| 12800003 | input method client error. | | 12800003 | input method client error. |
| 12800006 | Input method controller error. | | 12800006 | Input method controller error. |
...@@ -1878,12 +1801,9 @@ getForward(length:number): Promise&lt;string&gt; ...@@ -1878,12 +1801,9 @@ getForward(length:number): Promise&lt;string&gt;
```js ```js
let length = 1; let length = 1;
try { try {
inputClient inputClient.getForward(length).then((text) => {
.getForward(length) console.log('Succeeded in getting forward, text: ' + text);
.then((text) => { }).catch((err) => {
console.log("Succeeded in getting forward, text: " + text);
})
.catch((err) => {
console.error(`Failed to getForward: ${JSON.stringify(err)}`); console.error(`Failed to getForward: ${JSON.stringify(err)}`);
}); });
} catch (err) { } catch (err) {
...@@ -1895,23 +1815,23 @@ try { ...@@ -1895,23 +1815,23 @@ try {
getBackward(length:number, callback: AsyncCallback&lt;string&gt;): void getBackward(length:number, callback: AsyncCallback&lt;string&gt;): void
获取光标后固定长度的文本。使用 callback 异步回调。 获取光标后固定长度的文本。使用callback异步回调。
**系统能力:** SystemCapability.MiscServices.InputMethodFramework **系统能力:** SystemCapability.MiscServices.InputMethodFramework
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| -------- | --------------------------- | ---- | ------------------------------------------------------------------------------------------------- | | -------- | -------- | -------- | -------- |
| length | number | 是 | 文本长度。 | | length | number | 是 | 文本长度。 |
| callback | AsyncCallback&lt;string&gt; | 是 | 回调函数。当光标后固定长度的文本获取成功,err 为 undefined,data 为获取到的文本;否则为错误对象。 | | callback | AsyncCallback&lt;string&gt; | 是 | 回调函数。当光标后固定长度的文本获取成功,err为undefined,data为获取到的文本;否则为错误对象。|
**错误码:** **错误码:**
以下错误码的详细介绍请参见[输入法框架错误码](../errorcodes/errorcode-inputmethod-framework.md) 以下错误码的详细介绍请参见[输入法框架错误码](../errorcodes/errorcode-inputmethod-framework.md)
| 错误码 ID | 错误信息 | | 错误码ID | 错误信息 |
| --------- | ------------------------------ | | -------- | ------------------------------ |
| 12800003 | input method client error. | | 12800003 | input method client error. |
| 12800006 | Input method controller error. | | 12800006 | Input method controller error. |
...@@ -1925,7 +1845,7 @@ try { ...@@ -1925,7 +1845,7 @@ try {
console.error(`Failed to getBackward: ${JSON.stringify(err)}`); console.error(`Failed to getBackward: ${JSON.stringify(err)}`);
return; return;
} }
console.log("Succeeded in getting backward, text: " + text); console.log('Succeeded in getting backward, text: ' + text);
}); });
} catch (err) { } catch (err) {
console.error(`Failed to getBackward: ${JSON.stringify(err)}`); console.error(`Failed to getBackward: ${JSON.stringify(err)}`);
...@@ -1936,28 +1856,28 @@ try { ...@@ -1936,28 +1856,28 @@ try {
getBackward(length:number): Promise&lt;string&gt; getBackward(length:number): Promise&lt;string&gt;
获取光标后固定长度的文本。使用 promise 异步回调。 获取光标后固定长度的文本。使用promise异步回调。
**系统能力:** SystemCapability.MiscServices.InputMethodFramework **系统能力:** SystemCapability.MiscServices.InputMethodFramework
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| ------ | ------ | ---- | ---------- | | -------- | -------- | -------- | -------- |
| length | number | 是 | 文本长度。 | | length | number | 是 | 文本长度。 |
**返回值:** **返回值:**
| 类型 | 说明 | | 类型 | 说明 |
| --------------------- | ---------------------------------------- | | ------------------------------- | ------------------------------------------------------------ |
| Promise&lt;string&gt; | Promise 对象,返回光标后固定长度的文本。 | | Promise&lt;string&gt; | Promise对象,返回光标后固定长度的文本。 |
**错误码:** **错误码:**
以下错误码的详细介绍请参见[输入法框架错误码](../errorcodes/errorcode-inputmethod-framework.md) 以下错误码的详细介绍请参见[输入法框架错误码](../errorcodes/errorcode-inputmethod-framework.md)
| 错误码 ID | 错误信息 | | 错误码ID | 错误信息 |
| --------- | ------------------------------ | | -------- | ------------------------------ |
| 12800003 | input method client error. | | 12800003 | input method client error. |
| 12800006 | Input method controller error. | | 12800006 | Input method controller error. |
...@@ -1966,12 +1886,9 @@ getBackward(length:number): Promise&lt;string&gt; ...@@ -1966,12 +1886,9 @@ getBackward(length:number): Promise&lt;string&gt;
```js ```js
let length = 1; let length = 1;
try { try {
inputClient inputClient.getBackward(length).then((text) => {
.getBackward(length) console.log('Succeeded in getting backward, text: ' + text);
.then((text) => { }).catch((err) => {
console.log("Succeeded in getting backward, text: " + text);
})
.catch((err) => {
console.error(`Failed to getBackward: ${JSON.stringify(err)}`); console.error(`Failed to getBackward: ${JSON.stringify(err)}`);
}); });
} catch (err) { } catch (err) {
...@@ -1983,23 +1900,23 @@ try { ...@@ -1983,23 +1900,23 @@ try {
deleteForward(length:number, callback: AsyncCallback&lt;boolean&gt;): void deleteForward(length:number, callback: AsyncCallback&lt;boolean&gt;): void
删除光标前固定长度的文本。使用 callback 异步回调。 删除光标前固定长度的文本。使用callback异步回调。
**系统能力:** SystemCapability.MiscServices.InputMethodFramework **系统能力:** SystemCapability.MiscServices.InputMethodFramework
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| -------- | ---------------------------- | ---- | ------------------------------------------------------------------------------------------ | | -------- | -------- | -------- | -------- |
| length | number | 是 | 文本长度。 | | length | number | 是 | 文本长度。 |
| callback | AsyncCallback&lt;boolean&gt; | 是 | 回调函数。当光标前固定长度的文本删除成功,err 为 undefined,data 为 true;否则为错误对象。 | | callback | AsyncCallback&lt;boolean&gt; | 是 | 回调函数。当光标前固定长度的文本删除成功,err为undefined,data为true;否则为错误对象。 |
**错误码:** **错误码:**
以下错误码的详细介绍请参见[输入法框架错误码](../errorcodes/errorcode-inputmethod-framework.md) 以下错误码的详细介绍请参见[输入法框架错误码](../errorcodes/errorcode-inputmethod-framework.md)
| 错误码 ID | 错误信息 | | 错误码ID | 错误信息 |
| --------- | -------------------------- | | -------- | -------------------------- |
| 12800002 | Input method engine error. | | 12800002 | Input method engine error. |
| 12800003 | input method client error. | | 12800003 | input method client error. |
...@@ -2014,7 +1931,7 @@ try { ...@@ -2014,7 +1931,7 @@ try {
return; return;
} }
if (result) { if (result) {
console.log("Succeeded in deleting forward."); console.log('Succeeded in deleting forward.');
} else { } else {
console.error(`Failed to deleteForward: ${JSON.stringify(err)}`); console.error(`Failed to deleteForward: ${JSON.stringify(err)}`);
} }
...@@ -2028,7 +1945,7 @@ try { ...@@ -2028,7 +1945,7 @@ try {
deleteForward(length:number): Promise&lt;boolean&gt; deleteForward(length:number): Promise&lt;boolean&gt;
删除光标前固定长度的文本。使用 promise 异步回调。 删除光标前固定长度的文本。使用promise异步回调。
**系统能力:** SystemCapability.MiscServices.InputMethodFramework **系统能力:** SystemCapability.MiscServices.InputMethodFramework
...@@ -2041,15 +1958,15 @@ deleteForward(length:number): Promise&lt;boolean&gt; ...@@ -2041,15 +1958,15 @@ deleteForward(length:number): Promise&lt;boolean&gt;
**返回值:** **返回值:**
| 类型 | 说明 | | 类型 | 说明 |
| ---------------------- | ------------------------------------------------------------------------------------------------------- | | ---------------------- | -------------- |
| Promise&lt;boolean&gt; | Promise 对象。返回 true 表示删除光标前固定长度的文本成功;返回 false 表示删除光标前固定长度的文本失败。 | | Promise&lt;boolean&gt; | Promise对象。返回true表示删除光标前固定长度的文本成功;返回false表示删除光标前固定长度的文本失败。|
**错误码:** **错误码:**
以下错误码的详细介绍请参见[输入法框架错误码](../errorcodes/errorcode-inputmethod-framework.md) 以下错误码的详细介绍请参见[输入法框架错误码](../errorcodes/errorcode-inputmethod-framework.md)
| 错误码 ID | 错误信息 | | 错误码ID | 错误信息 |
| --------- | -------------------------- | | -------- | -------------------------- |
| 12800002 | Input method engine error. | | 12800002 | Input method engine error. |
| 12800003 | input method client error. | | 12800003 | input method client error. |
...@@ -2058,16 +1975,13 @@ deleteForward(length:number): Promise&lt;boolean&gt; ...@@ -2058,16 +1975,13 @@ deleteForward(length:number): Promise&lt;boolean&gt;
```js ```js
let length = 1; let length = 1;
try { try {
inputClient inputClient.deleteForward(length).then((result) => {
.deleteForward(length)
.then((result) => {
if (result) { if (result) {
console.log("Succeeded in deleting forward."); console.log('Succeeded in deleting forward.');
} else { } else {
console.error("Failed to delete Forward."); console.error('Failed to delete Forward.');
} }
}) }).catch((err) => {
.catch((err) => {
console.error(`Failed to deleteForward: ${JSON.stringify(err)}`); console.error(`Failed to deleteForward: ${JSON.stringify(err)}`);
}); });
} catch (err) { } catch (err) {
...@@ -2079,23 +1993,23 @@ try { ...@@ -2079,23 +1993,23 @@ try {
deleteBackward(length:number, callback: AsyncCallback&lt;boolean&gt;): void deleteBackward(length:number, callback: AsyncCallback&lt;boolean&gt;): void
删除光标后固定长度的文本。使用 callback 异步回调。 删除光标后固定长度的文本。使用callback异步回调。
**系统能力:** SystemCapability.MiscServices.InputMethodFramework **系统能力:** SystemCapability.MiscServices.InputMethodFramework
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| -------- | ---------------------------- | ---- | ------------------------------------------------------------------------------------------ | | -------- | ---------------------------- | ---- | -------------- |
| length | number | 是 | 文本长度。 | | length | number | 是 | 文本长度。 |
| callback | AsyncCallback&lt;boolean&gt; | 是 | 回调函数。当光标后固定长度的文本删除成功,err 为 undefined,data 为 true;否则为错误对象。 | | callback | AsyncCallback&lt;boolean&gt; | 是 | 回调函数。当光标后固定长度的文本删除成功,err为undefined,data为true;否则为错误对象。 |
**错误码:** **错误码:**
以下错误码的详细介绍请参见[输入法框架错误码](../errorcodes/errorcode-inputmethod-framework.md) 以下错误码的详细介绍请参见[输入法框架错误码](../errorcodes/errorcode-inputmethod-framework.md)
| 错误码 ID | 错误信息 | | 错误码ID | 错误信息 |
| --------- | -------------------------- | | -------- | -------------------------- |
| 12800002 | Input method engine error. | | 12800002 | Input method engine error. |
| 12800003 | input method client error. | | 12800003 | input method client error. |
...@@ -2110,13 +2024,13 @@ try { ...@@ -2110,13 +2024,13 @@ try {
return; return;
} }
if (result) { if (result) {
console.log("Succeeded in deleting backward."); console.log('Succeeded in deleting backward.');
} else { } else {
console.error(`Failed to deleteBackward: ${JSON.stringify(err)}`); console.error(`Failed to deleteBackward: ${JSON.stringify(err)}`);
} }
}); });
} catch (err) { } catch (err) {
console.error("deleteBackward err: " + JSON.stringify(err)); console.error('deleteBackward err: ' + JSON.stringify(err));
} }
``` ```
...@@ -2124,28 +2038,28 @@ try { ...@@ -2124,28 +2038,28 @@ try {
deleteBackward(length:number): Promise&lt;boolean&gt; deleteBackward(length:number): Promise&lt;boolean&gt;
删除光标后固定长度的文本。使用 promise 异步回调。 删除光标后固定长度的文本。使用promise异步回调。
**系统能力:** SystemCapability.MiscServices.InputMethodFramework **系统能力:** SystemCapability.MiscServices.InputMethodFramework
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| ------ | ------ | ---- | ---------- | | -------- | -------- | -------- | -------- |
| length | number | 是 | 文本长度。 | | length | number | 是 | 文本长度。 |
**返回值:** **返回值:**
| 类型 | 说明 | | 类型 | 说明 |
| ---------------------- | ------------------------------------------------------------------------------------------------------- | | ------------------------------- | ------------------------------------------------------------ |
| Promise&lt;boolean&gt; | Promise 对象。返回 true 表示删除光标后固定长度的文本成功;返回 false 表示删除光标后固定长度的文本失败。 | | Promise&lt;boolean&gt; | Promise对象。返回true表示删除光标后固定长度的文本成功;返回false表示删除光标后固定长度的文本失败。 |
**错误码:** **错误码:**
以下错误码的详细介绍请参见[输入法框架错误码](../errorcodes/errorcode-inputmethod-framework.md) 以下错误码的详细介绍请参见[输入法框架错误码](../errorcodes/errorcode-inputmethod-framework.md)
| 错误码 ID | 错误信息 | | 错误码ID | 错误信息 |
| --------- | -------------------------- | | -------- | -------------------------- |
| 12800002 | Input method engine error. | | 12800002 | Input method engine error. |
| 12800003 | input method client error. | | 12800003 | input method client error. |
...@@ -2153,56 +2067,53 @@ deleteBackward(length:number): Promise&lt;boolean&gt; ...@@ -2153,56 +2067,53 @@ deleteBackward(length:number): Promise&lt;boolean&gt;
```js ```js
let length = 1; let length = 1;
inputClient inputClient.deleteBackward(length).then((result) => {
.deleteBackward(length)
.then((result) => {
if (result) { if (result) {
console.log("Succeeded in deleting backward."); console.log('Succeeded in deleting backward.');
} else { } else {
console.error("Failed to deleteBackward."); console.error('Failed to deleteBackward.');
} }
}) }).catch((err) => {
.catch((err) => {
console.error(`Failed to deleteBackward: ${JSON.stringify(err)}`); console.error(`Failed to deleteBackward: ${JSON.stringify(err)}`);
}); });
``` ```
### insertText<sup>9+</sup> ### insertText<sup>9+</sup>
insertText(text:string, callback: AsyncCallback&lt;boolean&gt;): void insertText(text:string, callback: AsyncCallback&lt;boolean&gt;): void
插入文本。使用 callback 异步回调。 插入文本。使用callback异步回调。
**系统能力:** SystemCapability.MiscServices.InputMethodFramework **系统能力:** SystemCapability.MiscServices.InputMethodFramework
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| -------- | ---------------------------- | ---- | -------------------------------------------------------------------------- | | -------- | -------- | -------- | -------- |
| text | string | 是 | 文本内容。 | | text | string | 是 | 文本内容。 |
| callback | AsyncCallback&lt;boolean&gt; | 是 | 回调函数。当文本插入成功,err 为 undefined,data 为 true;否则为错误对象。 | | callback | AsyncCallback&lt;boolean&gt; | 是 | 回调函数。当文本插入成功,err为undefined,data为true;否则为错误对象。 |
**错误码:** **错误码:**
以下错误码的详细介绍请参见[输入法框架错误码](../errorcodes/errorcode-inputmethod-framework.md) 以下错误码的详细介绍请参见[输入法框架错误码](../errorcodes/errorcode-inputmethod-framework.md)
| 错误码 ID | 错误信息 | | 错误码ID | 错误信息 |
| --------- | -------------------------- | | -------- | -------------------------- |
| 12800002 | Input method engine error. | | 12800002 | Input method engine error. |
| 12800003 | input method client error. | | 12800003 | input method client error. |
**示例:** **示例:**
```js ```js
inputClient.insertText("test", (err, result) => { inputClient.insertText('test', (err, result) => {
if (err) { if (err) {
console.error(`Failed to insertText: ${JSON.stringify(err)}`); console.error(`Failed to insertText: ${JSON.stringify(err)}`);
return; return;
} }
if (result) { if (result) {
console.log("Succeeded in inserting text."); console.log('Succeeded in inserting text.');
} else { } else {
console.error("Failed to insertText."); console.error('Failed to insertText.');
} }
}); });
``` ```
...@@ -2211,28 +2122,28 @@ inputClient.insertText("test", (err, result) => { ...@@ -2211,28 +2122,28 @@ inputClient.insertText("test", (err, result) => {
insertText(text:string): Promise&lt;boolean&gt; insertText(text:string): Promise&lt;boolean&gt;
插入文本。使用 promise 异步回调。 插入文本。使用promise异步回调。
**系统能力:** SystemCapability.MiscServices.InputMethodFramework **系统能力:** SystemCapability.MiscServices.InputMethodFramework
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| ------ | ------ | ---- | ------ | | -------- | -------- | -------- | -------- |
| text | string | 是 | 文本。 | | text | string | 是 | 文本。 |
**返回值:** **返回值:**
| 类型 | 说明 | | 类型 | 说明 |
| ---------------------- | ----------------------------------------------------------------------- | | ------------------------------- | ------------------------------------------------------------ |
| Promise&lt;boolean&gt; | Promise 对象。返回 true 表示插入文本成功;返回 false 表示插入文本失败。 | | Promise&lt;boolean&gt; | Promise对象。返回true表示插入文本成功;返回false表示插入文本失败。 |
**错误码:** **错误码:**
以下错误码的详细介绍请参见[输入法框架错误码](../errorcodes/errorcode-inputmethod-framework.md) 以下错误码的详细介绍请参见[输入法框架错误码](../errorcodes/errorcode-inputmethod-framework.md)
| 错误码 ID | 错误信息 | | 错误码ID | 错误信息 |
| --------- | -------------------------- | | -------- | -------------------------- |
| 12800002 | Input method engine error. | | 12800002 | Input method engine error. |
| 12800003 | input method client error. | | 12800003 | input method client error. |
...@@ -2240,16 +2151,13 @@ insertText(text:string): Promise&lt;boolean&gt; ...@@ -2240,16 +2151,13 @@ insertText(text:string): Promise&lt;boolean&gt;
```js ```js
try { try {
inputClient inputClient.insertText('test').then((result) => {
.insertText("test")
.then((result) => {
if (result) { if (result) {
console.log("Succeeded in inserting text."); console.log('Succeeded in inserting text.');
} else { } else {
console.error("Failed to insertText."); console.error('Failed to insertText.');
} }
}) }).catch((err) => {
.catch((err) => {
console.error(`Failed to insertText: ${JSON.stringify(err)}`); console.error(`Failed to insertText: ${JSON.stringify(err)}`);
}); });
} catch (err) { } catch (err) {
...@@ -2261,22 +2169,22 @@ try { ...@@ -2261,22 +2169,22 @@ try {
getEditorAttribute(callback: AsyncCallback&lt;EditorAttribute&gt;): void getEditorAttribute(callback: AsyncCallback&lt;EditorAttribute&gt;): void
获取编辑框属性值。使用 callback 异步回调。 获取编辑框属性值。使用callback异步回调。
**系统能力:** SystemCapability.MiscServices.InputMethodFramework **系统能力:** SystemCapability.MiscServices.InputMethodFramework
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| -------- | -------------------------------------------------------- | ---- | ----------------------------------------------------------------------------------------- | | ------------------------------- | ------------------------------------------------------------ | ------------------------------------------------------------ | ------------------------------------------------------------ |
| callback | AsyncCallback&lt;[EditorAttribute](#editorattribute)&gt; | 是 | 回调函数。当编辑框属性值获取成功,err 为 undefined,data 为编辑框属性值;否则为错误对象。 | | callback | AsyncCallback&lt;[EditorAttribute](#editorattribute)&gt; | 是 | 回调函数。当编辑框属性值获取成功,err为undefined,data为编辑框属性值;否则为错误对象。|
**错误码:** **错误码:**
以下错误码的详细介绍请参见[输入法框架错误码](../errorcodes/errorcode-inputmethod-framework.md) 以下错误码的详细介绍请参见[输入法框架错误码](../errorcodes/errorcode-inputmethod-framework.md)
| 错误码 ID | 错误信息 | | 错误码ID | 错误信息 |
| --------- | -------------------------- | | -------- | -------------------------- |
| 12800003 | input method client error. | | 12800003 | input method client error. |
**示例:** **示例:**
...@@ -2287,14 +2195,8 @@ inputClient.getEditorAttribute((err, editorAttribute) => { ...@@ -2287,14 +2195,8 @@ inputClient.getEditorAttribute((err, editorAttribute) => {
console.error(`Failed to getEditorAttribute: ${JSON.stringify(err)}`); console.error(`Failed to getEditorAttribute: ${JSON.stringify(err)}`);
return; return;
} }
console.log( console.log('editorAttribute.inputPattern: ' + JSON.stringify(editorAttribute.inputPattern));
"editorAttribute.inputPattern: " + console.log('editorAttribute.enterKeyType: ' + JSON.stringify(editorAttribute.enterKeyType));
JSON.stringify(editorAttribute.inputPattern)
);
console.log(
"editorAttribute.enterKeyType: " +
JSON.stringify(editorAttribute.enterKeyType)
);
}); });
``` ```
...@@ -2302,65 +2204,56 @@ inputClient.getEditorAttribute((err, editorAttribute) => { ...@@ -2302,65 +2204,56 @@ inputClient.getEditorAttribute((err, editorAttribute) => {
getEditorAttribute(): Promise&lt;EditorAttribute&gt; getEditorAttribute(): Promise&lt;EditorAttribute&gt;
获取编辑框属性值。使用 promise 异步回调。 获取编辑框属性值。使用promise异步回调。
**系统能力:** SystemCapability.MiscServices.InputMethodFramework **系统能力:** SystemCapability.MiscServices.InputMethodFramework
**返回值:** **返回值:**
| 类型 | 说明 | | 类型 | 说明 |
| -------------------------------------------------- | -------------------------------- | | ------------------------------- | ------------------------------------------------------------ |
| Promise&lt;[EditorAttribute](#editorattribute)&gt; | Promise 对象,返回编辑框属性值。 | | Promise&lt;[EditorAttribute](#editorattribute)&gt; | Promise对象,返回编辑框属性值。 |
**错误码:** **错误码:**
以下错误码的详细介绍请参见[输入法框架错误码](../errorcodes/errorcode-inputmethod-framework.md) 以下错误码的详细介绍请参见[输入法框架错误码](../errorcodes/errorcode-inputmethod-framework.md)
| 错误码 ID | 错误信息 | | 错误码ID | 错误信息 |
| --------- | -------------------------- | | -------- | -------------------------- |
| 12800003 | input method client error. | | 12800003 | input method client error. |
**示例:** **示例:**
```js ```js
inputClient inputClient.getEditorAttribute().then((editorAttribute) => {
.getEditorAttribute() console.log('editorAttribute.inputPattern: ' + JSON.stringify(editorAttribute.inputPattern));
.then((editorAttribute) => { console.log('editorAttribute.enterKeyType: ' + JSON.stringify(editorAttribute.enterKeyType));
console.log( }).catch((err) => {
"editorAttribute.inputPattern: " +
JSON.stringify(editorAttribute.inputPattern)
);
console.log(
"editorAttribute.enterKeyType: " +
JSON.stringify(editorAttribute.enterKeyType)
);
})
.catch((err) => {
console.error(`Failed to getEditorAttribute: ${JSON.stringify(err)}`); console.error(`Failed to getEditorAttribute: ${JSON.stringify(err)}`);
}); });
``` ```
### 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
移动光标。使用 callback 异步回调。 移动光标。使用callback异步回调。
**系统能力:** SystemCapability.MiscServices.InputMethodFramework **系统能力:** SystemCapability.MiscServices.InputMethodFramework
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| --------- | ------------------------- | ---- | ------------------------------------------------------------ | | --------- | ------------------------- | ---- | -------------- |
| direction | number | 是 | 光标移动方向。 | | direction | number | 是 | 光标移动方向。 |
| callback | AsyncCallback&lt;void&gt; | 是 | 回调函数。当光标移动成功,err 为 undefined,否则为错误对象。 | | callback | AsyncCallback&lt;void&gt; | 是 | 回调函数。当光标移动成功,err为undefined,否则为错误对象。 |
**错误码:** **错误码:**
以下错误码的详细介绍请参见[输入法框架错误码](../errorcodes/errorcode-inputmethod-framework.md) 以下错误码的详细介绍请参见[输入法框架错误码](../errorcodes/errorcode-inputmethod-framework.md)
| 错误码 ID | 错误信息 | | 错误码ID | 错误信息 |
| --------- | -------------------------- | | -------- | -------------------------- |
| 12800003 | input method client error. | | 12800003 | input method client error. |
**示例:** **示例:**
...@@ -2372,7 +2265,7 @@ try { ...@@ -2372,7 +2265,7 @@ try {
console.error(`Failed to moveCursor: ${JSON.stringify(err)}`); console.error(`Failed to moveCursor: ${JSON.stringify(err)}`);
return; return;
} }
console.log("Succeeded in moving cursor."); console.log('Succeeded in moving cursor.');
}); });
} catch (err) { } catch (err) {
console.error(`Failed to moveCursor: ${JSON.stringify(err)}`); console.error(`Failed to moveCursor: ${JSON.stringify(err)}`);
...@@ -2383,7 +2276,7 @@ try { ...@@ -2383,7 +2276,7 @@ try {
moveCursor(direction: number): Promise&lt;void&gt; moveCursor(direction: number): Promise&lt;void&gt;
移动光标。使用 promise 异步回调。 移动光标。使用promise异步回调。
**系统能力:** SystemCapability.MiscServices.InputMethodFramework **系统能力:** SystemCapability.MiscServices.InputMethodFramework
...@@ -2396,27 +2289,24 @@ moveCursor(direction: number): Promise&lt;void&gt; ...@@ -2396,27 +2289,24 @@ moveCursor(direction: number): Promise&lt;void&gt;
**返回值:** **返回值:**
| 类型 | 说明 | | 类型 | 说明 |
| ------------------- | --------------------------- | | ------------------- | ------------------------- |
| Promise&lt;void&gt; | 无返回结果的 Promise 对象。 | | Promise&lt;void&gt; | 无返回结果的Promise对象。 |
**错误码:** **错误码:**
以下错误码的详细介绍请参见[输入法框架错误码](../errorcodes/errorcode-inputmethod-framework.md) 以下错误码的详细介绍请参见[输入法框架错误码](../errorcodes/errorcode-inputmethod-framework.md)
| 错误码 ID | 错误信息 | | 错误码ID | 错误信息 |
| --------- | -------------------------- | | -------- | -------------------------- |
| 12800003 | input method client error. | | 12800003 | input method client error. |
**示例:** **示例:**
```js ```js
try { try {
inputClient inputClient.moveCursor(inputMethodEngine.CURSOR_UP).then(() => {
.moveCursor(inputMethodEngine.CURSOR_UP) console.log('Succeeded in moving cursor.');
.then(() => { }).catch((err) => {
console.log("Succeeded in moving cursor.");
})
.catch((err) => {
console.error(`Failed to moveCursor: ${JSON.stringify(err)}`); console.error(`Failed to moveCursor: ${JSON.stringify(err)}`);
}); });
} catch (err) { } catch (err) {
...@@ -2428,23 +2318,23 @@ try { ...@@ -2428,23 +2318,23 @@ try {
selectByRange(range: Range, callback: AsyncCallback&lt;void&gt;): void selectByRange(range: Range, callback: AsyncCallback&lt;void&gt;): void
根据索引范围选中文本。使用 callback 异步回调。 根据索引范围选中文本。使用callback异步回调。
**系统能力:** SystemCapability.MiscServices.InputMethodFramework **系统能力:** SystemCapability.MiscServices.InputMethodFramework
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| -------- | ------------------------- | ---- | ------------------------------------------------------------------ | | -------- | --------------------------------------------------------- | ---- | ------------------------------------------------------------ |
| range | [Range](#range10) | 是 | 选中文本的范围。 | | range | [Range](#range10) | 是 | 选中文本的范围。 |
| callback | AsyncCallback&lt;void&gt; | 是 | 回调函数。当成功发送选中事件后,err 为 undefined,否则为错误对象。 | | callback | AsyncCallback&lt;void&gt; | 是 | 回调函数。当成功发送选中事件后,err为undefined,否则为错误对象。 |
**错误码:** **错误码:**
以下错误码的详细介绍请参见[输入法框架错误码](../errorcodes/errorcode-inputmethod-framework.md) 以下错误码的详细介绍请参见[输入法框架错误码](../errorcodes/errorcode-inputmethod-framework.md)
| 错误码 ID | 错误信息 | | 错误码ID | 错误信息 |
| --------- | -------------------------- | | -------- | -------------------------- |
| 401 | parameter error. | | 401 | parameter error. |
| 12800003 | input method client error. | | 12800003 | input method client error. |
...@@ -2452,12 +2342,12 @@ selectByRange(range: Range, callback: AsyncCallback&lt;void&gt;): void ...@@ -2452,12 +2342,12 @@ selectByRange(range: Range, callback: AsyncCallback&lt;void&gt;): void
```js ```js
try { try {
inputClient.selectByRange({ start: 0, end: 1 }, (err) => { inputClient.selectByRange({start: 0, end: 1}, (err) => {
if (err) { if (err) {
console.error(`Failed to selectByRange: ${JSON.stringify(err)}`); console.error(`Failed to selectByRange: ${JSON.stringify(err)}`);
return; return;
} }
console.log("Succeeded in selecting by range."); console.log('Succeeded in selecting by range.');
}); });
} catch (err) { } catch (err) {
console.error(`Failed to selectByRange: ${JSON.stringify(err)}`); console.error(`Failed to selectByRange: ${JSON.stringify(err)}`);
...@@ -2468,28 +2358,28 @@ try { ...@@ -2468,28 +2358,28 @@ try {
selectByRange(range: Range): Promise&lt;void&gt; selectByRange(range: Range): Promise&lt;void&gt;
根据索引范围选中文本。使用 promise 异步回调。 根据索引范围选中文本。使用promise异步回调。
**系统能力:** SystemCapability.MiscServices.InputMethodFramework **系统能力:** SystemCapability.MiscServices.InputMethodFramework
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| ------ | ----------------- | ---- | ---------------- | | ------ | --------------------------------------------------------- | ---- | ---------------- |
| range | [Range](#range10) | 是 | 选中文本的范围。 | | range | [Range](#range10) | 是 | 选中文本的范围。 |
**返回值:** **返回值:**
| 类型 | 说明 | | 类型 | 说明 |
| ------------------- | --------------------------- | | ------------------- | ------------------------- |
| Promise&lt;void&gt; | 无返回结果的 Promise 对象。 | | Promise&lt;void&gt; | 无返回结果的Promise对象。 |
**错误码:** **错误码:**
以下错误码的详细介绍请参见[输入法框架错误码](../errorcodes/errorcode-inputmethod-framework.md) 以下错误码的详细介绍请参见[输入法框架错误码](../errorcodes/errorcode-inputmethod-framework.md)
| 错误码 ID | 错误信息 | | 错误码ID | 错误信息 |
| --------- | -------------------------- | | -------- | -------------------------- |
| 401 | parameter error. | | 401 | parameter error. |
| 12800003 | input method client error. | | 12800003 | input method client error. |
...@@ -2497,12 +2387,9 @@ selectByRange(range: Range): Promise&lt;void&gt; ...@@ -2497,12 +2387,9 @@ selectByRange(range: Range): Promise&lt;void&gt;
```js ```js
try { try {
inputClient inputClient.selectByRange({start: 0, end:1}).then(() => {
.selectByRange({ start: 0, end: 1 }) console.log('Succeeded in selecting by range.');
.then(() => { }).catch((err) => {
console.log("Succeeded in selecting by range.");
})
.catch((err) => {
console.error(`Failed to selectByRange: ${JSON.stringify(err)}`); console.error(`Failed to selectByRange: ${JSON.stringify(err)}`);
}); });
} catch (err) { } catch (err) {
...@@ -2514,23 +2401,23 @@ try { ...@@ -2514,23 +2401,23 @@ try {
selectByMovement(movement: Movement, callback: AsyncCallback&lt;void&gt;): void selectByMovement(movement: Movement, callback: AsyncCallback&lt;void&gt;): void
根据光标移动方向选中文本。使用 callback 异步回调。 根据光标移动方向选中文本。使用callback异步回调。
**系统能力:** SystemCapability.MiscServices.InputMethodFramework **系统能力:** SystemCapability.MiscServices.InputMethodFramework
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| -------- | ------------------------- | ---- | ------------------------------------------------------------------ | | -------- | ------ | ---- | ------ |
| movement | [Movement](#movement10) | 是 | 选中时光标移动的方向。 | | movement | [Movement](#movement10) | 是 | 选中时光标移动的方向。 |
| callback | AsyncCallback&lt;void&gt; | 是 | 回调函数。当成功发送选中事件后,errundefined,否则为错误对象。 | | callback | AsyncCallback&lt;void&gt; | 是 | 回调函数。当成功发送选中事件后,errundefined,否则为错误对象。 |
**错误码:** **错误码:**
以下错误码的详细介绍请参见[输入法框架错误码](../errorcodes/errorcode-inputmethod-framework.md) 以下错误码的详细介绍请参见[输入法框架错误码](../errorcodes/errorcode-inputmethod-framework.md)
| 错误码 ID | 错误信息 | | 错误码ID | 错误信息 |
| --------- | -------------------------- | | -------- | -------------------------- |
| 401 | parameter error. | | 401 | parameter error. |
| 12800003 | input method client error. | | 12800003 | input method client error. |
...@@ -2538,12 +2425,12 @@ selectByMovement(movement: Movement, callback: AsyncCallback&lt;void&gt;): void ...@@ -2538,12 +2425,12 @@ selectByMovement(movement: Movement, callback: AsyncCallback&lt;void&gt;): void
```js ```js
try { try {
inputClient.selectByMovement({ direction: 1 }, (err) => { inputClient.selectByMovement({direction: 1}, (err) => {
if (err) { if (err) {
console.error(`Failed to selectByMovement: ${JSON.stringify(err)}`); console.error(`Failed to selectByMovement: ${JSON.stringify(err)}`);
return; return;
} }
console.log("Succeeded in selecting by movement."); console.log('Succeeded in selecting by movement.');
}); });
} catch (err) { } catch (err) {
console.error(`Failed to selectByMovement: ${JSON.stringify(err)}`); console.error(`Failed to selectByMovement: ${JSON.stringify(err)}`);
...@@ -2554,28 +2441,28 @@ try { ...@@ -2554,28 +2441,28 @@ try {
selectByMovement(movement: Movement): Promise&lt;void&gt; selectByMovement(movement: Movement): Promise&lt;void&gt;
根据索引范围选中文本。使用 promise 异步回调。 根据索引范围选中文本。使用promise异步回调。
**系统能力:** SystemCapability.MiscServices.InputMethodFramework **系统能力:** SystemCapability.MiscServices.InputMethodFramework
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| -------- | ----------------------- | ---- | ---------------------- | | -------- | ------------------------------------------------------------ | ---- | ---------------------- |
| movement | [Movement](#movement10) | 是 | 选中时光标移动的方向。 | | movement | [Movement](#movement10) | 是 | 选中时光标移动的方向。 |
**返回值:** **返回值:**
| 类型 | 说明 | | 类型 | 说明 |
| ------------------- | --------------------------- | | ------------------- | ------------------------- |
| Promise&lt;void&gt; | 无返回结果的 Promise 对象。 | | Promise&lt;void&gt; | 无返回结果的Promise对象。 |
**错误码:** **错误码:**
以下错误码的详细介绍请参见[输入法框架错误码](../errorcodes/errorcode-inputmethod-framework.md) 以下错误码的详细介绍请参见[输入法框架错误码](../errorcodes/errorcode-inputmethod-framework.md)
| 错误码 ID | 错误信息 | | 错误码ID | 错误信息 |
| --------- | -------------------------- | | -------- | -------------------------- |
| 401 | parameter error. | | 401 | parameter error. |
| 12800003 | input method client error. | | 12800003 | input method client error. |
...@@ -2583,12 +2470,9 @@ selectByMovement(movement: Movement): Promise&lt;void&gt; ...@@ -2583,12 +2470,9 @@ selectByMovement(movement: Movement): Promise&lt;void&gt;
```js ```js
try { try {
inputClient inputClient.selectByMovement({direction: 1}).then(() => {
.selectByMovement({ direction: 1 }) console.log('Succeeded in selecting by movement.');
.then(() => { }).catch((err) => {
console.log("Succeeded in selecting by movement.");
})
.catch((err) => {
console.error(`Failed to selectByMovement: ${JSON.stringify(err)}`); console.error(`Failed to selectByMovement: ${JSON.stringify(err)}`);
}); });
} catch (err) { } catch (err) {
...@@ -2600,22 +2484,22 @@ try { ...@@ -2600,22 +2484,22 @@ try {
getTextIndexAtCursor(callback: AsyncCallback&lt;number&gt;): void getTextIndexAtCursor(callback: AsyncCallback&lt;number&gt;): void
获取光标所在处的文本索引。使用 callback 异步回调。 获取光标所在处的文本索引。使用callback异步回调。
**系统能力:** SystemCapability.MiscServices.InputMethodFramework **系统能力:** SystemCapability.MiscServices.InputMethodFramework
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| -------- | --------------------------- | ---- | ---------------------------------------------------------------- | | -------- | --------------------------- | ---- | ------------------------------------------------------------ |
| callback | AsyncCallback&lt;number&gt; | 是 | 回调函数。当文本索引获取成功,errundefined,否则为错误对象。 | | callback | AsyncCallback&lt;number&gt; | 是 | 回调函数。当文本索引获取成功,errundefined,否则为错误对象。 |
**错误码:** **错误码:**
以下错误码的详细介绍请参见[输入法框架错误码](../errorcodes/errorcode-inputmethod-framework.md) 以下错误码的详细介绍请参见[输入法框架错误码](../errorcodes/errorcode-inputmethod-framework.md)
| 错误码 ID | 错误信息 | | 错误码ID | 错误信息 |
| --------- | ------------------------------ | | -------- | ------------------------------ |
| 12800003 | input method client error. | | 12800003 | input method client error. |
| 12800006 | Input method controller error. | | 12800006 | Input method controller error. |
...@@ -2627,7 +2511,7 @@ inputClient.getTextIndexAtCursor((err, index) => { ...@@ -2627,7 +2511,7 @@ inputClient.getTextIndexAtCursor((err, index) => {
console.error(`Failed to getTextIndexAtCursor: ${JSON.stringify(err)}`); console.error(`Failed to getTextIndexAtCursor: ${JSON.stringify(err)}`);
return; return;
} }
console.log("Succeeded in getTextIndexAtCursor: " + index); console.log('Succeeded in getTextIndexAtCursor: ' + index);
}); });
``` ```
...@@ -2635,43 +2519,40 @@ inputClient.getTextIndexAtCursor((err, index) => { ...@@ -2635,43 +2519,40 @@ inputClient.getTextIndexAtCursor((err, index) => {
getTextIndexAtCursor(): Promise&lt;number&gt; getTextIndexAtCursor(): Promise&lt;number&gt;
获取光标所在处的文本索引。使用 promise 异步回调。 获取光标所在处的文本索引。使用promise异步回调。
**系统能力:** SystemCapability.MiscServices.InputMethodFramework **系统能力:** SystemCapability.MiscServices.InputMethodFramework
**返回值:** **返回值:**
| 类型 | 说明 | | 类型 | 说明 |
| --------------------- | ---------------------------------------- | | --------------------- | --------------------------------------- |
| Promise&lt;number&gt; | Promise 对象,返回光标所在处的文本索引。 | | Promise&lt;number&gt; | Promise对象,返回光标所在处的文本索引。 |
**错误码:** **错误码:**
以下错误码的详细介绍请参见[输入法框架错误码](../errorcodes/errorcode-inputmethod-framework.md) 以下错误码的详细介绍请参见[输入法框架错误码](../errorcodes/errorcode-inputmethod-framework.md)
| 错误码 ID | 错误信息 | | 错误码ID | 错误信息 |
| --------- | ------------------------------ | | -------- | ------------------------------ |
| 12800003 | input method client error. | | 12800003 | input method client error. |
| 12800006 | Input method controller error. | | 12800006 | Input method controller error. |
**示例:** **示例:**
```js ```js
inputClient inputClient.getTextIndexAtCursor().then((index) => {
.getTextIndexAtCursor() console.log('Succeeded in getTextIndexAtCursor: ' + index);
.then((index) => { }).catch((err) => {
console.log("Succeeded in getTextIndexAtCursor: " + index);
})
.catch((err) => {
console.error(`Failed to getTextIndexAtCursor: ${JSON.stringify(err)}`); console.error(`Failed to getTextIndexAtCursor: ${JSON.stringify(err)}`);
}); });
``` ```
### sendExtendAction<sup>10+</sup> ### sendExtendAction<sup>10+</sup>
sendExtendAction(action: ExtendAction, callback: AsyncCallback&lt;void&gt;): void sendExtendAction(action: ExtendAction, callback: AsyncCallback&lt;void&gt;): void
发送扩展编辑操作。使用 callback 异步回调。 发送扩展编辑操作。使用callback异步回调。
> **说明** > **说明**
> >
...@@ -2682,16 +2563,16 @@ sendExtendAction(action: ExtendAction, callback: AsyncCallback&lt;void&gt;): voi ...@@ -2682,16 +2563,16 @@ sendExtendAction(action: ExtendAction, callback: AsyncCallback&lt;void&gt;): voi
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| -------- | ------------------------------- | ---- | ------------------------------------------------------ | | -------- | --------------------------- | ---- | ------------------------------------------------------------ |
| action | [ExtendAction](#extendaction10) | 是 | 要发送的扩展操作。 | | action | [ExtendAction](#extendaction10) | 是 | 要发送的扩展操作。 |
| callback | AsyncCallback&lt;void&gt; | 是 | 回调函数。发送成功,err 为 undefined,否则为错误对象。 | | callback | AsyncCallback&lt;void&gt; | 是 | 回调函数。发送成功,err为undefined,否则为错误对象。 |
**错误码:** **错误码:**
以下错误码的详细介绍请参见[输入法框架错误码](../errorcodes/errorcode-inputmethod-framework.md) 以下错误码的详细介绍请参见[输入法框架错误码](../errorcodes/errorcode-inputmethod-framework.md)
| 错误码 ID | 错误信息 | | 错误码ID | 错误信息 |
| --------- | ------------------------------ | | -------- | ------------------------------ |
| 12800003 | input method client error. | | 12800003 | input method client error. |
| 12800006 | Input method controller error. | | 12800006 | Input method controller error. |
...@@ -2704,9 +2585,9 @@ try { ...@@ -2704,9 +2585,9 @@ try {
console.error(`Failed to sendExtendAction: ${JSON.stringify(err)}`); console.error(`Failed to sendExtendAction: ${JSON.stringify(err)}`);
return; return;
} }
console.log("Succeeded in sending extend action."); console.log('Succeeded in sending extend action.');
}); });
} catch (err) { } catch(err) {
console.error(`Failed to sendExtendAction: ${JSON.stringify(err)}`); console.error(`Failed to sendExtendAction: ${JSON.stringify(err)}`);
} }
``` ```
...@@ -2715,9 +2596,9 @@ try { ...@@ -2715,9 +2596,9 @@ try {
sendExtendAction(action: ExtendAction): Promise&lt;void&gt; sendExtendAction(action: ExtendAction): Promise&lt;void&gt;
发送扩展编辑操作。使用 promise 异步回调。 发送扩展编辑操作。使用promise异步回调。
> **说明** >**说明**
> >
> 输入法应用调用该接口向编辑框发送扩展编辑操作,编辑框监听相应事件[on('handleExtendAction')](./js-apis-inputmethod.md#onhandleextendaction10),从而进一步做出处理。 > 输入法应用调用该接口向编辑框发送扩展编辑操作,编辑框监听相应事件[on('handleExtendAction')](./js-apis-inputmethod.md#onhandleextendaction10),从而进一步做出处理。
...@@ -2726,21 +2607,21 @@ sendExtendAction(action: ExtendAction): Promise&lt;void&gt; ...@@ -2726,21 +2607,21 @@ sendExtendAction(action: ExtendAction): Promise&lt;void&gt;
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| ------ | ------------------------------- | ---- | ------------------ | | -------- | -------- | -------- | -------- |
| action | [ExtendAction](#extendaction10) | 是 | 要发送的扩展操作。 | | action | [ExtendAction](#extendaction10) | 是 | 要发送的扩展操作。 |
**返回值:** **返回值:**
| 类型 | 说明 | | 类型 | 说明 |
| ------------------- | --------------------------- | | --------------------- | --------------------------------------- |
| Promise&lt;void&gt; | 无返回结果的 Promise 对象。 | | Promise&lt;void&gt; | 无返回结果的Promise对象。 |
**错误码:** **错误码:**
以下错误码的详细介绍请参见[输入法框架错误码](../errorcodes/errorcode-inputmethod-framework.md) 以下错误码的详细介绍请参见[输入法框架错误码](../errorcodes/errorcode-inputmethod-framework.md)
| 错误码 ID | 错误信息 | | 错误码ID | 错误信息 |
| --------- | ------------------------------ | | -------- | ------------------------------ |
| 12800003 | input method client error. | | 12800003 | input method client error. |
| 12800006 | Input method controller error. | | 12800006 | Input method controller error. |
...@@ -2748,15 +2629,12 @@ sendExtendAction(action: ExtendAction): Promise&lt;void&gt; ...@@ -2748,15 +2629,12 @@ sendExtendAction(action: ExtendAction): Promise&lt;void&gt;
```js ```js
try { try {
inputClient inputClient.sendExtendAction(inputMethodEngine.ExtendAction.COPY).then(() => {
.sendExtendAction(inputMethodEngine.ExtendAction.COPY) console.log('Succeeded in sending extend action.');
.then(() => { }).catch((err) => {
console.log("Succeeded in sending extend action.");
})
.catch((err) => {
console.error(`Failed to sendExtendAction: ${JSON.stringify(err)}`); console.error(`Failed to sendExtendAction: ${JSON.stringify(err)}`);
}); });
} catch (err) { } catch(err) {
console.error(`Failed to sendExtendAction: ${JSON.stringify(err)}`); console.error(`Failed to sendExtendAction: ${JSON.stringify(err)}`);
} }
``` ```
...@@ -2768,7 +2646,7 @@ try { ...@@ -2768,7 +2646,7 @@ try {
**系统能力:** SystemCapability.MiscServices.InputMethodFramework **系统能力:** SystemCapability.MiscServices.InputMethodFramework
| 名称 | 类型 | 可读 | 可写 | 说明 | | 名称 | 类型 | 可读 | 可写 | 说明 |
| ------------ | ------ | ---- | ---- | ------------------ | | ------------ | -------- | ---- | ---- | ------------------ |
| enterKeyType | number | 是 | 否 | 编辑框的功能属性。 | | enterKeyType | number | 是 | 否 | 编辑框的功能属性。 |
| inputPattern | number | 是 | 否 | 编辑框的文本属性。 | | inputPattern | number | 是 | 否 | 编辑框的文本属性。 |
...@@ -2779,9 +2657,9 @@ try { ...@@ -2779,9 +2657,9 @@ try {
**系统能力:** SystemCapability.MiscServices.InputMethodFramework **系统能力:** SystemCapability.MiscServices.InputMethodFramework
| 名称 | 类型 | 可读 | 可写 | 说明 | | 名称 | 类型 | 可读 | 可写 | 说明 |
| --------- | ------ | ---- | ---- | ---------------------------------------------------------------------------------- | | --------- | -------- | ---- | ---- | ------------ |
| keyCode | number | 是 | 否 | 按键的键值。键码值说明参考[KeyCode](js-apis-keycode.md#keycode)。 | | keyCode | number | 是 | 否 | 按键的键值。键码值说明参考[KeyCode](js-apis-keycode.md#keycode)。 |
| keyAction | number | 是 | 否 | 按键事件类型。<br/>- 当值为 2 时,表示按下事件;<br/>- 当值为 3 时,表示抬起事件。 | | keyAction | number | 是 | 否 | 按键事件类型。<br/>- 当值为2时,表示按下事件;<br/>- 当值为3时,表示抬起事件。 |
## PanelFlag<sup>10+</sup> ## PanelFlag<sup>10+</sup>
...@@ -2790,7 +2668,7 @@ try { ...@@ -2790,7 +2668,7 @@ try {
**系统能力:** SystemCapability.MiscServices.InputMethodFramework **系统能力:** SystemCapability.MiscServices.InputMethodFramework
| 名称 | 值 | 说明 | | 名称 | 值 | 说明 |
| ------------ | --- | ---------------- | | ------------ | -- | ------------------ |
| FLG_FIXED | 0 | 固定态面板类型。 | | FLG_FIXED | 0 | 固定态面板类型。 |
| FLG_FLOATING | 1 | 悬浮态面板类型。 | | FLG_FLOATING | 1 | 悬浮态面板类型。 |
...@@ -2801,7 +2679,7 @@ try { ...@@ -2801,7 +2679,7 @@ try {
**系统能力:** SystemCapability.MiscServices.InputMethodFramework **系统能力:** SystemCapability.MiscServices.InputMethodFramework
| 名称 | 值 | 说明 | | 名称 | 值 | 说明 |
| ------------- | --- | ------------ | | ------------ | -- | ------------------ |
| SOFT_KEYBOARD | 0 | 软键盘类型。 | | SOFT_KEYBOARD | 0 | 软键盘类型。 |
| STATUS_BAR | 1 | 状态栏类型。 | | STATUS_BAR | 1 | 状态栏类型。 |
...@@ -2812,7 +2690,7 @@ try { ...@@ -2812,7 +2690,7 @@ try {
输入法面板属性。 输入法面板属性。
| 名称 | 类型 | 可读 | 可写 | 说明 | | 名称 | 类型 | 可读 | 可写 | 说明 |
| ---- | ------ | ---- | ---- | ---------------- | | --------- | -------- | ---- | ---- | ------------ |
| type | number | 是 | 是 | 面板的类型。 | | type | number | 是 | 是 | 面板的类型。 |
| flag | number | 是 | 是 | 面板的状态类型。 | | flag | number | 是 | 是 | 面板的状态类型。 |
...@@ -2820,28 +2698,28 @@ try { ...@@ -2820,28 +2698,28 @@ try {
> **说明:** > **说明:**
> >
> 从 API version 8 开始支持,API version 9 开始废弃,建议使用[InputClient](#inputclient9)替代。 > 从API version 8开始支持,API version 9开始废弃,建议使用[InputClient](#inputclient9)替代。
下列 API 示例中都需使用[on('inputStart')](#oninputstart)回调获取到 TextInputClient 实例,再通过此实例调用对应方法。 下列API示例中都需使用[on('inputStart')](#oninputstart)回调获取到TextInputClient实例,再通过此实例调用对应方法。
### getForward<sup>(deprecated)</sup> ### getForward<sup>(deprecated)</sup>
getForward(length:number, callback: AsyncCallback&lt;string&gt;): void getForward(length:number, callback: AsyncCallback&lt;string&gt;): void
获取光标前固定长度的文本。使用 callback 异步回调。 获取光标前固定长度的文本。使用callback异步回调。
> **说明:** > **说明:**
> >
> 从 API version 8 开始支持,API version 9 开始废弃,建议使用[getForward](#getforward9)替代。 > 从API version 8开始支持,API version 9开始废弃,建议使用[getForward](#getforward9)替代。
**系统能力:** SystemCapability.MiscServices.InputMethodFramework **系统能力:** SystemCapability.MiscServices.InputMethodFramework
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| -------- | --------------------------- | ---- | ------------------------------------------------------------------------------------------------- | | -------- | -------- | -------- | -------- |
| length | number | 是 | 文本长度。 | | length | number | 是 | 文本长度。 |
| callback | AsyncCallback&lt;string&gt; | 是 | 回调函数。当光标前固定长度的文本获取成功,err 为 undefined,data 为获取到的文本;否则为错误对象。 | | callback | AsyncCallback&lt;string&gt; | 是 | 回调函数。当光标前固定长度的文本获取成功,err为undefined,data为获取到的文本;否则为错误对象。|
**示例:** **示例:**
...@@ -2852,7 +2730,7 @@ textInputClient.getForward(length, (err, text) => { ...@@ -2852,7 +2730,7 @@ textInputClient.getForward(length, (err, text) => {
console.error(`Failed to getForward: ${JSON.stringify(err)}`); console.error(`Failed to getForward: ${JSON.stringify(err)}`);
return; return;
} }
console.log("Succeeded in getting forward, text: " + text); console.log('Succeeded in getting forward, text: ' + text);
}); });
``` ```
...@@ -2860,58 +2738,55 @@ textInputClient.getForward(length, (err, text) => { ...@@ -2860,58 +2738,55 @@ textInputClient.getForward(length, (err, text) => {
getForward(length:number): Promise&lt;string&gt; getForward(length:number): Promise&lt;string&gt;
获取光标前固定长度的文本。使用 promise 异步回调。 获取光标前固定长度的文本。使用promise异步回调。
> **说明:** > **说明:**
> >
> 从 API version 8 开始支持,API version 9 开始废弃,建议使用[getForward](#getforward9)替代。 > 从API version 8开始支持,API version 9开始废弃,建议使用[getForward](#getforward9)替代。
**系统能力:** SystemCapability.MiscServices.InputMethodFramework **系统能力:** SystemCapability.MiscServices.InputMethodFramework
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| ------ | ------ | ---- | ---------- | | -------- | -------- | -------- | -------- |
| length | number | 是 | 文本长度。 | | length | number | 是 | 文本长度。 |
**返回值:** **返回值:**
| 类型 | 说明 | | 类型 | 说明 |
| --------------------- | ---------------------------------------- | | ------------------------------- | ------------------------------------------------------------ |
| Promise&lt;string&gt; | Promise 对象,返回光标前固定长度的文本。 | | Promise&lt;string&gt; | Promise对象,返回光标前固定长度的文本。 |
**示例:** **示例:**
```js ```js
let length = 1; let length = 1;
textInputClient textInputClient.getForward(length).then((text) => {
.getForward(length) console.log('Succeeded in getting forward, text: ' + text);
.then((text) => { }).catch((err) => {
console.log("Succeeded in getting forward, text: " + text);
})
.catch((err) => {
console.error(`Failed to getForward: ${JSON.stringify(err)}`); console.error(`Failed to getForward: ${JSON.stringify(err)}`);
}); });
``` ```
### getBackward<sup>(deprecated)</sup> ### getBackward<sup>(deprecated)</sup>
getBackward(length:number, callback: AsyncCallback&lt;string&gt;): void getBackward(length:number, callback: AsyncCallback&lt;string&gt;): void
获取光标后固定长度的文本。使用 callback 异步回调。 获取光标后固定长度的文本。使用callback异步回调。
> **说明:** > **说明:**
> >
> 从 API version 8 开始支持,API version 9 开始废弃,建议使用[getBackward](#getbackward9)替代。 > 从API version 8开始支持,API version 9开始废弃,建议使用[getBackward](#getbackward9)替代。
**系统能力:** SystemCapability.MiscServices.InputMethodFramework **系统能力:** SystemCapability.MiscServices.InputMethodFramework
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| -------- | --------------------------- | ---- | ------------------------------------------------------------------------------------------------- | | -------- | -------- | -------- | -------- |
| length | number | 是 | 文本长度。 | | length | number | 是 | 文本长度。 |
| callback | AsyncCallback&lt;string&gt; | 是 | 回调函数。当光标后固定长度的文本获取成功,err 为 undefined,data 为获取到的文本;否则为错误对象。 | | callback | AsyncCallback&lt;string&gt; | 是 | 回调函数。当光标后固定长度的文本获取成功,err为undefined,data为获取到的文本;否则为错误对象。 |
**示例:** **示例:**
...@@ -2922,7 +2797,7 @@ textInputClient.getBackward(length, (err, text) => { ...@@ -2922,7 +2797,7 @@ textInputClient.getBackward(length, (err, text) => {
console.error(`Failed to getBackward: ${JSON.stringify(err)}`); console.error(`Failed to getBackward: ${JSON.stringify(err)}`);
return; return;
} }
console.log("Succeeded in getting borward, text: " + text); console.log('Succeeded in getting borward, text: ' + text);
}); });
``` ```
...@@ -2930,58 +2805,55 @@ textInputClient.getBackward(length, (err, text) => { ...@@ -2930,58 +2805,55 @@ textInputClient.getBackward(length, (err, text) => {
getBackward(length:number): Promise&lt;string&gt; getBackward(length:number): Promise&lt;string&gt;
获取光标后固定长度的文本。使用 promise 异步回调。 获取光标后固定长度的文本。使用promise异步回调。
> **说明:** > **说明:**
> >
> 从 API version 8 开始支持,API version 9 开始废弃,建议使用[getBackward](#getbackward9)替代。 > 从API version 8开始支持,API version 9开始废弃,建议使用[getBackward](#getbackward9)替代。
**系统能力:** SystemCapability.MiscServices.InputMethodFramework **系统能力:** SystemCapability.MiscServices.InputMethodFramework
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| ------ | ------ | ---- | ---------- | | -------- | -------- | -------- | -------- |
| length | number | 是 | 文本长度。 | | length | number | 是 | 文本长度。 |
**返回值:** **返回值:**
| 类型 | 说明 | | 类型 | 说明 |
| --------------------- | ---------------------------------------- | | ------------------------------- | ------------------------------------------------------------ |
| Promise&lt;string&gt; | Promise 对象,返回光标后固定长度的文本。 | | Promise&lt;string&gt; | Promise对象,返回光标后固定长度的文本。 |
**示例:** **示例:**
```js ```js
let length = 1; let length = 1;
textInputClient textInputClient.getBackward(length).then((text) => {
.getBackward(length) console.log('Succeeded in getting backward: ' + JSON.stringify(text));
.then((text) => { }).catch((err) => {
console.log("Succeeded in getting backward: " + JSON.stringify(text));
})
.catch((err) => {
console.error(`Failed to getBackward: ${JSON.stringify(err)}`); console.error(`Failed to getBackward: ${JSON.stringify(err)}`);
}); });
``` ```
### deleteForward<sup>(deprecated)</sup> ### deleteForward<sup>(deprecated)</sup>
deleteForward(length:number, callback: AsyncCallback&lt;boolean&gt;): void deleteForward(length:number, callback: AsyncCallback&lt;boolean&gt;): void
删除光标前固定长度的文本。使用 callback 异步回调。 删除光标前固定长度的文本。使用callback异步回调。
> **说明:** > **说明:**
> >
> 从 API version 8 开始支持,API version 9 开始废弃,建议使用[deleteForward](#deleteforward9)替代。 > 从API version 8开始支持,API version 9开始废弃,建议使用[deleteForward](#deleteforward9)替代。
**系统能力:** SystemCapability.MiscServices.InputMethodFramework **系统能力:** SystemCapability.MiscServices.InputMethodFramework
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| -------- | ---------------------------- | ---- | ------------------------------------------------------------------------------------------ | | -------- | -------- | -------- | -------- |
| length | number | 是 | 文本长度。 | | length | number | 是 | 文本长度。 |
| callback | AsyncCallback&lt;boolean&gt; | 是 | 回调函数。当光标前固定长度的文本删除成功,err 为 undefined,data 为 true;否则为错误对象。 | | callback | AsyncCallback&lt;boolean&gt; | 是 | 回调函数。当光标前固定长度的文本删除成功,err为undefined,data为true;否则为错误对象。 |
**示例:** **示例:**
...@@ -2993,9 +2865,9 @@ textInputClient.deleteForward(length, (err, result) => { ...@@ -2993,9 +2865,9 @@ textInputClient.deleteForward(length, (err, result) => {
return; return;
} }
if (result) { if (result) {
console.log("Succeeded in deleting forward."); console.log('Succeeded in deleting forward.');
} else { } else {
console.error("Failed to deleteForward."); console.error('Failed to deleteForward.');
} }
}); });
``` ```
...@@ -3004,11 +2876,11 @@ textInputClient.deleteForward(length, (err, result) => { ...@@ -3004,11 +2876,11 @@ textInputClient.deleteForward(length, (err, result) => {
deleteForward(length:number): Promise&lt;boolean&gt; deleteForward(length:number): Promise&lt;boolean&gt;
删除光标前固定长度的文本。使用 promise 异步回调。 删除光标前固定长度的文本。使用promise异步回调。
> **说明:** > **说明:**
> >
> 从 API version 8 开始支持,API version 9 开始废弃,建议使用[deleteForward](#deleteforward9)替代。 > 从API version 8开始支持,API version 9开始废弃,建议使用[deleteForward](#deleteforward9)替代。
**系统能力:** SystemCapability.MiscServices.InputMethodFramework **系统能力:** SystemCapability.MiscServices.InputMethodFramework
...@@ -3021,45 +2893,42 @@ deleteForward(length:number): Promise&lt;boolean&gt; ...@@ -3021,45 +2893,42 @@ deleteForward(length:number): Promise&lt;boolean&gt;
**返回值:** **返回值:**
| 类型 | 说明 | | 类型 | 说明 |
| ---------------------- | ------------------------------------------------------------------------------------------------------- | | ---------------------- | -------------- |
| Promise&lt;boolean&gt; | Promise 对象。返回 true 表示删除光标前固定长度的文本成功;返回 false 表示删除光标前固定长度的文本失败。 | | Promise&lt;boolean&gt; | Promise对象。返回true表示删除光标前固定长度的文本成功;返回false表示删除光标前固定长度的文本失败。|
**示例:** **示例:**
```js ```js
let length = 1; let length = 1;
textInputClient textInputClient.deleteForward(length).then((result) => {
.deleteForward(length)
.then((result) => {
if (result) { if (result) {
console.log("Succeeded in deleting forward."); console.log('Succeeded in deleting forward.');
} else { } else {
console.error("Failed to delete forward."); console.error('Failed to delete forward.');
} }
}) }).catch((err) => {
.catch((err) => {
console.error(`Failed to deleteForward: ${JSON.stringify(err)}`); console.error(`Failed to deleteForward: ${JSON.stringify(err)}`);
}); });
``` ```
### deleteBackward<sup>(deprecated)</sup> ### deleteBackward<sup>(deprecated)</sup>
deleteBackward(length:number, callback: AsyncCallback&lt;boolean&gt;): void deleteBackward(length:number, callback: AsyncCallback&lt;boolean&gt;): void
删除光标后固定长度的文本。使用 callback 异步回调。 删除光标后固定长度的文本。使用callback异步回调。
> **说明:** > **说明:**
> >
> 从 API version 8 开始支持,API version 9 开始废弃,建议使用[deleteBackward](#deletebackward9)替代。 > 从API version 8开始支持,API version 9开始废弃,建议使用[deleteBackward](#deletebackward9)替代。
**系统能力:** SystemCapability.MiscServices.InputMethodFramework **系统能力:** SystemCapability.MiscServices.InputMethodFramework
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| -------- | ---------------------------- | ---- | ------------------------------------------------------------------------------------------ | | -------- | ---------------------------- | ---- | -------------- |
| length | number | 是 | 文本长度。 | | length | number | 是 | 文本长度。 |
| callback | AsyncCallback&lt;boolean&gt; | 是 | 回调函数。当光标后固定长度的文本删除成功,err 为 undefined,data 为 true;否则为错误对象。 | | callback | AsyncCallback&lt;boolean&gt; | 是 | 回调函数。当光标后固定长度的文本删除成功,err为undefined,data为true;否则为错误对象。|
**示例:** **示例:**
...@@ -3071,9 +2940,9 @@ textInputClient.deleteBackward(length, (err, result) => { ...@@ -3071,9 +2940,9 @@ textInputClient.deleteBackward(length, (err, result) => {
return; return;
} }
if (result) { if (result) {
console.log("Succeeded in deleting backward."); console.log('Succeeded in deleting backward.');
} else { } else {
console.error("Failed to deleteBackward."); console.error('Failed to deleteBackward.');
} }
}); });
``` ```
...@@ -3082,62 +2951,58 @@ textInputClient.deleteBackward(length, (err, result) => { ...@@ -3082,62 +2951,58 @@ textInputClient.deleteBackward(length, (err, result) => {
deleteBackward(length:number): Promise&lt;boolean&gt; deleteBackward(length:number): Promise&lt;boolean&gt;
删除光标后固定长度的文本。使用 promise 异步回调。 删除光标后固定长度的文本。使用promise异步回调。
> **说明:** > **说明:**
> >
> 从 API version 8 开始支持,API version 9 开始废弃,建议使用[deleteBackward](#deletebackward9)替代。 > 从API version 8开始支持,API version 9开始废弃,建议使用[deleteBackward](#deletebackward9)替代。
**系统能力:** SystemCapability.MiscServices.InputMethodFramework **系统能力:** SystemCapability.MiscServices.InputMethodFramework
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| ------ | ------ | ---- | ---------- | | -------- | -------- | -------- | -------- |
| length | number | 是 | 文本长度。 | | length | number | 是 | 文本长度。 |
**返回值:** **返回值:**
| 类型 | 说明 | | 类型 | 说明 |
| ---------------------- | ------------------------------------------------------------------------------------------------------- | | ------------------------------- | ------------------------------------------------------------ |
| Promise&lt;boolean&gt; | Promise 对象。返回 true 表示删除光标后固定长度的文本成功;返回 false 表示删除光标后固定长度的文本失败。 | | Promise&lt;boolean&gt; | Promise对象。返回true表示删除光标后固定长度的文本成功;返回false表示删除光标后固定长度的文本失败。|
**示例:** **示例:**
```js ```js
let length = 1; let length = 1;
textInputClient textInputClient.deleteBackward(length).then((result) => {
.deleteBackward(length)
.then((result) => {
if (result) { if (result) {
console.log("Succeeded in deleting backward."); console.log('Succeeded in deleting backward.');
} else { } else {
console.error("Failed to deleteBackward."); console.error('Failed to deleteBackward.');
} }
}) }).catch((err) => {
.catch((err) => {
console.error(`Failed to deleteBackward: ${JSON.stringify(err)}`); console.error(`Failed to deleteBackward: ${JSON.stringify(err)}`);
}); });
``` ```
### sendKeyFunction<sup>(deprecated)</sup> ### sendKeyFunction<sup>(deprecated)</sup>
sendKeyFunction(action: number, callback: AsyncCallback&lt;boolean&gt;): void sendKeyFunction(action: number, callback: AsyncCallback&lt;boolean&gt;): void
发送功能键。使用 callback 异步回调。 发送功能键。使用callback异步回调。
> **说明:** > **说明:**
> >
> 从 API version 8 开始支持,API version 9 开始废弃,建议使用[sendKeyFunction](#sendkeyfunction9)替代。 > 从API version 8开始支持,API version 9开始废弃,建议使用[sendKeyFunction](#sendkeyfunction9)替代。
**系统能力:** SystemCapability.MiscServices.InputMethodFramework **系统能力:** SystemCapability.MiscServices.InputMethodFramework
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| -------- | ---------------------------- | ---- | ------------------------------------------------------------------------------------------ | | -------- | -------- | -------- | -------- |
| action | number | 是 | 功能键键值。<br/>- 当值为 0 时,表示无效按键;<br/>- 当值为 1 时,表示确认键(即回车键)。 | | action | number | 是 | 功能键键值。<br/>- 当值为0时,表示无效按键;<br/>- 当值为1时,表示确认键(即回车键)。 |
| callback | AsyncCallback&lt;boolean&gt; | 是 | 回调函数。当功能键发送成功,err 为 undefined,data 为 true;否则为错误对象。 | | callback | AsyncCallback&lt;boolean&gt; | 是 | 回调函数。当功能键发送成功,err为undefined,data为true;否则为错误对象。 |
**示例:** **示例:**
...@@ -3149,9 +3014,9 @@ textInputClient.sendKeyFunction(action, (err, result) => { ...@@ -3149,9 +3014,9 @@ textInputClient.sendKeyFunction(action, (err, result) => {
return; return;
} }
if (result) { if (result) {
console.log("Succeeded in sending key function."); console.log('Succeeded in sending key function.');
} else { } else {
console.error("Failed to sendKeyFunction."); console.error('Failed to sendKeyFunction.');
} }
}); });
``` ```
...@@ -3160,75 +3025,72 @@ textInputClient.sendKeyFunction(action, (err, result) => { ...@@ -3160,75 +3025,72 @@ textInputClient.sendKeyFunction(action, (err, result) => {
sendKeyFunction(action: number): Promise&lt;boolean&gt; sendKeyFunction(action: number): Promise&lt;boolean&gt;
发送功能键。使用 promise 异步回调。 发送功能键。使用promise异步回调。
> **说明:** > **说明:**
> >
> 从 API version 8 开始支持,API version 9 开始废弃,建议使用[sendKeyFunction](#sendkeyfunction9)替代。 > 从API version 8开始支持,API version 9开始废弃,建议使用[sendKeyFunction](#sendkeyfunction9)替代。
**系统能力:** SystemCapability.MiscServices.InputMethodFramework **系统能力:** SystemCapability.MiscServices.InputMethodFramework
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| ------ | ------ | ---- | -------------------------------------------------------------------------------------- | | -------- | -------- | -------- | -------- |
| action | number | 是 | 功能键键值。<br/>当值为 0 时,表示无效按键;<br/>当值为 1 时,表示确认键(即回车键)。 | | action | number | 是 | 功能键键值。<br/>当值为0时,表示无效按键;<br/>当值为1时,表示确认键(即回车键)。 |
**返回值:** **返回值:**
| 类型 | 说明 | | 类型 | 说明 |
| ---------------------- | --------------------------------------------------------------------------- | | ------------------------------- | ------------------------------------------------------------ |
| Promise&lt;boolean&gt; | Promise 对象。返回 true 表示发送功能键成功;返回 false 表示发送功能键失败。 | | Promise&lt;boolean&gt; | Promise对象。返回true表示发送功能键成功;返回false表示发送功能键失败。 |
**示例:** **示例:**
```js ```js
let action = 1; let action = 1;
textInputClient textInputClient.sendKeyFunction(action).then((result) => {
.sendKeyFunction(action)
.then((result) => {
if (result) { if (result) {
console.log("Succeeded in sending key function."); console.log('Succeeded in sending key function.');
} else { } else {
console.error("Failed to sendKeyFunction."); console.error('Failed to sendKeyFunction.');
} }
}) }).catch((err) => {
.catch((err) => {
console.error(`Failed to sendKeyFunction: ${JSON.stringify(err)}`); console.error(`Failed to sendKeyFunction: ${JSON.stringify(err)}`);
}); });
``` ```
### insertText<sup>(deprecated)</sup> ### insertText<sup>(deprecated)</sup>
insertText(text:string, callback: AsyncCallback&lt;boolean&gt;): void insertText(text:string, callback: AsyncCallback&lt;boolean&gt;): void
插入文本。使用 callback 异步回调。 插入文本。使用callback异步回调。
> **说明:** > **说明:**
> >
> 从 API version 8 开始支持,API version 9 开始废弃,建议使用[insertText](#inserttext9)替代。 > 从API version 8开始支持,API version 9开始废弃,建议使用[insertText](#inserttext9)替代。
**系统能力:** SystemCapability.MiscServices.InputMethodFramework **系统能力:** SystemCapability.MiscServices.InputMethodFramework
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| -------- | ---------------------------- | ---- | -------------------------------------------------------------------------- | | -------- | -------- | -------- | -------- |
| text | string | 是 | 文本。 | | text | string | 是 | 文本。 |
| callback | AsyncCallback&lt;boolean&gt; | 是 | 回调函数。当文本插入成功,err 为 undefined,data 为 true;否则为错误对象。 | | callback | AsyncCallback&lt;boolean&gt; | 是 | 回调函数。当文本插入成功,err为undefined,data为true;否则为错误对象。 |
**示例:** **示例:**
```js ```js
textInputClient.insertText("test", (err, result) => { textInputClient.insertText('test', (err, result) => {
if (err) { if (err) {
console.error(`Failed to insertText: ${JSON.stringify(err)}`); console.error(`Failed to insertText: ${JSON.stringify(err)}`);
return; return;
} }
if (result) { if (result) {
console.log("Succeeded in inserting text."); console.log('Succeeded in inserting text.');
} else { } else {
console.error("Failed to insertText."); console.error('Failed to insertText.');
} }
}); });
``` ```
...@@ -3237,60 +3099,57 @@ textInputClient.insertText("test", (err, result) => { ...@@ -3237,60 +3099,57 @@ textInputClient.insertText("test", (err, result) => {
insertText(text:string): Promise&lt;boolean&gt; insertText(text:string): Promise&lt;boolean&gt;
插入文本。使用 promise 异步回调。 插入文本。使用promise异步回调。
> **说明:** > **说明:**
> >
> 从 API version 8 开始支持,API version 9 开始废弃,建议使用[insertText](#inserttext9)替代。 > 从API version 8开始支持,API version 9开始废弃,建议使用[insertText](#inserttext9)替代。
**系统能力:** SystemCapability.MiscServices.InputMethodFramework **系统能力:** SystemCapability.MiscServices.InputMethodFramework
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| ------ | ------ | ---- | ------ | | -------- | -------- | -------- | -------- |
| text | string | 是 | 文本。 | | text | string | 是 | 文本。 |
**返回值:** **返回值:**
| 类型 | 说明 | | 类型 | 说明 |
| ---------------------- | ----------------------------------------------------------------------- | | ------------------------------- | ------------------------------------------------------------ |
| Promise&lt;boolean&gt; | Promise 对象。返回 true 表示插入文本成功;返回 false 表示插入文本失败。 | | Promise&lt;boolean&gt; | Promise对象。返回true表示插入文本成功;返回false表示插入文本失败。 |
**示例:** **示例:**
```js ```js
textInputClient textInputClient.insertText('test').then((result) => {
.insertText("test")
.then((result) => {
if (result) { if (result) {
console.log("Succeeded in inserting text."); console.log('Succeeded in inserting text.');
} else { } else {
console.error("Failed to insertText."); console.error('Failed to insertText.');
} }
}) }).catch((err) => {
.catch((err) => {
console.error(`Failed to insertText: ${JSON.stringify(err)}`); console.error(`Failed to insertText: ${JSON.stringify(err)}`);
}); });
``` ```
### getEditorAttribute<sup>(deprecated)</sup> ### getEditorAttribute<sup>(deprecated)</sup>
getEditorAttribute(callback: AsyncCallback&lt;EditorAttribute&gt;): void getEditorAttribute(callback: AsyncCallback&lt;EditorAttribute&gt;): void
获取编辑框属性值。使用 callback 异步回调。 获取编辑框属性值。使用callback异步回调。
> **说明:** > **说明:**
> >
> 从 API version 8 开始支持,API version 9 开始废弃,建议使用[getEditorAttribute](#geteditorattribute9)替代。 > 从API version 8开始支持,API version 9开始废弃,建议使用[getEditorAttribute](#geteditorattribute9)替代。
**系统能力:** SystemCapability.MiscServices.InputMethodFramework **系统能力:** SystemCapability.MiscServices.InputMethodFramework
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| -------- | -------------------------------------------------------- | ---- | ------------------------------------------------------------------------------------------- | | -------- | ----- | ----- | ----- |
| callback | AsyncCallback&lt;[EditorAttribute](#editorattribute)&gt; | 是 | 回调函数。当编辑框的属性值获取成功,err 为 undefined,data 为编辑框属性值;否则为错误对象。 | | callback | AsyncCallback&lt;[EditorAttribute](#editorattribute)&gt; | 是 | 回调函数。当编辑框的属性值获取成功,err为undefined,data为编辑框属性值;否则为错误对象。|
**示例:** **示例:**
...@@ -3300,14 +3159,8 @@ textInputClient.getEditorAttribute((err, editorAttribute) => { ...@@ -3300,14 +3159,8 @@ textInputClient.getEditorAttribute((err, editorAttribute) => {
console.error(`Failed to getEditorAttribute: ${JSON.stringify(err)}`); console.error(`Failed to getEditorAttribute: ${JSON.stringify(err)}`);
return; return;
} }
console.log( console.log('editorAttribute.inputPattern: ' + JSON.stringify(editorAttribute.inputPattern));
"editorAttribute.inputPattern: " + console.log('editorAttribute.enterKeyType: ' + JSON.stringify(editorAttribute.enterKeyType));
JSON.stringify(editorAttribute.inputPattern)
);
console.log(
"editorAttribute.enterKeyType: " +
JSON.stringify(editorAttribute.enterKeyType)
);
}); });
``` ```
...@@ -3315,38 +3168,28 @@ textInputClient.getEditorAttribute((err, editorAttribute) => { ...@@ -3315,38 +3168,28 @@ textInputClient.getEditorAttribute((err, editorAttribute) => {
getEditorAttribute(): Promise&lt;EditorAttribute&gt; getEditorAttribute(): Promise&lt;EditorAttribute&gt;
获取编辑框属性值。使用 promise 异步回调。 获取编辑框属性值。使用promise异步回调。
> **说明:** > **说明:**
> >
> 从 API version 8 开始支持,API version 9 开始废弃,建议使用[getEditorAttribute](#geteditorattribute9)替代。 > 从API version 8开始支持,API version 9开始废弃,建议使用[getEditorAttribute](#geteditorattribute9)替代。
**系统能力:** SystemCapability.MiscServices.InputMethodFramework **系统能力:** SystemCapability.MiscServices.InputMethodFramework
**返回值:** **返回值:**
| 类型 | 说明 | | 类型 | 说明 |
| -------------------------------------------------- | -------------------------------- | | ------------------------------- | ------------------------------------------------------------ |
| Promise&lt;[EditorAttribute](#editorattribute)&gt; | Promise 对象,返回编辑框属性值。 | | Promise&lt;[EditorAttribute](#editorattribute)&gt; | Promise对象,返回编辑框属性值。 |
**示例:** **示例:**
```js ```js
textInputClient textInputClient.getEditorAttribute().then((editorAttribute) => {
.getEditorAttribute() console.log('editorAttribute.inputPattern: ' + JSON.stringify(editorAttribute.inputPattern));
.then((editorAttribute) => { console.log('editorAttribute.enterKeyType: ' + JSON.stringify(editorAttribute.enterKeyType));
console.log( }).catch((err) => {
"editorAttribute.inputPattern: " +
JSON.stringify(editorAttribute.inputPattern)
);
console.log(
"editorAttribute.enterKeyType: " +
JSON.stringify(editorAttribute.enterKeyType)
);
})
.catch((err) => {
console.error(`Failed to getEditorAttribute: ${JSON.stringify(err)}`); console.error(`Failed to getEditorAttribute: ${JSON.stringify(err)}`);
}); });
``` ```
<!--no_check--> <!--no_check-->
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册