diff --git a/zh-cn/application-dev/reference/apis/js-apis-inputmethod-InputMethodCommon.md b/zh-cn/application-dev/reference/apis/js-apis-inputmethod-InputMethodCommon.md deleted file mode 100644 index 325d2f7aca6ddf2f093409faa8ac96e6c9bf84fd..0000000000000000000000000000000000000000 --- a/zh-cn/application-dev/reference/apis/js-apis-inputmethod-InputMethodCommon.md +++ /dev/null @@ -1,41 +0,0 @@ -# InputMethodCommon - -> **说明:** -> 本模块首批接口从API version 10 开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 - -输入法框架接口定义的公共属性信息。 - -## Direction - -光标移动方向类型枚举。 - - **系统能力:** SystemCapability.MiscServices.InputMethodFramework - -| 名称 | 值 | 说明 | -| ------------ | ---- | ---------- | -| CURSOR_UP | 1 | 光标上移。 | -| CURSOR_DOWN | 2 | 光标下移。 | -| CURSOR_LEFT | 3 | 光标左移。 | -| CURSOR_RIGHT | 4 | 光标右移。 | - -## Range - -描述选中文本的范围。 - - **系统能力:** SystemCapability.MiscServices.InputMethodFramework - -| 名称 | 类型 | 可读 | 可写 | 说明 | -| ----- | ------ | ---- | ---- | ---------------------------------- | -| start | number | 是 | 是 | 选中文本的首字符在编辑框的索引值。 | -| end | number | 是 | 是 | 选中文本的末字符在编辑框的索引值。 | - -## Movement - -描述进行选中文本动作时光标移动的方向。 - - **系统能力:** SystemCapability.MiscServices.InputMethodFramework - -| 名称 | 类型 | 可读 | 可写 | 说明 | -| --------- | ----------------------- | ---- | ---- | ---------------------------------- | -| direction | [Direction](#direction) | 是 | 是 | 进行选中文本动作时光标移动的方向。 | - diff --git a/zh-cn/application-dev/reference/apis/js-apis-inputmethod-extension-ability.md b/zh-cn/application-dev/reference/apis/js-apis-inputmethod-extension-ability.md index df38bad2078cc61c642a4999236d2c83cab7201e..4218b64b14a83133b512b8dc8c3bc0d5df8f8058 100644 --- a/zh-cn/application-dev/reference/apis/js-apis-inputmethod-extension-ability.md +++ b/zh-cn/application-dev/reference/apis/js-apis-inputmethod-extension-ability.md @@ -38,9 +38,9 @@ Extension生命周期回调,在拉起Extension输入法应用时调用,执 ```js class InputMethodExt extends InputMethodExtensionAbility { - onCreate(want) { - console.log('onCreate, want:' + want.abilityName); - } + onCreate(want) { + console.log('onCreate, want:' + want.abilityName); + } } ``` @@ -56,8 +56,8 @@ Extension生命周期回调,在销毁输入法应用时回调,执行资源 ```js class InputMethodExt extends InputMethodExtensionAbility { - onDestroy() { - console.log('onDestroy'); - } + onDestroy() { + console.log('onDestroy'); + } } ``` diff --git a/zh-cn/application-dev/reference/apis/js-apis-inputmethod-extension-context.md b/zh-cn/application-dev/reference/apis/js-apis-inputmethod-extension-context.md index 263b4f1da9cb4ce51ee3449c806c1f65cc6ed95d..fa5ba2aec075b22fc0900199d0dc200ede8529df 100644 --- a/zh-cn/application-dev/reference/apis/js-apis-inputmethod-extension-context.md +++ b/zh-cn/application-dev/reference/apis/js-apis-inputmethod-extension-context.md @@ -21,9 +21,9 @@ import InputMethodExtensionContext from '@ohos.InputMethodExtensionContext'; ```js import InputMethodExtensionAbility from '@ohos.InputMethodExtensionAbility'; class EntryAbility extends InputMethodExtensionAbility { - onCreate() { - let context = this.context; - } + onCreate() { + let context = this.context; + } } ``` @@ -44,8 +44,8 @@ destroy(callback: AsyncCallback\): void **示例:** ```js -this.context.destroy((err) => { - console.log('destroy result:' + JSON.stringify(err)); +this.context.destroy(() => { + console.log('Succeeded in destroying context.'); }); ``` @@ -67,8 +67,6 @@ destroy(): Promise\; ```js this.context.destroy().then(() => { - console.log('Succeed in destoring context.'); -}).catch((error) => { - console.log('Failed to destory context: ' + JSON.stringify(error)); + console.log('Succeed in destroying context.'); }); ``` diff --git a/zh-cn/application-dev/reference/apis/js-apis-inputmethod.md b/zh-cn/application-dev/reference/apis/js-apis-inputmethod.md index 3b05f3c4a6784b92844b5a21ffaf47715f9598da..c485e0dbe524d76ef59518e0947e7a6b4d7cda91 100644 --- a/zh-cn/application-dev/reference/apis/js-apis-inputmethod.md +++ b/zh-cn/application-dev/reference/apis/js-apis-inputmethod.md @@ -31,13 +31,13 @@ import inputMethod from '@ohos.inputMethod'; | 名称 | 类型 | 可读 | 可写 | 说明 | | -------- | -------- | -------- | -------- | -------- | -| name9+ | string | 是 | 否 | 输入法内部名称。必填。| -| id9+ | string | 是 | 否 | 输入法唯一标识。必填。| -| label9+ | string | 是 | 否 | 输入法对外显示名称。 非必填。| -| labelId10+ | string | 是 | 否 | 输入法对外显示名称资源号。 非必填。| -| icon9+ | string | 是 | 否 | 输入法图标数据。非必填。 | -| iconId9+ | number | 是 | 否 | 输入法图标资源号。非必填。 | -| extra9+ | object | 是 | 是 | 输入法扩展信息。 非必填。
**说明:** 从API version 10开始改为非必选参数。| +| name9+ | string | 是 | 否 | 必填。输入法内部名称。| +| id9+ | string | 是 | 否 | 必填。输入法唯一标识。| +| label9+ | string | 是 | 否 | 非必填。输入法对外显示名称。| +| labelId10+ | string | 是 | 否 | 非必填。输入法对外显示名称资源号。| +| icon9+ | string | 是 | 否 | 非必填。输入法图标数据。| +| iconId9+ | number | 是 | 否 | 非必填。输入法图标资源号。 | +| extra10+ | object | 是 | 是 | 非必填。输入法扩展信息。| | packageName(deprecated) | string | 是 | 否 | 输入法包名。必填。
**说明:** 从API version 8开始支持,从API version 9开始废弃,建议使用name替代。 | | methodId(deprecated) | string | 是 | 否 | 输入法唯一标识。必填。
**说明:** 从API version 8开始支持,从API version 9开始废弃,建议使用id替代。 | @@ -126,28 +126,21 @@ switchInputMethod(target: InputMethodProperty, callback: AsyncCallback<boolea **示例:** ```js -let im = inputMethod.getCurrentInputMethod(); -let prop = { - packageName: im.packageName, - methodId: im.methodId, - name: im.packageName, - id: im.methodId, - extra: {} -} +let currentIme = inputMethod.getCurrentInputMethod(); try{ - inputMethod.switchInputMethod(prop, (err, result) => { - if (err !== undefined) { - console.error('Failed to switchInputMethod: ' + JSON.stringify(err)); - return; - } - if (result) { - console.info('Succeeded in switching inputmethod.'); - } else { - console.error('Failed to switchInputMethod.'); - } - }); + inputMethod.switchInputMethod(currentIme, (err, result) => { + if (err) { + console.error(`Failed to switchInputMethod: ${JSON.stringify(err)}`); + return; + } + if (result) { + console.log('Succeeded in switching inputmethod.'); + } else { + console.error('Failed to switchInputMethod.'); + } + }); } catch(err) { - console.error('Failed to switchInputMethod: ' + JSON.stringify(err)); + console.error(`Failed to switchInputMethod: ${JSON.stringify(err)}`); } ``` ## inputMethod.switchInputMethod9+ @@ -183,26 +176,19 @@ switchInputMethod(target: InputMethodProperty): Promise<boolean> **示例:** ```js -let im = inputMethod.getCurrentInputMethod(); -let prop = { - packageName: im.packageName, - methodId: im.methodId, - name: im.packageName, - id: im.methodId, - extra: {} -} +let currentIme = inputMethod.getCurrentInputMethod(); try { - inputMethod.switchInputMethod(prop).then((result) => { - if (result) { - console.info('Succeeded in switching inputmethod.'); - } else { - console.error('Failed to switchInputMethod.'); - } - }).catch((err) => { - console.error('Failed to switchInputMethod: ' + JSON.stringify(err)); - }) + inputMethod.switchInputMethod(currentIme).then((result) => { + if (result) { + console.log('Succeeded in switching inputmethod.'); + } else { + console.error('Failed to switchInputMethod.'); + } + }).catch((err) => { + console.error(`Failed to switchInputMethod: ${JSON.stringify(err)}`); + }) } catch(err) { - console.error('Failed to switchInputMethod: ' + JSON.stringify(err)); + console.error(`Failed to switchInputMethod: ${JSON.stringify(err)}`); } ``` @@ -226,7 +212,7 @@ getCurrentInputMethod(): InputMethodProperty let currentIme = inputMethod.getCurrentInputMethod(); ``` -## inputMethod.switchCurrentInputMethodSubtype9+ +## inputMethod.switchCurrentInputMethodSubtype10+ switchCurrentInputMethodSubtype(target: InputMethodSubtype, callback: AsyncCallback\): void @@ -256,33 +242,33 @@ switchCurrentInputMethodSubtype(target: InputMethodSubtype, callback: AsyncCallb ```js try { - inputMethod.switchCurrentInputMethodSubtype({ - id: "ServiceExtAbility", - label: "", - name: "com.example.kikakeyboard", - mode: "upper", - locale: "", - language: "", - icon: "", - iconId: 0, - extra: {} - }, (err, result) => { - if (err !== undefined) { - console.error('Failed to switchCurrentInputMethodSubtype: ' + JSON.stringify(err)); - return; - } - if (result) { - console.info('Succeeded in switching currentInputMethodSubtype.'); - } else { - console.error('Failed to switchCurrentInputMethodSubtype'); - } - }); + inputMethod.switchCurrentInputMethodSubtype({ + id: "ServiceExtAbility", + label: "", + name: "com.example.kikakeyboard", + mode: "upper", + locale: "", + language: "", + icon: "", + iconId: 0, + extra: {} + }, (err, result) => { + if (err) { + console.error(`Failed to switchCurrentInputMethodSubtype: ${JSON.stringify(err)}`); + return; + } + if (result) { + console.log('Succeeded in switching currentInputMethodSubtype.'); + } else { + console.error('Failed to switchCurrentInputMethodSubtype'); + } + }); } catch(err) { - console.error('Failed to switchCurrentInputMethodSubtype: ' + JSON.stringify(err)); + console.error(`Failed to switchCurrentInputMethodSubtype: ${JSON.stringify(err)}`); } ``` -## inputMethod.switchCurrentInputMethodSubtype9+ +## inputMethod.switchCurrentInputMethodSubtype10+ switchCurrentInputMethodSubtype(target: InputMethodSubtype): Promise<boolean> @@ -317,27 +303,27 @@ switchCurrentInputMethodSubtype(target: InputMethodSubtype): Promise<boolean& ```js try { - inputMethod.switchCurrentInputMethodSubtype({ - id: "ServiceExtAbility", - label: "", - name: "com.example.kikakeyboard", - mode: "upper", - locale: "", - language: "", - icon: "", - iconId: 0, - extra: {} - }).then((result) => { - if (result) { - console.info('Succeeded in switching currentInputMethodSubtype.'); - } else { - console.error('Failed to switchCurrentInputMethodSubtype.'); - } - }).catch((err) => { - console.error('Failed to switchCurrentInputMethodSubtype: ' + JSON.stringify(err)); - }) + inputMethod.switchCurrentInputMethodSubtype({ + id: "ServiceExtAbility", + label: "", + name: "com.example.kikakeyboard", + mode: "upper", + locale: "", + language: "", + icon: "", + iconId: 0, + extra: {} + }).then((result) => { + if (result) { + console.log('Succeeded in switching currentInputMethodSubtype.'); + } else { + console.error('Failed to switchCurrentInputMethodSubtype.'); + } + }).catch((err) => { + console.error(`Failed to switchCurrentInputMethodSubtype: ${JSON.stringify(err)}`); + }) } catch(err) { - console.error('Failed to switchCurrentInputMethodSubtype: ' + JSON.stringify(err)); + console.error(`Failed to switchCurrentInputMethodSubtype: ${JSON.stringify(err)}`); } ``` @@ -365,19 +351,1292 @@ let currentImeSubType = inputMethod.getCurrentInputMethodSubtype(); switchCurrentInputMethodAndSubtype(inputMethodProperty: InputMethodProperty, inputMethodSubtype: InputMethodSubtype, callback: AsyncCallback\): void -切换至指定输入法应用的指定子类型,用于跨输入法应用切换子类型。使用callback异步回调。 +切换至指定输入法应用的指定子类型,用于跨输入法应用切换子类型。使用callback异步回调。 + +**需要权限:** ohos.permission.CONNECT_IME_ABILITY,仅系统应用可用。 + +**系统能力:** SystemCapability.MiscServices.InputMethodFramework + +**参数:** + +| 参数名 | 类型 | 必填 | 说明 | +| -------- | -------- | -------- | -------- | +|inputMethodProperty | [InputMethodProperty](#inputmethodproperty8)| 是 | 传入要切换的目标输入法。 | +|inputMethodSubtype | [InputMethodSubtype](./js-apis-inputmethod-subtype.md#inputmethodsubtype)| 是 | 传入要切换的目标输入法子类型。 | +| callback | AsyncCallback<boolean> | 是 | 回调函数。当输入法和子类型切换成功,err为undefined,data为获取到的切换子类型结果true;否则为错误对象。 | + +**错误码:** + +以下错误码的详细介绍请参见[输入法框架错误码](../errorcodes/errorcode-inputmethod-framework.md)。 + +| 错误码ID | 错误信息 | +| -------- | -------------------------------------- | +| 12800005 | Configuration persisting error. | +| 12800008 | Input method manager service error. | + +**示例:** + +```js +let currentIme = inputMethod.getCurrentInputMethod(); +let imSubType = inputMethod.getCurrentInputMethodSubtype(); +try { + inputMethod.switchCurrentInputMethodAndSubtype(currentIme, imSubType, (err,result) => { + if (err) { + console.error(`Failed to switchCurrentInputMethodAndSubtype: ${JSON.stringify(err)}`); + return; + } + if (result) { + console.log('Succeeded in switching currentInputMethodAndSubtype.'); + } else { + console.error('Failed to switchCurrentInputMethodAndSubtype.'); + } + }); +} catch (err) { + console.error(`Failed to switchCurrentInputMethodAndSubtype: ${JSON.stringify(err)}`); +} +``` + +## inputMethod.switchCurrentInputMethodAndSubtype9+ + +switchCurrentInputMethodAndSubtype(inputMethodProperty: InputMethodProperty, inputMethodSubtype: InputMethodSubtype): Promise<boolean> + +切换至指定输入法应用的指定子类型,用于跨输入法应用切换子类型。使用promise异步回调。 + +**需要权限:** ohos.permission.CONNECT_IME_ABILITY,仅系统应用可用。 + +**系统能力:** SystemCapability.MiscServices.InputMethodFramework + +**参数:** + +| 参数名 | 类型 | 必填 | 说明 | +| -------- | -------- | -------- | -------- | +|inputMethodProperty | [InputMethodProperty](#inputmethodproperty8)| 是 | 传入要切换的目标输入法。 | +|inputMethodSubtype | [InputMethodSubtype](./js-apis-inputmethod-subtype.md#inputmethodsubtype)| 是 | 传入要切换的目标输入法子类型。 | + +**返回值:** + +| 类型 | 说明 | +| ----------------------------------------- | ---------------------------- | +| Promise\ | Promise对象。返回true表示切换至指定输入法应用的指定子类型成功;返回false表示切换至指定输入法应用的指定子类型失败。 | + +**错误码:** + +以下错误码的详细介绍请参见[输入法框架错误码](../errorcodes/errorcode-inputmethod-framework.md)。 + +| 错误码ID | 错误信息 | +| -------- | -------------------------------------- | +| 12800005 | Configuration persisting error. | +| 12800008 | Input method manager service error. | + +**示例:** + +```js +let currentIme = inputMethod.getCurrentInputMethod(); +let imSubType = inputMethod.getCurrentInputMethodSubtype(); +try { + inputMethod.switchCurrentInputMethodAndSubtype(currentIme, imSubType).then((result) => { + if (result) { + console.log('Succeeded in switching currentInputMethodAndSubtype.'); + } else { + console.error('Failed to switchCurrentInputMethodAndSubtype.'); + } + }).catch((err) => { + console.error(`Failed to switchCurrentInputMethodAndSubtype: ${JSON.stringify(err)}`); + }) +} catch(err) { + console.error(`Failed to switchCurrentInputMethodAndSubtype: ${JSON.stringify(err)}`); +} +``` + +## inputMethod.getInputMethodController(deprecated) + +getInputMethodController(): InputMethodController + +获取客户端实例[InputMethodController](#inputmethodcontroller)。 + +> **说明:** +> +> 从API version 6开始支持,从API version 9开始废弃,建议使用[getController()](#inputmethodgetcontroller9)替代。 + +**系统能力:** SystemCapability.MiscServices.InputMethodFramework + +**返回值:** + +| 类型 | 说明 | +| ----------------------------------------------- | ------------------------ | +| [InputMethodController](#inputmethodcontroller) | 回调返回当前客户端实例。 | + +**示例:** + +```js +let inputMethodController = inputMethod.getInputMethodController(); +``` + +## inputMethod.getInputMethodSetting(deprecated) + +getInputMethodSetting(): InputMethodSetting + +获取客户端设置实例[InputMethodSetting](#inputmethodsetting8)。 + +> **说明:** +> +> 从API version 6开始支持,从API version 9开始废弃,建议使用[getSetting()](#inputmethodgetsetting9)替代。 + +**系统能力:** SystemCapability.MiscServices.InputMethodFramework + +**返回值:** + +| 类型 | 说明 | +| ----------------------------------------- | ---------------------------- | +| [InputMethodSetting](#inputmethodsetting8) | 回调返回当前客户端设置实例。 | + +**示例:** + +```js +let inputMethodSetting = inputMethod.getInputMethodSetting(); +``` + +## TextInputType10+ + +文本输入类型。 + +**系统能力:** SystemCapability.MiscServices.InputMethodFramework + +| 名称 | 值 |说明 | +| -------- | -------- |-------- | +| NONE | -1 |NONE。 | +| TEXT | 0 |文本类型。 | +| MULTILINE | 1 |多行类型。 | +| NUMBER | 2 |数字类型。 | +| PHONE | 3 |电话号码类型。 | +| DATETIME | 4 |日期类型。 | +| EMAIL_ADDRESS | 5 |邮箱地址类型。 | +| URL | 6 |链接类型。 | +| VISIBLE_PASSWORD | 7 |密码类型。 | + +## EnterKeyType10+ + +输入法Enter键所代表的功能类型。 + +**系统能力:** SystemCapability.MiscServices.InputMethodFramework + +| 名称 | 值 |说明 | +| -------- | -------- |-------- | +| UNSPECIFIED | 0 |未指定。 | +| NONE | 1 |NONE。 | +| GO | 2 |前往。 | +| SEARCH | 3 |查找。 | +| SEND | 4 |发送。 | +| NEXT | 5 |下一步。 | +| DONE | 6 |完成。 | +| PREVIOUS | 7 |上一步。 | + +## KeyboardStatus10+ + +输入法软键盘状态。 + +**系统能力:** SystemCapability.MiscServices.InputMethodFramework + +| 名称 | 值 |说明 | +| -------- | -------- |-------- | +| NONE | 0 |NONE。 | +| HIDE | 1 |隐藏状态。 | +| SHOW | 2 |显示状态。 | + +## Direction10+ + +光标移动方向。 + +**系统能力:** SystemCapability.MiscServices.InputMethodFramework + +| 名称 | 值 |说明 | +| -------- | -------- |-------- | +| CURSOR_UP | 1 |向上。 | +| CURSOR_DOWN | 2 |向下。 | +| CURSOR_LEFT | 3 |向左。 | +| CURSOR_RIGHT | 4 |向右。 | + +## ExtendAction10+ + +对编辑框中文本的扩展编辑操作类型。 + +**系统能力:** SystemCapability.MiscServices.InputMethodFramework + +| 名称 | 值 |说明 | +| -------- | -------- |-------- | +| SELECT_ALL | 0 |全选。 | +| CUT | 3 |剪切。 | +| COPY | 4 |复制。 | +| PASTE | 5 |粘贴。 | + +## FunctionKey10+ + +输入法功能键类型。 + +**系统能力:** SystemCapability.MiscServices.InputMethodFramework + +| 名称 | 类型 | 可读 | 可写 | 说明 | +| -------- | -------- | -------- | -------- | -------- | +| enterKeyType10+ | [EnterKeyType](#enterkeytype10) | 是 | 是 | 输入法enter键类型。| + +## InputAttribute10+ + +编辑框属性,包含文本输入类型,Enter键功能类型。 + +**系统能力:** SystemCapability.MiscServices.InputMethodFramework + +| 名称 | 类型 | 可读 | 可写 | 说明 | +| -------- | -------- | -------- | -------- | -------- | +| textInputType10+ | [TextInputType](#textinputtype10) | 是 | 是 | 文本输入类型。| +| enterKeyType10+ | [EnterKeyType](#enterkeytype10) | 是 | 是 | Enter键功能类型。| + +## TextConfig10+ + +编辑控件配置信息。编辑控件请求绑定输入法应用时传入,将编辑控件相关属性配置信息保存到输入法框架内。 + +**系统能力:** SystemCapability.MiscServices.InputMethodFramework + +| 名称 | 类型 | 可读 | 可写 | 说明 | +| -------- | -------- | -------- | -------- | -------- | +| inputAttribute10+ | [InputAttribute](#inputattribute10) | 是 | 是 | 编辑框属性。| + +## CursorInfo10+ + +光标信息。 + +**系统能力:** SystemCapability.MiscServices.InputMethodFramework + +| 名称 | 类型 | 可读 | 可写 | 说明 | +| -------- | -------- | -------- | -------- | -------- | +| left | number | 是 | 是 | 光标的left坐标。| +| top | number | 是 | 是 | 光标的top坐标。| +| width | number | 是 | 是 | 光标的宽度。| +| height | number | 是 | 是 | 光标的高度。| + +## Range10+ + +描述选中文本的范围。 + +**系统能力:** SystemCapability.MiscServices.InputMethodFramework + +| 名称 | 类型 | 可读 | 可写 | 说明 | +| -------- | -------- | -------- | -------- | -------- | +| start | number | 是 | 是 | 选中文本的首字符在编辑框的索引值。| +| end | number | 是 | 是 | 选中文本的末字符在编辑框的索引值。| + +## Movement10+ + +描述进行选中文本动作时光标移动的方向。 + +**系统能力:** SystemCapability.MiscServices.InputMethodFramework + +| 名称 | 类型 | 可读 | 可写 | 说明 | +| -------- | -------- | -------- | -------- | -------- | +| direction | [Direction](#direction10) | 是 | 是 | 进行选中文本动作时光标移动的方向。| + +## InputMethodController + +下列API示例中都需使用[getController](#inputmethodgetcontroller9)获取到InputMethodController实例,再通过此实例调用对应方法。 + +### attach10+ + +attach(showKeyboard: boolean, textConfig: TextConfig, callback: AsyncCallback<void>): void + +用于自绘控件绑定输入法应用。使用callback异步回调。 + +必须先调用此接口完成自绘控件与输入法应用的绑定,才可以使用输入法框架的以下功能:显示、隐藏键盘;更新光标信息;更改编辑框选中范围;保存配置信息;监听处理由输入法应用发送的信息或命令等。 + +**系统能力:** SystemCapability.MiscServices.InputMethodFramework + +**参数:** + +| 参数名 | 类型 | 必填 | 说明 | +| -------- | -------- | -------- | -------- | +| showKeyboard | boolean | 是 | 绑定输入法成功后是否拉起输入法键盘。 | +| textConfig | [TextConfig](#textconfig10) | 是 | 编辑控件配置信息。 | +| callback | AsyncCallback<void> | 是 | 回调函数。当绑定输入法成功后,err为undefined;否则为错误对象。 | + +**错误码:** + +以下错误码的详细介绍请参见[输入法框架错误码](../errorcodes/errorcode-inputmethod-framework.md)。 + +| 错误码ID | 错误信息 | +| -------- | -------------------------------------- | +| 12800003 | Input method client error. | +| 12800008 | Input method manager service error. | + +**示例:** + +```js +try { + let textConfig: inputMethod.TextConfig = { + inputAttribute: { + textInputType: 0, + enterKeyType: 1 + } + }; + inputMethodController.attach(true, textConfig, (err) => { + if (err) { + console.error(`Failed to attach: ${JSON.stringify(err)}`); + return; + } + console.log('Succeeded in attaching the inputMethod.'); + }); +} catch(err) { + console.error(`Failed to attach: ${JSON.stringify(err)}`); +} +``` + +### attach10+ + +attach(showKeyboard: boolean, textConfig: TextConfig): Promise<void> + +用于自绘控件绑定输入法应用。使用callback异步回调。 + +必须先调用此接口完成自绘控件与输入法应用的绑定,才可以使用输入法框架的以下功能:显示、隐藏键盘;更新光标信息;更改编辑框选中范围;保存配置信息;监听处理由输入法应用发送的信息或命令等。 + +**系统能力:** SystemCapability.MiscServices.InputMethodFramework + +**参数:** + +| 参数名 | 类型 | 必填 | 说明 | +| -------- | -------- | -------- | -------- | +| showKeyboard | boolean | 是 | 绑定输入法成功后是否拉起输入法键盘。 | +| textConfig | [TextConfig](#textconfig10) | 是 | 编辑框属性。 | + +**返回值:** + +| 类型 | 说明 | +| -------- | -------- | +| Promise<void> | 无返回结果的Promise对象。 | + +**错误码:** + +以下错误码的详细介绍请参见[输入法框架错误码](../errorcodes/errorcode-inputmethod-framework.md)。 + +| 错误码ID | 错误信息 | +| -------- | -------------------------------------- | +| 12800003 | Input method client error. | +| 12800008 | Input method manager service error. | + +**示例:** + +```js +try { + let textConfig: inputMethod.TextConfig = { + inputAttribute: { + textInputType: 0, + enterKeyType: 1 + } + }; + inputMethodController.attach(true, textConfig).then(() => { + console.log('Succeeded in attaching inputMethod.'); + }).catch((err) => { + console.error(`Failed to attach: ${JSON.stringify(err)}`); + }) +} catch(err) { + console.error(`Failed to attach: ${JSON.stringify(err)}`); +} +``` + +### showTextInput10+ + +showTextInput(callback: AsyncCallback<void>): void + +进入文本编辑状态。使用callback异步回调。 + +编辑控件与输入法应用绑定成功后,可调用该接口去拉起软键盘。 + +**系统能力:** SystemCapability.MiscServices.InputMethodFramework + +**参数:** + +| 参数名 | 类型 | 必填 | 说明 | +| -------- | -------- | -------- | -------- | +| callback | AsyncCallback<void> | 是 | 回调函数。若成功进入编辑状态,err为undefined;否则为错误对象。 | + +**错误码:** + +以下错误码的详细介绍请参见[输入法框架错误码](../errorcodes/errorcode-inputmethod-framework.md)。 + +| 错误码ID | 错误信息 | +| -------- | -------------------------------------- | +| 12800003 | Input method client error. | +| 12800008 | Input method manager service error. | +| 12800009 | Input method client is detached. | + +**示例:** + +```js +inputMethodController.showTextInput((err) => { + if (err) { + console.error(`Failed to showTextInput: ${JSON.stringify(err)}`); + return; + } + console.log('Succeeded in showing the inputMethod.'); +}); +``` + +### showTextInput10+ + +showTextInput(): Promise<void> + +进入文本编辑状态。使用promise异步回调。 + +编辑控件与输入法应用绑定成功后,可调用该接口去拉起软键盘。 + +**系统能力:** SystemCapability.MiscServices.InputMethodFramework + +**返回值:** + +| 类型 | 说明 | +| -------- | -------- | +| Promise<void> | 无返回结果的Promise对象。 | + +**错误码:** + +以下错误码的详细介绍请参见[输入法框架错误码](../errorcodes/errorcode-inputmethod-framework.md)。 + +| 错误码ID | 错误信息 | +| -------- | -------------------------------------- | +| 12800003 | Input method client error. | +| 12800008 | Input method manager service error. | +| 12800009 | Input method client is detached. | + +**示例:** + +```js +inputMethodController.showTextInput().then(() => { + console.log('Succeeded in showing text input.'); +}).catch((err) => { + console.error(`Failed to showTextInput: ${JSON.stringify(err)}`); +}); +``` + +### hideTextInput10+ + +hideTextInput(callback: AsyncCallback<void>): void + +退出文本编辑状态。使用callback异步回调。 + +编辑控件可调用该接口退出编辑状态。若调用该接口时当前软键盘处于显示状态,则调用该接口后软键盘会被隐藏。 + +调用该接口不解除与输入法应用的绑定,再次调用[showTextInput](#showtextinput10)时,可重新进入编辑状态。 + +**系统能力:** SystemCapability.MiscServices.InputMethodFramework + +**参数:** + +| 参数名 | 类型 | 必填 | 说明 | +| -------- | -------- | -------- | -------- | +| callback | AsyncCallback<void> | 是 | 回调函数。当成功退出编辑状态时,err为undefined;否则为错误对象。 | + +**错误码:** + +以下错误码的详细介绍请参见[输入法框架错误码](../errorcodes/errorcode-inputmethod-framework.md)。 + +| 错误码ID | 错误信息 | +| -------- | -------------------------------------- | +| 12800003 | Input method client error. | +| 12800008 | Input method manager service error. | +| 12800009 | Input method client is detached. | + +**示例:** + +```js +inputMethodController.hideTextInput((err) => { + if (err) { + console.error(`Failed to hideTextInput: ${JSON.stringify(err)}`); + return; + } + console.log('Succeeded in hiding text input.'); +}); +``` + +### hideTextInput10+ + +hideTextInput(): Promise<void> + +退出文本编辑状态。使用promise异步回调。 + +编辑控件可调用该接口退出编辑状态。若调用该接口时当前软键盘处于显示状态,则调用该接口后软键盘会被隐藏。 + +调用该接口不解除与输入法应用的绑定,再次调用[showTextInput](#showtextinput10)时,可重新进入编辑状态。 + +**系统能力:** SystemCapability.MiscServices.InputMethodFramework + +**返回值:** + +| 类型 | 说明 | +| -------- | -------- | +| Promise<void> | 无返回结果的Promise对象。 | + +**错误码:** + +以下错误码的详细介绍请参见[输入法框架错误码](../errorcodes/errorcode-inputmethod-framework.md)。 + +| 错误码ID | 错误信息 | +| -------- | -------------------------------------- | +| 12800003 | Input method client error. | +| 12800008 | Input method manager service error. | +| 12800009 | Input method client is detached. | + +**示例:** + +```js +inputMethodController.hideTextInput().then(() => { + console.log('Succeeded in hiding inputMethod.'); +}).catch((err) => { + console.error(`Failed to hideTextInput: ${JSON.stringify(err)}`); +}) +``` + +### detach10+ + +detach(callback: AsyncCallback<void>): void + +解除与输入法应用的绑定。使用callback异步回调。 + +**系统能力:** SystemCapability.MiscServices.InputMethodFramework + +**参数:** + +| 参数名 | 类型 | 必填 | 说明 | +| -------- | -------- | -------- | -------- | +| callback | AsyncCallback<void> | 是 | 回调函数。当解绑定输入法成功时,err为undefined;否则为错误对象。 | + +**错误码:** + +以下错误码的详细介绍请参见[输入法框架错误码](../errorcodes/errorcode-inputmethod-framework.md)。 + +| 错误码ID | 错误信息 | +| -------- | -------------------------------------- | +| 12800003 | Input method client error. | +| 12800008 | Input method manager service error. | + +**示例:** + +```js +inputMethodController.detach((err) => { + if (err) { + console.error(`Failed to detach: ${JSON.stringify(err)}`); + return; + } + console.log('Succeeded in detaching inputMethod.'); +}); +``` + +### detach10+ + +detach(): Promise<void> + +解除与输入法应用的绑定。使用promise异步回调。 + +**系统能力:** SystemCapability.MiscServices.InputMethodFramework + +**返回值:** + +| 类型 | 说明 | +| -------- | -------- | +| Promise<void> | 无返回结果的Promise对象。 | + +**错误码:** + +以下错误码的详细介绍请参见[输入法框架错误码](../errorcodes/errorcode-inputmethod-framework.md)。 + +| 错误码ID | 错误信息 | +| -------- | -------------------------------------- | +| 12800003 | Input method client error. | +| 12800008 | Input method manager service error. | + +**示例:** + +```js +inputMethodController.detach().then(() => { + console.log('Succeeded in detaching inputMethod.'); +}).catch((err) => { + console.error(`Failed to detach: ${JSON.stringify(err)}`); +}); +``` + +### setCallingWindow10+ + +setCallingWindow(windowId: number, callback: AsyncCallback<void>): void + +设置要避让的窗口。使用callback异步回调。 + +比如:将当前绑定到输入法的应用程序的窗口ID通知系统,正确设置后,客户端所在的窗口可以避开输入法窗口。预留能力,当前暂不支持获取windowId。 + +**系统能力:** SystemCapability.MiscServices.InputMethodFramework + +**参数:** + +| 参数名 | 类型 | 必填 | 说明 | +| -------- | -------- | -------- | -------- | +| windowId | number | 是 | 要避让的窗口id。 | +| callback | AsyncCallback<void> | 是 | 回调函数。当设置成功时,err为undefined;否则为错误对象。 | + +**错误码:** + +以下错误码的详细介绍请参见[输入法框架错误码](../errorcodes/errorcode-inputmethod-framework.md)。 + +| 错误码ID | 错误信息 | +| -------- | -------------------------------------- | +| 12800003 | Input method client error. | +| 12800008 | Input method manager service error. | +| 12800009 | Input method client is detached. | + +**示例:** + +```js +try { + let windowId: number = 2000; + inputMethodController.setCallingWindow(windowId, (err) => { + if (err) { + console.error(`Failed to setCallingWindow: ${JSON.stringify(err)}`); + return; + } + console.log('Succeeded in setting callingWindow.'); + }); +} catch(err) { + console.error(`Failed to setCallingWindow: ${JSON.stringify(err)}`); +} +``` + +### setCallingWindow10+ + +setCallingWindow(windowId: number): Promise<void> + +设置要避让的窗口。使用promise异步回调。 + +比如:将当前绑定到输入法的应用程序的窗口ID通知系统,正确设置后,客户端所在的窗口可以避开输入法窗口。预留能力,当前暂不支持获取windowId。 + +**系统能力:** SystemCapability.MiscServices.InputMethodFramework + +**参数:** + +| 参数名 | 类型 | 必填 | 说明 | +| -------- | -------- | -------- | -------- | +| windowId | number | 是 | 要避让的窗口id。 | + +**返回值:** + +| 类型 | 说明 | +| -------- | -------- | +| Promise<void> | 无返回结果的Promise对象。 | + +**错误码:** + +以下错误码的详细介绍请参见[输入法框架错误码](../errorcodes/errorcode-inputmethod-framework.md)。 + +| 错误码ID | 错误信息 | +| -------- | -------------------------------------- | +| 12800003 | Input method client error. | +| 12800008 | Input method manager service error. | +| 12800009 | Input method client is detached. | + +**示例:** + +```js +try { + let windowId: number = 2000; + inputMethodController.setCallingWindow(windowId).then(() => { + console.log('Succeeded in setting callingWindow.'); + }).catch((err) => { + console.error(`Failed to setCallingWindow: ${JSON.stringify(err)}`); + }) +} catch(err) { + console.error(`Failed to setCallingWindow: ${JSON.stringify(err)}`); +} +``` + +### updateCursor10+ + +updateCursor(cursorInfo: CursorInfo, callback: AsyncCallback<void>): void + +更新当前编辑框内光标信息。使用callback异步回调。 + +当光标信息发生变化时,可调用该接口更新光标信息,从而被输入法应用感知到光标变化。 + +**系统能力:** SystemCapability.MiscServices.InputMethodFramework + +**参数:** + +| 参数名 | 类型 | 必填 | 说明 | +| -------- | -------- | -------- | -------- | +| cursorInfo | [CursorInfo](#cursorinfo10) | 是 | 光标信息。 | +| callback | AsyncCallback<void> | 是 | 回调函数。当光标信息更新成功时,err为undefined;否则为错误对象。 | + +**错误码:** + +以下错误码的详细介绍请参见[输入法框架错误码](../errorcodes/errorcode-inputmethod-framework.md)。 + +| 错误码ID | 错误信息 | +| -------- | -------------------------------------- | +| 12800003 | Input method client error. | +| 12800008 | Input method manager service error. | +| 12800009 | Input method client is detached. | + +**示例:** + +```js +try { + inputMethodController.updateCursor({left: 0, top: 0, width: 600, height: 800}, (err) => { + if (err) { + console.error(`Failed to updateCursor: ${JSON.stringify(err)}`); + return; + } + console.log('Succeeded in updating cursorInfo.'); + }); +} catch(err) { + console.error(`Failed to updateCursor: ${JSON.stringify(err)}`); +} +``` + +### updateCursor10+ + +updateCursor(cursorInfo: CursorInfo): Promise<void> + +更新当前编辑控件内的光标信息。使用promise异步回调。 + +当光标信息发生变化时,编辑控件可调用该接口更新光标信息,从而被输入法应用感知到光标变化。 + +**系统能力:** SystemCapability.MiscServices.InputMethodFramework + +**参数:** + +| 参数名 | 类型 | 必填 | 说明 | +| -------- | -------- | -------- | -------- | +| cursorInfo | [CursorInfo](#cursorinfo10) | 是 | 光标信息。 | + +**返回值:** + +| 类型 | 说明 | +| -------- | -------- | +| Promise<void> | 无返回结果的Promise对象。 | + +**错误码:** + +以下错误码的详细介绍请参见[输入法框架错误码](../errorcodes/errorcode-inputmethod-framework.md)。 + +| 错误码ID | 错误信息 | +| -------- | -------------------------------------- | +| 12800003 | Input method client error. | +| 12800008 | Input method manager service error. | +| 12800009 | Input method client is detached. | + +**示例:** + +```js +try { + inputMethodController.updateCursor({left: 0, top: 0, width: 600, height: 800}).then(() => { + console.log('Succeeded in updating cursorInfo.'); + }).catch((err) => { + console.error(`Failed to updateCursor: ${JSON.stringify(err)}`); + }) +} catch(err) { + console.error(`Failed to updateCursor: ${JSON.stringify(err)}`); +} +``` + +### changeSelection10+ + +changeSelection(text: string, start: number, end: number, callback: AsyncCallback<void>): void + +向输入法应用更新当前编辑框内被选中的文本信息,当选中的文本内容或文本范围发生变化时,可调用该接口更新文本信息。使用callback异步回调。 + +**系统能力:** SystemCapability.MiscServices.InputMethodFramework + +**参数:** + +| 参数名 | 类型 | 必填 | 说明 | +| -------- | -------- | -------- | -------- | +| text | string | 是 | 整个输入文本。 | +| start | number | 是 | 所选文本的起始位置。 | +| end | number | 是 | 所选文本的结束位置。 | +| callback | AsyncCallback<void> | 是 | 回调函数。当隐藏输入法成功时,err为undefined;否则为错误对象。 | + +**错误码:** + +以下错误码的详细介绍请参见[输入法框架错误码](../errorcodes/errorcode-inputmethod-framework.md)。 + +| 错误码ID | 错误信息 | +| -------- | -------------------------------------- | +| 12800003 | Input method client error. | +| 12800008 | Input method manager service error. | +| 12800009 | Input method client is detached. | + +**示例:** + +```js +try { + inputMethodController.changeSelection('text', 0, 5, (err) => { + if (err) { + console.error(`Failed to changeSelection: ${JSON.stringify(err)}`); + return; + } + console.log('Succeeded in changing selection.'); + }); +} catch(err) { + console.error(`Failed to changeSelection: ${JSON.stringify(err)}`); +} +``` + +### changeSelection10+ + +changeSelection(text: string, start: number, end: number): Promise<void> + +向输入法应用更新当前编辑框内被选中的文本信息,当选中的文本内容或文本范围发生变化时,可调用该接口更新文本信息。使用promise异步回调。 + +**系统能力:** SystemCapability.MiscServices.InputMethodFramework + +**参数:** + +| 参数名 | 类型 | 必填 | 说明 | +| -------- | -------- | -------- | -------- | +| text | string | 是 | 整个输入文本。 | +| start | number | 是 | 所选文本的起始位置。 | +| end | number | 是 | 所选文本的结束位置。 | + +**返回值:** + +| 类型 | 说明 | +| -------- | -------- | +| Promise<void> | 无返回结果的Promise对象。 | + +**错误码:** + +以下错误码的详细介绍请参见[输入法框架错误码](../errorcodes/errorcode-inputmethod-framework.md)。 + +| 错误码ID | 错误信息 | +| -------- | -------------------------------------- | +| 12800003 | Input method client error. | +| 12800008 | Input method manager service error. | +| 12800009 | Input method client is detached. | + +**示例:** + +```js +try { + inputMethodController.changeSelection('test', 0, 5).then(() => { + console.log('Succeeded in changing selection.'); + }).catch((err) => { + console.error(`Failed to changeSelection: ${JSON.stringify(err)}`); + }) +} catch(err) { + console.error(`Failed to changeSelection: ${JSON.stringify(err)}`); +} +``` + +### updateAttribute10+ + +updateAttribute(attribute: InputAttribute, callback: AsyncCallback<void>): void + +更新编辑框属性配置信息。使用callback异步回调。 + +**系统能力:** SystemCapability.MiscServices.InputMethodFramework + +**参数:** + +| 参数名 | 类型 | 必填 | 说明 | +| -------- | -------- | -------- | -------- | +| attribute | [InputAttribute](#inputattribute10) | 是 | InputAttribute对象,包含的额外信息。 | +| callback | AsyncCallback<void> | 是 | 回调函数。当隐藏输入法成功时,err为undefined;否则为错误对象。 | + +**错误码:** + +以下错误码的详细介绍请参见[输入法框架错误码](../errorcodes/errorcode-inputmethod-framework.md)。 + +| 错误码ID | 错误信息 | +| -------- | -------------------------------------- | +| 12800003 | Input method client error. | +| 12800008 | Input method manager service error. | +| 12800009 | Input method client is detached. | + +**示例:** + +```js +try { + inputMethodController.updateAttribute({textInputType: 0, enterKeyType: 1}, (err) => { + if (err) { + console.error(`Failed to updateAttribute: ${JSON.stringify(err)}`); + return; + } + console.log('Succeeded in updating attribute.'); + }); +} catch(err) { + console.error(`Failed to updateAttribute: ${JSON.stringify(err)}`); +} +``` + +### updateAttribute10+ + +updateAttribute(attribute: InputAttribute): Promise<void> + +更新编辑框属性配置信息。使用promise异步回调。 + +**系统能力:** SystemCapability.MiscServices.InputMethodFramework + +**参数:** + +| 参数名 | 类型 | 必填 | 说明 | +| -------- | -------- | -------- | -------- | +| attribute | [InputAttribute](#inputattribute10) | 是 | InputAttribute对象,包含的额外信息。 | + +**返回值:** + +| 类型 | 说明 | +| -------- | -------- | +| Promise<void> | 无返回结果的Promise对象。 | + +**错误码:** + +以下错误码的详细介绍请参见[输入法框架错误码](../errorcodes/errorcode-inputmethod-framework.md)。 + +| 错误码ID | 错误信息 | +| -------- | -------------------------------------- | +| 12800003 | Input method client error. | +| 12800008 | Input method manager service error. | +| 12800009 | Input method client is detached. | + +**示例:** + +```js +try { + inputMethodController.updateAttribute({textInputType: 0, enterKeyType: 1}).then(() => { + console.log('Succeeded in updating attribute.'); + }).catch((err) => { + console.error(`Failed to updateAttribute: ${JSON.stringify(err)}`); + }) +} catch(err) { + console.error(`Failed to updateAttribute: ${JSON.stringify(err)}`); +} +``` + +### stopInputSession9+ + +stopInputSession(callback: AsyncCallback<boolean>): void + +结束输入会话。使用callback异步回调。 + +需要与编辑控件(如:输入框)绑定使用。当点击编辑控件后,才可通过调用该接口结束输入会话。 + +**系统能力:** SystemCapability.MiscServices.InputMethodFramework + +**参数:** + +| 参数名 | 类型 | 必填 | 说明 | +| -------- | -------- | -------- | -------- | +| callback | AsyncCallback<boolean> | 是 | 回调函数。当结束输入会话成功时,err为undefined,data为true;否则为错误对象。 | + +**错误码:** + +以下错误码的详细介绍请参见[输入法框架错误码](../errorcodes/errorcode-inputmethod-framework.md)。 + +| 错误码ID | 错误信息 | +| -------- | -------------------------------------- | +| 12800003 | Input method client error. | +| 12800008 | Input method manager service error. | + +**示例:** + +```js +try { + inputMethodController.stopInputSession((err, result) => { + if (err) { + console.error(`Failed to stopInputSession: ${JSON.stringify(err)}`); + return; + } + if (result) { + console.log('Succeeded in stopping inputSession.'); + } else { + console.error('Failed to stopInputSession.'); + } + }); +} catch(err) { + console.error(`Failed to stopInputSession: ${JSON.stringify(err)}`); +} +``` + +### stopInputSession9+ + +stopInputSession(): Promise<boolean> + +结束输入会话。使用promise异步回调。 + +需要与编辑控件(如:输入框)绑定使用。当点击编辑控件后,才可通过调用该接口结束输入会话。 + +**系统能力:** SystemCapability.MiscServices.InputMethodFramework + +**返回值:** + +| 类型 | 说明 | +| -------- | -------- | +| Promise<boolean> | Promise对象。返回true表示结束输入会话成功;返回false表示结束输入会话失败。 | + +**错误码:** + +以下错误码的详细介绍请参见[输入法框架错误码](../errorcodes/errorcode-inputmethod-framework.md)。 + +| 错误码ID | 错误信息 | +| -------- | -------------------------------------- | +| 12800003 | Input method client error. | +| 12800008 | Input method manager service error. | + +**示例:** + +```js +try { + inputMethodController.stopInputSession().then((result) => { + if (result) { + console.log('Succeeded in stopping inputSession.'); + } else { + console.error('Failed to stopInputSession.'); + } + }).catch((err) => { + console.error(`Failed to stopInputSession: ${JSON.stringify(err)}`); + }) +} catch(err) { + console.error(`Failed to stopInputSession: ${JSON.stringify(err)}`); +} +``` + +### showSoftKeyboard9+ + +showSoftKeyboard(callback: AsyncCallback<void>): void + +显示软键盘。使用callback异步回调。 + +需要与编辑控件(如:输入框)绑定使用。当点击编辑控件后,才可通过该接口的调用显示出当前输入法的软键盘。 + +**需要权限:** ohos.permission.CONNECT_IME_ABILITY,仅系统应用可用。 + +**系统能力:** SystemCapability.MiscServices.InputMethodFramework + +**参数:** + +| 参数名 | 类型 | 必填 | 说明 | +| -------- | ------------------------- | ---- | ---------- | +| callback | AsyncCallback<void> | 是 | 回调函数。当软键盘显示成功。err为undefined,否则为错误对象。 | + +**错误码:** + +以下错误码的详细介绍请参见[输入法框架错误码](../errorcodes/errorcode-inputmethod-framework.md)。 + +| 错误码ID | 错误信息 | +| -------- | -------------------------------------- | +| 12800003 | Input method client error. | +| 12800008 | Input method manager service error. | + +**示例:** + +```js +inputMethodController.showSoftKeyboard((err) => { + if (!err) { + console.log('Succeeded in showing softKeyboard.'); + } else { + console.error(`Failed to show softKeyboard: ${JSON.stringify(err)}`); + } +}) +``` + +### showSoftKeyboard9+ + +showSoftKeyboard(): Promise<void> + +显示软键盘。使用Promise异步回调。 + +需要与编辑控件(如:输入框)绑定使用。当点击编辑控件后,才可通过该接口的调用显示出当前输入法的软键盘。 + +**需要权限:** ohos.permission.CONNECT_IME_ABILITY,仅系统应用可用。 + +**系统能力:** SystemCapability.MiscServices.InputMethodFramework + +**返回值:** + +| 类型 | 说明 | +| ------------------- | ------------------------- | +| Promise<void> | 无返回结果的Promise对象。 | + +**错误码:** + +以下错误码的详细介绍请参见[输入法框架错误码](../errorcodes/errorcode-inputmethod-framework.md)。 + +| 错误码ID | 错误信息 | +| -------- | -------------------------------------- | +| 12800003 | Input method client error. | +| 12800008 | Input method manager service error. | + +**示例:** + +```js +inputMethodController.showSoftKeyboard().then(() => { + console.log('Succeeded in showing softKeyboard.'); +}).catch((err) => { + console.error(`Failed to show softKeyboard: ${JSON.stringify(err)}`); +}); +``` + +### hideSoftKeyboard9+ + +hideSoftKeyboard(callback: AsyncCallback<void>): void + +隐藏软键盘。使用callback异步回调。 + +需要与编辑控件(如:输入框)绑定使用。当点击编辑控件后,才可通过调用该接口隐藏当前输入法的软键盘。 + +**需要权限:** ohos.permission.CONNECT_IME_ABILITY,仅系统应用可用。 + +**系统能力:** SystemCapability.MiscServices.InputMethodFramework + +**参数:** + +| 参数名 | 类型 | 必填 | 说明 | +| -------- | ------------------------- | ---- | ---------- | +| callback | AsyncCallback<void> | 是 | 回调函数。当软键盘隐藏成功。err为undefined,否则为错误对象。 | + +**错误码:** + +以下错误码的详细介绍请参见[输入法框架错误码](../errorcodes/errorcode-inputmethod-framework.md)。 + +| 错误码ID | 错误信息 | +| -------- | -------------------------------------- | +| 12800003 | Input method client error. | +| 12800008 | Input method manager service error. | + +**示例:** + +```js +inputMethodController.hideSoftKeyboard((err) => { + if (!err) { + console.log('Succeeded in hiding softKeyboard.'); + } else { + console.error(`Failed to hide softKeyboard: ${JSON.stringify(err)}`); + } +}) +``` + +### hideSoftKeyboard9+ + +hideSoftKeyboard(): Promise<void> + +隐藏软键盘。使用Promise异步回调。 + +需要与编辑控件(如:输入框)绑定使用。当点击编辑控件后,才可通过调用该接口隐藏当前输入法的软键盘。 + +**需要权限:** ohos.permission.CONNECT_IME_ABILITY,仅系统应用可用。 + +**系统能力:** SystemCapability.MiscServices.InputMethodFramework + +**返回值:** + +| 类型 | 说明 | +| ------------------- | ------------------------- | +| Promise<void> | 无返回结果的Promise对象。 | + +**错误码:** + +以下错误码的详细介绍请参见[输入法框架错误码](../errorcodes/errorcode-inputmethod-framework.md)。 + +| 错误码ID | 错误信息 | +| -------- | -------------------------------------- | +| 12800003 | Input method client error. | +| 12800008 | Input method manager service error. | + +**示例:** + +```js +inputMethodController.hideSoftKeyboard().then(() => { + console.log('Succeeded in hiding softKeyboard.'); +}).catch((err) => { + console.error(`Failed to hide softKeyboard: ${JSON.stringify(err)}`); +}); +``` + +### stopInput(deprecated) + +stopInput(callback: AsyncCallback<boolean>): void + +结束输入会话。使用callback异步回调。 + +需要与编辑控件(如:输入框)绑定使用。当点击编辑控件后,才可通过调用该接口结束输入会话。 + +> **说明:** +> +> 从API version 6开始支持,从API version 9开始废弃,建议使用[stopInputSession()](#stopinputsession9)替代。 + +**系统能力:** SystemCapability.MiscServices.InputMethodFramework + +**参数:** + +| 参数名 | 类型 | 必填 | 说明 | +| -------- | -------- | -------- | -------- | +| callback | AsyncCallback<boolean> | 是 | 回调函数。当输入法隐藏成功,err为undefined,data为true;否则为错误对象。 | + +**示例:** + +```js +inputMethodController.stopInput((err, result) => { + if (err) { + console.error(`Failed to stopInput: ${JSON.stringify(err)}`); + return; + } + if (result) { + console.log('Succeeded in stopping input.'); + } else { + console.error('Failed to stopInput.'); + } +}); +``` + +### stopInput(deprecated) + +stopInput(): Promise<boolean> + +结束输入会话。使用promise异步回调。 + +需要与编辑控件(如:输入框)绑定使用。当点击编辑控件后,才可通过调用该接口结束输入会话。 + +> **说明:** +> +> 从API version 6开始支持,从API version 9开始废弃,建议使用[stopInputSession()](#stopinputsession9)替代。 + +**系统能力:** SystemCapability.MiscServices.InputMethodFramework + +**返回值:** + +| 类型 | 说明 | +| -------- | -------- | +| Promise<boolean> | Promise对象。返回true表示输入法隐藏成功;返回false表示输入法隐藏失败。 | + +**示例:** + +```js +inputMethodController.stopInput().then((result) => { + if (result) { + console.log('Succeeded in stopping input.'); + } else { + console.error('Failed to stopInput.'); + } +}).catch((err) => { + console.error(`Failed to stopInput: ${JSON.stringify(err)}`); +}) +``` + +### on('insertText')10+ + +on(type: 'insertText', callback: (text: string) => void): void; -**需要权限:** ohos.permission.CONNECT_IME_ABILITY,仅系统应用可用。 +订阅输入法应用插入文本事件。使用callback异步回调。 **系统能力:** SystemCapability.MiscServices.InputMethodFramework **参数:** -| 参数名 | 类型 | 必填 | 说明 | -| -------- | -------- | -------- | -------- | -|inputMethodProperty | [InputMethodProperty](#inputmethodproperty8)| 是 | 传入要切换的目标输入法。 | -|inputMethodSubtype | [InputMethodSubtype](./js-apis-inputmethod-subtype.md#inputmethodsubtype)| 是 | 传入要切换的目标输入法子类型。 | -| callback | AsyncCallback<boolean> | 是 | 回调函数。当输入法和子类型切换成功,err为undefined,data为获取到的切换子类型结果true;否则为错误对象。 | +| 参数名 | 类型 | 必填 | 说明 | +| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | +| type | string | 是 | 设置监听类型。
- type为‘insertText’时表示订阅输入法应用插入文本事件监听。 | +| callback | (text: string) => void | 是 | 回调函数,返回需要插入的文本内容。
开发者需要在回调函数中根据传入的文本内容操作编辑框中的内容。 | **错误码:** @@ -385,53 +1644,54 @@ switchCurrentInputMethodAndSubtype(inputMethodProperty: InputMethodProperty, inp | 错误码ID | 错误信息 | | -------- | -------------------------------------- | -| 12800005 | Configuration persisting error. | -| 12800008 | Input method manager service error. | +| 12800009 | Input method client is detached. | **示例:** ```js -let im = inputMethod.getCurrentInputMethod(); -let imSubType = inputMethod.getCurrentInputMethodSubtype(); try { - inputMethod.switchCurrentInputMethodAndSubtype(im, imSubType, (err,result) => { - if (err !== undefined) { - console.error('Failed to switchCurrentInputMethodAndSubtype: ' + JSON.stringify(err)); - return; - } - if (result) { - console.info('Succeeded in switching currentInputMethodAndSubtype.'); - } else { - console.error('Failed to switchCurrentInputMethodAndSubtype.'); - } - }); -} catch (err) { - console.error('Failed to switchCurrentInputMethodAndSubtype: ' + JSON.stringify(err)); + inputMethodController.on('insertText', (text) => { + console.log(`Succeeded in subscribing insertText: ${text}`); + }); +} catch(err) { + console.error(`Failed to subscribe insertText: ${JSON.stringify(err)}`); } ``` -## inputMethod.switchCurrentInputMethodAndSubtype9+ - -switchCurrentInputMethodAndSubtype(inputMethodProperty: InputMethodProperty, inputMethodSubtype: InputMethodSubtype): Promise<boolean> +### off('insertText')10+ -切换至指定输入法应用的指定子类型,用于跨输入法应用切换子类型。使用promise异步回调。 +off(type: 'insertText'): void -**需要权限:** ohos.permission.CONNECT_IME_ABILITY,仅系统应用可用。 +取消订阅输入法应用插入文本事件。 **系统能力:** SystemCapability.MiscServices.InputMethodFramework **参数:** -| 参数名 | 类型 | 必填 | 说明 | -| -------- | -------- | -------- | -------- | -|inputMethodProperty | [InputMethodProperty](#inputmethodproperty8)| 是 | 传入要切换的目标输入法。 | -|inputMethodSubtype | [InputMethodSubtype](./js-apis-inputmethod-subtype.md#inputmethodsubtype)| 是 | 传入要切换的目标输入法子类型。 | +| 参数名 | 类型 | 必填 | 说明 | +| ------ | ------ | ---- | ------------------------------------------------------------ | +| type | string | 是 | 设置监听类型。
- type为‘insertText’时表示取消订阅输入法应用插入文本事件监听。 | -**返回值:** +**示例:** -| 类型 | 说明 | -| ----------------------------------------- | ---------------------------- | -| Promise\ | Promise对象。返回true表示切换至指定输入法应用的指定子类型成功;返回false表示切换至指定输入法应用的指定子类型失败。 | +```js +inputMethodController.off('insertText'); +``` + +### on('deleteLeft' | 'deleteRight')10+ + +on(type: 'deleteLeft' | 'deleteRight', callback: (length: number) => void): void + +订阅输入法应用向左删除或向右删除事件。使用callback异步回调。 + +**系统能力:** SystemCapability.MiscServices.InputMethodFramework + +**参数:** + +| 参数名 | 类型 | 必填 | 说明 | +| -------- | ----- | ---- | ----- | +| type | string | 是 | 设置监听类型。
- type为‘deleteLeft’时表示订阅输入法应用向左删除事件监听。
- type为‘deleteRight’时表示订阅输入法应用向右删除事件监听。| +| callback | (length: number) => void | 是 | 回调函数,返回需要向左或向右删除的文本的长度。
开发者需要在回调函数中根据传入的删除长度操作编辑框中相应文本。 | **错误码:** @@ -439,94 +1699,63 @@ switchCurrentInputMethodAndSubtype(inputMethodProperty: InputMethodProperty, inp | 错误码ID | 错误信息 | | -------- | -------------------------------------- | -| 12800005 | Configuration persisting error. | -| 12800008 | Input method manager service error. | +| 12800009 | Input method client is detached. | **示例:** ```js -let im = inputMethod.getCurrentInputMethod(); -let imSubType = inputMethod.getCurrentInputMethodSubtype(); try { - inputMethod.switchCurrentInputMethodAndSubtype(im, imSubType).then((result) => { - if (result) { - console.info('Succeeded in switching currentInputMethodAndSubtype.'); - } else { - console.error('Failed to switchCurrentInputMethodAndSubtype.'); - } - }).catch((err) => { - console.error('Failed to switchCurrentInputMethodAndSubtype: ' + JSON.stringify(err)); - }) + inputMethodController.on('deleteLeft', (length) => { + console.log(`Succeeded in subscribing deleteLeft, length: ${length}`); + }); } catch(err) { - console.error('Failed to switchCurrentInputMethodAndSubtype: ' + JSON.stringify(err)); + console.error(`Failed to subscribe deleteLeft: ${JSON.stringify(err)}`); } -``` - -## inputMethod.getInputMethodController(deprecated) - -getInputMethodController(): InputMethodController -获取客户端实例[InputMethodController](#inputmethodcontroller)。 - -> **说明:** -> -> 从API version 6开始支持,从API version 9开始废弃, 建议使用[getController()](#inputmethodgetcontroller9)替代。 - -**系统能力:** SystemCapability.MiscServices.InputMethodFramework - -**返回值:** - -| 类型 | 说明 | -| ----------------------------------------------- | ------------------------ | -| [InputMethodController](#inputmethodcontroller) | 回调返回当前客户端实例。 | - -**示例:** - -```js -let inputMethodController = inputMethod.getInputMethodController(); +try { + inputMethodController.on('deleteRight', (length) => { + console.log(`Succeeded in subscribing deleteRight, length: ${length}`); + }); +} catch(err) { + console.error(`Failed to subscribe deleteRight: ${JSON.stringify(err)}`); +} ``` -## inputMethod.getInputMethodSetting(deprecated) - -getInputMethodSetting(): InputMethodSetting +### off('deleteLeft' | 'deleteRight')10+ -获取客户端设置实例[InputMethodSetting](#inputmethodsetting8)。 +off(type: 'deleteLeft' | 'deleteRight'): void -> **说明:** -> -> 从API version 6开始支持,从API version 9开始废弃, 建议使用[getSetting()](#inputmethodgetsetting9)替代。 +取消订阅输入法应用向左或向右删除文本事件。 **系统能力:** SystemCapability.MiscServices.InputMethodFramework -**返回值:** +**参数:** -| 类型 | 说明 | -| ----------------------------------------- | ---------------------------- | -| [InputMethodSetting](#inputmethodsetting8) | 回调返回当前客户端设置实例。 | +| 参数名 | 类型 | 必填 | 说明 | +| ------ | ------ | ---- | ------------------------------------------------------------ | +| type | string | 是 | 设置监听类型。
- type为‘deleteLeft’时表示取消订阅输入法应用向左删除的事件监听。
- type为‘deleteRight’时表示取消订阅输入法应用向右删除的事件监听。| **示例:** ```js -let inputMethodSetting = inputMethod.getInputMethodSetting(); +inputMethodController.off('deleteLeft'); +inputMethodController.off('deleteRight'); ``` -## InputMethodController - -下列API示例中都需使用[getController](#inputmethodgetcontroller9)获取到InputMethodController实例,再通过此实例调用对应方法。 - -### stopInputSession9+ +### on('sendKeyboardStatus')10+ -stopInputSession(callback: AsyncCallback<boolean>): void +on(type: 'sendKeyboardStatus', callback: (keyBoardStatus: KeyboardStatus) => void): void -结束输入会话。通过点击输入框实现输入会话的开启之后该接口的调用才可生效。使用callback异步回调。 +订阅输入法应用发送键盘状态事件。使用callback异步回调。 **系统能力:** SystemCapability.MiscServices.InputMethodFramework **参数:** -| 参数名 | 类型 | 必填 | 说明 | -| -------- | -------- | -------- | -------- | -| callback | AsyncCallback<boolean> | 是 | 回调函数。当结束输入会话成功时,err为undefined,data为true;否则为错误对象。 | +| 参数名 | 类型 | 必填 | 说明 | +| -------- | ------ | ---- | ---- | +| type | string | 是 | 设置监听类型。
- type为‘sendKeyboardStatus’时表示订阅输入法应用发送键盘状态事件监听。 | +| callback | (keyBoardStatus: [KeyboardStatus](#keyboardstatus10)) => void | 是 | 回调函数,返回键盘状态。
开发者需要在回调函数中根据传入的键盘状态做相应动作。 | **错误码:** @@ -534,85 +1763,54 @@ stopInputSession(callback: AsyncCallback<boolean>): void | 错误码ID | 错误信息 | | -------- | -------------------------------------- | -| 12800003 | Input method client error. | -| 12800008 | Input method manager service error. | +| 12800009 | Input method client is detached. | **示例:** ```js try { - inputMethodController.stopInputSession((error, result) => { - if (error !== undefined) { - console.error('Failed to stopInputSession: ' + JSON.stringify(error)); - return; - } - if (result) { - console.info('Succeeded in stopping inputSession.'); - } else { - console.error('Failed to stopInputSession.'); - } - }); -} catch(error) { - console.error('Failed to stopInputSession: ' + JSON.stringify(error)); + inputMethodController.on('sendKeyboardStatus', (keyBoardStatus) => { + console.log(`Succeeded in subscribing sendKeyboardStatus, keyBoardStatus: ${keyBoardStatus}`); + }); +} catch(err) { + console.error(`Failed to subscribe sendKeyboardStatus: ${JSON.stringify(err)}`); } ``` -### stopInputSession9+ +### off('sendKeyboardStatus')10+ -stopInputSession(): Promise<boolean> +off(type: 'sendKeyboardStatus'): void -结束输入会话。通过点击输入框实现输入会话的开启之后此接口才可生效。使用promise异步回调。 +取消订阅输入法应用发送键盘状态事件。 **系统能力:** SystemCapability.MiscServices.InputMethodFramework -**返回值:** - -| 类型 | 说明 | -| -------- | -------- | -| Promise<boolean> | Promise对象。返回true表示结束输入会话成功;返回false表示结束输入会话失败。 | - -**错误码:** - -以下错误码的详细介绍请参见[输入法框架错误码](../errorcodes/errorcode-inputmethod-framework.md)。 +**参数:** -| 错误码ID | 错误信息 | -| -------- | -------------------------------------- | -| 12800003 | Input method client error. | -| 12800008 | Input method manager service error. | +| 参数名 | 类型 | 必填 | 说明 | +| ------ | ------ | ---- | ------------------------------------------------------------ | +| type | string | 是 | 设置监听类型。
- type为‘sendKeyboardStatus’时表示取消订阅输入法应用发送键盘状态事件监听。 | **示例:** ```js -try { - inputMethodController.stopInputSession().then((result) => { - if (result) { - console.info('Succeeded in stopping inputSession.'); - } else { - console.error('Failed to stopInputSession.'); - } - }).catch((err) => { - console.error('Failed to stopInputSession: ' + JSON.stringify(err)); - }) -} catch(err) { - console.error('Failed to stopInputSession: ' + JSON.stringify(err)); -} +inputMethodController.off('sendKeyboardStatus'); ``` -### showSoftKeyboard9+ - -showSoftKeyboard(callback: AsyncCallback<void>): void +### on('sendFunctionKey')10+ -显示软键盘。需要与输入框绑定使用。当点击输入框后,才可通过该接口的调用显示出当前输入法的软键盘。使用callback异步回调。 +on(type: 'sendFunctionKey', callback: (functionKey: FunctionKey) => void): void -**需要权限:** ohos.permission.CONNECT_IME_ABILITY,仅系统应用可用。 +订阅输入法应用发送功能键事件。使用callback异步回调。 -**系统能力:** SystemCapability.MiscServices.InputMethodFramework +**系统能力:** SystemCapability.MiscServices.InputMethodFramework **参数:** -| 参数名 | 类型 | 必填 | 说明 | -| -------- | ------------------------- | ---- | ---------- | -| callback | AsyncCallback<void> | 是 | 回调函数。当软键盘显示成功。err为undefined,否则为错误对象。 | +| 参数名 | 类型 | 必填 | 说明 | +| -------- | -------- | ---- | ----- | +| type | string | 是 | 设置监听类型。
- type为‘sendFunctionKey’时表示订阅输入法应用发送功能键事件监听。 | +| callback | (functionKey: [FunctionKey](#functionkey10)) => void | 是 | 回调函数,返回输入法应用发送的功能键信息。
开发者需要根据返回的功能键做相应的操作。 | **错误码:** @@ -620,192 +1818,148 @@ showSoftKeyboard(callback: AsyncCallback<void>): void | 错误码ID | 错误信息 | | -------- | -------------------------------------- | -| 12800003 | Input method client error. | -| 12800008 | Input method manager service error. | +| 12800009 | Input method client is detached. | **示例:** ```js -inputMethodController.showSoftKeyboard((err) => { - if (err === undefined) { - console.info('Succeeded in showing softKeyboard.'); - } else { - console.error('Failed to showSoftKeyboard: ' + JSON.stringify(err)); - } -}) +try { + inputMethodController.on('sendFunctionKey', (functionKey) => { + console.log(`Succeeded in subscribing sendFunctionKey, functionKey.enterKeyType: ${functionKey.enterKeyType}`); + }); +} catch(err) { + console.error(`Failed to subscribe sendFunctionKey: ${JSON.stringify(err)}`); +} ``` -### showSoftKeyboard9+ - -showSoftKeyboard(): Promise<void> - -显示软键盘。需要与输入框绑定使用。当点击输入框后,才可通过该接口的调用显示出当前输入法的软键盘。使用Promise异步回调。 - -**需要权限:** ohos.permission.CONNECT_IME_ABILITY,仅系统应用可用。 - -**系统能力:** SystemCapability.MiscServices.InputMethodFramework +### off('sendFunctionKey')10+ -**返回值:** +off(type: 'sendFunctionKey'): void -| 类型 | 说明 | -| ------------------- | ------------------------- | -| Promise<void> | 无返回结果的Promise对象。 | +取消订阅输入法应用发送FunctionKey事件。 -**错误码:** +**系统能力:** SystemCapability.MiscServices.InputMethodFramework -以下错误码的详细介绍请参见[输入法框架错误码](../errorcodes/errorcode-inputmethod-framework.md)。 +**参数:** -| 错误码ID | 错误信息 | -| -------- | -------------------------------------- | -| 12800003 | Input method client error. | -| 12800008 | Input method manager service error. | +| 参数名 | 类型 | 必填 | 说明 | +| ------ | ------ | ---- | ------------------------------------------------------------ | +| type | string | 是 | 设置监听类型。
- type为‘sendFunctionKey’时表示取消订阅输入法应用发送FunctionKey事件监听。 | **示例:** ```js -inputMethodController.showSoftKeyboard().then(() => { - console.log('Succeeded in showing softKeyboard.'); -}).catch((err) => { - console.error('Failed to showSoftKeyboard: ' + JSON.stringify(err)); -}); +inputMethodController.off('sendFunctionKey'); ``` -### hideSoftKeyboard9+ - -hideSoftKeyboard(callback: AsyncCallback<void>): void +### on('moveCursor')10+ -隐藏软键盘。需要与输入框绑定使用。点击输入框后,才可以使用该接口的调用隐藏软键盘。使用callback异步回调。 +on(type: 'moveCursor', callback: (direction: Direction) => void): void -**需要权限:** ohos.permission.CONNECT_IME_ABILITY,仅系统应用可用。 +订阅输入法应用移动光标事件。使用callback异步回调。 -**系统能力:** SystemCapability.MiscServices.InputMethodFramework +**系统能力:** SystemCapability.MiscServices.InputMethodFramework **参数:** -| 参数名 | 类型 | 必填 | 说明 | -| -------- | ------------------------- | ---- | ---------- | -| callback | AsyncCallback<void> | 是 | 回调函数。当软键盘隐藏成功。err为undefined,否则为错误对象。 | +| 参数名 | 类型 | 必填 | 说明 | +| -------- | ------ | ---- | ------ | +| type | string | 是 | 设置监听类型。
- type为‘moveCursor’时表示订阅输入法应用移动光标事件监听。 | +| callback | callback: (direction: [Direction10+](#direction10)) => void | 是 | 回调函数,返回光标信息。
开发者需要根据返回的光标移动方向改变光标位置。 | **错误码:** 以下错误码的详细介绍请参见[输入法框架错误码](../errorcodes/errorcode-inputmethod-framework.md)。 -| 错误码ID | 错误信息 | -| -------- | -------------------------------------- | -| 12800003 | Input method client error. | -| 12800008 | Input method manager service error. | +| 错误码ID | 错误信息 | +| -------- | -------------------------------- | +| 12800009 | Input method client is detached. | **示例:** ```js -inputMethodController.hideSoftKeyboard((err) => { - if (err === undefined) { - console.info('Succeeded in hiding softKeyboard.'); - } else { - console.error('Failed to hideSoftKeyboard: ' + JSON.stringify(err)); - } -}) +try { + inputMethodController.on('moveCursor', (direction) => { + console.log(`Succeeded in subscribing moveCursor, direction: ${direction}`); + }); +} catch(err) { + console.error(`Failed to subscribe moveCursor: ${JSON.stringify(err)}`); +} ``` -### hideSoftKeyboard9+ - -hideSoftKeyboard(): Promise<void> - -隐藏软键盘。需要与输入框绑定使用。点击输入框后,才可以使用该接口的调用隐藏软键盘。使用Promise异步回调。 - -**需要权限:** ohos.permission.CONNECT_IME_ABILITY,仅系统应用可用。 - -**系统能力:** SystemCapability.MiscServices.InputMethodFramework +### off('moveCursor')10+ -**返回值:** +off(type: 'moveCursor'): void -| 类型 | 说明 | -| ------------------- | ------------------------- | -| Promise<void> | 无返回结果的Promise对象。 | +取消订阅输入法应用移动光标事件。 -**错误码:** +**系统能力:** SystemCapability.MiscServices.InputMethodFramework -以下错误码的详细介绍请参见[输入法框架错误码](../errorcodes/errorcode-inputmethod-framework.md)。 +**参数:** -| 错误码ID | 错误信息 | -| -------- | -------------------------------------- | -| 12800003 | Input method client error. | -| 12800008 | Input method manager service error. | +| 参数名 | 类型 | 必填 | 说明 | +| ------ | ------ | ---- | ---- | +| type | string | 是 | 设置监听类型。
- type为‘moveCursor’时表示取消订阅输入法应用发送移动光标事件监听。 | **示例:** ```js -inputMethodController.hideSoftKeyboard().then(() => { - console.log('Succeeded in hiding softKeyboard.'); -}).catch((err) => { - console.error('Failed to hideSoftKeyboard: ' + JSON.stringify(err)); -}); +inputMethodController.off('moveCursor'); ``` -### stopInput(deprecated) - -stopInput(callback: AsyncCallback<boolean>): void +### on('handleExtendAction')10+ -结束输入会话。通过点击输入框实现输入会话的开启之后该接口的调用才可生效。使用callback异步回调。 +on(type: 'handleExtendAction', callback: (action: ExtendAction) => void): void -> **说明:** -> -> 从API version 6开始支持,从API version 9开始废弃, 建议使用[stopInputSession()](#stopinputsession9)替代。 +订阅输入法应用发送扩展操作事件。使用callback异步回调。 **系统能力:** SystemCapability.MiscServices.InputMethodFramework **参数:** -| 参数名 | 类型 | 必填 | 说明 | -| -------- | -------- | -------- | -------- | -| callback | AsyncCallback<boolean> | 是 | 回调函数。当输入法隐藏成功,err为undefined,data为true;否则为错误对象。 | +| 参数名 | 类型 | 必填 | 说明 | +| -------- | ------ | ---- | -------- | +| type | string | 是 | 设置监听类型。
- type为‘handleExtendAction’时表示订阅输入法应用发送扩展操作代码事件监听。 | +| callback | callback: (action: [ExtendAction](#extendaction10)) => void | 是 | 回调函数,返回扩展操作类型。
开发者需要在回调函数中根据传入的扩展操作类型做相应的操作。 | + +**错误码:** + +以下错误码的详细介绍请参见[输入法框架错误码](../errorcodes/errorcode-inputmethod-framework.md)。 + +| 错误码ID | 错误信息 | +| -------- | -------------------------------------- | +| 12800009 | Input method client is detached. | **示例:** ```js -inputMethodController.stopInput((error, result) => { - if (error !== undefined) { - console.error('Failed to stopInput: ' + JSON.stringify(error)); - return; - } - if (result) { - console.info('Succeeded in stopping input.'); - } else { - console.error('Failed to stopInput.'); - } -}); +try { + inputMethodController.on('handleExtendAction', (action) => { + console.log(`Succeeded in subscribing handleExtendAction, action: ${action}`); + }); +} catch(err) { + console.error(`Failed to subscribe handleExtendAction: ${JSON.stringify(err)}`); +} ``` -### stopInput(deprecated) - -stopInput(): Promise<boolean> +### off('handleExtendAction')10+ -结束输入会话。通过点击输入框实现输入会话的开启之后该接口的调用才可生效。使用promise异步回调。 +off(type: 'handleExtendAction'): void -> **说明:** -> -> 从API version 6开始支持,从API version 9开始废弃, 建议使用[stopInputSession()](#stopinputsession9)替代。 +取消订阅输入法应用发送扩展操作事件。 **系统能力:** SystemCapability.MiscServices.InputMethodFramework -**返回值:** +**参数:** -| 类型 | 说明 | -| -------- | -------- | -| Promise<boolean> | Promise对象。返回true表示输入法隐藏成功;返回false表示输入法隐藏失败。 | +| 参数名 | 类型 | 必填 | 说明 | +| ------ | ------ | ---- | ------- | +| type | string | 是 | 设置监听类型。
- type为‘handleExtendAction’时表示取消订阅输入法应用发送扩展代码事件监听。 | **示例:** ```js -inputMethodController.stopInput().then((result) => { - if (result) { - console.info('Succeeded in stopping input.'); - } else { - console.error('Failed to stopInput.'); - } -}).catch((err) => { - console.error('Failed to stopInput: ' + err); -}) +inputMethodController.off('handleExtendAction'); ``` ### on('selectByRange')10+ @@ -818,16 +1972,16 @@ on(type: 'selectByRange', callback: Callback<Range>): void **参数:** -| 参数名 | 类型 | 必填 | 说明 | -| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | -| type | string | 是 | 设置监听类型。
-type为‘selectByRange’时表示订阅输入法应用按范围选中文本事件监听。 | -| callback | Callback<[Range](./js-apis-inputmethod-InputMethodCommon.md#range)> | 是 | 回调函数,返回需要选中的文本的范围。
开发者需要在回调函数中根据传入的范围选中编辑框中相应文本。 | +| 参数名 | 类型 | 必填 | 说明 | +| -------- | ---- | ---- | ------- | +| type | string | 是 | 设置监听类型。
- type为‘selectByRange’时表示订阅输入法应用按范围选中文本事件监听。 | +| callback | Callback<[Range](#range10)> | 是 | 回调函数,返回需要选中的文本的范围。
开发者需要在回调函数中根据传入的范围选中编辑框中相应文本。 | **示例:** ```js inputMethodController.on('selectByRange', (range) => { - console.info('Succeeded in subscribing selectByRange: start: ' + range.start + " , end: " + range.end); + console.log(`Succeeded in subscribing selectByRange: start: ${range.start} , end: ${range.end}`); }); ``` @@ -843,7 +1997,7 @@ off(type: 'selectByRange'): void | 参数名 | 类型 | 必填 | 说明 | | ------ | ------ | ---- | ------------------------------------------------------------ | -| type | string | 是 | 设置监听类型。
-type为‘selectByRange’时表示取消订阅输入法应用按范围选中文本事件监听。 | +| type | string | 是 | 设置监听类型。
- type为‘selectByRange’时表示取消订阅输入法应用按范围选中文本事件监听。 | **示例:** @@ -861,16 +2015,16 @@ on(type: 'selectByMovement', callback: Callback<Movement>): void **参数:** -| 参数名 | 类型 | 必填 | 说明 | -| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | -| type | string | 是 | 设置监听类型。
-type为‘selectByMovement’时表示订阅输入法应用按光标移动动作选中文本事件监听。 | -| callback | Callback<[Movement](./js-apis-inputmethod-InputMethodCommon.md#movement)> | 是 | 回调函数,返回需要选中的文本的范围。
开发者需要在回调函数中根据传入的光标动作选中编辑框中相应文本。 | +| 参数名 | 类型 | 必填 | 说明 | +| -------- | ----- | ---- | ------ | +| type | string | 是 | 设置监听类型。
- type为‘selectByMovement’时表示订阅输入法应用按光标移动动作选中文本事件监听。 | +| callback | Callback<[Movement](#movement10)> | 是 | 回调函数,返回需要选中的文本的范围。
开发者需要在回调函数中根据传入的光标动作选中编辑框中相应文本。 | **示例:** ```js inputMethodController.on('selectByMovement', (movement) => { - console.info('Succeeded in subscribing selectByMovement: direction: ' + movement.direction); + console.log('Succeeded in subscribing selectByMovement: direction: ' + movement.direction); }); ``` @@ -886,7 +2040,7 @@ off(type: 'selectByMovement'): void | 参数名 | 类型 | 必填 | 说明 | | ------ | ------ | ---- | ------------------------------------------------------------ | -| type | string | 是 | 设置监听类型。
-type为‘selectByMovement’时表示取消订阅输入法应用按范围选中文本事件监听。 | +| type | string | 是 | 设置监听类型。
- type为‘selectByMovement’时表示取消订阅输入法应用按范围选中文本事件监听。 | **示例:** @@ -910,14 +2064,14 @@ on(type: 'imeChange', callback: (inputMethodProperty: InputMethodProperty, input | 参数名 | 类型 | 必填 | 说明 | | -------- | ------------------------------- | ---- | ------------------------------------------------------------ | -| type | string | 是 | 设置监听类型。
-type为‘imeChange’时表示订阅输入法及子类型变化监听事件。 | +| type | string | 是 | 设置监听类型。
- type为‘imeChange’时表示订阅输入法及子类型变化监听事件。 | | callback | (inputMethodProperty: [InputMethodProperty](#inputmethodproperty8), inputMethodSubtype: [InputMethodSubtype](./js-apis-inputmethod-subtype.md#inputmethodsubtype)) => void | 是 | 回调函数,返回输入法属性对象及输入法子类型对象。 | **示例:** ```js inputMethodSetting.on('imeChange', (inputMethodProperty, inputMethodSubtype) => { - console.info('Succeeded in subscribing imeChange: inputMethodProperty: ' + JSON.stringify(inputMethodProperty) + " , inputMethodSubtype: " + JSON.stringify(inputMethodSubtype)); + console.log('Succeeded in subscribing imeChange: inputMethodProperty: ' + JSON.stringify(inputMethodProperty) + " , inputMethodSubtype: " + JSON.stringify(inputMethodSubtype)); }); ``` @@ -931,9 +2085,9 @@ off(type: 'imeChange', callback?: (inputMethodProperty: InputMethodProperty, inp **参数:** -| 参数名 | 类型 | 必填 | 说明 | -| -------- | ------------------------------- | ---- | ------------------------------------------------------------ | -| type | string | 是 | 设置监听类型。
-type为‘imeChange’时表示取消订阅输入法及子类型变化监听事件。 | +| 参数名 | 类型 | 必填 | 说明 | +| -------- | --------- | ---- | --------------- | +| type | string | 是 | 设置监听类型。
- type为‘imeChange’时表示取消订阅输入法及子类型变化监听事件。 | | callback | (inputMethodProperty: [InputMethodProperty](#inputmethodproperty8), inputMethodSubtype: [InputMethodSubtype](./js-apis-inputmethod-subtype.md#inputmethodsubtype)) => void | 否 | 回调函数,返回取消订阅的输入法属性对象及输入法子类型对象。 | **示例:** @@ -954,7 +2108,7 @@ listInputMethodSubtype(inputMethodProperty: InputMethodProperty, callback: Async | 参数名 | 类型 | 必填 | 说明 | | -------- | -------------------------------------------------- | ---- | ---------------------- | -| inputMethodProperty | InputMethodProperty| 是 | 子类型所属的输入法应用。 | +| inputMethodProperty | [InputMethodProperty](#inputmethodproperty8)| 是 | 子类型所属的输入法应用。 | | callback | AsyncCallback<Array<[InputMethodSubtype](./js-apis-inputmethod-subtype.md#inputmethodsubtype)>> | 是 | 回调函数,返回指定输入法应用的所有子类型。 | **错误码:** @@ -970,22 +2124,19 @@ listInputMethodSubtype(inputMethodProperty: InputMethodProperty, callback: Async ```js let inputMethodProperty = { - packageName: 'com.example.kikakeyboard', - methodId: 'com.example.kikakeyboard', - name: 'com.example.kikakeyboard', - id: 'com.example.kikakeyboard', - extra:{} + name: 'com.example.kikakeyboard', + id: 'propertyId', } try { - inputMethodSetting.listInputMethodSubtype(inputMethodProperty, (err,data) => { - if (err !== undefined) { - console.error('Failed to listInputMethodSubtype: ' + JSON.stringify(err)); - return; - } - console.log('Succeeded in listing inputMethodSubtype.'); - }); + inputMethodSetting.listInputMethodSubtype(inputMethodProperty, (err, data) => { + if (err) { + console.error(`Failed to listInputMethodSubtype: ${JSON.stringify(err)}`); + return; + } + console.log('Succeeded in listing inputMethodSubtype.'); + }); } catch (err) { - console.error('Failed to listInputMethodSubtype: ' + JSON.stringify(err)); + console.error(`Failed to listInputMethodSubtype: ${JSON.stringify(err)}`); } ``` @@ -1001,7 +2152,7 @@ listInputMethodSubtype(inputMethodProperty: InputMethodProperty): Promise<Arr | 参数名 | 类型 | 必填 | 说明 | | -------- | -------------------------------------------------- | ---- | ---------------------- | -| inputMethodProperty | InputMethodProperty| 是 | 子类型所属的输入法应用。 | +| inputMethodProperty | [InputMethodProperty](#inputmethodproperty8)| 是 | 子类型所属的输入法应用。 | **返回值:** @@ -1022,20 +2173,17 @@ listInputMethodSubtype(inputMethodProperty: InputMethodProperty): Promise<Arr ```js let inputMethodProperty = { - packageName: 'com.example.kikakeyboard', - methodId: 'com.example.kikakeyboard', - name: 'com.example.kikakeyboard', - id: 'com.example.kikakeyboard', - extra:{} + name: 'com.example.kikakeyboard', + id: 'propertyId', } try { - inputMethodSetting.listInputMethodSubtype(inputMethodProperty).then((data) => { - console.info('Succeeded in listing inputMethodSubtype.'); - }).catch((err) => { - console.error('Failed to listInputMethodSubtype: ' + JSON.stringify(err)); - }) + inputMethodSetting.listInputMethodSubtype(inputMethodProperty).then((data) => { + console.log('Succeeded in listing inputMethodSubtype.'); + }).catch((err) => { + console.error(`Failed to listInputMethodSubtype: ${JSON.stringify(err)}`); + }) } catch(err) { - console.error('Failed to listInputMethodSubtype: ' + JSON.stringify(err)); + console.error(`Failed to listInputMethodSubtype: ${JSON.stringify(err)}`); } ``` @@ -1066,15 +2214,15 @@ listCurrentInputMethodSubtype(callback: AsyncCallback<Array<InputMethodSub ```js try { - inputMethodSetting.listCurrentInputMethodSubtype((err, data) => { - if (err !== undefined) { - console.error('Failed to listCurrentInputMethodSubtype: ' + JSON.stringify(err)); - return; - } - console.log('Succeeded in listing currentInputMethodSubtype.'); - }); + inputMethodSetting.listCurrentInputMethodSubtype((err, data) => { + if (err) { + console.error(`Failed to listCurrentInputMethodSubtype: ${JSON.stringify(err)}`); + return; + } + console.log('Succeeded in listing currentInputMethodSubtype.'); + }); } catch(err) { - console.error('Failed to listCurrentInputMethodSubtype: ' + JSON.stringify(err)); + console.error(`Failed to listCurrentInputMethodSubtype: ${JSON.stringify(err)}`); } ``` @@ -1105,13 +2253,13 @@ listCurrentInputMethodSubtype(): Promise<Array<InputMethodSubtype>> ```js try { - inputMethodSetting.listCurrentInputMethodSubtype().then((data) => { - console.info('Succeeded in listing currentInputMethodSubtype.'); - }).catch((err) => { - console.error('Failed to listCurrentInputMethodSubtype: ' + JSON.stringify(err)); - }) + inputMethodSetting.listCurrentInputMethodSubtype().then((data) => { + console.log('Succeeded in listing currentInputMethodSubtype.'); + }).catch((err) => { + console.error(`Failed to listCurrentInputMethodSubtype: ${JSON.stringify(err)}`); + }) } catch(err) { - console.error('Failed to listCurrentInputMethodSubtype: ' + JSON.stringify(err)); + console.error(`Failed to listCurrentInputMethodSubtype: ${JSON.stringify(err)}`); } ``` @@ -1119,7 +2267,9 @@ try { getInputMethods(enable: boolean, callback: AsyncCallback<Array<InputMethodProperty>>): void -获取已激活/未激活输入法列表。参数enable取true,返回已激活输入法列表,取false返回未激活输入法列表。已激活/未激活输入法的确切功能当前版本未支持。当前版本中,已激活输入法包括当前使用的输入法,未激活输入法包括当前输入法以外的其他已安装的输入法。使用callback异步回调。 +获取已激活/未激活输入法列表。使用callback异步回调。 + +参数enable取true,返回已激活输入法列表;取false返回未激活输入法列表。已激活/未激活为预留概念,当前暂未支持。当前版本中,已激活输入法包括当前使用的输入法,未激活输入法包括当前输入法以外的其他已安装的输入法。 **系统能力:** SystemCapability.MiscServices.InputMethodFramework @@ -1143,15 +2293,15 @@ getInputMethods(enable: boolean, callback: AsyncCallback<Array<InputMethod ```js try { - inputMethodSetting.getInputMethods(true, (err,data) => { - if (err !== undefined) { - console.error('Failed to getInputMethods: ' + JSON.stringify(err)); - return; - } - console.log('Succeeded in getting inputMethods.'); - }); + inputMethodSetting.getInputMethods(true, (err, data) => { + if (err) { + console.error(`Failed to getInputMethods: ${JSON.stringify(err)}`); + return; + } + console.log('Succeeded in getting inputMethods.'); + }); } catch (err) { - console.error('Failed to getInputMethods: ' + JSON.stringify(err)); + console.error(`Failed to getInputMethods: ${JSON.stringify(err)}`); } ``` @@ -1159,7 +2309,9 @@ try { getInputMethods(enable: boolean): Promise<Array<InputMethodProperty>> -获取已激活/未激活输入法列表。参数enable取true,返回已激活输入法列表,取false返回未激活输入法列表。已激活/未激活输入法的确切功能当前版本未支持。当前版本中,已激活输入法包括当前使用的输入法,未激活输入法包括当前输入法以外的其他已安装的输入法。使用promise异步回调。 +获取已激活/未激活输入法列表。使用promise异步回调。 + +参数enable取true,返回已激活输入法列表;取false返回未激活输入法列表。已激活/未激活为预留概念,当前暂未支持。当前版本中,已激活输入法包括当前使用的输入法,未激活输入法包括当前输入法以外的其他已安装的输入法。 **系统能力:** SystemCapability.MiscServices.InputMethodFramework @@ -1188,13 +2340,13 @@ getInputMethods(enable: boolean): Promise<Array<InputMethodProperty>> ```js try { - inputMethodSetting.getInputMethods(true).then((data) => { - console.info('Succeeded in getting inputMethods.'); - }).catch((err) => { - console.error('Failed to getInputMethods: ' + JSON.stringify(err)); - }) + inputMethodSetting.getInputMethods(true).then((data) => { + console.log('Succeeded in getting inputMethods.'); + }).catch((err) => { + console.error(`Failed to getInputMethods: ${JSON.stringify(err)}`); + }) } catch(err) { - console.error('Failed to getInputMethods: ' + JSON.stringify(err)); + console.error(`Failed to getInputMethods: ${JSON.stringify(err)}`); } ``` @@ -1224,15 +2376,15 @@ showOptionalInputMethods(callback: AsyncCallback<boolean>): void ```js try { - inputMethodSetting.showOptionalInputMethods((err, data) => { - if (err !== undefined) { - console.error('Failed to showOptionalInputMethods: ' + JSON.stringify(err)); - return; - } - console.info('Succeeded in showing optionalInputMethods.'); - }); + inputMethodSetting.showOptionalInputMethods((err, data) => { + if (err) { + console.error(`Failed to showOptionalInputMethods: ${JSON.stringify(err)}`); + return; + } + console.log('Succeeded in showing optionalInputMethods.'); + }); } catch (err) { - console.error('Failed to showOptionalInputMethods: ' + JSON.stringify(err)); + console.error(`Failed to showOptionalInputMethods: ${JSON.stringify(err)}`); } ``` @@ -1262,9 +2414,9 @@ showOptionalInputMethods(): Promise<boolean> ```js inputMethodSetting.showOptionalInputMethods().then((data) => { - console.info('Succeeded in showing optionalInputMethods.'); + console.log('Succeeded in showing optionalInputMethods.'); }).catch((err) => { - console.error('Failed to showOptionalInputMethods: ' + JSON.stringify(err)); + console.error(`Failed to showOptionalInputMethods: ${JSON.stringify(err)}`); }) ``` @@ -1276,7 +2428,7 @@ listInputMethod(callback: AsyncCallback<Array<InputMethodProperty>>) > **说明:** > -> 从API version 8开始支持,从API version 9开始废弃, 建议使用[getInputMethods](#getinputmethods9)替代。 +> 从API version 8开始支持,从API version 9开始废弃,建议使用[getInputMethods](#getinputmethods9)替代。 **系统能力:** SystemCapability.MiscServices.InputMethodFramework @@ -1289,12 +2441,12 @@ listInputMethod(callback: AsyncCallback<Array<InputMethodProperty>>) **示例:** ```js -inputMethodSetting.listInputMethod((err,data) => { - if (err !== undefined) { - console.error('Failed to listInputMethod: ' + JSON.stringify(err)); - return; - } - console.log('Succeeded in listing inputMethod.'); +inputMethodSetting.listInputMethod((err, data) => { + if (err) { + console.error(`Failed to listInputMethod: ${JSON.stringify(err)}`); + return; + } + console.log('Succeeded in listing inputMethod.'); }); ``` @@ -1306,7 +2458,7 @@ listInputMethod(): Promise<Array<InputMethodProperty>> > **说明:** > -> 从API version 8开始支持,从API version 9开始废弃, 建议使用[getInputMethods](#getinputmethods9-1)替代。 +> 从API version 8开始支持,从API version 9开始废弃,建议使用[getInputMethods](#getinputmethods9-1)替代。 **系统能力:** SystemCapability.MiscServices.InputMethodFramework @@ -1320,9 +2472,9 @@ listInputMethod(): Promise<Array<InputMethodProperty>> ```js inputMethodSetting.listInputMethod().then((data) => { - console.info('Succeeded in listing inputMethod.'); + console.log('Succeeded in listing inputMethod.'); }).catch((err) => { - console.error('Failed to listInputMethod: ' + JSON.stringify(err)); + console.error(`Failed to listInputMethod: ${JSON.stringify(err)}`); }) ``` @@ -1334,7 +2486,7 @@ displayOptionalInputMethod(callback: AsyncCallback<void>): void > **说明:** > -> 从API version 8开始支持,从API version 9开始废弃, 建议使用[showOptionalInputMethods()](#showoptionalinputmethods9)替代。 +> 从API version 8开始支持,从API version 9开始废弃,建议使用[showOptionalInputMethods()](#showoptionalinputmethods9)替代。 **系统能力:** SystemCapability.MiscServices.InputMethodFramework @@ -1348,11 +2500,11 @@ displayOptionalInputMethod(callback: AsyncCallback<void>): void ```js inputMethodSetting.displayOptionalInputMethod((err) => { - if (err !== undefined) { - console.error('Failed to displayOptionalInputMethod: ' + JSON.stringify(err)); - return; - } - console.info('Succeeded in displaying optionalInputMethod.'); + if (err) { + console.error(`Failed to displayOptionalInputMethod: ${JSON.stringify(err)}`); + return; + } + console.log('Succeeded in displaying optionalInputMethod.'); }); ``` @@ -1364,7 +2516,7 @@ displayOptionalInputMethod(): Promise<void> > **说明:** > -> 从API version 8开始支持,从API version 9开始废弃, 建议使用[showOptionalInputMethods()](#showoptionalinputmethods9-1)替代。 +> 从API version 8开始支持,从API version 9开始废弃,建议使用[showOptionalInputMethods()](#showoptionalinputmethods9-1)替代。 **系统能力:** SystemCapability.MiscServices.InputMethodFramework @@ -1378,8 +2530,8 @@ displayOptionalInputMethod(): Promise<void> ```js inputMethodSetting.displayOptionalInputMethod().then(() => { - console.info('Succeeded in displaying optionalInputMethod.'); + console.log('Succeeded in displaying optionalInputMethod.'); }).catch((err) => { - console.error('Failed to displayOptionalInputMethod: ' + JSON.stringify(err)); + console.error(`Failed to displayOptionalInputMethod: ${JSON.stringify(err)}`); }) ``` diff --git a/zh-cn/application-dev/reference/apis/js-apis-inputmethodengine.md b/zh-cn/application-dev/reference/apis/js-apis-inputmethodengine.md index a57312c378648d09c9928f1431ccd4d6fdc29324..fb2f36800068a663d2625e9bcffeb2ff627998f4 100644 --- a/zh-cn/application-dev/reference/apis/js-apis-inputmethodengine.md +++ b/zh-cn/application-dev/reference/apis/js-apis-inputmethodengine.md @@ -56,7 +56,9 @@ import inputMethodEngine from '@ohos.inputMethodEngine'; getInputMethodAbility(): InputMethodAbility -为输入法应用获取输入法应用客户端实例[InputMethodAbility](#inputmethodability)。输入法应用获取该实例可订阅软键盘显示/隐藏请求事件、创建/销毁输入法应用面板等。 +为输入法应用获取输入法应用客户端实例[InputMethodAbility](#inputmethodability)。 +该接口仅限于输入法应用调用。 +输入法应用获取该实例可订阅软键盘显示/隐藏请求事件、创建/销毁输入法应用面板等。 **系统能力:** SystemCapability.MiscServices.InputMethodFramework @@ -100,7 +102,7 @@ getInputMethodEngine(): InputMethodEngine > **说明:** > -> 从API version 8开始支持,API version 9开始废弃, 建议使用[getInputMethodAbility()](#inputmethodenginegetinputmethodability9)替代。 +> 从API version 8开始支持,API version 9开始废弃,建议使用[getInputMethodAbility()](#inputmethodenginegetinputmethodability9)替代。 **系统能力:** SystemCapability.MiscServices.InputMethodFramework @@ -124,7 +126,7 @@ createKeyboardDelegate(): KeyboardDelegate > **说明:** > ->从API version 8开始支持,API version 9开始废弃, 建议使用[getKeyboardDelegate()](#inputmethodenginegetkeyboarddelegate9)替代。 +>从API version 8开始支持,API version 9开始废弃,建议使用[getKeyboardDelegate()](#inputmethodenginegetkeyboarddelegate9)替代。 **系统能力:** SystemCapability.MiscServices.InputMethodFramework @@ -163,8 +165,8 @@ on(type: 'inputStart', callback: (kbController: KeyboardController, textInputCli ```js inputMethodEngine.getInputMethodEngine().on('inputStart', (kbController, textClient) => { - let keyboardController = kbController; - let textInputClient = textClient; + let keyboardController = kbController; + let textInputClient = textClient; }); ``` @@ -187,7 +189,7 @@ off(type: 'inputStart', callback?: (kbController: KeyboardController, textInputC ```js inputMethodEngine.getInputMethodEngine().off('inputStart', (kbController, textInputClient) => { - console.log('delete inputStart notification.'); + console.log('delete inputStart notification.'); }); ``` @@ -210,10 +212,10 @@ on(type: 'keyboardShow'|'keyboardHide', callback: () => void): void ```js inputMethodEngine.getInputMethodEngine().on('keyboardShow', () => { - console.log('inputMethodEngine keyboardShow.'); + console.log('inputMethodEngine keyboardShow.'); }); inputMethodEngine.getInputMethodEngine().on('keyboardHide', () => { - console.log('inputMethodEngine keyboardHide.'); + console.log('inputMethodEngine keyboardHide.'); }); ``` @@ -262,8 +264,8 @@ on(type: 'inputStart', callback: (kbController: KeyboardController, inputClient: ```js inputMethodEngine.getInputMethodAbility().on('inputStart', (kbController, client) => { - let keyboardController = kbController; - let inputClient = client; + let keyboardController = kbController; + let inputClient = client; }); ``` @@ -307,7 +309,7 @@ on(type: 'inputStop', callback: () => void): void ```js inputMethodEngine.getInputMethodAbility().on('inputStop', () => { - console.log('inputMethodAbility inputStop'); + console.log('inputMethodAbility inputStop'); }); ``` @@ -330,7 +332,7 @@ off(type: 'inputStop', callback: () => void): void ```js inputMethodEngine.getInputMethodAbility().off('inputStop', () => { - console.log('inputMethodAbility delete inputStop notification.'); + console.log('inputMethodAbility delete inputStop notification.'); }); ``` @@ -353,7 +355,7 @@ on(type: 'setCallingWindow', callback: (wid: number) => void): void ```js inputMethodEngine.getInputMethodAbility().on('setCallingWindow', (wid) => { - console.log('inputMethodAbility setCallingWindow'); + console.log('inputMethodAbility setCallingWindow'); }); ``` @@ -376,7 +378,7 @@ off(type: 'setCallingWindow', callback: (wid:number) => void): void ```js inputMethodEngine.getInputMethodAbility().off('setCallingWindow', () => { - console.log('inputMethodAbility delete setCallingWindow notification.'); + console.log('inputMethodAbility delete setCallingWindow notification.'); }); ``` @@ -399,10 +401,10 @@ on(type: 'keyboardShow'|'keyboardHide', callback: () => void): void ```js inputMethodEngine.getInputMethodAbility().on('keyboardShow', () => { - console.log('InputMethodAbility keyboardShow.'); + console.log('InputMethodAbility keyboardShow.'); }); inputMethodEngine.getInputMethodAbility().on('keyboardHide', () => { - console.log('InputMethodAbility keyboardHide.'); + console.log('InputMethodAbility keyboardHide.'); }); ``` @@ -425,10 +427,10 @@ off(type: 'keyboardShow'|'keyboardHide', callback?: () => void): void ```js inputMethodEngine.getInputMethodAbility().off('keyboardShow', () => { - console.log('InputMethodAbility delete keyboardShow notification.'); + console.log('InputMethodAbility delete keyboardShow notification.'); }); inputMethodEngine.getInputMethodAbility().off('keyboardHide', () => { - console.log('InputMethodAbility delete keyboardHide notification.'); + console.log('InputMethodAbility delete keyboardHide notification.'); }); ``` @@ -442,16 +444,16 @@ on(type: 'setSubtype', callback: (inputMethodSubtype: InputMethodSubtype) => voi **参数:** -| 参数名 | 类型 | 必填 | 说明 | -| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | -| type | string | 是 | 设置监听类型。
- type为'setSubtype',表示订阅输入法子类型的设置事件。 | +| 参数名 | 类型 | 必填 | 说明 | +| -------- | --- | ---- | --- | +| type | string | 是 | 设置监听类型。
- type为'setSubtype',表示订阅输入法子类型的设置事件。 | | callback | (inputMethodSubtype: [InputMethodSubtype](js-apis-inputmethod-subtype.md)) => void | 是 | 回调函数,返回设置的输入法子类型。 | **示例:** ```js inputMethodEngine.getInputMethodAbility().on('setSubtype', (inputMethodSubtype) => { - console.log('InputMethodAbility setSubtype.'); + console.log('InputMethodAbility setSubtype.'); }); ``` @@ -465,16 +467,16 @@ off(type: 'setSubtype', callback?: (inputMethodSubtype: InputMethodSubtype) => v **参数:** -| 参数名 | 类型 | 必填 | 说明 | -| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | -| type | string | 是 | 设置监听类型。
- type为'setSubtype',表示取消订阅输入法子类型的设置事件。 | +| 参数名 | 类型 | 必填 | 说明 | +| ------- | ----- | ---- | ---- | +| type | string | 是 | 设置监听类型。
- type为'setSubtype',表示取消订阅输入法子类型的设置事件。 | | callback | (inputMethodSubtype: [InputMethodSubtype](js-apis-inputmethod-subtype.md)) => void | 否 | 回调函数,返回设置的输入法子类型。 | **示例:** ```js inputMethodEngine.getInputMethodAbility().off('setSubtype', () => { - console.log('InputMethodAbility delete setSubtype notification.'); + console.log('InputMethodAbility delete setSubtype notification.'); }); ``` @@ -482,7 +484,9 @@ inputMethodEngine.getInputMethodAbility().off('setSubtype', () => { createPanel(ctx: BaseContext, info: PanelInfo, callback: AsyncCallback\): void -创建输入法应用面板。仅支持输入法应用或者具有system_core权限的系统应用调用。单个输入法应用仅仅允许创建一个SOFT_KEYBOARD及一个STATUS_BAR类型的面板。使用callback异步回调。 +创建输入法应用面板。使用callback异步回调。 + +仅支持输入法应用调用。单个输入法应用仅仅允许创建一个SOFT_KEYBOARD及一个STATUS_BAR类型的面板。 **系统能力:** SystemCapability.MiscServices.InputMethodFramework @@ -504,19 +508,19 @@ createPanel(ctx: BaseContext, info: PanelInfo, callback: AsyncCallback\): ```js let panelInfo: inputMethodEngine.PanelInfo = { - panelType: SOFT_KEYBOARD, - panelFlag: FLG_FIXED + panelType: inputMethodEngine.PanelType.SOFT_KEYBOARD, + panelFlag: inputMethodEngine.PanelFlag.FLG_FIXED } try { inputMethodEngine.getInputMethodAbility().createPanel(this.context, panelInfo, (err, panel) => { - if (err !== undefined) { - console.log('Failed to create panel, err: ' + JSON.stringify(err)); + if (err) { + console.error(`Failed to createPanel: ${JSON.stringify(err)}`); return; } console.log('Succeed in creating panel.'); }) } catch(err) { - console.log('Failed to create panel, err: ' + JSON.stringify(err)); + console.error(`Failed to createPanel: ${JSON.stringify(err)}`); } ``` @@ -524,7 +528,9 @@ try { createPanel(ctx: BaseContext, info: PanelInfo): Promise\ -创建输入法应用面板。仅支持输入法应用或者具有system_core权限的系统应用调用。单个输入法应用仅仅允许创建一个SOFT_KEYBOARD及一个STATUS_BAR类型的面板。使用promise异步回调。 +创建输入法应用面板。使用promise异步回调。 + +仅支持输入法应用调用。单个输入法应用仅仅允许创建一个SOFT_KEYBOARD及一个STATUS_BAR类型的面板。 **系统能力:** SystemCapability.MiscServices.InputMethodFramework @@ -550,13 +556,13 @@ createPanel(ctx: BaseContext, info: PanelInfo): Promise\ ```js let panelInfo: inputMethodEngine.PanelInfo = { - panelType: SOFT_KEYBOARD, - panelFlag: FLG_FIXED + panelType: inputMethodEngine.PanelType.SOFT_KEYBOARD, + panelFlag: inputMethodEngine.PanelFlag.FLG_FIXED } inputMethodEngine.getInputMethodAbility().createPanel(this.context, panelInfo).then((panel) => { console.log('Succeed in creating panel.'); }).catch((err) => { - console.log('Failed to create panel, err: ' + JSON.stringify(err)); + console.error(`Failed to create panel: ${JSON.stringify(err)}`); }) ``` @@ -579,32 +585,32 @@ destroyPanel(panel: Panel, callback: AsyncCallback\): void; ```js let panelInfo: inputMethodEngine.PanelInfo = { - panelType: SOFT_KEYBOARD, - panelFlag: FLG_FIXED + panelType: inputMethodEngine.PanelType.SOFT_KEYBOARD, + panelFlag: inputMethodEngine.PanelFlag.FLG_FIXED } try { inputMethodEngine.getInputMethodAbility().createPanel(this.context, panelInfo, (err, panel) => { - if (err !== undefined) { - console.log('Failed to create panel, err: ' + JSON.stringify(err)); + if (err) { + console.error(`Failed to create panel: ${JSON.stringify(err)}`); return; } globalThis.inputMethodPanel = panel; console.log('Succeed in creating panel.'); }) } catch(err) { - console.log('Failed to create panel, err: ' + JSON.stringify(err)); + console.error(`Failed to create panel: ${JSON.stringify(err)}`); } try { inputMethodEngine.getInputMethodAbility().destroyPanel(globalThis.inputMethodPanel, (err) => { if(err !== undefined) { - console.log('Failed to destroy panel, err: ' + JSON.stringify(err)); + console.error(`Failed to destroy panel: ${JSON.stringify(err)}`); return; } console.log('Succeed in destroying panel.'); }) } catch(err) { - console.log('Failed to destroy panel, err: ' + JSON.stringify(err)); + console.error(`Failed to destroy panel: ${JSON.stringify(err)}`); } ``` @@ -631,30 +637,30 @@ destroyPanel(panel: Panel): Promise\; ```js let panelInfo: inputMethodEngine.PanelInfo = { - panelType: SOFT_KEYBOARD, - panelFlag: FLG_FIXED + panelType: inputMethodEngine.PanelType.SOFT_KEYBOARD, + panelFlag: inputMethodEngine.PanelFlag.FLG_FIXED } try { inputMethodEngine.getInputMethodAbility().createPanel(this.context, panelInfo, (err, panel) => { - if (err !== undefined) { - console.log('Failed to create panel, err: ' + JSON.stringify(err)); + if (err) { + console.error(`Failed to create panel: ${JSON.stringify(err)}`); return; } globalThis.inputMethodPanel = panel; console.log('Succeed in creating panel.'); }) } catch(err) { - console.log('Failed to create panel, err: ' + JSON.stringify(err)); + console.error(`Failed to create panel: ${JSON.stringify(err)}`); } try { inputMethodEngine.getInputMethodAbility().destroyPanel(globalThis.inputMethodPanel).then(() => { console.log('Succeed in destroying panel.'); }).catch((err) => { - console.log('Failed to destroy panel, err: ' + JSON.stringify(err)); + console.error(`Failed to destroy panel: ${JSON.stringify(err)}`); }); } catch (err) { - console.log('Failed to destroy panel, err: ' + JSON.stringify(err)); + console.error(`Failed to destroy panel: ${JSON.stringify(err)}`); } ``` @@ -681,14 +687,14 @@ on(type: 'keyDown'|'keyUp', callback: (event: KeyEvent) => boolean): void ```js inputMethodEngine.getKeyboardDelegate().on('keyUp', (keyEvent) => { - console.info('inputMethodEngine keyCode.(keyUp):' + JSON.stringify(keyEvent.keyCode)); - console.info('inputMethodEngine keyAction.(keyUp):' + JSON.stringify(keyEvent.keyAction)); - return true; + console.log('inputMethodEngine keyCode.(keyUp):' + JSON.stringify(keyEvent.keyCode)); + console.log('inputMethodEngine keyAction.(keyUp):' + JSON.stringify(keyEvent.keyAction)); + return true; }); inputMethodEngine.getKeyboardDelegate().on('keyDown', (keyEvent) => { - console.info('inputMethodEngine keyCode.(keyDown):' + JSON.stringify(keyEvent.keyCode)); - console.info('inputMethodEngine keyAction.(keyDown):' + JSON.stringify(keyEvent.keyAction)); - return true; + console.log('inputMethodEngine keyCode.(keyDown):' + JSON.stringify(keyEvent.keyCode)); + console.log('inputMethodEngine keyAction.(keyDown):' + JSON.stringify(keyEvent.keyAction)); + return true; }); ``` @@ -702,21 +708,21 @@ off(type: 'keyDown'|'keyUp', callback?: (event: KeyEvent) => boolean): void **参数:** -| 参数名 | 类型 | 必填 | 说明 | -| -------- | ----------------------------------------- | ---- | ------------------------------------------------------------ | -| type | string | 是 | 设置监听类型。
- type为'keyDown',表示取消订阅硬键盘按下事件。
- type为'keyUp',表示取消订阅硬键盘抬起事件。 | +| 参数名 | 类型 | 必填 | 说明 | +| -------- | ------- | ---- | ----- | +| type | string | 是 | 设置监听类型。
- type为'keyDown',表示取消订阅硬键盘按下事件。
- type为'keyUp',表示取消订阅硬键盘抬起事件。 | | callback | (event: [KeyEvent](#keyevent)) => boolean | 否 | 回调函数,返回按键信息。 | **示例:** ```js inputMethodEngine.getKeyboardDelegate().off('keyUp', (keyEvent) => { - console.log('delete keyUp notification.'); - return true; + console.log('delete keyUp notification.'); + return true; }); inputMethodEngine.getKeyboardDelegate().off('keyDown', (keyEvent) => { - console.log('delete keyDown notification.'); - return true; + console.log('delete keyDown notification.'); + return true; }); ``` @@ -730,18 +736,18 @@ on(type: 'cursorContextChange', callback: (x: number, y:number, height:number) = **参数:** -| 参数名 | 类型 | 必填 | 说明 | -| -------- | ---------------------------------------------- | ---- | ------------------------------------------------------------ | -| type | string | 是 | 光标变化事件。
- type为’cursorContextChange‘时,表示订阅光标变化事件。 | +| 参数名 | 类型 | 必填 | 说明 | +| -------- | ---- | ---- | ----- | +| type | string | 是 | 光标变化事件。
- type为’cursorContextChange‘时,表示订阅光标变化事件。 | | callback | (x: number, y: number, height: number) => void | 是 | 回调函数,返回光标信息。
- x为光标上端的的x坐标值。
- y为光标上端的y坐标值。
- height为光标的高度值。 | **示例:** ```js inputMethodEngine.getKeyboardDelegate().on('cursorContextChange', (x, y, height) => { - console.log('inputMethodEngine cursorContextChange x:' + x); - console.log('inputMethodEngine cursorContextChange y:' + y); - console.log('inputMethodEngine cursorContextChange height:' + height); + console.log('inputMethodEngine cursorContextChange x:' + x); + console.log('inputMethodEngine cursorContextChange y:' + y); + console.log('inputMethodEngine cursorContextChange height:' + height); }); ``` @@ -755,9 +761,9 @@ off(type: 'cursorContextChange', callback?: (x: number, y: number, height: numbe **参数:** -| 参数名 | 类型 | 必填 | 说明 | -| -------- | -------------------------------------------- | ---- | ------------------------------------------------------------ | -| type | string | 是 | 光标变化事件。
- type为’cursorContextChange‘时,表示光标变化。 | +| 参数名 | 类型 | 必填 | 说明 | +| -------- | ---- | ---- | ------ | +| type | string | 是 | 光标变化事件。
- type为’cursorContextChange‘时,表示光标变化。 | | callback | (x: number, y:number, height:number) => void | 否 | 回调函数,返回光标信息。
- x为光标上端的的x坐标值。
- y为光标上端的y坐标值。
- height为光标的高度值。
| @@ -765,7 +771,7 @@ off(type: 'cursorContextChange', callback?: (x: number, y: number, height: numbe ```js inputMethodEngine.getKeyboardDelegate().off('cursorContextChange', (x, y, height) => { - console.log('delete cursorContextChange notification.'); + console.log('delete cursorContextChange notification.'); }); ``` ### on('selectionChange') @@ -778,19 +784,19 @@ on(type: 'selectionChange', callback: (oldBegin: number, oldEnd: number, newBegi **参数:** -| 参数名 | 类型 | 必填 | 说明 | -| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | -| type | string | 是 | 文本选择变化事件。
- type为’selectionChange‘时,表示选择文本变化。 | +| 参数名 | 类型 | 必填 | 说明 | +| -------- | ----- | ---- | ---- | +| type | string | 是 | 文本选择变化事件。
- type为’selectionChange‘时,表示选择文本变化。 | | callback | (oldBegin: number, oldEnd: number, newBegin: number, newEnd: number) => void | 是 | 回调函数,返回文本选择信息。
- oldBegin为变化之前被选中文本的起始下标。
- oldEnd为变化之前被选中文本的终止下标。
- newBegin为变化之后被选中文本的起始下标。
- newEnd为变化之后被选中文本的终止下标。 | **示例:** ```js inputMethodEngine.getKeyboardDelegate().on('selectionChange', (oldBegin, oldEnd, newBegin, newEnd) => { - console.log('inputMethodEngine beforeEach selectionChange oldBegin:' + oldBegin); - console.log('inputMethodEngine beforeEach selectionChange oldEnd:' + oldEnd); - console.log('inputMethodEngine beforeEach selectionChange newBegin:' + newBegin); - console.log('inputMethodEngine beforeEach selectionChange newEnd:' + newEnd); + console.log('inputMethodEngine beforeEach selectionChange oldBegin:' + oldBegin); + console.log('inputMethodEngine beforeEach selectionChange oldEnd:' + oldEnd); + console.log('inputMethodEngine beforeEach selectionChange newBegin:' + newBegin); + console.log('inputMethodEngine beforeEach selectionChange newEnd:' + newEnd); }); ``` @@ -804,9 +810,9 @@ off(type: 'selectionChange', callback?: (oldBegin: number, oldEnd: number, newBe **参数:** -| 参数名 | 类型 | 必填 | 说明 | -| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | -| type | string | 是 | 文本选择变化事件。
- type为’selectionChange‘时,表示选择文本变化。 | +| 参数名 | 类型 | 必填 | 说明 | +| -------- | ------- | ---- | ------- | +| type | string | 是 | 文本选择变化事件。
- type为’selectionChange‘时,表示选择文本变化。 | | callback | (oldBegin: number, oldEnd: number, newBegin: number, newEnd: number) => void | 否 | 回调函数,返回文本选择信息。
- oldBegin为变化之前被选中文本的起始下标。
- oldEnd为变化之前被选中文本的终止下标。
- newBegin为变化之后被选中文本的起始下标。
- newEnd为变化之后被选中文本的终止下标。
| **示例:** @@ -831,13 +837,13 @@ on(type: 'textChange', callback: (text: string) => void): void | 参数名 | 类型 | 必填 | 说明 | | -------- | ------ | ---- | ------------------------------------------------------------ | | type | string | 是 | 文本变化事件。
- type为’textChange‘时,表示订阅文本变化事件。 | -| callback | (text: string) => void | 是 | 回调函数,返回订阅的文本内容。 | +| callback | (text: string) => void | 是 | 回调函数,返回订阅的文本内容。| **示例:** ```js inputMethodEngine.getKeyboardDelegate().on('textChange', (text) => { - console.log('inputMethodEngine textChange. text:' + text); + console.log('inputMethodEngine textChange. text:' + text); }); ``` @@ -860,7 +866,7 @@ off(type: 'textChange', callback?: (text: string) => void): void ```js inputMethodEngine.getKeyboardDelegate().off('textChange', (text) => { - console.log('delete textChange notification. text:' + text); + console.log('delete textChange notification. text:' + text); }); ``` @@ -889,13 +895,13 @@ setUiContent(path: string, callback: AsyncCallback\): void try { panel.setUiContent('pages/page2/page2', (err) => { if (err) { - console.error('Failed to set the content. err:' + JSON.stringify(err)); + console.error(`Failed to setUiContent: ${JSON.stringify(err)}`); return; } - console.info('Succeeded in setting the content.'); + console.log('Succeeded in setting the content.'); }); -} catch (exception) { - console.error('Failed to set the content. err:' + JSON.stringify(exception)); +} catch (err) { + console.error(`Failed to setUiContent: ${JSON.stringify(err)}`); } ``` @@ -925,12 +931,12 @@ setUiContent(path: string): Promise\ try { let promise = panel.setUiContent('pages/page2/page2'); promise.then(() => { - console.info('Succeeded in setting the content.'); + console.log('Succeeded in setting the content.'); }).catch((err) =>{ - console.error('Failed to set the content. err: ' + JSON.stringify(err)); + console.error(`Failed to setUiContent: ${JSON.stringify(err)}`); }); -} catch (exception) { - console.error('Failed to set the content. err: ' + JSON.stringify(exception)); +} catch (err) { + console.error(`Failed to setUiContent: ${JSON.stringify(err)}`); } ``` @@ -958,13 +964,13 @@ storage.setOrCreate('storageSimpleProp',121); try { panel.setUiContent('pages/page2/page2', storage, (err) => { if (err) { - console.error('Failed to set the content. err:' + JSON.stringify(err)); + console.error(`Failed to setUiContent: ${JSON.stringify(err)}`); return; } - console.info('Succeeded in setting the content.'); + console.log('Succeeded in setting the content.'); }); -} catch (exception) { - console.error('Failed to set the content. err:' + JSON.stringify(exception)); +} catch (err) { + console.error(`Failed to setUiContent: ${JSON.stringify(err)}`); } ``` @@ -997,12 +1003,12 @@ storage.setOrCreate('storageSimpleProp',121); try { let promise = panel.setUiContent('pages/page2/page2'); promise.then(() => { - console.info('Succeeded in setting the content.'); + console.log('Succeeded in setting the content.'); }).catch((err) =>{ - console.error('Failed to set the content. err: ' + JSON.stringify(err)); + console.error(`Failed to setUiContent: ${JSON.stringify(err)}`); }); -} catch (exception) { - console.error('Failed to set the content. err: ' + JSON.stringify(exception)); +} catch (err) { + console.error(`Failed to setUiContent: ${JSON.stringify(err)}`); } ``` @@ -1011,6 +1017,7 @@ try { resize(width: number, height: number, callback: AsyncCallback\): void 改变当前面板大小,使用callback异步回调。 + 面板存在大小限制,面板宽度不超出屏幕宽度,面板高度不高于屏幕高度的二分之一。 **系统能力:** SystemCapability.MiscServices.InputMethodFramework @@ -1029,13 +1036,13 @@ resize(width: number, height: number, callback: AsyncCallback\): void try { panel.resize(500, 1000, (err) => { if (err) { - console.error('Failed to change the panel size. Cause:' + JSON.stringify(err)); + console.error(`Failed to resize panel: ${JSON.stringify(err)}`); return; } - console.info('Succeeded in changing the panel size.'); + console.log('Succeeded in changing the panel size.'); }); -} catch (exception) { - console.error('Failed to change the panel size. Cause:' + JSON.stringify(exception)); +} catch (err) { + console.error(`Failed to resize panel: ${JSON.stringify(err)}`); } ``` @@ -1044,6 +1051,7 @@ try { resize(width: number, height: number): Promise\; 改变当前面板大小,使用Promise异步回调。 + 面板存在大小限制,面板宽度不超出屏幕宽度,面板高度不高于屏幕高度的二分之一。 **系统能力:** SystemCapability.MiscServices.InputMethodFramework @@ -1067,12 +1075,12 @@ resize(width: number, height: number): Promise\; try { let promise = panel.resize(500, 1000); promise.then(() => { - console.info('Succeeded in changing the panel size.'); + console.log('Succeeded in changing the panel size.'); }).catch((err) =>{ - console.error('Failed to change the panel size. err: ' + JSON.stringify(err)); + console.error(`Failed to resize panel: ${JSON.stringify(err)}`); }); -} catch (exception) { - console.error('Failed to change the panel size. err: ' + JSON.stringify(exception)); +} catch (err) { + console.error(`Failed to resize panel: ${JSON.stringify(err)}`); } ``` @@ -1081,6 +1089,7 @@ try { moveTo(x: number, y: number, callback: AsyncCallback\): void 移动面板位置,使用callback异步回调。 + 对FLG_FIXED状态的panel不产生实际移动效果。 **系统能力:** SystemCapability.MiscServices.InputMethodFramework @@ -1099,13 +1108,13 @@ moveTo(x: number, y: number, callback: AsyncCallback\): void try { panel.moveTo(300, 300, (err) =>{ if (err) { - console.error('Failed to move the panel. err:' + JSON.stringify(err)); + console.error(`Failed to move panel: ${JSON.stringify(err)}`); return; } - console.info('Succeeded in moving the panel.'); + console.log('Succeeded in moving the panel.'); }); -} catch (exception) { - console.error('Failed to move the panel. err:' + JSON.stringify(exception)); +} catch (err) { + console.error(`Failed to move panel: ${JSON.stringify(err)}`); } ``` @@ -1114,6 +1123,7 @@ try { moveTo(x: number, y: number): Promise\ 移动面板位置,使用callback异步回调。 + 对FLG_FIXED状态的panel不产生实际移动效果。 **系统能力:** SystemCapability.MiscServices.InputMethodFramework @@ -1137,12 +1147,12 @@ moveTo(x: number, y: number): Promise\ try { let promise = windowClass.moveTo(300, 300); promise.then(() => { - console.info('Succeeded in moving the panel.'); + console.log('Succeeded in moving the panel.'); }).catch((err) =>{ - console.error('Failed to move the panel. Cause: ' + JSON.stringify(err)); + console.error(`Failed to move panel: ${JSON.stringify(err)}`); }); -} catch (exception) { - console.error('Failed to move the panel. Cause:' + JSON.stringify(exception)); +} catch (err) { + console.error(`Failed to move panel: ${JSON.stringify(err)}`); } ``` @@ -1165,10 +1175,10 @@ show(callback: AsyncCallback\): void ```js panel.show((err) => { if (err) { - console.error('Failed to show the panel. Cause: ' + JSON.stringify(err)); + console.error(`Failed to show panel: ${JSON.stringify(err)}`); return; } - console.info('Succeeded in showing the panel.'); + console.log('Succeeded in showing the panel.'); }); ``` @@ -1191,9 +1201,9 @@ show(): Promise\ ```js let promise = panel.show(); promise.then(() => { - console.info('Succeeded in showing the panel.'); + console.log('Succeeded in showing the panel.'); }).catch((err) =>{ - console.error('Failed to show the panel. err: ' + JSON.stringify(err)); + console.error(`Failed to show panel: ${JSON.stringify(err)}`); }); ``` @@ -1216,10 +1226,10 @@ hide(callback: AsyncCallback\): void ```js panel.hide((err) => { if (err) { - console.error('Failed to hide the panel. Cause: ' + JSON.stringify(err)); + console.error(`Failed to hide panel: ${JSON.stringify(err)}`); return; } - console.info('Succeeded in hiding the panel.'); + console.log('Succeeded in hiding the panel.'); }); ``` @@ -1242,9 +1252,9 @@ hide(): Promise\ ```js let promise = panel.hide(); promise.then(() => { - console.info('Succeeded in hiding the panel.'); + console.log('Succeeded in hiding the panel.'); }).catch((err) =>{ - console.error('Failed to hide the panel. err: ' + JSON.stringify(err)); + console.error(`Failed to hide panel: ${JSON.stringify(err)}`); }); ``` @@ -1252,7 +1262,7 @@ promise.then(() => { on(type: 'show' | 'hide', callback: () => void): void -监听当前面板状态,可监听面板类型为show或者hide, 使用callback异步回调。 +监听当前面板状态,使用callback异步回调。 **系统能力:** SystemCapability.MiscServices.InputMethodFramework @@ -1267,7 +1277,7 @@ on(type: 'show' | 'hide', callback: () => void): void ```js panel.on('show', () => { - console.info('Panel is showing.'); + console.log('Panel is showing.'); }); ``` @@ -1275,7 +1285,7 @@ panel.on('show', () => { off(type: 'show' | 'hide', callback?: () => void): void -取消监听当前面板状态,可取消监听的面板类型为show或者hide,使用callback异步回调。 +取消监听当前面板状态,使用callback异步回调。 **系统能力:** SystemCapability.MiscServices.InputMethodFramework @@ -1283,7 +1293,7 @@ off(type: 'show' | 'hide', callback?: () => void): void | 参数名 | 类型 | 必填 | 说明 | | -------- | ---------------------- | ---- | -------- | -| type | 'show'/'hide' | 是 | 要取消监听的当前面板状态类型,show表示显示状态,hide表示隐藏状态 | +| type | 'show'\|'hide' | 是 | 要取消监听的当前面板状态类型,show表示显示状态,hide表示隐藏状态 | | callback | () => void | 否 | 回调函数。 | **示例:** @@ -1343,11 +1353,11 @@ hide(callback: AsyncCallback<void>): void ```js keyboardController.hide((err) => { - if (err !== undefined) { - console.error('Failed to hide keyboard: ' + JSON.stringify(err)); - return; - } - console.log('Succeeded in hiding keyboard.'); + if (err) { + console.error(`Failed to hide: ${JSON.stringify(err)}`); + return; + } + console.log('Succeeded in hiding keyboard.'); }); ``` @@ -1377,9 +1387,9 @@ hide(): Promise<void> ```js keyboardController.hide().then(() => { - console.info('Succeeded in hiding keyboard.'); + console.log('Succeeded in hiding keyboard.'); }).catch((err) => { - console.info('Failed to hide keyboard: ' + JSON.stringify(err)); + console.log(`Failed to hide: ${JSON.stringify(err)}`); }); ``` @@ -1391,7 +1401,7 @@ hideKeyboard(callback: AsyncCallback<void>): void > **说明:** > -> 从API version 8开始支持,API version 9开始废弃, 建议使用[hide](#hide9)替代。 +> 从API version 8开始支持,API version 9开始废弃,建议使用[hide](#hide9)替代。 **系统能力:** SystemCapability.MiscServices.InputMethodFramework @@ -1405,11 +1415,11 @@ hideKeyboard(callback: AsyncCallback<void>): void ```js keyboardController.hideKeyboard((err) => { - if (err !== undefined) { - console.error('Failed to hide Keyboard: ' + JSON.stringify(err)); - return; - } - console.log('Succeeded in hiding keyboard.'); + if (err) { + console.error(`Failed to hideKeyboard: ${JSON.stringify(err)}`); + return; + } + console.log('Succeeded in hiding keyboard.'); }); ``` @@ -1421,7 +1431,7 @@ hideKeyboard(): Promise<void> > **说明:** > -> 从API version 8开始支持,API version 9开始废弃, 建议使用[hide](#hide9-1)替代。 +> 从API version 8开始支持,API version 9开始废弃,建议使用[hide](#hide9-1)替代。 **系统能力:** SystemCapability.MiscServices.InputMethodFramework @@ -1435,12 +1445,59 @@ hideKeyboard(): Promise<void> ```js keyboardController.hideKeyboard().then(() => { - console.info('Succeeded in hiding keyboard.'); + console.log('Succeeded in hiding keyboard.'); }).catch((err) => { - console.info('Failed to hide Keyboard: ' + JSON.stringify(err)); + console.log(`Failed to hideKeyboard: ${JSON.stringify(err)}`); }); ``` +## ExtendAction10+ + +对编辑框中文本的扩展编辑操作类型。 + +**系统能力**: SystemCapability.MiscServices.InputMethodFramework + +| 名称 | 值 |说明 | +| -------- | -------- |-------- | +| SELECT_ALL | 0 |全选。 | +| CUT | 3 |剪切。 | +| COPY | 4 |复制。 | +| PASTE | 5 |粘贴。 | + +## Direction10+ + +输入法光标移动方向。 + +**系统能力**: SystemCapability.MiscServices.InputMethodFramework + +| 名称 | 值 |说明 | +| -------- | -------- |-------- | +| CURSOR_UP | 1 |向上。 | +| CURSOR_DOWN | 2 |向下。 | +| CURSOR_LEFT | 3 |向左。 | +| CURSOR_RIGHT | 4 |向右。 | + +## Range10+ + +描述选中文本的范围。 + +**系统能力:** SystemCapability.MiscServices.InputMethodFramework + +| 名称 | 类型 | 可读 | 可写 | 说明 | +| -------- | -------- | -------- | -------- | -------- | +| start | number | 是 | 是 | 选中文本的首字符在编辑框的索引值。| +| end | number | 是 | 是 | 选中文本的末字符在编辑框的索引值。| + +## Movement10+ + +描述进行选中文本动作时光标移动的方向。 + +**系统能力:** SystemCapability.MiscServices.InputMethodFramework + +| 名称 | 类型 | 可读 | 可写 | 说明 | +| -------- | -------- | -------- | -------- | -------- | +| direction | [Direction](#direction10) | 是 | 是 | 进行选中文本动作时光标移动的方向。| + ## InputClient9+ 下列API示例中都需使用[on('inputStart')](#oninputstart9)回调获取到InputClient实例,再通过此实例调用对应方法。 @@ -1457,7 +1514,7 @@ sendKeyFunction(action:number, callback: AsyncCallback<boolean>): void | 参数名 | 类型 | 必填 | 说明 | | -------- | -------- | -------- | -------- | -| action | number | 是 | 功能键键值。
当值为0时,表示无效按键;
当值为1时,表示确认键(即回车键)。 | +| action | number | 是 | 功能键键值。
- 当值为0时,表示无效按键;
- 当值为1时,表示确认键(即回车键)。 | | callback | AsyncCallback<boolean> | 是 | 回调函数。当功能键发送成功,err为undefined,data为true;否则为错误对象。 | **错误码:** @@ -1473,19 +1530,19 @@ sendKeyFunction(action:number, callback: AsyncCallback<boolean>): void ```js let action = 1; try { - inputClient.sendKeyFunction(action, (err, result) => { - if (err !== undefined) { - console.error('Failed to sendKeyFunction: ' + JSON.stringify(err)); - return; - } - if (result) { - console.info('Succeeded in sending key function. '); - } else { - console.error('Failed to sendKeyFunction. '); - } - }); + inputClient.sendKeyFunction(action, (err, result) => { + if (err) { + console.error(`Failed to sendKeyFunction: ${JSON.stringify(err)}`); + return; + } + if (result) { + console.log('Succeeded in sending key function.'); + } else { + console.error('Failed to sendKeyFunction.'); + } + }); } catch (err) { - console.error('sendKeyFunction err: ' + JSON.stringify(err)); + console.error(`Failed to sendKeyFunction: ${JSON.stringify(err)}`); } ``` @@ -1522,17 +1579,17 @@ sendKeyFunction(action: number): Promise<boolean> ```js let action = 1; try { - inputClient.sendKeyFunction(action).then((result) => { - if (result) { - console.info('Succeeded in sending key function. '); - } else { - console.error('Failed to sendKeyFunction. '); - } - }).catch((err) => { - console.error('Failed to sendKeyFunction:' + JSON.stringify(err)); - }); + inputClient.sendKeyFunction(action).then((result) => { + if (result) { + console.log('Succeeded in sending key function.'); + } else { + console.error('Failed to sendKeyFunction.'); + } + }).catch((err) => { + console.error(`Failed to sendKeyFunction: ${JSON.stringify(err)}`); + }); } catch (err) { - console.error('Failed to sendKeyFunction: ' + JSON.stringify(err)); + console.error(`Failed to sendKeyFunction: ${JSON.stringify(err)}`); } ``` @@ -1565,15 +1622,15 @@ getForward(length:number, callback: AsyncCallback<string>): void ```js let length = 1; try { - inputClient.getForward(length, (err, text) => { - if (err !== undefined) { - console.error('Failed to getForward: ' + JSON.stringify(err)); - return; - } - console.log('Succeeded in getting forward, text: ' + text); - }); + inputClient.getForward(length, (err, text) => { + if (err) { + console.error(`Failed to getForward: ${JSON.stringify(err)}`); + return; + } + 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)}`); } ``` @@ -1611,13 +1668,13 @@ getForward(length:number): Promise<string> ```js let length = 1; try { - inputClient.getForward(length).then((text) => { - console.info('Succeeded in getting forward, text: ' + text); - }).catch((err) => { - console.error('Failed to getForward: ' + JSON.stringify(err)); - }); + inputClient.getForward(length).then((text) => { + console.log('Succeeded in getting forward, text: ' + text); + }).catch((err) => { + console.error(`Failed to getForward: ${JSON.stringify(err)}`); + }); } catch (err) { - console.error('Failed to getForward: ' + JSON.stringify(err)); + console.error(`Failed to getForward: ${JSON.stringify(err)}`); } ``` @@ -1650,15 +1707,15 @@ getBackward(length:number, callback: AsyncCallback<string>): void ```js let length = 1; try { - inputClient.getBackward(length, (err, text) => { - if (err !== undefined) { - console.error('Failed to getForward: ' + JSON.stringify(err)); - return; - } - console.log('Succeeded in getting backward, text: ' + text); - }); + inputClient.getBackward(length, (err, text) => { + if (err) { + console.error(`Failed to getBackward: ${JSON.stringify(err)}`); + return; + } + console.log('Succeeded in getting backward, text: ' + text); + }); } catch (err) { - console.error('Failed to getForward: ' + JSON.stringify(err)); + console.error(`Failed to getBackward: ${JSON.stringify(err)}`); } ``` @@ -1696,13 +1753,13 @@ getBackward(length:number): Promise<string> ```js let length = 1; try { - inputClient.getBackward(length).then((text) => { - console.info('Succeeded in getting backward, text: ' + text); - }).catch((err) => { - console.error('Failed to getForward: ' + JSON.stringify(err)); - }); + inputClient.getBackward(length).then((text) => { + console.log('Succeeded in getting backward, text: ' + text); + }).catch((err) => { + console.error(`Failed to getBackward: ${JSON.stringify(err)}`); + }); } catch (err) { - console.error('Failed to getForward: ' + JSON.stringify(err)); + console.error(`Failed to getBackward: ${JSON.stringify(err)}`); } ``` @@ -1735,19 +1792,19 @@ deleteForward(length:number, callback: AsyncCallback<boolean>): void ```js let length = 1; try { - inputClient.deleteForward(length, (err, result) => { - if (err !== undefined) { - console.error('Failed to delete forward: ' + JSON.stringify(err)); - return; - } - if (result) { - console.info('Succeeded in deleting forward. '); - } else { - console.error('Failed to delete forward: ' + JSON.stringify(err)); - } - }); + inputClient.deleteForward(length, (err, result) => { + if (err) { + console.error(`Failed to deleteForward: ${JSON.stringify(err)}`); + return; + } + if (result) { + console.log('Succeeded in deleting forward.'); + } else { + console.error(`Failed to deleteForward: ${JSON.stringify(err)}`); + } + }); } catch (err) { - console.error('Failed to delete forward: ' + JSON.stringify(err)); + console.error(`Failed to deleteForward: ${JSON.stringify(err)}`); } ``` @@ -1785,17 +1842,17 @@ deleteForward(length:number): Promise<boolean> ```js let length = 1; try { - inputClient.deleteForward(length).then((result) => { - if (result) { - console.info('Succeeded in deleting forward. '); - } else { - console.error('Failed to delete Forward. '); - } - }).catch((err) => { - console.error('Failed to delete Forward: ' + JSON.stringify(err)); - }); + inputClient.deleteForward(length).then((result) => { + if (result) { + console.log('Succeeded in deleting forward.'); + } else { + console.error('Failed to delete Forward.'); + } + }).catch((err) => { + console.error(`Failed to deleteForward: ${JSON.stringify(err)}`); + }); } catch (err) { - console.error('Failed to delete Forward: ' + JSON.stringify(err)); + console.error(`Failed to deleteForward: ${JSON.stringify(err)}`); } ``` @@ -1828,19 +1885,19 @@ deleteBackward(length:number, callback: AsyncCallback<boolean>): void ```js let length = 1; try { - inputClient.deleteBackward(length, (err, result) => { - if (err !== undefined) { - console.error('Failed to delete Backward: ' + JSON.stringify(err)); - return; - } - if (result) { - console.info('Succeeded in deleting backward. '); - } else { - console.error('Failed to delete Backward: ' + JSON.stringify(err)); - } - }); + inputClient.deleteBackward(length, (err, result) => { + if (err) { + console.error(`Failed to deleteBackward: ${JSON.stringify(err)}`); + return; + } + if (result) { + console.log('Succeeded in deleting backward.'); + } else { + console.error(`Failed to deleteBackward: ${JSON.stringify(err)}`); + } + }); } catch (err) { - console.error('deleteBackward err: ' + JSON.stringify(err)); + console.error('deleteBackward err: ' + JSON.stringify(err)); } ``` @@ -1878,13 +1935,13 @@ deleteBackward(length:number): Promise<boolean> ```js let length = 1; inputClient.deleteBackward(length).then((result) => { - if (result) { - console.info('Succeeded in deleting backward. '); - } else { - console.error('Failed to deleteBackward. '); - } + if (result) { + console.log('Succeeded in deleting backward.'); + } else { + console.error('Failed to deleteBackward.'); + } }).catch((err) => { - console.error('Failed to deleteBackward: ' + JSON.stringify(err)); + console.error(`Failed to deleteBackward: ${JSON.stringify(err)}`); }); ``` @@ -1916,15 +1973,15 @@ insertText(text:string, callback: AsyncCallback<boolean>): void ```js inputClient.insertText('test', (err, result) => { - if (err !== undefined) { - console.error('Failed to insertText: ' + JSON.stringify(err)); - return; - } - if (result) { - console.info('Succeeded in inserting text. '); - } else { - console.error('Failed to insertText. '); - } + if (err) { + console.error(`Failed to insertText: ${JSON.stringify(err)}`); + return; + } + if (result) { + console.log('Succeeded in inserting text.'); + } else { + console.error('Failed to insertText.'); + } }); ``` @@ -1961,17 +2018,17 @@ insertText(text:string): Promise<boolean> ```js try { - inputClient.insertText('test').then((result) => { - if (result) { - console.info('Succeeded in inserting text. '); - } else { - console.error('Failed to insertText. '); - } - }).catch((err) => { - console.error('Failed to insertText: ' + JSON.stringify(err)); - }); + inputClient.insertText('test').then((result) => { + if (result) { + console.log('Succeeded in inserting text.'); + } else { + console.error('Failed to insertText.'); + } + }).catch((err) => { + console.error(`Failed to insertText: ${JSON.stringify(err)}`); + }); } catch (err) { - console.error('Failed to insertText: ' + JSON.stringify(err)); + console.error(`Failed to insertText: ${JSON.stringify(err)}`); } ``` @@ -2001,12 +2058,12 @@ getEditorAttribute(callback: AsyncCallback<EditorAttribute>): void ```js inputClient.getEditorAttribute((err, editorAttribute) => { - if (err !== undefined) { - console.error('Failed to getEditorAttribute: ' + JSON.stringify(err)); - return; - } - console.log('editorAttribute.inputPattern: ' + JSON.stringify(editorAttribute.inputPattern)); - console.log('editorAttribute.enterKeyType: ' + JSON.stringify(editorAttribute.enterKeyType)); + if (err) { + console.error(`Failed to getEditorAttribute: ${JSON.stringify(err)}`); + return; + } + console.log('editorAttribute.inputPattern: ' + JSON.stringify(editorAttribute.inputPattern)); + console.log('editorAttribute.enterKeyType: ' + JSON.stringify(editorAttribute.enterKeyType)); }); ``` @@ -2036,10 +2093,10 @@ getEditorAttribute(): Promise<EditorAttribute> ```js inputClient.getEditorAttribute().then((editorAttribute) => { - console.info('editorAttribute.inputPattern: ' + JSON.stringify(editorAttribute.inputPattern)); - console.info('editorAttribute.enterKeyType: ' + JSON.stringify(editorAttribute.enterKeyType)); + console.log('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)}`); }); ``` @@ -2070,15 +2127,15 @@ moveCursor(direction: number, callback: AsyncCallback<void>): void ```js try { - inputClient.moveCursor(inputMethodEngine.CURSOR_UP, (err) => { - if (err !== undefined) { - console.error('Failed to moveCursor: ' + JSON.stringify(err)); - return; - } - console.info('Succeeded in moving cursor.'); - }); + inputClient.moveCursor(inputMethodEngine.CURSOR_UP, (err) => { + if (err) { + console.error(`Failed to moveCursor: ${JSON.stringify(err)}`); + return; + } + console.log('Succeeded in moving cursor.'); + }); } catch (err) { - console.error('Failed to moveCursor: ' + JSON.stringify(err)); + console.error(`Failed to moveCursor: ${JSON.stringify(err)}`); } ``` @@ -2114,13 +2171,13 @@ moveCursor(direction: number): Promise<void> ```js try { - inputClient.moveCursor(inputMethodEngine.CURSOR_UP).then(() => { - console.log('Succeeded in moving cursor.'); - }).catch((err) => { - console.error('Failed to moveCursor: ' + JSON.stringify(err)); - }); + inputClient.moveCursor(inputMethodEngine.CURSOR_UP).then(() => { + console.log('Succeeded in moving cursor.'); + }).catch((err) => { + console.error(`Failed to moveCursor: ${JSON.stringify(err)}`); + }); } catch (err) { - console.log('Failed to moveCursor: ' + JSON.stringify(err)); + console.error(`Failed to moveCursor: ${JSON.stringify(err)}`); } ``` @@ -2136,7 +2193,7 @@ selectByRange(range: Range, callback: AsyncCallback<void>): void | 参数名 | 类型 | 必填 | 说明 | | -------- | --------------------------------------------------------- | ---- | ------------------------------------------------------------ | -| range | [Range](./js-apis-inputmethod-InputMethodCommon.md#range) | 是 | 选中文本的范围。 | +| range | [Range](#range10) | 是 | 选中文本的范围。 | | callback | AsyncCallback<void> | 是 | 回调函数。当成功发送选中事件后,err为undefined,否则为错误对象。 | **错误码:** @@ -2152,15 +2209,15 @@ selectByRange(range: Range, callback: AsyncCallback<void>): void ```js try { - inputClient.selectByRange({start: 0, end: 1}, (err) => { - if (err !== undefined) { - console.error('Failed to selectByRange: ${err.message}'); - return; - } - console.info('Succeeded in selecting by range.'); - }); + inputClient.selectByRange({start: 0, end: 1}, (err) => { + if (err) { + console.error(`Failed to selectByRange: ${JSON.stringify(err)}`); + return; + } + console.log('Succeeded in selecting by range.'); + }); } catch (err) { - console.error('Failed to selectByRange: ${err.message}'); + console.error(`Failed to selectByRange: ${JSON.stringify(err)}`); } ``` @@ -2176,7 +2233,7 @@ selectByRange(range: Range): Promise<void> | 参数名 | 类型 | 必填 | 说明 | | ------ | --------------------------------------------------------- | ---- | ---------------- | -| range | [Range](./js-apis-inputmethod-InputMethodCommon.md#range) | 是 | 选中文本的范围。 | +| range | [Range](#range10) | 是 | 选中文本的范围。 | **返回值:** @@ -2197,13 +2254,13 @@ selectByRange(range: Range): Promise<void> ```js try { - inputClient.selectByRange({start: 0, end:1}).then(() => { - console.log('Succeeded in selecting by range.'); - }).catch((err) => { - console.error('Failed to selectByRange: ${err.message}'); - }); + inputClient.selectByRange({start: 0, end:1}).then(() => { + console.log('Succeeded in selecting by range.'); + }).catch((err) => { + console.error(`Failed to selectByRange: ${JSON.stringify(err)}`); + }); } catch (err) { - console.log('Failed to selectByRange: ${err.message}'); + console.error(`Failed to selectByRange: ${JSON.stringify(err)}`); } ``` @@ -2217,10 +2274,10 @@ selectByMovement(movement: Movement, callback: AsyncCallback<void>): void **参数:** -| 参数名 | 类型 | 必填 | 说明 | -| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | -| movement | [Movement](./js-apis-inputmethod-InputMethodCommon.md#movement) | 是 | 选中时光标移动的方向。 | -| callback | AsyncCallback<void> | 是 | 回调函数。当成功发送选中事件后,err为undefined,否则为错误对象。 | +| 参数名 | 类型 | 必填 | 说明 | +| -------- | ------ | ---- | ------ | +| movement | [Movement](#movement10) | 是 | 选中时光标移动的方向。 | +| callback | AsyncCallback<void> | 是 | 回调函数。当成功发送选中事件后,err为undefined,否则为错误对象。 | **错误码:** @@ -2235,15 +2292,15 @@ selectByMovement(movement: Movement, callback: AsyncCallback<void>): void ```js try { - inputClient.selectByMovement({direction: 1}, (err) => { - if (err !== undefined) { - console.error('Failed to selectByMovement: ${err.message}'); - return; - } - console.info('Succeeded in selecting by movement.'); - }); + inputClient.selectByMovement({direction: 1}, (err) => { + if (err) { + console.error(`Failed to selectByMovement: ${JSON.stringify(err)}`); + return; + } + console.log('Succeeded in selecting by movement.'); + }); } catch (err) { - console.error('Failed to selectByMovement: ${err.message}'); + console.error(`Failed to selectByMovement: ${JSON.stringify(err)}`); } ``` @@ -2259,7 +2316,7 @@ selectByMovement(movement: Movement): Promise<void> | 参数名 | 类型 | 必填 | 说明 | | -------- | ------------------------------------------------------------ | ---- | ---------------------- | -| movement | [Movement](./js-apis-inputmethod-InputMethodCommon.md#movement) | 是 | 选中时光标移动的方向。 | +| movement | [Movement](#movement10) | 是 | 选中时光标移动的方向。 | **返回值:** @@ -2280,13 +2337,13 @@ selectByMovement(movement: Movement): Promise<void> ```js try { - inputClient.selectByMovement({direction: 1}).then(() => { - console.log('Succeeded in selecting by movement.'); - }).catch((err) => { - console.error('Failed to selectByMovement: ${err.message}'); - }); + inputClient.selectByMovement({direction: 1}).then(() => { + console.log('Succeeded in selecting by movement.'); + }).catch((err) => { + console.error(`Failed to selectByMovement: ${JSON.stringify(err)}`); + }); } catch (err) { - console.log('Failed to selectByMovement: ${err.message}'); + console.error(`Failed to selectByMovement: ${JSON.stringify(err)}`); } ``` @@ -2310,7 +2367,6 @@ getTextIndexAtCursor(callback: AsyncCallback<number>): void | 错误码ID | 错误信息 | | -------- | ------------------------------ | -| 401 | parameter error. | | 12800003 | input method client error. | | 12800006 | Input method controller error. | @@ -2318,11 +2374,11 @@ getTextIndexAtCursor(callback: AsyncCallback<number>): void ```js inputClient.getTextIndexAtCursor((err, index) => { - if (err !== undefined) { - console.error('Failed to getTextIndexAtCursor: ${err.message}'); - return; - } - console.info('Succeeded in getTextIndexAtCursor: ' + index); + if (err) { + console.error(`Failed to getTextIndexAtCursor: ${JSON.stringify(err)}`); + return; + } + console.log('Succeeded in getTextIndexAtCursor: ' + index); }); ``` @@ -2353,12 +2409,99 @@ getTextIndexAtCursor(): Promise<number> ```js inputClient.getTextIndexAtCursor().then((index) => { - console.info('Succeeded in getTextIndexAtCursor: ' + index); + console.log('Succeeded in getTextIndexAtCursor: ' + index); }).catch((err) => { - console.error('Failed to getTextIndexAtCursor: ${err.message}'); + console.error(`Failed to getTextIndexAtCursor: ${JSON.stringify(err)}`); }); ``` +### sendExtendAction10+ + +sendExtendAction(action: ExtendAction, callback: AsyncCallback<void>): void + +发送扩展编辑操作。使用callback异步回调。 + +输入法应用调用该接口向编辑控件(如:输入框)发送扩展编辑操作,编辑控件监听相应事件[on(handleExtendAction)](./js-apis-inputmethod.md#onhandleextendaction10),从而进一步做出处理。 + +**系统能力:** SystemCapability.MiscServices.InputMethodFramework + +**参数:** + +| 参数名 | 类型 | 必填 | 说明 | +| -------- | --------------------------- | ---- | ------------------------------------------------------------ | +| action | [ExtendAction](#extendaction10) | 是 | 要发送的扩展操作。 | +| callback | AsyncCallback<void> | 是 | 回调函数。发送成功,err为undefined,否则为错误对象。 | + +**错误码:** + +以下错误码的详细介绍请参见[输入法框架错误码](../errorcodes/errorcode-inputmethod-framework.md)。 + +| 错误码ID | 错误信息 | +| -------- | ------------------------------ | +| 12800003 | input method client error. | +| 12800006 | Input method controller error. | + +**示例:** + +```js +try { + inputClient.sendExtendAction(inputMethodEngine.ExtendAction.COPY, (err) => { + if (err) { + console.error(`Failed to sendExtendAction: ${JSON.stringify(err)}`); + return; + } + console.log('Succeeded in sending extend action.'); + }); +} catch(err) { + console.error(`Failed to sendExtendAction: ${JSON.stringify(err)}`); +} +``` + +### sendExtendAction10+ + +sendExtendAction(action: ExtendAction): Promise<void> + +发送扩展编辑操作。使用promise异步回调。 + +输入法应用调用该接口向编辑控件(如:输入框)发送扩展编辑操作,编辑控件监听相应事件[on(handleExtendAction)](./js-apis-inputmethod.md#onhandleextendaction10),从而进一步做出处理。 + +**系统能力:** SystemCapability.MiscServices.InputMethodFramework + +**参数:** + +| 参数名 | 类型 | 必填 | 说明 | +| -------- | -------- | -------- | -------- | +| action | [ExtendAction](#extendaction10) | 是 | 要发送的扩展操作。 | + +**返回值:** + +| 类型 | 说明 | +| --------------------- | --------------------------------------- | +| Promise<void> | 无返回结果的Promise对象。 | + +**错误码:** + +以下错误码的详细介绍请参见[输入法框架错误码](../errorcodes/errorcode-inputmethod-framework.md)。 + +| 错误码ID | 错误信息 | +| -------- | ------------------------------ | +| 12800003 | Input method client error. | +| 12800006 | Input method controller error. | + +**示例:** + +```js +try { + inputClient.sendExtendAction(inputMethodEngine.ExtendAction.COPY).then(() => { + console.log('Succeeded in sending extend action.'); + }).catch((err) => { + console.error(`Failed to sendExtendAction: ${JSON.stringify(err)}`); + }); +} catch(err) { + console.error(`Failed to sendExtendAction: ${JSON.stringify(err)}`); +} +``` + ## EditorAttribute 编辑框属性值。 @@ -2418,7 +2561,7 @@ inputClient.getTextIndexAtCursor().then((index) => { > **说明:** > -> 从API version 8开始支持,API version 9开始废弃, 建议使用[InputClient](#inputclient9)替代。 +> 从API version 8开始支持,API version 9开始废弃,建议使用[InputClient](#inputclient9)替代。 下列API示例中都需使用[on('inputStart')](#oninputstart)回调获取到TextInputClient实例,再通过此实例调用对应方法。 @@ -2430,7 +2573,7 @@ getForward(length:number, callback: AsyncCallback<string>): void > **说明:** > -> 从API version 8开始支持,API version 9开始废弃, 建议使用[getForward](#getforward9)替代。 +> 从API version 8开始支持,API version 9开始废弃,建议使用[getForward](#getforward9)替代。 **系统能力:** SystemCapability.MiscServices.InputMethodFramework @@ -2446,11 +2589,11 @@ getForward(length:number, callback: AsyncCallback<string>): void ```js let length = 1; textInputClient.getForward(length, (err, text) => { - if (err !== undefined) { - console.error('Failed to getForward: ' + JSON.stringify(err)); - return; - } - console.log('Succeeded in getting forward, text: ' + text); + if (err) { + console.error(`Failed to getForward: ${JSON.stringify(err)}`); + return; + } + console.log('Succeeded in getting forward, text: ' + text); }); ``` @@ -2462,7 +2605,7 @@ getForward(length:number): Promise<string> > **说明:** > -> 从API version 8开始支持,API version 9开始废弃, 建议使用[getForward](#getforward9)替代。 +> 从API version 8开始支持,API version 9开始废弃,建议使用[getForward](#getforward9)替代。 **系统能力:** SystemCapability.MiscServices.InputMethodFramework @@ -2483,9 +2626,9 @@ getForward(length:number): Promise<string> ```js let length = 1; textInputClient.getForward(length).then((text) => { - console.info('Succeeded in getting forward, text: ' + text); + 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)}`); }); ``` @@ -2497,7 +2640,7 @@ getBackward(length:number, callback: AsyncCallback<string>): void > **说明:** > -> 从API version 8开始支持,API version 9开始废弃, 建议使用[getBackward](#getbackward9)替代。 +> 从API version 8开始支持,API version 9开始废弃,建议使用[getBackward](#getbackward9)替代。 **系统能力:** SystemCapability.MiscServices.InputMethodFramework @@ -2513,11 +2656,11 @@ getBackward(length:number, callback: AsyncCallback<string>): void ```js let length = 1; textInputClient.getBackward(length, (err, text) => { - if (err !== undefined) { - console.error('Failed to getBackward: ' + JSON.stringify(err)); - return; - } - console.log('Succeeded in getting borward, text: ' + text); + if (err) { + console.error(`Failed to getBackward: ${JSON.stringify(err)}`); + return; + } + console.log('Succeeded in getting borward, text: ' + text); }); ``` @@ -2529,7 +2672,7 @@ getBackward(length:number): Promise<string> > **说明:** > -> 从API version 8开始支持,API version 9开始废弃, 建议使用[getBackward](#getbackward9)替代。 +> 从API version 8开始支持,API version 9开始废弃,建议使用[getBackward](#getbackward9)替代。 **系统能力:** SystemCapability.MiscServices.InputMethodFramework @@ -2550,9 +2693,9 @@ getBackward(length:number): Promise<string> ```js let length = 1; textInputClient.getBackward(length).then((text) => { - console.info('Succeeded in getting backward: ' + JSON.stringify(text)); + 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)}`); }); ``` @@ -2564,7 +2707,7 @@ deleteForward(length:number, callback: AsyncCallback<boolean>): void > **说明:** > -> 从API version 8开始支持,API version 9开始废弃, 建议使用[deleteForward](#deleteforward9)替代。 +> 从API version 8开始支持,API version 9开始废弃,建议使用[deleteForward](#deleteforward9)替代。 **系统能力:** SystemCapability.MiscServices.InputMethodFramework @@ -2580,15 +2723,15 @@ deleteForward(length:number, callback: AsyncCallback<boolean>): void ```js let length = 1; textInputClient.deleteForward(length, (err, result) => { - if (err !== undefined) { - console.error('Failed to deleteForward: ' + JSON.stringify(err)); - return; - } - if (result) { - console.info('Succeeded in deleting forward. '); - } else { - console.error('Failed to deleteForward. '); - } + if (err) { + console.error(`Failed to deleteForward: ${JSON.stringify(err)}`); + return; + } + if (result) { + console.log('Succeeded in deleting forward.'); + } else { + console.error('Failed to deleteForward.'); + } }); ``` @@ -2600,7 +2743,7 @@ deleteForward(length:number): Promise<boolean> > **说明:** > -> 从API version 8开始支持,API version 9开始废弃, 建议使用[deleteForward](#deleteforward9)替代。 +> 从API version 8开始支持,API version 9开始废弃,建议使用[deleteForward](#deleteforward9)替代。 **系统能力:** SystemCapability.MiscServices.InputMethodFramework @@ -2621,13 +2764,13 @@ deleteForward(length:number): Promise<boolean> ```js let length = 1; textInputClient.deleteForward(length).then((result) => { - if (result) { - console.info('Succeeded in deleting forward. '); - } else { - console.error('Failed to delete forward. '); - } + if (result) { + console.log('Succeeded in deleting forward.'); + } else { + console.error('Failed to delete forward.'); + } }).catch((err) => { - console.error('Failed to delete forward: ' + JSON.stringify(err)); + console.error(`Failed to deleteForward: ${JSON.stringify(err)}`); }); ``` @@ -2639,31 +2782,31 @@ deleteBackward(length:number, callback: AsyncCallback<boolean>): void > **说明:** > -> 从API version 8开始支持,API version 9开始废弃, 建议使用[deleteBackward](#deletebackward9)替代。 +> 从API version 8开始支持,API version 9开始废弃,建议使用[deleteBackward](#deletebackward9)替代。 **系统能力:** SystemCapability.MiscServices.InputMethodFramework - **参数:** +**参数:** | 参数名 | 类型 | 必填 | 说明 | | -------- | ---------------------------- | ---- | -------------- | | length | number | 是 | 文本长度。 | | callback | AsyncCallback<boolean> | 是 | 回调函数。当光标后固定长度的文本删除成功,err为undefined,data为true;否则为错误对象。| - **示例:** +**示例:** ```js let length = 1; textInputClient.deleteBackward(length, (err, result) => { - if (err !== undefined) { - console.error('Failed to delete backward: ' + JSON.stringify(err)); - return; - } - if (result) { - console.info('Succeeded in deleting backward. '); - } else { - console.error('Failed to deleteBackward. '); - } + if (err) { + console.error(`Failed to deleteBackward: ${JSON.stringify(err)}`); + return; + } + if (result) { + console.log('Succeeded in deleting backward.'); + } else { + console.error('Failed to deleteBackward.'); + } }); ``` @@ -2675,7 +2818,7 @@ deleteBackward(length:number): Promise<boolean> > **说明:** > -> 从API version 8开始支持,API version 9开始废弃, 建议使用[deleteBackward](#deletebackward9)替代。 +> 从API version 8开始支持,API version 9开始废弃,建议使用[deleteBackward](#deletebackward9)替代。 **系统能力:** SystemCapability.MiscServices.InputMethodFramework @@ -2696,13 +2839,13 @@ deleteBackward(length:number): Promise<boolean> ```js let length = 1; textInputClient.deleteBackward(length).then((result) => { - if (result) { - console.info('Succeeded in deleting backward. '); - } else { - console.error('Failed to deleteBackward. '); - } + if (result) { + console.log('Succeeded in deleting backward.'); + } else { + console.error('Failed to deleteBackward.'); + } }).catch((err) => { - console.error('Failed to deleteBackward: ' + JSON.stringify(err)); + console.error(`Failed to deleteBackward: ${JSON.stringify(err)}`); }); ``` ### sendKeyFunction(deprecated) @@ -2713,31 +2856,31 @@ sendKeyFunction(action: number, callback: AsyncCallback<boolean>): void > **说明:** > -> 从API version 8开始支持,API version 9开始废弃, 建议使用[sendKeyFunction](#sendkeyfunction9)替代。 +> 从API version 8开始支持,API version 9开始废弃,建议使用[sendKeyFunction](#sendkeyfunction9)替代。 **系统能力:** SystemCapability.MiscServices.InputMethodFramework - **参数:** +**参数:** | 参数名 | 类型 | 必填 | 说明 | | -------- | -------- | -------- | -------- | -| action | number | 是 | 功能键键值。
当值为0时,表示无效按键;
当值为1时,表示确认键(即回车键)。 | +| action | number | 是 | 功能键键值。
- 当值为0时,表示无效按键;
- 当值为1时,表示确认键(即回车键)。 | | callback | AsyncCallback<boolean> | 是 | 回调函数。当功能键发送成功,err为undefined,data为true;否则为错误对象。 | - **示例:** +**示例:** ```js let action = 1; textInputClient.sendKeyFunction(action, (err, result) => { - if (err !== undefined) { - console.error('Failed to sendKeyFunction: ' + JSON.stringify(err)); - return; - } - if (result) { - console.info('Succeeded in sending key function. '); - } else { - console.error('Failed to sendKeyFunction. '); - } + if (err) { + console.error(`Failed to sendKeyFunction: ${JSON.stringify(err)}`); + return; + } + if (result) { + console.log('Succeeded in sending key function.'); + } else { + console.error('Failed to sendKeyFunction.'); + } }); ``` @@ -2749,7 +2892,7 @@ sendKeyFunction(action: number): Promise<boolean> > **说明:** > -> 从API version 8开始支持,API version 9开始废弃, 建议使用[sendKeyFunction](#sendkeyfunction9)替代。 +> 从API version 8开始支持,API version 9开始废弃,建议使用[sendKeyFunction](#sendkeyfunction9)替代。 **系统能力:** SystemCapability.MiscServices.InputMethodFramework @@ -2770,13 +2913,13 @@ sendKeyFunction(action: number): Promise<boolean> ```js let action = 1; textInputClient.sendKeyFunction(action).then((result) => { - if (result) { - console.info('Succeeded in sending key function. '); - } else { - console.error('Failed to sendKeyFunction. '); - } + if (result) { + console.log('Succeeded in sending key function.'); + } else { + console.error('Failed to sendKeyFunction.'); + } }).catch((err) => { - console.error('Failed to sendKeyFunction:' + JSON.stringify(err)); + console.error(`Failed to sendKeyFunction: ${JSON.stringify(err)}`); }); ``` @@ -2788,7 +2931,7 @@ insertText(text:string, callback: AsyncCallback<boolean>): void > **说明:** > -> 从API version 8开始支持,API version 9开始废弃, 建议使用[insertText](#inserttext9)替代。 +> 从API version 8开始支持,API version 9开始废弃,建议使用[insertText](#inserttext9)替代。 **系统能力:** SystemCapability.MiscServices.InputMethodFramework @@ -2803,15 +2946,15 @@ insertText(text:string, callback: AsyncCallback<boolean>): void ```js textInputClient.insertText('test', (err, result) => { - if (err !== undefined) { - console.error('Failed to insertText: ' + JSON.stringify(err)); - return; - } - if (result) { - console.info('Succeeded in inserting text. '); - } else { - console.error('Failed to insertText. '); - } + if (err) { + console.error(`Failed to insertText: ${JSON.stringify(err)}`); + return; + } + if (result) { + console.log('Succeeded in inserting text.'); + } else { + console.error('Failed to insertText.'); + } }); ``` @@ -2823,7 +2966,7 @@ insertText(text:string): Promise<boolean> > **说明:** > -> 从API version 8开始支持,API version 9开始废弃, 建议使用[insertText](#inserttext9)替代。 +> 从API version 8开始支持,API version 9开始废弃,建议使用[insertText](#inserttext9)替代。 **系统能力:** SystemCapability.MiscServices.InputMethodFramework @@ -2843,13 +2986,13 @@ insertText(text:string): Promise<boolean> ```js textInputClient.insertText('test').then((result) => { - if (result) { - console.info('Succeeded in inserting text. '); - } else { - console.error('Failed to insertText. '); - } + if (result) { + console.log('Succeeded in inserting text.'); + } else { + console.error('Failed to insertText.'); + } }).catch((err) => { - console.error('Failed to insertText: ' + JSON.stringify(err)); + console.error(`Failed to insertText: ${JSON.stringify(err)}`); }); ``` @@ -2861,26 +3004,26 @@ getEditorAttribute(callback: AsyncCallback<EditorAttribute>): void > **说明:** > -> 从API version 8开始支持,API version 9开始废弃, 建议使用[getEditorAttribute](#geteditorattribute9)替代。 +> 从API version 8开始支持,API version 9开始废弃,建议使用[getEditorAttribute](#geteditorattribute9)替代。 **系统能力:** SystemCapability.MiscServices.InputMethodFramework **参数:** -| 参数名 | 类型 | 必填 | 说明 | -| ------------------------------- | ------------------------------------------------------------ | ------------------------------------------------------------ | ------------------------------------------------------------ | +| 参数名 | 类型 | 必填 | 说明 | +| -------- | ----- | ----- | ----- | | callback | AsyncCallback<[EditorAttribute](#editorattribute)> | 是 | 回调函数。当编辑框的属性值获取成功,err为undefined,data为编辑框属性值;否则为错误对象。| **示例:** ```js textInputClient.getEditorAttribute((err, editorAttribute) => { - if (err !== undefined) { - console.error('Failed to getEditorAttribute: ' + JSON.stringify(err)); - return; - } - console.log('editorAttribute.inputPattern: ' + JSON.stringify(editorAttribute.inputPattern)); - console.log('editorAttribute.enterKeyType: ' + JSON.stringify(editorAttribute.enterKeyType)); + if (err) { + console.error(`Failed to getEditorAttribute: ${JSON.stringify(err)}`); + return; + } + console.log('editorAttribute.inputPattern: ' + JSON.stringify(editorAttribute.inputPattern)); + console.log('editorAttribute.enterKeyType: ' + JSON.stringify(editorAttribute.enterKeyType)); }); ``` @@ -2892,7 +3035,7 @@ getEditorAttribute(): Promise<EditorAttribute> > **说明:** > -> 从API version 8开始支持,API version 9开始废弃, 建议使用[getEditorAttribute](#geteditorattribute9)替代。 +> 从API version 8开始支持,API version 9开始废弃,建议使用[getEditorAttribute](#geteditorattribute9)替代。 **系统能力:** SystemCapability.MiscServices.InputMethodFramework @@ -2906,10 +3049,10 @@ getEditorAttribute(): Promise<EditorAttribute> ```js textInputClient.getEditorAttribute().then((editorAttribute) => { - console.info('editorAttribute.inputPattern: ' + JSON.stringify(editorAttribute.inputPattern)); - console.info('editorAttribute.enterKeyType: ' + JSON.stringify(editorAttribute.enterKeyType)); + console.log('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 newline at end of file diff --git a/zh-cn/application-dev/reference/errorcodes/errorcode-inputmethod-framework.md b/zh-cn/application-dev/reference/errorcodes/errorcode-inputmethod-framework.md index 8da20d94a83b74fdfa869de87ec68d8b27708dac..eb67bae3c5e047017cad5fc8a590baed7871b1be 100644 --- a/zh-cn/application-dev/reference/errorcodes/errorcode-inputmethod-framework.md +++ b/zh-cn/application-dev/reference/errorcodes/errorcode-inputmethod-framework.md @@ -58,23 +58,23 @@ Input method client error. 重新将输入法应用与三方应用进行绑定:将三方应用后台进程杀死,重新启动三方应用,通过点击对话框等方式触发输入法键盘的显示,若键盘正常显示,则问题解决。 -## 12800004 按键事件处理异常 +## 12800004 不是输入法应用 **错误信息** -Key event processing error. +Not an input method extension. **错误描述** -当按键事件异常时,系统会报此错误码。 +当其他应用调用了仅支持输入法应用调用的接口时,系统会报此错误码。 **可能原因** -按键事件分发、消费、监听异常时会报错。 +在其他应用中调用了仅支持输入法应用调用的接口。 **处理步骤** -无 +在输入法应用中调用此接口。 ## 12800005 配置固化失败 @@ -146,4 +146,22 @@ Input method manager service error. **处理步骤** -通过ps -A|grep inputmethod查看是否存在输入法服务的进程号,如果存在,则服务正常。 \ No newline at end of file +通过ps -A|grep inputmethod查看是否存在输入法服务的进程号,如果存在,则服务正常。 + +## 12800009 输入法客户端未绑定 + +**错误信息** + +Input method client is detached. + +**错误描述** + +当前应用未绑定输入法应用。 + +**可能原因** + +当前应用在没有绑定输入法的情况下执行了比如showTextInput、hideTextInput等操作。 + +**处理步骤** + +先执行attach接口操作即可。 \ No newline at end of file