diff --git a/zh-cn/application-dev/reference/apis/Readme-CN.md b/zh-cn/application-dev/reference/apis/Readme-CN.md index fa059f26d31f655d191450b8b6562bf0f2680903..bb5ca929eabd6a97f1cb2a5245cf28147bc2162e 100755 --- a/zh-cn/application-dev/reference/apis/Readme-CN.md +++ b/zh-cn/application-dev/reference/apis/Readme-CN.md @@ -202,6 +202,7 @@ - [@ohos.inputmethodengine (输入法服务)](js-apis-inputmethodengine.md) - [@ohos.inputmethodextensionability (InputMethodExtensionAbility)](js-apis-inputmethod-extension-ability.md) - [@ohos.inputmethodextensioncontext (InputMethodExtensionContext)](js-apis-inputmethod-extension-context.md) + - [@ohos.inputmethodsubtype(输入法子类型)](js-apis-inputmethod-subtype.md) - [@ohos.pasteboard (剪贴板)](js-apis-pasteboard.md) - [@ohos.screenLock (锁屏管理)](js-apis-screen-lock.md) - [@ohos.systemTime (系统时间、时区)](js-apis-system-time.md) 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 32b5e53b412e1a4c071ce7cfbcabf36c62ad0b82..6f381f501ab77c7b76e03734dd6311fe61801b7c 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 @@ -1,11 +1,10 @@ # InputMethodExtensionAbility -InputMethodExtensionAbility模块,提供生态输入法应用开发者通过InputMethodExtensionAbility、InputMethodExtensionContext接口创作输入法应用,并管理输入法应用生命周期。 +开发者可通过继承本模块开发自己的输入法应用并管理输入法应用生命周期。 > **说明:** -> -> 本模块首批接口从API version 9开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 -> 本模块接口仅可在Stage模型下使用。 +> +>本模块首批接口从API version 9开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 ## 导入模块 @@ -15,7 +14,7 @@ import InputMethodExtensionAbility from '@ohos.inputmethodextensionability'; ## 属性 -**系统能力**:SystemCapability.MiscServices.InputMethodFramework +**系统能力:** SystemCapability.MiscServices.InputMethodFramework | 名称 | 参数类型 | 可读 | 可写 | 说明 | | -------- | -------- | -------- | -------- | -------- | @@ -24,11 +23,11 @@ import InputMethodExtensionAbility from '@ohos.inputmethodextensionability'; ## InputMethodExtensionAbility.onCreate() -onCreate(want: Want): void; +onCreate(want: Want): void Extension生命周期回调,在拉起Extension输入法应用时调用,执行初始化输入法应用操作。 -**系统能力**:SystemCapability.MiscServices.InputMethodFramework +**系统能力:** SystemCapability.MiscServices.InputMethodFramework **参数:** @@ -38,29 +37,29 @@ Extension生命周期回调,在拉起Extension输入法应用时调用,执 **示例:** - ```js - class InputMethodExt extends InputMethodExtensionAbility { +```js +class InputMethodExt extends InputMethodExtensionAbility { onCreate(want) { - console.log('onCreate, want:' + want.abilityName); + console.log('onCreate, want:' + want.abilityName); } - } - ``` +} +``` ## InputMethodExtensionAbility.onDestroy() -onDestroy(): void; +onDestroy(): void Extension生命周期回调,在销毁输入法应用时回调,执行资源清理等操作。 -**系统能力**:SystemCapability.MiscServices.InputMethodFramework +**系统能力:** SystemCapability.MiscServices.InputMethodFramework **示例:** - ```js - class InputMethodExt extends InputMethodExtensionAbility { +```js +class InputMethodExt extends InputMethodExtensionAbility { onDestroy() { - console.log('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 3d7a9ad9e0ec73c4b87c35a0100192aeef9f46df..acd2a268fdec54a7e82e531b5345c25a1d62bf0f 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 @@ -5,9 +5,8 @@ InputMethodExtensionContext模块是InputMethodExtensionAbility的上下文环 InputMethodExtensionContext模块提供InputMethodExtensionAbility具有的能力和接口,包括启动、停止、绑定、解绑Ability。 > **说明:** -> -> 本模块首批接口从API version 9开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 -> 本模块接口仅可在Stage模型下使用。 +> +>本模块首批接口从API version 9开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 ## 导入模块 @@ -20,151 +19,56 @@ import InputMethodExtensionContext from '@ohos.inputmethodextensioncontext'; 在使用InputMethodExtensionContext的功能前,需要通过InputMethodExtensionAbility子类实例获取。 ```js - import InputMethodExtensionAbility from '@ohos.inputmethodextensionability'; - class MainAbility extends InputMethodExtensionAbility { - onCreate() { - let context = this.context; - } - } +import InputMethodExtensionAbility from '@ohos.inputmethodextensionability'; +class MainAbility extends InputMethodExtensionAbility { + onCreate() { + let context = this.context; + } +} ``` -## InputMethodExtensionContext.startAbility +## InputMethodExtensionContext.destroy -startAbility(want: Want, callback: AsyncCallback<void>): void; +destroy(callback: AsyncCallback\): void -启动Ability,包含一个Want类型参数。callback形式返回启动结果。 +停止输入法应用自身。使用callback异步回调。 -**系统能力**:SystemCapability.MiscServices.InputMethodFramework +**系统能力:** SystemCapability.MiscServices.InputMethodFramework **参数:** -| 参数名 | 类型 | 必填 | 说明 | -| -------- | -------- | -------- | -------- | -| want | [Want](js-apis-application-Want.md) | 是 | Want类型参数,传入需要启动的ability的信息,如ability名称,包名等。 | -| callback | AsyncCallback<void> | 是 | 回调函数,返回接口调用是否成功的结果。 | +| 参数名 | 类型 | 必填 | 说明 | +| -------- | -------------------- | ---- | ------------------------------------------------------------ | +| callback | AsyncCallback\ | 是 | 回调函数。当停止输入法应用自身成功时,err为undefined;否则为错误对象。 | **示例:** - ```js - let want = { - 'bundleName': 'com.example.myapp', - 'abilityName': 'MyAbility' - }; - this.context.startAbility(want, (err) => { - console.log('startAbility result:' + JSON.stringify(err)); - }); - ``` - -## InputMethodExtensionContext.startAbility - -startAbility(want: Want, options?: StartOptions): Promise\; - -启动Ability,包含Want类型参数,以及可选填的StartOption类型参数。通过Promise方法返回结果。 - -**系统能力**:SystemCapability.MiscServices.InputMethodFramework - -**参数:** - -| 参数名 | 类型 | 必填 | 说明 | -| -------- | -------- | -------- | -------- | -| want | [Want](js-apis-application-Want.md) | 是 | Want类型参数,传入需要启动的ability的信息,如ability名称,包名等。 | -| options | [StartOptions](js-apis-application-StartOptions.md) | 否 | 启动Ability所携带的参数。 | - -**返回值:** - - | 类型 | 说明 | - | -------- | -------- | - | Promise<void> | 返回一个Promise,包含接口的结果。 | - -**示例:** - - ```js - let want = { - 'bundleName': 'com.example.myapp', - 'abilityName': 'MyAbility' - }; - this.context.startAbility(want).then((data) => { - console.log('success:' + JSON.stringify(data)); - }).catch((error) => { - console.log('failed:' + JSON.stringify(error)); - }); - - ``` - -## InputMethodExtensionContext.startAbility - -startAbility(want: Want, options: StartOptions, callback: AsyncCallback<void>): void - -启动Ability,包含有两个参数,Want类型和StartOption类型参数。callback形式返回启动结果。 - -**系统能力**:SystemCapability.MiscServices.InputMethodFramework - -**参数:** - -| 参数名 | 类型 | 必填 | 说明 | -| -------- | -------- | -------- | -------- | -| want | [Want](js-apis-application-Want.md) | 是 | 启动Ability的want信息。 | -| options | [StartOptions](js-apis-application-StartOptions.md) | 是 | 启动Ability所携带的参数。 | -| callback | AsyncCallback<void> | 是 | callback形式返回启动结果。 | - -**示例:** - - ```js - var want = { - 'deviceId': '', - 'bundleName': 'com.extreme.test', - 'abilityName': 'MainAbility' - }; - var options = { - windowMode: 0, - }; - this.context.startAbility(want, options, (error) => { - console.log('error.code = ' + error.code) - }) - ``` - -## InputMethodExtensionContext.terminateSelf - -terminateSelf(callback: AsyncCallback<void>): void; - -停止输入法应用自身,通过Callback方法返回接口调用是否成功。 - -**系统能力**:SystemCapability.MiscServices.InputMethodFramework - -**参数:** - -| 参数名 | 类型 | 必填 | 说明 | -| -------- | ------------------------- | ---- | -------------------------------------- | -| callback | AsyncCallback<void> | 是 | 回调函数,返回接口调用是否成功的结果。 | - -**示例:** - - ```js -this.context.terminateSelf((err) => { - console.log('terminateSelf result:' + JSON.stringify(err)); +```js +this.context.destroy((err) => { + console.log('destroy result:' + JSON.stringify(err)); }); - ``` +``` -## InputMethodExtensionContext.terminateSelf +## InputMethodExtensionContext.destroy -terminateSelf(): Promise<void>; +destroy(): Promise { - console.log('success:' + JSON.stringify(data)); - }).catch((error) => { - console.log('failed:' + JSON.stringify(error)); - }); - ``` +```js +this.context.destroy().then((data) => { + console.log('success:' + JSON.stringify(data)); +}).catch((error) => { + console.log('failed:' + JSON.stringify(error)); +}); +``` \ No newline at end of file diff --git a/zh-cn/application-dev/reference/apis/js-apis-inputmethod-subtype.md b/zh-cn/application-dev/reference/apis/js-apis-inputmethod-subtype.md new file mode 100644 index 0000000000000000000000000000000000000000..fc8a1b1dbed1656eae864432eec81480fe96f55c --- /dev/null +++ b/zh-cn/application-dev/reference/apis/js-apis-inputmethod-subtype.md @@ -0,0 +1,31 @@ +# 输入法子类型 + +本模块提供对输入法子类型的属性管理。 + +> **说明:** +> +>本模块首批接口从API version 9开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 + +## 导入模块 + +``` +import inputMethodEngine from '@ohos.inputMethodSubtype'; +``` + +## 属性 + +属性值。 + +**系统能力:** SystemCapability.MiscServices.InputMethodFramework + +| 名称 | 参数类型 | 可读 | 可写 | 必选 | 说明 | +| -------- | -------- | -------- | -------- | -------- | -------- | +| label | string | 是 | 否 | 否 | 输入法子类型的标签。 | +| name | string | 是 | 否 | 是 | 输入法子类型的名字。 | +| id | string | 是 | 否 | 是 | 输入法子类型的id。 | +| mode | string | 是 | 否 | 否 | 输入法子类型的模式,包括upper(大写)和lower(小写)。 | +| locale | string | 是 | 否 | 是 | 输入法子类型的方言版本。 | +| language | string | 是 | 否 | 是 | 输入法子类型的语言。 | +| icon | string | 是 | 否 | 否 | 输入法子类型的图标。 | +| iconId | number | 是 | 否 | 否 | 输入法子类型的图标id。 | +| extra | object | 是 | 是 | 是 | 输入法子类型的其他信息。 | \ No newline at end of file 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 91f8b10169a191b95599051b5a390ca0b12bc650..08383f51ffe342900ed135280352af89b4b31b0f 100644 --- a/zh-cn/application-dev/reference/apis/js-apis-inputmethod.md +++ b/zh-cn/application-dev/reference/apis/js-apis-inputmethod.md @@ -2,9 +2,9 @@ 本模块提供对输入法框架的管理,包括隐藏输入法、查询已安装的输入法列表和显示输入法选择对话框。 -> **说明:** +>**说明:** > -> 本模块首批接口从API version 6开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 +>本模块首批接口从API version 6开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 ## 导入模块 @@ -13,35 +13,40 @@ import inputMethod from '@ohos.inputmethod'; ``` -## inputMethod8+ +## 常量8+ 常量值。 -**系统能力**:以下各项对应的系统能力均为SystemCapability.MiscServices.InputMethodFramework - -| 名称 | 参数类型 | 可读 | 可写 | 说明 | -| -------- | -------- | -------- | -------- | -------- | -| MAX_TYPE_NUM | number | 是 | 否 | 可支持的最大输入法个数。 | +**系统能力:** SystemCapability.MiscServices.InputMethodFramework +| 参数名 | 参数类型 | 常量值 | 说明 | +| -------- | -------- | -------- | -------- | +| MAX_TYPE_NUM | number | 128 | 可支持的最大输入法个数。 | ## InputMethodProperty8+ 输入法应用属性。 -**系统能力**:以下各项对应的系统能力均为SystemCapability.MiscServices.InputMethodFramework +**系统能力:** SystemCapability.MiscServices.InputMethodFramework | 名称 | 参数类型 | 可读 | 可写 | 说明 | | -------- | -------- | -------- | -------- | -------- | -| packageName | string | 是 | 否 | 包名。 | -| methodId | string | 是 | 否 | Ability名。 | +| packageName(deprecated) | string | 是 | 否 | 输入法包名。
**说明:** 从API8开始支持,从API9开始废弃,建议使用name替代。 | +| methodId(deprecated) | string | 是 | 否 | 输入法唯一标识。
**说明:** 从API8开始支持,从API9开始废弃,建议使用id替代。 | +| name9+ | string | 是 | 否 | 输入法内部名称。 | +| id9+ | string | 是 | 否 | 输入法唯一标识。 | +| label9+ | string | 是 | 否 | 输入法对外显示名称。 | +| icon9+ | string | 是 | 否 | 输入法图标数据。 | +| iconId9+ | number | 是 | 否 | 输入法图标资源号。 | +| extra9+ | object | 是 | 否 | 输入法扩展信息。 | -## inputMethod.getInputMethodController +## inputMethod.getController9+ -getInputMethodController(): InputMethodController +getController(): InputMethodController 获取客户端实例[InputMethodController](#inputmethodcontroller)。 -**系统能力**:SystemCapability.MiscServices.InputMethodFramework +**系统能力:** SystemCapability.MiscServices.InputMethodFramework **返回值:** @@ -49,19 +54,27 @@ getInputMethodController(): InputMethodController | ----------------------------------------------- | ------------------------ | | [InputMethodController](#inputmethodcontroller) | 回调返回当前客户端实例。 | +**错误码:** + +以下错误码的详细介绍请参见[输入法框架错误码](../errorcodes/errcode-inputmethod-framework.md)。 + +| 错误码ID | 错误码信息 | +| -------- | ------------------------------ | +| 12800006 | Input method controller error. | + **示例:** ```js - var InputMethodController = inputMethod.getInputMethodController(); +let InputMethodController = inputMethod.getController(); ``` -## inputMethod.getInputMethodSetting8+ +## inputMethod.getSetting9+ -getInputMethodSetting(): InputMethodSetting +getSetting(): InputMethodSetting 获取客户端设置实例[InputMethodSetting](#inputmethodsetting8)。 -**系统能力**: SystemCapability.MiscServices.InputMethodFramework +**系统能力:** SystemCapability.MiscServices.InputMethodFramework **返回值:** @@ -69,49 +82,73 @@ getInputMethodSetting(): InputMethodSetting | ----------------------------------------- | ---------------------------- | | [InputMethodSetting](#inputmethodsetting8) | 回调返回当前客户端设置实例。 | +**错误码:** + +以下错误码的详细介绍请参见[输入法框架错误码](../errorcodes/errcode-inputmethod-framework.md)。 + +| 错误码ID | 错误码信息 | +| -------- | -------------------------------------- | +| 12800007 | Input method settings extension error. | **示例:** ```js - var InputMethodSetting = inputMethod.getInputMethodSetting(); +let InputMethodSetting = inputMethod.getSetting(); ``` + ## inputMethod.switchInputMethod9+ switchInputMethod(target: InputMethodProperty, callback: AsyncCallback<boolean>): void -切换输入法。此接口仅可在Stage模型下使用。使用callback形式返回结果。参数个数为2,否则抛出异常。 +切换输入法。使用callback异步回调。 + +**需要权限:** ohos.permission.CONNECT_IME_ABILITY -**系统能力**:SystemCapability.MiscServices.InputMethodFramework +**系统能力:** SystemCapability.MiscServices.InputMethodFramework **参数:** - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - |target | [InputmethodProperty](#inputmethodproperty8) | 是 | 传入要切换的目标输入法。 | - | callback | AsyncCallback<boolean> | 是 | 返回输入法切换是否成功。 | +| 参数名 | 类型 | 必填 | 说明 | +| -------- | -------- | -------- | -------- | +| target | [InputMethodProperty](#inputmethodproperty8) | 是 | 传入要切换的目标输入法。 | +| callback | AsyncCallback<boolean> | 是 | 回调函数。当输入法切换成功,err为undefined,data为true;否则为错误对象。 | + +**错误码:** +以下错误码的详细介绍请参见[输入法框架错误码](../errorcodes/errcode-inputmethod-framework.md)。 + +| 错误码ID | 错误码信息 | +| -------- | -------------------------------------- | +| 12800005 | Configuration persisting error. | +| 12800008 | Input method settings extension error. | **示例:** ```js -inputMethod.switchInputMethod({packageName:'com.example.kikakeyboard', methodId:'com.example.kikakeyboard'} ,(err,result) => { - if (err) { - console.error('switchInputMethod err: ' + JSON.stringify(err)); - return; - } - if (result) { - console.info('Success to switchInputMethod.(callback)'); - } else { - console.error('Failed to switchInputMethod.(callback)'); - } -}); +try{ + inputMethod.switchInputMethod({packageName:'com.example.kikakeyboard', methodId:'com.example.kikakeyboard'}, (err, result) => { + if (err) { + console.error('switchInputMethod err: ' + JSON.stringify(err)); + return; + } + if (result) { + console.info('Success to switchInputMethod.(callback)'); + } else { + console.error('Failed to switchInputMethod.(callback)'); + } + }); +} catch(err) { + console.error('switchInputMethod err: ' + JSON.stringify(err)); +} ``` ## inputMethod.switchInputMethod9+ switchInputMethod(target: InputMethodProperty): Promise<boolean> -切换输入法。此接口仅可在Stage模型下使用。使用promise形式返回结果。参数个数为1,否则抛出异常。 +切换输入法。使用promise异步回调。 -**系统能力**: SystemCapability.MiscServices.InputMethodFramework +**需要权限:** ohos.permission.CONNECT_IME_ABILITY + +**系统能力:** SystemCapability.MiscServices.InputMethodFramework **参数:** @@ -123,29 +160,42 @@ switchInputMethod(target: InputMethodProperty): Promise<boolean> | 类型 | 说明 | | ----------------------------------------- | ---------------------------- | - | Promise\ | 回调返回切换后的输入法。 | + | Promise\ | Promise对象。返回true表示切换输入法成功;返回false表示切换输入法失败。 | -**示例:** +**错误码:** +以下错误码的详细介绍请参见[输入法框架错误码](../errorcodes/errcode-inputmethod-framework.md)。 + +| 错误码ID | 错误码信息 | +| -------- | -------------------------------------- | +| 12800005 | Configuration persisting error. | +| 12800008 | Input method settings extension error. | + +**示例:** ```js -inputMethod.switchInputMethod({packageName:'com.example.kikakeyboard', methodId:'com.example.kikakeyboard'}).then((result) => { - if (result) { - console.info('Success to switchInputMethod.(promise)'); - } else { - console.error('Failed to switchInputMethod.(promise)'); - } -}).catch((err) => { - console.error('switchInputMethod promise err: ' + err); -}) +try { + inputMethod.switchInputMethod({packageName:'com.example.kikakeyboard', methodId:'com.example.kikakeyboard'}).then((result) => { + if (result) { + console.info('Success to switchInputMethod.'); + } else { + console.error('Failed to switchInputMethod.'); + } + }).catch((err) => { + console.error('switchInputMethod err: ' + JSON.stringify(err)); + }) +} catch(err) { + console.error('switchInputMethod err: ' + JSON.stringify(err)); +} ``` + ## inputMethod.getCurrentInputMethod9+ getCurrentInputMethod(): InputMethodProperty -获取当前输入法扩展应用,提供同步接口,返回当前输入法属性对象。 +获取当前输入法扩展应用,提供同步接口,返回当前输入法属性。 -**系统能力**: SystemCapability.MiscServices.InputMethodFramework +**系统能力:** SystemCapability.MiscServices.InputMethodFramework **返回值:** @@ -155,79 +205,391 @@ getCurrentInputMethod(): InputMethodProperty **示例:** +```js +let currentIme = inputMethod.getCurrentInputMethod(); +``` + +## inputMethod.switchCurrentInputMethodSubtype9+ + +switchCurrentInputMethodSubtype(target: InputMethodSubtype, callback: AsyncCallback\): void + +在当前输入法应用内切换子类型。使用callback异步回调。 + +**需要权限:** ohos.permission.CONNECT_IME_ABILITY + +**系统能力:** SystemCapability.MiscServices.InputMethodFramework + +**参数:** + +| 参数名 | 类型 | 必填 | 说明 | +| -------- | -------- | -------- | -------- | +| target | [InputMethodSubtype](./js-apis-inputmethod-subtype.md#inputmethodsubtype)| 是 | 传入要切换的目标输入法子类型。 | +| callback | AsyncCallback<boolean> | 是 | 回调函数。当输入法子类型切换成功,err为undefined,data为true;否则为错误对象。| + +**错误码:** + +以下错误码的详细介绍请参见[输入法框架错误码](../errorcodes/errcode-inputmethod-framework.md)。 + +| 错误码ID | 错误码信息 | +| -------- | -------------------------------------- | +| 12800005 | Configuration persisting error. | +| 12800008 | Input method settings extension error. | + +**示例:** + +```js +let inputMethodSubtype = { + id: "com.example.kikainput", + label: "ServiceExtAbility" +} +try { + inputMethod.switchCurrentInputMethodSubtype(inputMethodSubtype, (err, result) => { + if (err) { + console.error('switchCurrentInputMethodSubtype err: ' + JSON.stringify(err)); + return; + } + if (result) { + console.info('Success to switchCurrentInputMethodSubtype.(callback)'); + } else { + console.error('Failed to switchCurrentInputMethodSubtype.(callback)'); + } + }); +} catch(err) { + console.error('switchCurrentInputMethodSubtype err: ' + JSON.stringify(err)); +} +``` + +## inputMethod.switchCurrentInputMethodSubtype9+ + +switchCurrentInputMethodSubtype(target: InputMethodSubtype): Promise<boolean> + +在当前输入法应用内切换子类型。使用promise异步回调。 + +**需要权限:** ohos.permission.CONNECT_IME_ABILITY + +**系统能力:** SystemCapability.MiscServices.InputMethodFramework + +**参数:** + +| 参数名 | 类型 | 必填 | 说明 | +| -------- | -------- | -------- | -------- | +|target | [InputMethodSubtype](./js-apis-inputmethod-subtype.md#inputmethodsubtype)| 是 | 传入要切换的目标输入法子类型。 | + +**返回值:** + +| 类型 | 说明 | +| ----------------------------------------- | ---------------------------- | +| Promise\ | Promise对象。返回true表示在当前输入法应用内切换子类型成功;返回false表示在当前输入法应用内切换子类型失败。 | + +**错误码:** + +以下错误码的详细介绍请参见[输入法框架错误码](../errorcodes/errcode-inputmethod-framework.md)。 + +| 错误码ID | 错误码信息 | +| -------- | -------------------------------------- | +| 12800005 | Configuration persisting error. | +| 12800008 | Input method settings extension error. | + +**示例:** + +```js +let inputMethodSubtype = { + id: "com.example.kikainput", + label: "ServiceExtAbility" +} +try { + inputMethod.switchCurrentInputMethodSubtype(inputMethodSubtype).then((result) => { + if (result) { + console.info('Success to switchCurrentInputMethodSubtype.'); + } else { + console.error('Failed to switchCurrentInputMethodSubtype.'); + } + }).catch((err) => { + console.error('switchCurrentInputMethodSubtype err: ' + JSON.stringify(err)); + }) +} catch(err) { + console.error('switchCurrentInputMethodSubtype err: ' + JSON.stringify(err)); +} +``` + +## inputMethod.getCurrentInputMethodSubtype9+ + +getCurrentInputMethodSubtype(): InputMethodSubtype + +获取当前输入法子类型。 + +**系统能力:** SystemCapability.MiscServices.InputMethodFramework + +**返回值:** + +| 类型 | 说明 | +| -------------------------------------------- | ------------------------ | +| [InputMethodSubtype](./js-apis-inputmethod-subtype.md#inputmethodsubtype) | 返回当前输入法子类型对象。 | + +**示例:** + +```js +let currentImeSubType = inputMethod.getCurrentInputMethodSubtype(); +``` + +## inputMethod.switchCurrentInputMethodAndSubtype9+ + +switchCurrentInputMethodAndSubtype(inputMethodProperty: InputMethodProperty, inputMethodSubtype: InputMethodSubtype, callback: AsyncCallback\): void + +切换至指定输入法应用的指定子类型,用于跨输入法应用切换子类型。使用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/errcode-inputmethod-framework.md)。 + +| 错误码ID | 错误码信息 | +| -------- | -------------------------------------- | +| 12800005 | Configuration persisting error. | +| 12800008 | Input method settings extension error. | + +**示例:** + +```js +let inputMethodProperty = { + packageName:"com.example.kikakeyboard", + methodId:"ServiceExtAbility" +} +let inputMethodSubProperty = { + id: "com.example.kikainput", + label: "ServiceExtAbility" +} +try { + inputMethod.switchCurrentInputMethodAndSubtype(inputMethodProperty, inputMethodSubProperty, (err,result) => { + if (err) { + console.error('switchCurrentInputMethodAndSubtype err: ' + JSON.stringify(err)); + return; + } + if (result) { + console.info('Success to switchCurrentInputMethodAndSubtype.(callback)'); + } else { + console.error('Failed to switchCurrentInputMethodAndSubtype.(callback)'); + } + }); +} catch (err) { + console.error('switchCurrentInputMethodAndSubtype err: ' + JSON.stringify(err)); +} +``` + +## inputMethod.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/errcode-inputmethod-framework.md)。 + +| 错误码ID | 错误码信息 | +| -------- | -------------------------------------- | +| 12800005 | Configuration persisting error. | +| 12800008 | Input method settings extension error. | + +**示例:** + +```js +let inputMethodProperty = { + name: "com.example.kikakeyboard", + id: "ServiceExtAbility" +} +let inputMethodSubProperty = { + id: "com.example.kikakeyboard", + name: "", + locale: "", + label: "ServiceExtAbility", + language: "", + extra : {} +} +try { + inputMethod.switchCurrentInputMethodAndSubtype(property, subType).then((result) => { + if (result) { + console.info('Success to switchCurrentInputMethodAndSubtype.'); + } else { + console.error('Failed to switchCurrentInputMethodAndSubtype.'); + } + }).catch((err) => { + console.error('switchCurrentInputMethodAndSubtype err: ' + err); + }) +} catch(err) { + console.error('switchCurrentInputMethodAndSubtype err: ' + err); +} +``` + +## inputMethod.getInputMethodController(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 -var currentIme = inputMethod.getCurrentInputMethod(); +let InputMethodSetting = inputMethod.getInputMethodSetting(); ``` ## InputMethodController -下列API示例中都需使用[getInputMethodController](#inputmethodgetinputmethodcontroller)回调获取到InputMethodController实例,再通过此实例调用对应方法。 +下列API示例中都需使用[getController](#inputmethodgetcontroller9)回调获取到InputMethodController实例,再通过此实例调用对应方法。 -### stopInput +### stopInputSession9+ -stopInput(callback: AsyncCallback<boolean>): void +stopInputSession(callback: AsyncCallback<boolean>): void -隐藏输入法。使用callback形式返回结果。参数个数为1,否则抛出异常。 +结束输入会话。使用callback异步回调。 -**系统能力**:SystemCapability.MiscServices.InputMethodFramework +**系统能力:** SystemCapability.MiscServices.InputMethodFramework **参数:** | 参数名 | 类型 | 必填 | 说明 | | -------- | -------- | -------- | -------- | -| callback | AsyncCallback<boolean> | 是 | 返回输入法隐藏是否成功。 | +| callback | AsyncCallback<boolean> | 是 | 回调函数。当输入法隐藏成功,err为undefined,data为true;否则为错误对象。 | + +**错误码:** + +以下错误码的详细介绍请参见[输入法框架错误码](../errorcodes/errcode-inputmethod-framework.md)。 + +| 错误码ID | 错误码信息 | +| -------- | -------------------------------------- | +| 12800003 | Input method client error. | +| 12800008 | Input method settings extension error. | **示例:** ```js -InputMethodController.stopInput((error, result) => { - if (error) { - console.error('failed to stopInput because: ' + JSON.stringify(error)); - return; - } - if (result) { - console.info('Success to stopInput.(callback)'); - } else { - console.error('Failed to stopInput.(callback)'); - } -}); +try { + InputMethodController.stopInputSession((error, result) => { + if (error) { + console.error('stopInputSession err: ' + JSON.stringify(error)); + return; + } + if (result) { + console.info('Success to stopInputSession.(callback)'); + } else { + console.error('Failed to stopInputSession.(callback)'); + } + }); +} catch(error) { + console.error('stopInputSession err: ' + JSON.stringify(error)); +} ``` -### stopInput +### stopInputSession9+ -stopInput(): Promise<boolean> +stopInputSession(): Promise<boolean> -隐藏输入法。使用promise形式返回结果。参数个数为0,否则抛出异常。 +结束输入会话。使用promise异步回调。 -**系统能力**: SystemCapability.MiscServices.InputMethodFramework +**系统能力:** SystemCapability.MiscServices.InputMethodFramework **返回值:** | 类型 | 说明 | | -------- | -------- | -| Promise<boolean> | 返回输入法隐藏是否成功。 | +| Promise<boolean> | Promise对象。返回true表示输入法隐藏成功;返回false表示输入法隐藏失败。 | -**示例:** +**错误码:** +以下错误码的详细介绍请参见[输入法框架错误码](../errorcodes/errcode-inputmethod-framework.md)。 + +| 错误码ID | 错误码信息 | +| -------- | -------------------------------------- | +| 12800003 | Input method client error. | +| 12800008 | Input method settings extension error. | + +**示例:** ```js -InputMethodController.stopInput().then((result) => { - if (result) { - console.info('Success to stopInput.(promise)'); - } else { - console.error('Failed to stopInput.(promise)'); - } -}).catch((err) => { - console.error('stopInput promise err: ' + err); -}) +try { + InputMethodController.stopInputSession().then((result) => { + if (result) { + console.info('Success to stopInputSession.'); + } else { + console.error('Failed to stopInputSession.'); + } + }).catch((err) => { + console.error('stopInputSession err: ' + JSON.stringify(err)); + }) +} catch(err) { + console.error('stopInputSession err: ' + JSON.stringify(err)); +} ``` -### showSoftKeyboard9+ ### +### showSoftKeyboard9+ showSoftKeyboard(callback: AsyncCallback<void>): void -显示软键盘,使用callback异步回调。参数个数为1,否则抛出异常。 +显示软键盘。使用callback异步回调。 + +**需要权限:** ohos.permission.CONNECT_IME_ABILITY **系统能力:** SystemCapability.MiscServices.InputMethodFramework @@ -235,7 +597,16 @@ showSoftKeyboard(callback: AsyncCallback<void>): void | 参数名 | 参数类型 | 必填 | 说明 | | -------- | ------------------------- | ---- | ---------- | -| callback | AsyncCallback<void> | 是 | 回调函数。 | +| callback | AsyncCallback<void> | 是 | 回调函数。当软键盘显示成功。err为undefined,否则为错误对象。 | + +**错误码:** + +以下错误码的详细介绍请参见[输入法框架错误码](../errorcodes/errcode-inputmethod-framework.md)。 + +| 错误码ID | 错误码信息 | +| -------- | -------------------------------------- | +| 12800003 | Input method client error. | +| 12800008 | Input method settings extension error. | **示例:** @@ -249,12 +620,13 @@ InputMethodController.showSoftKeyboard((err) => { }) ``` - -### showSoftKeyboard9+ ### +### showSoftKeyboard9+ showSoftKeyboard(): Promise<void> -显示软键盘,使用Promise异步回调。参数个数为0,否则抛出异常。 +显示软键盘,使用Promise异步回调。 + +**需要权限:** ohos.permission.CONNECT_IME_ABILITY **系统能力:** SystemCapability.MiscServices.InputMethodFramework @@ -264,21 +636,32 @@ showSoftKeyboard(): Promise<void> | ------------------- | ------------------------- | | Promise<void> | 无返回结果的Promise对象。 | +**错误码:** + +以下错误码的详细介绍请参见[输入法框架错误码](../errorcodes/errcode-inputmethod-framework.md)。 + +| 错误码ID | 错误码信息 | +| -------- | -------------------------------------- | +| 12800003 | Input method client error. | +| 12800008 | Input method settings extension error. | + **示例:** ```js InputMethodController.showSoftKeyboard().then(async (err) => { console.log('showSoftKeyboard success'); }).catch((err) => { - console.error('showSoftKeyboard promise err: ' + JSON.stringify(err)); + console.error('showSoftKeyboard err: ' + JSON.stringify(err)); }); ``` -### hideSoftKeyboard9+ ### +### hideSoftKeyboard9+ hideSoftKeyboard(callback: AsyncCallback<void>): void -隐藏软键盘,使用callback异步回调。参数个数为1,否则抛出异常。 +隐藏软键盘。使用callback异步回调。 + +**需要权限:** ohos.permission.CONNECT_IME_ABILITY **系统能力:** SystemCapability.MiscServices.InputMethodFramework @@ -286,7 +669,16 @@ hideSoftKeyboard(callback: AsyncCallback<void>): void | 参数名 | 参数类型 | 必填 | 说明 | | -------- | ------------------------- | ---- | ---------- | -| callback | AsyncCallback<void> | 是 | 回调函数。 | +| callback | AsyncCallback<void> | 是 | 回调函数。当软键盘隐藏成功。err为undefined,否则为错误对象。 | + +**错误码:** + +以下错误码的详细介绍请参见[输入法框架错误码](../errorcodes/errcode-inputmethod-framework.md)。 + +| 错误码ID | 错误码信息 | +| -------- | -------------------------------------- | +| 12800003 | Input method client error. | +| 12800008 | Input method settings extension error. | **示例:** @@ -300,13 +692,14 @@ InputMethodController.hideSoftKeyboard((err) => { }) ``` - -### hideSoftKeyboard9+ ### +### hideSoftKeyboard9+ hideSoftKeyboard(): Promise<void> 隐藏软键盘,使用Promise异步回调。参数个数为0,否则抛出异常。 +**需要权限:** ohos.permission.CONNECT_IME_ABILITY + **系统能力:** SystemCapability.MiscServices.InputMethodFramework **返回值:** @@ -315,54 +708,356 @@ hideSoftKeyboard(): Promise<void> | ------------------- | ------------------------- | | Promise<void> | 无返回结果的Promise对象。 | +**错误码:** + +以下错误码的详细介绍请参见[输入法框架错误码](../errorcodes/errcode-inputmethod-framework.md)。 + +| 错误码ID | 错误码信息 | +| -------- | -------------------------------------- | +| 12800003 | Input method client error. | +| 12800008 | Input method settings extension error. | + **示例:** ```js InputMethodController.hideSoftKeyboard().then(async (err) => { console.log('hideSoftKeyboard success'); }).catch((err) => { - console.error('hideSoftKeyboard promise err: ' + JSON.stringify(err)); + console.error('hideSoftKeyboard err: ' + 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((error, result) => { + if (error) { + console.error('failed to stopInput because: ' + JSON.stringify(error)); + return; + } + if (result) { + console.info('Success to stopInput.(callback)'); + } else { + console.error('Failed to stopInput.(callback)'); + } +}); +``` + +### stopInput(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.info('Success to stopInput.'); + } else { + console.error('Failed to stopInput.'); + } +}).catch((err) => { + console.error('stopInput err: ' + err); +}) +``` + ## InputMethodSetting8+ -下列API示例中都需使用[getInputMethodSetting](#inputmethodgetinputmethodcontroller)回调获取到InputMethodSetting实例,再通过此实例调用对应方法。 +下列API示例中都需使用[getSetting](#inputmethodgetsetting9)回调获取到InputMethodSetting实例,再通过此实例调用对应方法。 + +### on('imeChange')9+ + +on(type: 'imeChange', callback: (inputMethodProperty: InputMethodProperty, inputMethodSubtype: InputMethodSubtype) => void): void + +订阅输入法及子类型变化监听事件。使用callback异步回调。 + +**系统能力:** SystemCapability.MiscServices.InputMethodFramework + +**参数:** + +| 参数名 | 类型 | 必填 | 说明 | +| -------- | ------------------------------- | ---- | ------------------------------------------------------------ | +| type | string | 是 | 设置监听类型。
-type为‘imeChange’时表示订阅输入法及子类型变化监听事件。 | +| callback | [InputMethodProperty](#inputmethodproperty8), [InputMethodSubtype](./js-apis-inputmethod-subtype.md#inputmethodsubtype) | 是 | 回调函数,返回输入法属性对象及输入法子类型对象。 | + +**示例:** + +```js +let InputMethodSetting = inputMethod.getSetting(); +InputMethodSetting.on('imeChange', (inputMethodProperty, inputMethodSubtype) => { + InputMethodProperty = inputMethodProperty; + InputMethodSubtype = inputMethodSubtype; +}); +``` -### listInputMethod9+ +### off('imeChange')9+ -listInputMethod(enable: boolean, callback: AsyncCallback<Array<InputMethodProperty>>): void +off(type: 'imeChange', callback?: (inputMethodProperty: InputMethodProperty, inputMethodSubtype: InputMethodSubtype) => void): void -获取已激活/未激活输入法列表。参数enable取true,返回已激活输入法列表,取false返回未激活输入法列表。使用callback形式返回结果。参数个数为2,否则抛出异常。 +取消订阅输入法及子类型变化监听事件。使用callback异步回调。 -**系统能力**: SystemCapability.MiscServices.InputMethodFramework +**系统能力:** SystemCapability.MiscServices.InputMethodFramework + +**参数:** + +| 参数名 | 类型 | 必填 | 说明 | +| -------- | ------------------------------- | ---- | ------------------------------------------------------------ | +| type | string | 是 | 设置监听类型。
-type为‘imeChange’时表示取消订阅输入法及子类型变化监听事件。 | +| callback | [InputMethodProperty](#inputmethodproperty8), [InputMethodSubtype](./js-apis-inputmethod-subtype.md#inputmethodsubtype) | 否 | 回调函数,返回取消订阅的输入法属性对象及输入法子类型对象。 | + +**示例:** + +```js +let InputMethodSetting = inputMethod.getSetting(); +InputMethodSetting.off('imeChange'); +``` + +### listInputMethodSubtype9+ + +listInputMethodSubtype(inputMethodProperty: InputMethodProperty, callback: AsyncCallback<Array<InputMethodSubtype>>): void + +获取指定输入法应用的所有子类型。使用callback异步回调。 + +**系统能力:** SystemCapability.MiscServices.InputMethodFramework + +**参数:** + +| 参数名 | 类型 | 必填 | 说明 | +| -------- | -------------------------------------------------- | ---- | ---------------------- | +| inputMethodProperty | InputMethodProperty| 是 | 指定获取子类型所属的输入法应用。 | +| callback | Array<[InputMethodSubtype](./js-apis-inputmethod-subtype.md#inputmethodsubtype)> | 是 | 回调函数,返回指定输入法应用的所有子类型。 | + +**错误码:** + +以下错误码的详细介绍请参见[输入法框架错误码](../errorcodes/errcode-inputmethod-framework.md)。 + +| 错误码ID | 错误码信息 | +| -------- | -------------------------------------- | +| 12800001 | Package manager error. | +| 12800008 | Input method settings extension error. | + +**示例:** + +```js +let inputMethodProperty = { + packageName:'com.example.kikakeyboard', + methodId:'com.example.kikakeyboard' +} +try { + InputMethodSetting.listInputMethodSubtype(inputMethodProperty, (err,data) => { + if (err) { + console.error('listInputMethodSubtype failed: ' + JSON.stringify(err)); + return; + } + console.log('listInputMethodSubtype success'); + }); +} catch (err) { + console.error('listInputMethodSubtype failed: ' + JSON.stringify(err)); +} +``` + +### listInputMethodSubtype9+ + +listInputMethodSubtype(inputMethodProperty: InputMethodProperty): Promise<Array<InputMethodSubtype>> + +获取指定输入法应用的所有子类型。使用promise异步回调。 + +**系统能力:** SystemCapability.MiscServices.InputMethodFramework + +**参数:** + +| 参数名 | 类型 | 必填 | 说明 | +| -------- | -------------------------------------------------- | ---- | ---------------------- | +| inputMethodProperty | InputMethodProperty| 是 | 指定获取子类型所属的输入法应用。 | + +**返回值:** + +| 类型 | 说明 | +| ----------------------------------------------------------- | ---------------------- | +| Promise> | Promise对象,返回已安装输入法子类型列表。 | + +**错误码:** + +以下错误码的详细介绍请参见[输入法框架错误码](../errorcodes/errcode-inputmethod-framework.md)。 + +| 错误码ID | 错误码信息 | +| -------- | -------------------------------------- | +| 12800001 | Package manager error. | +| 12800008 | Input method settings extension error. | + +**示例:** + +```js +let inputMethodProperty = { + packageName:'com.example.kikakeyboard', + methodId:'com.example.kikakeyboard', +} +try { + InputMethodSetting.listInputMethodSubtype(inputMethodProperty).then((data) => { + console.info('listInputMethodSubtype success'); + }).catch((err) => { + console.error('listInputMethodSubtype err: ' + JSON.stringify(err)); + }) +} catch(err) { + console.error('listInputMethodSubtype err: ' + JSON.stringify(err)); +} +``` + +### listCurrentInputMethodSubtype9+ + +listCurrentInputMethodSubtype(callback: AsyncCallback<Array<InputMethodSubtype>>): void + +查询当前输入法应用的所有子类型。使用callback异步回调。 + +**系统能力:** SystemCapability.MiscServices.InputMethodFramework + +**参数:** + +| 参数名 | 类型 | 必填 | 说明 | +| -------- | -------------------------------------------------- | ---- | ---------------------- | +| callback | Array<[InputMethodSubtype](./js-apis-inputmethod-subtype.md#inputmethodsubtype)> | 是 | 回调函数,返回当前输入法应用的所有子类型。 | + +**错误码:** + +以下错误码的详细介绍请参见[输入法框架错误码](../errorcodes/errcode-inputmethod-framework.md)。 + +| 错误码ID | 错误码信息 | +| -------- | -------------------------------------- | +| 12800001 | Package manager error. | +| 12800008 | Input method settings extension error. | + +**示例:** + +```js +try { + InputMethodSetting.listCurrentInputMethodSubtype((err, data) => { + if (err) { + console.error('listCurrentInputMethodSubtype failed: ' + JSON.stringify(err)); + return; + } + console.log('listCurrentInputMethodSubtype success'); + }); +} catch(err) { + console.error('listCurrentInputMethodSubtype err: ' + JSON.stringify(err)); +} +``` + +### listCurrentInputMethodSubtype9+ + +listCurrentInputMethodSubtype(): Promise<Array<InputMethodSubtype>> + +查询当前输入法的子类型列表。使用promise异步回调。 + +**系统能力:** SystemCapability.MiscServices.InputMethodFramework + +**返回值:** + +| 类型 | 说明 | +| ----------------------------------------------------------- | ---------------------- | +| Promise> | Promise对象,返回当前输入法的子类型列表。 | + +**错误码:** + +以下错误码的详细介绍请参见[输入法框架错误码](../errorcodes/errcode-inputmethod-framework.md)。 + +| 错误码ID | 错误码信息 | +| -------- | -------------------------------------- | +| 12800001 | Package manager error. | +| 12800008 | Input method settings extension error. | + +**示例:** + +```js +try { + InputMethodSetting.listCurrentInputMethodSubtype().then((data) => { + console.info('listCurrentInputMethodSubtype success'); + }).catch((err) => { + console.error('listCurrentInputMethodSubtype err: ' + err); + }) +} catch(err) { + console.error('listCurrentInputMethodSubtype err: ' + JSON.stringify(err)); +} +``` + +### getInputMethods9+ + +getInputMethods(enable: boolean, callback: AsyncCallback<Array<InputMethodProperty>>): void + +获取已激活/未激活输入法列表。参数enable取true,返回已激活输入法列表,取false返回未激活输入法列表。使用callback异步回调。 + +**系统能力:** SystemCapability.MiscServices.InputMethodFramework **参数:** | 参数名 | 类型 | 必填 | 说明 | | -------- | --------------------------------------------------- | ---- | ----------------------------- | | enable | boolean | 是 | 指定返回已激活/未激活。 | -| callback | Array<[InputMethodProperty](#inputmethodproperty8)> | 是 | 返回已激活/未激活输入法列表。 | +| callback | Array<[InputMethodProperty](#inputmethodproperty8)> | 是 | 回调函数,返回已激活/未激活输入法列表。 | + +**错误码:** + +以下错误码的详细介绍请参见[输入法框架错误码](../errorcodes/errcode-inputmethod-framework.md)。 + +| 错误码ID | 错误码信息 | +| -------- | -------------------------------------- | +| 12800001 | Package manager error. | +| 12800008 | Input method settings extension error. | **示例:** ```js -InputMethodSetting.listInputMethod(true, (err,data) => { - if (err) { - console.error('listInputMethod failed because: ' + JSON.stringify(err)); - return; - } - console.log('listInputMethod success'); - }); +try { + InputMethodSetting.getInputMethods(true, (err,data) => { + if (err) { + console.error('getInputMethods failed: ' + JSON.stringify(err)); + return; + } + console.log('getInputMethods success'); + }); +} catch (err) { + console.error('getInputMethods failed: ' + JSON.stringify(err)); +} ``` -### listInputMethod9+ +### getInputMethods9+ -listInputMethod(enable: boolean): Promise<Array<InputMethodProperty>> +getInputMethods(enable: boolean): Promise<Array<InputMethodProperty>> -获取已激活/未激活输入法列表。参数enable取true返回已激活输入法列表,取false返回未激活输入法列表。使用promise形式返回结果。参数个数为0,否则抛出异常。 +获取已激活/未激活输入法列表。参数enable取true返回已激活输入法列表,取false返回未激活输入法列表。使用promise异步回调。 -**系统能力**: SystemCapability.MiscServices.InputMethodFramework +**系统能力:** SystemCapability.MiscServices.InputMethodFramework **参数:** @@ -370,35 +1065,126 @@ listInputMethod(enable: boolean): Promise<Array<InputMethodProperty>> | ------ | ------- | ---- | ----------------------- | | enable | boolean | 是 | 指定返回已激活/未激活。 | +**错误码:** + +以下错误码的详细介绍请参见[输入法框架错误码](../errorcodes/errcode-inputmethod-framework.md)。 + +| 错误码ID | 错误码信息 | +| -------- | -------------------------------------- | +| 12800001 | Package manager error. | +| 12800008 | Input method settings extension error. | + **返回值:** | 类型 | 说明 | | ------------------------------------------------------------ | ----------------------------- | -| Promise> | 返回已激活/未激活输入法列表。 | +| Promise> | Promise对象,返回已激活/未激活输入法列表。 | **示例:** ```js -InputMethodSetting.listInputMethod(true).then((data) => { - console.info('listInputMethod success'); +try { + InputMethodSetting.getInputMethods(true).then((data) => { + console.info('getInputMethods success'); + }).catch((err) => { + console.error('getInputMethods err: ' + JSON.stringify(err)); + }) +} catch(err) { + console.error('getInputMethods err: ' + JSON.stringify(err)); +} +``` + +### showOptionalInputMethods9+ + +showOptionalInputMethods(callback: AsyncCallback<boolean>): void + +显示输入法选择对话框。使用callback异步回调。 + +**需要权限:** ohos.permission.CONNECT_IME_ABILITY + +**系统能力:** SystemCapability.MiscServices.InputMethodFramework + +**参数:** + +| 参数名 | 类型 | 必填 | 说明 | +| -------- | -------- | -------- | -------- | +| callback | AsyncCallback<boolean> | 是 | 回调函数。当输入法选择对话框显示成功,err为undefined,data为true;否则为错误对象。 | + +**错误码:** + +以下错误码的详细介绍请参见[输入法框架错误码](../errorcodes/errcode-inputmethod-framework.md)。 + +| 错误码ID | 错误码信息 | +| -------- | -------------------------------------- | +| 12800008 | Input method settings extension error. | + +**示例:** + +```js +try { + InputMethodSetting.showOptionalInputMethods((err, data) => { + if (err) { + console.error('showOptionalInputMethods failed: ' + JSON.stringify(err)); + return; + } + console.info('showOptionalInputMethods success'); + }); +} catch (err) { + console.error('showOptionalInputMethods failed: ' + JSON.stringify(err)); +} +``` + +### showOptionalInputMethods9+ + +showOptionalInputMethods(): Promise<boolean> + +显示输入法选择对话框。使用promise异步回调。 + +**需要权限:** ohos.permission.CONNECT_IME_ABILITY + +**系统能力:** SystemCapability.MiscServices.InputMethodFramework + +**返回值:** + +| 类型 | 说明 | +| -------- | -------- | +| Promise<boolean> | Promise对象。返回true表示输入法选择对话框显示成功;返回false表示输入法选择对话框显示失败。 | + +**错误码:** + +以下错误码的详细介绍请参见[输入法框架错误码](../errorcodes/errcode-inputmethod-framework.md)。 + +| 错误码ID | 错误码信息 | +| -------- | -------------------------------------- | +| 12800008 | Input method settings extension error. | + +**示例:** + +```js +InputMethodSetting.showOptionalInputMethods().then((data) => { + console.info('displayOptionalInputMethod success.'); }).catch((err) => { - console.error('listInputMethod promise err: ' + err); + console.error('displayOptionalInputMethod err: ' + err); }) ``` -### listInputMethod +### listInputMethod(deprecated) listInputMethod(callback: AsyncCallback<Array<InputMethodProperty>>): void -查询已安装的输入法列表。使用callback形式返回结果。参数个数为1,否则抛出异常。 +查询已安装的输入法列表。使用callback异步回调。 -**系统能力**: SystemCapability.MiscServices.InputMethodFramework +> **说明:** +> +> 从API version 8开始支持,从API version 9开始废弃, 建议使用[getInputMethods](#getinputmethods9)替代。 + +**系统能力:** SystemCapability.MiscServices.InputMethodFramework **参数:** | 参数名 | 类型 | 必填 | 说明 | | -------- | -------------------------------------------------- | ---- | ---------------------- | -| callback | Array<[InputMethodProperty](#inputmethodproperty8)> | 是 | 返回已安装输入法列表。 | +| callback | Array<[InputMethodProperty](#inputmethodproperty8)> | 是 | 回调函数,返回已安装的输入法列表。 | **示例:** @@ -412,19 +1198,23 @@ InputMethodSetting.listInputMethod((err,data) => { }); ``` -### listInputMethod +### listInputMethod(deprecated) listInputMethod(): Promise<Array<InputMethodProperty>> -查询已安装的输入法列表。使用promise形式返回结果。参数个数为0,否则抛出异常。 +查询已安装的输入法列表。使用promise异步回调。 + +> **说明:** +> +> 从API version 8开始支持,从API version 9开始废弃, 建议使用[getInputMethods](#getinputmethods9-1)替代。 -**系统能力**: SystemCapability.MiscServices.InputMethodFramework +**系统能力:** SystemCapability.MiscServices.InputMethodFramework **返回值:** | 类型 | 说明 | | ----------------------------------------------------------- | ---------------------- | -| Promise> | 返回已安装输入法列表。 | +| Promise> | Promise对象,返回已安装输入法列表。 | **示例:** @@ -432,23 +1222,27 @@ listInputMethod(): Promise<Array<InputMethodProperty>> InputMethodSetting.listInputMethod().then((data) => { console.info('listInputMethod success'); }).catch((err) => { - console.error('listInputMethod promise err: ' + err); + console.error('listInputMethod err: ' + JSON.stringify(err)); }) ``` -### displayOptionalInputMethod +### displayOptionalInputMethod(deprecated) displayOptionalInputMethod(callback: AsyncCallback<void>): void -显示输入法选择对话框。使用callback形式返回结果。参数个数为1,否则抛出异常。 +显示输入法选择对话框。使用callback异步回调。 -**系统能力**: SystemCapability.MiscServices.InputMethodFramework +> **说明:** +> +> 从API version 8开始支持,从API version 9开始废弃, 建议使用[showOptionalInputMethods()](#showoptionalinputmethods9)替代。 + +**系统能力:** SystemCapability.MiscServices.InputMethodFramework **参数:** | 参数名 | 类型 | 必填 | 说明 | | -------- | -------- | -------- | -------- | -| callback | AsyncCallback<void> | 是 | 回调函数。 | +| callback | AsyncCallback<void> | 是 | 回调函数。当输入法选择对话框显示成功。err为undefined,否则为错误对象。 | **示例:** @@ -462,13 +1256,17 @@ InputMethodSetting.displayOptionalInputMethod((err) => { }); ``` -### displayOptionalInputMethod +### displayOptionalInputMethod(deprecated) + +displayOptionalInputMethod(): Promise<void> - displayOptionalInputMethod(): Promise<void> +显示输入法选择对话框。使用promise异步回调。 - 显示输入法选择对话框。使用promise形式返回结果。参数个数为0,否则抛出异常。 +> **说明:** +> +> 从API version 8开始支持,API version 9开始废弃, 建议使用[showOptionalInputMethods()](#showoptionalinputmethods9-1)替代。 - **系统能力**: SystemCapability.MiscServices.InputMethodFramework +**系统能力:** SystemCapability.MiscServices.InputMethodFramework **返回值:** @@ -480,8 +1278,8 @@ InputMethodSetting.displayOptionalInputMethod((err) => { ```js InputMethodSetting.displayOptionalInputMethod().then(() => { - console.info('displayOptionalInputMethod success.(promise)'); + console.info('displayOptionalInputMethod success'); }).catch((err) => { - console.error('displayOptionalInputMethod promise err: ' + err); + console.error('displayOptionalInputMethod err: ' + err); }) -``` \ No newline at end of file +``` 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 40bbe0fdb9bee5e1d71374c064528a423a758ed9..d98281b3b4215925417165965c8982f2723f0164 100644 --- a/zh-cn/application-dev/reference/apis/js-apis-inputmethodengine.md +++ b/zh-cn/application-dev/reference/apis/js-apis-inputmethodengine.md @@ -1,9 +1,10 @@ # 输入法服务 - 本模块的作用是拉通应用和输入法,保证应用可以通过输入法进行文本输入,以及应用与输入法服务的绑定、应用对输入法的显示和隐藏请求、监听输入法当前的状态等等。 +本模块的作用是拉通普通应用和输入法应用,功能包括:普通应用通过输入法应用进行文本输入、普通应用与输入法服务绑定、普通应用对输入法应用进行显示请求和隐藏请求、普通应用对输入法应用当前状态进行监听等等。 -> ![icon-note.gif](public_sys-resources/icon-note.gif) **说明:** -> 本模块首批接口从API version 8开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 +> **说明:** +> +>本模块首批接口从API version 8开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 ## 导入模块 @@ -11,146 +12,194 @@ import inputMethodEngine from '@ohos.inputmethodengine'; ``` -## inputMethodEngine - -常量值。 - -**系统能力**:以下各项对应的系统能力均为SystemCapability.MiscServices.InputMethodFramework - -| 名称 | 参数类型 | 可读 | 可写 | 说明 | -| -------- | -------- | -------- | -------- | -------- | -| ENTER_KEY_TYPE_UNSPECIFIED | number | 是 | 否 | 无功能键。 | -| ENTER_KEY_TYPE_GO | number | 是 | 否 | “前往”功能键。 | -| ENTER_KEY_TYPE_SEARCH | number | 是 | 否 | “搜索”功能键。 | -| ENTER_KEY_TYPE_SEND | number | 是 | 否 | “发送”功能键。 | -| ENTER_KEY_TYPE_NEXT | number | 是 | 否 | “下一个”功能键。 | -| ENTER_KEY_TYPE_DONE | number | 是 | 否 | “回车”功能键。 | -| ENTER_KEY_TYPE_PREVIOUS | number | 是 | 否 | “前一个”功能键。 | -| PATTERN_NULL | number | 是 | 否 | 无特殊性编辑框。 | -| PATTERN_TEXT | number | 是 | 否 | 文本编辑框。 | -| PATTERN_NUMBER | number | 是 | 否 | 数字编辑框。 | -| PATTERN_PHONE | number | 是 | 否 | 电话号码编辑框。 | -| PATTERN_DATETIME | number | 是 | 否 | 日期编辑框。 | -| PATTERN_EMAIL | number | 是 | 否 | 邮件编辑框。 | -| PATTERN_URI | number | 是 | 否 | 超链接编辑框。 | -| PATTERN_PASSWORD | number | 是 | 否 | 密码编辑框。 | -| OPTION_ASCII | number | 是 | 否 | 允许输入ASCII值。 | -| OPTION_NONE | number | 是 | 否 | 不指定编辑框输入属性。 | -| OPTION_AUTO_CAP_CHARACTERS | number | 是 | 否 | 允许输入字符。 | -| OPTION_AUTO_CAP_SENTENCES | number | 是 | 否 | 允许输入句子。 | -| OPTION_AUTO_WORDS | number | 是 | 否 | 允许输入单词。 | -| OPTION_MULTI_LINE | number | 是 | 否 | 允许输入多行。 | -| OPTION_NO_FULLSCREEN | number | 是 | 否 | 半屏样式。 | -| FLAG_SELECTING | number | 是 | 否 | 编辑框处于选择状态。 | -| FLAG_SINGLE_LINE | number | 是 | 否 | 编辑框为单行。 | -| DISPLAY_MODE_PART | number | 是 | 否 | 编辑框显示为半屏。 | -| DISPLAY_MODE_FULL | number | 是 | 否 | 编辑框显示为全屏。 | -| CURSOR_UP9+ | number | 是 | 否 | 光标上移。 | -| CURSOR_DOWN9+ | number | 是 | 否 | 光标下移。 | -| CURSOR_LEFT9+ | number | 是 | 否 | 光标左移。 | -| CURSOR_RIGHT9+ | number | 是 | 否 | 光标右移。 | -| WINDOW_TYPE_INPUT_METHOD_FLOAT9+ | number | 是 | 否 | 输入法应用窗口风格标识。 | - -## inputMethodEngine.getInputMethodEngine +## 常量 + +功能键常量值、编辑框常量值及光标常量值。 + +**系统能力:** SystemCapability.MiscServices.InputMethodFramework + +| 名称 | 参数类型 | 值 | 说明 | +| -------- | -------- | -------- | -------- | +| ENTER_KEY_TYPE_UNSPECIFIED | number | 0 | 无功能键。 | +| ENTER_KEY_TYPE_GO | number | 2 | “前往”功能键。 | +| ENTER_KEY_TYPE_SEARCH | number | 3 | “搜索”功能键。 | +| ENTER_KEY_TYPE_SEND | number | 4 | “发送”功能键。 | +| ENTER_KEY_TYPE_NEXT | number | 5 | “下一个”功能键。 | +| ENTER_KEY_TYPE_DONE | number | 6 | “回车”功能键。 | +| ENTER_KEY_TYPE_PREVIOUS | number | 7 | “前一个”功能键。 | +| PATTERN_NULL | number | -1 | 无特殊性编辑框。 | +| PATTERN_TEXT | number | 0 | 文本编辑框。 | +| PATTERN_NUMBER | number | 2 | 数字编辑框。 | +| PATTERN_PHONE | number | 3 | 电话号码编辑框。 | +| PATTERN_DATETIME | number | 4 | 日期编辑框。 | +| PATTERN_EMAIL | number | 5 | 邮件编辑框。 | +| PATTERN_URI | number | 6 | 超链接编辑框。 | +| PATTERN_PASSWORD | number | 7 | 密码编辑框。 | +| OPTION_ASCII | number | 20 | 允许输入ASCII值。 | +| OPTION_NONE | number | 0 | 不指定编辑框输入属性。 | +| OPTION_AUTO_CAP_CHARACTERS | number | 2 | 允许输入字符。 | +| OPTION_AUTO_CAP_SENTENCES | number | 8 | 允许输入句子。 | +| OPTION_AUTO_WORDS | number | 4 | 允许输入单词。 | +| OPTION_MULTI_LINE | number | 1 | 允许输入多行。 | +| OPTION_NO_FULLSCREEN | number | 10 | 半屏样式。 | +| FLAG_SELECTING | number | 2 | 编辑框处于选择状态。 | +| FLAG_SINGLE_LINE | number | 1 | 编辑框为单行。 | +| DISPLAY_MODE_PART | number | 0 | 编辑框显示为半屏。 | +| DISPLAY_MODE_FULL | number | 1 | 编辑框显示为全屏。 | +| CURSOR_UP9+ | number | 1 | 光标上移。 | +| CURSOR_DOWN9+ | number | 2 | 光标下移。 | +| CURSOR_LEFT9+ | number | 3 | 光标左移。 | +| CURSOR_RIGHT9+ | number | 4 | 光标右移。 | +| WINDOW_TYPE_INPUT_METHOD_FLOAT9+ | number | 2105 | 输入法应用窗口风格标识。 | + +## inputMethodEngine.getInputMethodAbility9+ + +getInputMethodAbility(): InputMethodAbility + +获取服务端实例。 + +**系统能力:** SystemCapability.MiscServices.InputMethodFramework + +**返回值:** + +| 类型 | 说明 | +| --------------------------------------- | ------------ | +| [InputMethodAbility](#inputmethodability) | 服务端实例。 | + +**示例:** + +```js +let InputMethodAbility = inputMethodAbility.getInputMethodAbility(); +``` + +## inputMethodEngine.getKeyboardDelegate9+ + +getKeyboardDelegate(): KeyboardDelegate + +获取客户端监听实例。 + +**系统能力:** SystemCapability.MiscServices.InputMethodFramework + +**返回值:** + +| 类型 | 说明 | +| ------------------------------------- | ---------------- | +| [KeyboardDelegate](#keyboarddelegate) | 客户端监听实例。 | + +**示例:** + +```js +let KeyboardDelegate = inputMethodAbility.getKeyboardDelegate(); +``` + +## inputMethodEngine.getInputMethodEngine(deprecated) getInputMethodEngine(): InputMethodEngine 获取服务端实例。 -**系统能力**: SystemCapability.MiscServices.InputMethodFramework +> **说明:** +> +>从API version 8开始支持,API version 9开始废弃, 建议使用[getInputMethodAbility()](#inputmethodenginegetinputmethodability9)替代。 + +**系统能力:** SystemCapability.MiscServices.InputMethodFramework **返回值:** | 类型 | 说明 | | --------------------------------------- | ------------ | -| [InputMethodEngine](#InputMethodEngine) | 服务端实例。 | +| [InputMethodEngine](#inputmethodengine-1) | 服务端实例。 | **示例:** - ```js - var InputMethodEngine = inputMethodEngine.getInputMethodEngine(); - ``` +```js +let InputMethodEngine = inputMethodEngine.getInputMethodEngine(); +``` -## inputMethodEngine.createKeyboardDelegate +## inputMethodEngine.createKeyboardDelegate(deprecated) createKeyboardDelegate(): KeyboardDelegate 获取客户端监听实例。 -**系统能力**: SystemCapability.MiscServices.InputMethodFramework +> **说明:** +> +>从API version 8开始支持,API version 9开始废弃, 建议使用[getKeyboardDelegate()](#inputmethodenginegetkeyboarddelegate9)替代。 + +**系统能力:** SystemCapability.MiscServices.InputMethodFramework **返回值:** | 类型 | 说明 | | ------------------------------------- | ---------------- | -| [KeyboardDelegate](#KeyboardDelegate) | 客户端监听实例。 | +| [KeyboardDelegate](#keyboarddelegate) | 客户端监听实例。 | **示例:** - ```js - var KeyboardDelegate = inputMethodEngine.createKeyboardDelegate(); - ``` +```js +let KeyboardDelegate = inputMethodEngine.createKeyboardDelegate(); +``` -## InputMethodEngine +## InputMethodEngine -下列API示例中都需使用[getInputMethodEngine](#getInputMethodEngine)回调获取到InputMethodEngine实例,再通过此实例调用对应方法。 +下列API示例中都需使用[getInputMethodEngine](#inputmethodenginegetinputmethodenginedeprecated)回调获取到InputMethodEngine实例,再通过此实例调用对应方法。 -### on('inputStart') +### on('inputStart') on(type: 'inputStart', callback: (kbController: KeyboardController, textInputClient: TextInputClient) => void): void -订阅输入法绑定成功事件,使用callback回调返回输入法操作相关实例。参数个数为2,参数1为napi_string,参数2为napi_function,否则抛出异常。 +订阅输入法绑定成功事件。使用callback异步回调。 -**系统能力**: SystemCapability.MiscServices.InputMethodFramework +**系统能力:** SystemCapability.MiscServices.InputMethodFramework **参数:** | 参数名 | 类型 | 必填 | 说明 | | -------- | ------------------------------- | ---- | ------------------------------------------------------------ | | type | string | 是 | 设置监听类型。
-type为‘inputStart’时表示订阅输入法绑定。 | -| callback | [KeyboardController](#KeyboardController), [TextInputClient](#TextInputClient) | 是 | 回调返回输入法操作相关实例。 | +| callback | [KeyboardController](#keyboardcontroller), [TextInputClient](#textinputclient) | 是 | 回调函数,返回订阅输入法的KeyboardController和TextInputClient实例。 | **示例:** - ```js - InputMethodEngine.on('inputStart', (kbController, textInputClient) => { - KeyboardController = kbController; - TextInputClient = textInputClient; - }); - ``` +```js +inputMethodEngine.getInputMethodEngine().on('inputStart', (kbController, textInputClient) => { + KeyboardController = kbController; + TextInputClient = textInputClient; +}); +``` ### off('inputStart') off(type: 'inputStart', callback?: (kbController: KeyboardController, textInputClient: TextInputClient) => void): void -取消订阅输入法绑定成功事件。参数个数不为1或2抛出异常。若为1,参数不为napi_string抛出异常;若为2,参数1不为napi_string,参数2不为napi_function抛出异常。参数若为1,取消此类型所有监听;参数若为2,取消此类型当前监听。 +取消订阅输入法绑定成功事件。 -**系统能力**: SystemCapability.MiscServices.InputMethodFramework +**系统能力:** SystemCapability.MiscServices.InputMethodFramework **参数:** | 参数名 | 类型 | 必填 | 说明 | | -------- | -------------------- | ---- | ------------------------ | | type | string | 是 | 设置监听类型。
-type为‘inputStart’时表示订阅输入法绑定。 | -| callback | [KeyboardController](#KeyboardController), [TextInputClient](#TextInputClient) | 否 | 回调返回输入法操作相关实例。 | +| callback | [KeyboardController](#keyboardcontroller), [TextInputClient](#textinputclient) | 否 | 回调函数,返回取消订阅的KeyboardController和TextInputClient实例。 | **示例:** - ```js - InputMethodEngine.off('inputStart', (kbController, textInputClient) => { - console.log('delete inputStart notification.'); - }); - ``` +```js +inputMethodEngine.getInputMethodEngine().off('inputStart', (kbController, textInputClient) => { + console.log('delete inputStart notification.'); +}); +``` ### on('inputStop')9+ on(type: 'inputStop', callback: () => void): void -订阅停止输入法应用事件,使用callback回调。 +订阅停止输入法应用事件。使用callback异步回调。 -**系统能力**: SystemCapability.MiscServices.InputMethodFramework +**系统能力:** SystemCapability.MiscServices.InputMethodFramework **参数:** @@ -161,19 +210,19 @@ on(type: 'inputStop', callback: () => void): void **示例:** - ```js -InputMethodEngine.getInputMethodEngine().on('inputStop', () => { +```js +inputMethodEngine.getInputMethodEngine().on('inputStop', () => { console.log('inputMethodEngine inputStop'); }); - ``` +``` ### off('inputStop')9+ off(type: 'inputStop', callback: () => void): void -取消订阅停止输入法应用事件。使用callback回调。 +取消订阅停止输入法应用事件。使用callback异步回调。 -**系统能力**: SystemCapability.MiscServices.InputMethodFramework +**系统能力:** SystemCapability.MiscServices.InputMethodFramework **参数:** @@ -184,65 +233,65 @@ off(type: 'inputStop', callback: () => void): void **示例:** - ```js -InputMethodEngine.getInputMethodEngine().off('inputStop', () => { +```js +inputMethodEngine.getInputMethodEngine().off('inputStop', () => { console.log('inputMethodEngine delete inputStop notification.'); }); - ``` +``` ### on('setCallingWindow')9+ on(type: 'setCallingWindow', callback: (wid:number) => void): void -订阅设置调用窗口事件,使用callback回调。 +订阅设置调用窗口事件。使用callback异步回调。 -**系统能力**: SystemCapability.MiscServices.InputMethodFramework +**系统能力:** SystemCapability.MiscServices.InputMethodFramework **参数:** | 参数名 | 类型 | 必填 | 说明 | | -------- | ------ | ---- | ------------------------------------------------------------ | | type | string | 是 | 设置监听类型。
-type为‘setCallingWindow’时表示订阅设置调用窗口事件。 | -| callback | number | 是 | 调用方window id。 | +| callback | number | 是 | 回调函数,返回调用方window id。 | **示例:** - ```js -InputMethodEngine.getInputMethodEngine().on('setCallingWindow', (wid) => { +```js +inputMethodEngine.getInputMethodEngine().on('setCallingWindow', (wid) => { console.log('inputMethodEngine setCallingWindow'); }); - ``` +``` ### off('setCallingWindow')9+ off(type: 'setCallingWindow', callback: (wid:number) => void): void -取消订阅设置调用窗口事件。使用callback回调。 +取消订阅设置调用窗口事件。使用callback异步回调。 -**系统能力**: SystemCapability.MiscServices.InputMethodFramework +**系统能力:** SystemCapability.MiscServices.InputMethodFramework **参数:** | 参数名 | 类型 | 必填 | 说明 | | -------- | ------ | ---- | ------------------------------------------------------------ | | type | string | 是 | 设置监听类型。
-type为‘setCallingWindow’时表示订阅设置调用窗口事件。 | -| callback | number | 是 | 调用方window id。 | +| callback | number | 是 | 回调函数,返回调用方window id。 | **示例:** - ```js -InputMethodEngine.getInputMethodEngine().off('setCallingWindow', () => { +```js +inputMethodEngine.getInputMethodEngine().off('setCallingWindow', () => { console.log('inputMethodEngine delete setCallingWindow notification.'); }); - ``` +``` ### on('keyboardShow'|'keyboardHide') on(type: 'keyboardShow'|'keyboardHide', callback: () => void): void -订阅输入法事件。参数个数为2,参数1为napi_string,参数2为napi_function,否则抛出异常。 +订阅输入法事件。使用callback异步回调。 -**系统能力**: SystemCapability.MiscServices.InputMethodFramework +**系统能力:** SystemCapability.MiscServices.InputMethodFramework **参数:** @@ -253,22 +302,217 @@ on(type: 'keyboardShow'|'keyboardHide', callback: () => void): void **示例:** - ```js - InputMethodEngine.on('keyboardShow', () => { - console.log('inputMethodEngine keyboardShow.'); - }); - InputMethodEngine.on('keyboardHide', () => { - console.log('inputMethodEngine keyboardHide.'); - }); - ``` +```js +inputMethodEngine.getInputMethodEngine().on('keyboardShow', () => { + console.log('inputMethodEngine keyboardShow.'); +}); +inputMethodEngine.getInputMethodEngine().on('keyboardHide', () => { + console.log('inputMethodEngine keyboardHide.'); +}); +``` ### off('keyboardShow'|'keyboardHide') off(type: 'keyboardShow'|'keyboardHide', callback?: () => void): void -取消订阅输入法事件。参数个数不为1或2抛出异常。若为1,参数不为napi_string抛出异常;若为2,参数1不为napi_string,参数2不为napi_function抛出异常。参数若为1,取消此类型所有监听;参数若为2,取消此类型当前监听。 +取消订阅输入法事件。使用callback异步回调。 + +**系统能力:** SystemCapability.MiscServices.InputMethodFramework + +**参数:** + +| 参数名 | 类型 | 必填 | 说明 | +| -------- | ------ | ---- | ------------------------------------------------------------ | +| type | string | 是 | 设置监听类型。
- type为'keyboardShow',表示订阅输入法显示。
- type为'keyboardHide',表示订阅输入法隐藏。 | +| callback | void | 否 | 回调函数。 | + +**示例:** + +```js +inputMethodEngine.getInputMethodEngine().off('keyboardShow', () => { + console.log('inputMethodEngine delete keyboardShow notification.'); +}); +inputMethodEngine.getInputMethodEngine().off('keyboardHide', () => { + console.log('inputMethodEngine delete keyboardHide notification.'); +}); +``` + +## InputMethodAbility + +下列API示例中都需使用[getInputMethodAbility](#inputmethodenginegetinputmethodability9)回调获取到InputMethodAbility实例,再通过此实例调用对应方法。 + +### on('inputStart')9+ + +on(type: 'inputStart', callback: (kbController: KeyboardController, inputClient: InputClient) => void): void + +订阅输入法绑定成功事件。使用callback异步回调。 + +**系统能力:** SystemCapability.MiscServices.InputMethodFramework + +**参数:** + +| 参数名 | 类型 | 必填 | 说明 | +| -------- | ------------------------------- | ---- | ------------------------------------------------------------ | +| type | string | 是 | 设置监听类型。
-type为‘inputStart’时表示订阅输入法绑定。 | +| callback | [KeyboardController](#keyboardcontroller), [InputClient](#inputclient9) | 是 | 回调函数,返回输入法操作相关实例。 | + +**示例:** + +```js +inputMethodEngine.getInputMethodAbility().on('inputStart', (kbController, inputClient) => { + KeyboardController = kbController; + InputClient = inputClient; +}); +``` + +### off('inputStart')9+ + +off(type: 'inputStart', callback?: (kbController: KeyboardController, inputClient: InputClient) => void): void + +取消订阅输入法绑定成功事件。使用callback异步回调。 + +**系统能力:** SystemCapability.MiscServices.InputMethodFramework + +**参数:** + +| 参数名 | 类型 | 必填 | 说明 | +| -------- | -------------------- | ---- | ------------------------ | +| type | string | 是 | 设置监听类型。
-type为‘inputStart’时表示订阅输入法绑定。 | +| callback | [KeyboardController](#keyboardcontroller), [InputClient](#inputclient9) | 否 | 回调函数,返回输入法操作相关实例。 | + +**示例:** + +```js +inputMethodEngine.getInputMethodAbility().off('inputStart', (kbController, inputClient) => { + console.log('delete inputStart notification.'); +}); +``` + +### on('inputStop')9+ + +on(type: 'inputStop', callback: () => void): void + +订阅停止输入法应用事件。使用callback异步回调。 + +**系统能力:** SystemCapability.MiscServices.InputMethodFramework + +**参数:** + +| 参数名 | 类型 | 必填 | 说明 | +| -------- | ------ | ---- | ------------------------------------------------------------ | +| type | string | 是 | 设置监听类型。
-type为‘inputStop’时表示订阅停止输入法应用事件。 | +| callback | void | 是 | 回调函数。 | + +**示例:** + +```js +inputMethodEngine.getInputMethodAbility().on('inputStop', () => { + console.log('inputMethodAbility inputStop'); +}); +``` + +### off('inputStop')9+ + +off(type: 'inputStop', callback: () => void): void + +取消订阅停止输入法应用事件。使用callback异步回调。 + +**系统能力:** SystemCapability.MiscServices.InputMethodFramework + +**参数:** + +| 参数名 | 类型 | 必填 | 说明 | +| -------- | ------ | ---- | ------------------------------------------------------------ | +| type | string | 是 | 设置监听类型。
-type为‘inputStop’时表示订阅停止输入法应用事件。 | +| callback | void | 是 | 回调函数。 | + +**示例:** + +```js +inputMethodEngine.getInputMethodAbility().off('inputStop', () => { + console.log('inputMethodAbility delete inputStop notification.'); +}); +``` + +### on('setCallingWindow')9+ + +on(type: 'setCallingWindow', callback: (wid:number) => void): void + +订阅设置调用窗口事件。使用callback异步回调。 + +**系统能力:** SystemCapability.MiscServices.InputMethodFramework + +**参数:** + +| 参数名 | 类型 | 必填 | 说明 | +| -------- | ------ | ---- | ------------------------------------------------------------ | +| type | string | 是 | 设置监听类型。
-type为‘setCallingWindow’时表示订阅设置调用窗口事件。 | +| callback | number | 是 | 回调函数,返回调用方window id。 | + +**示例:** + +```js +inputMethodEngine.getInputMethodAbility().on('setCallingWindow', (wid) => { + console.log('inputMethodAbility setCallingWindow'); +}); +``` + +### off('setCallingWindow')9+ + +off(type: 'setCallingWindow', callback: (wid:number) => void): void + +取消订阅设置调用窗口事件。使用callback异步回调。 + +**系统能力:** SystemCapability.MiscServices.InputMethodFramework + +**参数:** + +| 参数名 | 类型 | 必填 | 说明 | +| -------- | ------ | ---- | ------------------------------------------------------------ | +| type | string | 是 | 设置监听类型。
-type为‘setCallingWindow’时表示订阅设置调用窗口事件。 | +| callback | number | 是 | 回调函数,返回调用方window id。 | + +**示例:** + +```js +inputMethodEngine.getInputMethodAbility().off('setCallingWindow', () => { + console.log('inputMethodAbility delete setCallingWindow notification.'); +}); +``` + +### on('keyboardShow'|'keyboardHide')9+ + +on(type: 'keyboardShow'|'keyboardHide', callback: () => void): void + +订阅输入法事件。使用callback异步回调。 + +**系统能力:** SystemCapability.MiscServices.InputMethodFramework + +**参数:** + +| 参数名 | 类型 | 必填 | 说明 | +| -------- | ------ | ---- | ------------------------------------------------------------ | +| type | string | 是 | 设置监听类型。
- type为'keyboardShow',表示订阅输入法显示。
- type为'keyboardHide',表示订阅输入法隐藏。 | +| callback | void | 否 | 回调函数。 | + +**示例:** + +```js +inputMethodEngine.getInputMethodAbility().on('keyboardShow', () => { + console.log('InputMethodAbility keyboardShow.'); +}); +inputMethodEngine.getInputMethodAbility().on('keyboardHide', () => { + console.log('InputMethodAbility keyboardHide.'); +}); +``` + +### off('keyboardShow'|'keyboardHide')9+ + +off(type: 'keyboardShow'|'keyboardHide', callback?: () => void): void + +取消订阅输入法事件。使用callback异步回调。 -**系统能力**: SystemCapability.MiscServices.InputMethodFramework +**系统能力:** SystemCapability.MiscServices.InputMethodFramework **参数:** @@ -279,101 +523,144 @@ off(type: 'keyboardShow'|'keyboardHide', callback?: () => void): void **示例:** - ```js - InputMethodEngine.off('keyboardShow', () => { - console.log('inputMethodEngine delete keyboardShow notification.'); - }); - InputMethodEngine.off('keyboardHide', () => { - console.log('inputMethodEngine delete keyboardHide notification.'); - }); - ``` +```js +inputMethodEngine.getInputMethodAbility().off('keyboardShow', () => { + console.log('InputMethodAbility delete keyboardShow notification.'); +}); +inputMethodEngine.getInputMethodAbility().off('keyboardHide', () => { + console.log('InputMethodAbility delete keyboardHide notification.'); +}); +``` + +### on('setSubtype')9+ + +on(type: 'setSubtype', callback: (inputMethodSubtype: InputMethodSubtype) => void): void + +订阅设置输入法子类型事件。使用callback异步回调。 + +**系统能力:** SystemCapability.MiscServices.InputMethodFramework + +**参数:** + +| 参数名 | 类型 | 必填 | 说明 | +| -------- | ------ | ---- | ------------------------------------------------------------ | +| type | string | 是 | 设置监听类型。
- type为'setSubtype',表示订阅输入法子类型设置。
- type为'keyboardHide',表示订阅输入法隐藏。 | +| callback | InputMethodSubtype | 是 | 回调函数,返回调用方的输入法子类型。 | + +**示例:** + +```js +inputMethodEngine.getInputMethodAbility().on('setSubtype', (inputMethodSubtype) => { + console.log('InputMethodAbility setSubtype.'); +}); +``` + +### off('setSubtype')9+ + +off(ype: 'setSubtype', callback?: (inputMethodSubtype: InputMethodSubtype) => void): void +取消订阅输入法子类型事件。使用callback异步回调。 -## KeyboardDelegate +**系统能力:** SystemCapability.MiscServices.InputMethodFramework -下列API示例中都需使用[createKeyboardDelegate](#createKeyboardDelegate)回调获取到KeyboardDelegate实例,再通过此实例调用对应方法。 +**参数:** + +| 参数名 | 类型 | 必填 | 说明 | +| -------- | ------ | ---- | ------------------------------------------------------------ | +| type | string | 是 | 设置监听类型。
- type为'setSubtype',表示取消订阅输入法子类型设置。
- type为'keyboardHide',表示订阅输入法隐藏。 | +| callback | InputMethodSubtype | 是 | 回调函数,返回调用方的输入法子类型。 | + +**示例:** + +```js +inputMethodEngine.getInputMethodAbility().off('setSubtype', () => { + console.log('InputMethodAbility delete setSubtype notification.'); +}); +``` + +## KeyboardDelegate + +下列API示例中都需使用[getKeyboardDelegate](#inputmethodenginegetkeyboarddelegate9)回调获取到KeyboardDelegate实例,再通过此实例调用对应方法。 ### on('keyDown'|'keyUp') on(type: 'keyDown'|'keyUp', callback: (event: KeyEvent) => boolean): void -订阅硬键盘事件,使用callback回调返回按键信息。参数个数为2,参数1为napi_string,参数2为napi_function,否则抛出异常。 +订阅硬键盘事件。使用callback异步回调。 -**系统能力**: SystemCapability.MiscServices.InputMethodFramework +**系统能力:** SystemCapability.MiscServices.InputMethodFramework **参数:** | 参数名 | 类型 | 必填 | 说明 | | -------- | ------------------------------- | ---- | ------------------------------------------------------------ | | type | string | 是 | 设置监听类型。
- type为'keyDown',表示订阅硬键盘按下。
- type为'keyUp',表示订阅硬键盘抬起。 | -| callback | [KeyEvent](#KeyEvent) | 是 | 回调返回按键信息。 | - - +| callback | [KeyEvent](#keyevent) | 是 | 回调函数,返回按键信息。 | **示例:** - ```js - KeyboardDelegate.on('keyUp', (keyEvent) => { - console.info('inputMethodEngine keyCode.(keyUp):' + JSON.stringify(keyEvent.keyCode)); - console.info('inputMethodEngine keyAction.(keyUp):' + JSON.stringify(keyEvent.keyAction)); - return true; - }); - KeyboardDelegate.on('keyDown', (keyEvent) => { - console.info('inputMethodEngine keyCode.(keyDown):' + JSON.stringify(keyEvent.keyCode)); - console.info('inputMethodEngine keyAction.(keyDown):' + JSON.stringify(keyEvent.keyAction)); - return true; - }); - ``` +```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; +}); +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; +}); +``` ### off('keyDown'|'keyUp') off(type: 'keyDown'|'keyUp', callback?: (event: KeyEvent) => boolean): void -取消订阅硬键盘事件。参数个数不为1或2抛出异常。若为1,参数不为napi_string抛出异常;若为2,参数1不为napi_string,参数2不为napi_function抛出异常。参数若为1,取消此类型所有监听;参数若为2,取消此类型当前监听。 +取消订阅硬键盘事件。使用callback异步回调。 -**系统能力**: SystemCapability.MiscServices.InputMethodFramework +**系统能力:** SystemCapability.MiscServices.InputMethodFramework **参数:** | 参数名 | 类型 | 必填 | 说明 | | -------- | --------------------- | ---- | ------------------------------------------------------------ | | type | string | 是 | 设置监听类型。
- type为'keyDown',表示订阅硬键盘按下。
- type为'keyUp',表示订阅硬键盘抬起。 | -| callback | [KeyEvent](#KeyEvent) | 否 | 回调返回按键信息。 | +| callback | [KeyEvent](#keyevent) | 否 | 回调函数,返回按键信息。 | **示例:** - ```js - KeyboardDelegate.off('keyUp', (keyEvent) => { - console.log('delete keyUp notification.'); - return true; - }); - KeyboardDelegate.off('keyDown', (keyEvent) => { - console.log('delete keyDown notification.'); - return true; - }); - ``` +```js +inputMethodEngine.getKeyboardDelegate().off('keyUp', (keyEvent) => { + console.log('delete keyUp notification.'); + return true; +}); +inputMethodEngine.getKeyboardDelegate().off('keyDown', (keyEvent) => { + console.log('delete keyDown notification.'); + return true; +}); +``` ### on('cursorContextChange') on(type: 'cursorContextChange', callback: (x: number, y:number, height:number) => void): void -订阅光标变化事件,使用callback回调返回光标信息。使用callback回调返回光标信息。参数个数为2,参数1为napi_string,参数2为napi_function,否则抛出异常。 +订阅光标变化事件。使用callback异步回调。 - **系统能力**: SystemCapability.MiscServices.InputMethodFramework + **系统能力:** SystemCapability.MiscServices.InputMethodFramework **参数:** | 参数名 | 类型 | 必填 | 说明 | | -------- | ------ | ---- | ------------------------------------------------------------ | | type | string | 是 | 光标变化事件。
-type为’cursorContextChange‘时,表示光标变化。 | -| callback | number | 是 | 回调返回光标信息。 | +| callback | number | 是 | 回调函数,返回光标信息。 | **示例:** ```js -KeyboardDelegate.on('cursorContextChange', (x, y, height) => { +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); @@ -384,22 +671,22 @@ KeyboardDelegate.on('cursorContextChange', (x, y, height) => { off(type: 'cursorContextChange', callback?: (x: number, y:number, height:number) => void): void -取消订阅光标变化事件。参数个数不为1或2抛出异常。若为1,参数不为napi_string抛出异常;若为2,参数1不为napi_string,参数2不为napi_function抛出异常。参数若为1,取消此类型所有监听;参数若为2,取消此类型当前监听。 +取消订阅光标变化事件。使用callback异步回调。 -**系统能力**: SystemCapability.MiscServices.InputMethodFramework +**系统能力:** SystemCapability.MiscServices.InputMethodFramework **参数:** | 参数名 | 类型 | 必填 | 说明 | | -------- | ------ | ---- | ------------------------------------------------------------ | | type | string | 是 | 光标变化事件。
-type为’cursorContextChange‘时,表示光标变化。 | -| callback | number | 否 | 回调返回光标信息。 | +| callback | number | 否 | 回调函数,返回光标信息。 | **示例:** ```js -KeyboardDelegate.off('cursorContextChange', (x, y, height) => { +inputMethodEngine.getKeyboardDelegate().off('cursorContextChange', (x, y, height) => { console.log('delete cursorContextChange notification.'); }); ``` @@ -407,21 +694,21 @@ KeyboardDelegate.off('cursorContextChange', (x, y, height) => { on(type: 'selectionChange', callback: (oldBegin: number, oldEnd: number, newBegin: number, newEnd: number) => void): void -订阅文本选择变化事件,使用callback回调返回文本选择信息。参数个数为2,参数1为napi_string,参数2为napi_function,否则抛出异常。 +订阅文本选择变化事件。使用callback异步回调。 -**系统能力**: SystemCapability.MiscServices.InputMethodFramework +**系统能力:** SystemCapability.MiscServices.InputMethodFramework **参数:** | 参数名 | 类型 | 必填 | 说明 | | -------- | ------ | ---- | ------------------------------------------------------------ | | type | string | 是 | 文本选择变化事件。
-type为’selectionChange‘时,表示选择文本变化。 | -| callback | number | 是 | 回调返回文本选择信息。 | +| callback | number | 是 | 回调函数,返回文本选择信息。 | **示例:** ```js -KeyboardDelegate.on('selectionChange', (oldBegin, oldEnd, newBegin, newEnd) => { +inputMethodEngine.getKeyboardDelegate().on('selectionChange', (oldBegin, oldEnd, newBegin, newEnd) => { console.log('inputMethodEngine beforeEach selectionChange oldBegin:' + oldBegin); console.log('inputMethodEngine beforeEach selectionChange oldEnd:' + oldEnd); console.log('inputMethodEngine beforeEach selectionChange newBegin:' + newBegin); @@ -433,21 +720,21 @@ KeyboardDelegate.on('selectionChange', (oldBegin, oldEnd, newBegin, newEnd) => { off(type: 'selectionChange', callback?: (oldBegin: number, oldEnd: number, newBegin: number, newEnd: number) => void): void -取消订阅文本选择变化事件。参数个数不为1或2抛出异常。若为1,参数不为napi_string抛出异常;若为2,参数1不为napi_string,参数2不为napi_function抛出异常。参数若为1,取消此类型所有监听;参数若为2,取消此类型当前监听。 +取消订阅文本选择变化事件。使用callback异步回调。 -**系统能力**: SystemCapability.MiscServices.InputMethodFramework +**系统能力:** SystemCapability.MiscServices.InputMethodFramework **参数:** | 参数名 | 类型 | 必填 | 说明 | | -------- | ------ | ---- | ------------------------------------------------------------ | | type | string | 是 | 文本选择变化事件。
-type为’selectionChange‘时,表示选择文本变化。 | -| callback | number | 否 | 回调返回文本选择信息。 | +| callback | number | 否 | 回调函数,返回文本选择信息。 | **示例:** ```js -KeyboardDelegate.off('selectionChange', (oldBegin, oldEnd, newBegin, newEnd) => { +inputMethodEngine.getKeyboardDelegate().off('selectionChange', (oldBegin, oldEnd, newBegin, newEnd) => { console.log('delete selectionChange notification.'); }); ``` @@ -457,21 +744,21 @@ KeyboardDelegate.off('selectionChange', (oldBegin, oldEnd, newBegin, newEnd) => on(type: 'textChange', callback: (text: string) => void): void -订阅文本变化事件,使用callback回调返回当前文本内容。参数个数为2,参数1为napi_string,参数2为napi_function,否则抛出异常。 +订阅文本变化事件。使用callback异步回调。 -**系统能力**: SystemCapability.MiscServices.InputMethodFramework +**系统能力:** SystemCapability.MiscServices.InputMethodFramework **参数:** | 参数名 | 类型 | 必填 | 说明 | | -------- | ------ | ---- | ------------------------------------------------------------ | | type | string | 是 | 文本变化事件。
-type为’textChange‘时,表示当前文本变化。 | -| callback | string | 是 | 回调返回当前文本内容。 | +| callback | string | 是 | 回调函数,返回当前文本内容。 | **示例:** ```js -KeyboardDelegate.on('textChange', (text) => { +inputMethodEngine.getKeyboardDelegate().on('textChange', (text) => { console.log('inputMethodEngine textChange. text:' + text); }); ``` @@ -480,63 +767,138 @@ KeyboardDelegate.on('textChange', (text) => { off(type: 'textChange', callback?: (text: string) => void): void -取消订阅文本变化事件。参数个数不为1或2抛出异常。若为1,参数不为napi_string抛出异常;若为2,参数1不为napi_string,参数2不为napi_function抛出异常。参数若为1,取消此类型所有监听;参数若为2,取消此类型当前监听。 +取消订阅文本变化事件。使用callback异步回调。 -**系统能力**: SystemCapability.MiscServices.InputMethodFramework +**系统能力:** SystemCapability.MiscServices.InputMethodFramework **参数:** | 参数名 | 类型 | 必填 | 说明 | | -------- | ------ | ---- | ------------------------------------------------------------ | | type | string | 是 | 文本变化事件。
-type为’textChange‘时,表示当前文本变化。 | -| callback | string | 否 | 回调返回当前文本内容。 | +| callback | string | 否 | 回调函数,返回当前文本内容。 | **示例:** ```js -keyboardDelegate.off('textChange', (text) => { +inputMethodEngine.getKeyboardDelegate().off('textChange', (text) => { console.log('delete textChange notification. text:' + text); }); ``` -## KeyboardController +## KeyboardController -下列API示例中都需使用[inputStart](#inputStart)回调获取到KeyboardController实例,再通过此实例调用对应方法。 +下列API示例中都需使用[on('inputStart')](#oninputstart9)回调获取到KeyboardController实例,再通过此实例调用对应方法。 -### hideKeyboard +### hide9+ -hideKeyboard(callback: AsyncCallback<void>): void +hide(callback: AsyncCallback<void>): void -隐藏输入法。使用callback形式返回结果。参数个数为1,否则抛出异常。 +隐藏输入法。使用callback异步回调。 -**系统能力**: SystemCapability.MiscServices.InputMethodFramework +**系统能力:** SystemCapability.MiscServices.InputMethodFramework **参数:** | 参数名 | 类型 | 必填 | 说明 | | -------- | ---------------------- | ---- | -------- | -| callback | AsyncCallback<void> | 否 | 回调函数 | +| callback | AsyncCallback<void> | 否 | 回调函数。当输入法隐藏成功,err为undefined,否则为错误对象。 | -**示例:** +**错误码:** +以下错误码的详细介绍请参见[输入法框架错误码](../errorcodes/errcode-inputmethod-framework.md)。 + +| 错误码ID | 错误码信息 | +| -------- | -------------------------- | +| 12800003 | Input method client error. | + +**示例:** ```js -KeyboardController.hideKeyboard((err) => { +KeyboardController.hide((err) => { if (err === undefined) { - console.error('hideKeyboard callback result---err: ' + err.msg); + console.error('hide err: ' + JSON.stringify(err)); return; } - console.log('hideKeyboard callback.'); + console.log('hide success.'); }); ``` -### hideKeyboard +### hide9+ -hideKeyboard(): Promise<void> +hide(): Promise<void> -隐藏输入法。使用peomise形式返回结果。参数个数为0,否则抛出异常。 +隐藏输入法。使用promise异步回调。 -**系统能力**: SystemCapability.MiscServices.InputMethodFramework +**系统能力:** SystemCapability.MiscServices.InputMethodFramework + +**返回值:** + +| 类型 | 说明 | +| ---------------- | ------------------------- | +| Promise<void> | 无返回结果的Promise对象。 | + +**错误码:** + +以下错误码的详细介绍请参见[输入法框架错误码](../errorcodes/errcode-inputmethod-framework.md)。 + +| 错误码ID | 错误码信息 | +| -------- | -------------------------- | +| 12800003 | Input method client error. | + +**示例:** + +```js +async function InputMethodEngine() { + await KeyboardController.hide().then(() => { + console.info('hide success.'); + }).catch((err) => { + console.info('hide err: ' + JSON.stringify(err)); + }); +} +``` + +### hideKeyboard(deprecated) + +hideKeyboard(callback: AsyncCallback<void>): void + +隐藏输入法。使用callback异步回调。 + +> **说明:** +> +> 从API version 8开始支持,API version 9开始废弃, 建议使用[hide](#hide9)替代。 + +**系统能力:** SystemCapability.MiscServices.InputMethodFramework + +**参数:** + +| 参数名 | 类型 | 必填 | 说明 | +| -------- | ---------------------- | ---- | -------- | +| callback | AsyncCallback<void> | 否 | 回调函数。当输入法隐藏成功,err为undefined,否则为错误对象。 | + +**示例:** + +```js +KeyboardController.hideKeyboard((err) => { + if (err === undefined) { + console.error('hideKeyboard err: ' + JSON.stringify(err)); + return; + } + console.log('hideKeyboard success.'); +}); +``` + +### hideKeyboard(deprecated) + +hideKeyboard(): Promise<void> + +隐藏输入法。使用promise异步回调。 + +> **说明:** +> +> 从API version 8开始支持,API version 9开始废弃, 建议使用[hide](#hide9-1)替代。 + +**系统能力:** SystemCapability.MiscServices.InputMethodFramework **返回值:** @@ -549,52 +911,785 @@ hideKeyboard(): Promise<void> ```js async function InputMethodEngine() { await KeyboardController.hideKeyboard().then(() => { - console.info('hideKeyboard promise.'); + console.info('hideKeyboard success.'); + }).catch((err) => { + console.info('hideKeyboard err: ' + JSON.stringify(err)); + }); +} +``` + +## InputClient9+ + +下列API示例中都需使用[on('inputStart')](#oninputstart9)回调获取到InputClient实例,再通过此实例调用对应方法。 + +### sendKeyFunction9+ + +sendKeyFunction(action:number, callback: AsyncCallback<boolean>): void + +发送功能键。使用callback异步回调。 + +**系统能力:** SystemCapability.MiscServices.InputMethodFramework + + **参数:** + +| 参数名 | 类型 | 必填 | 说明 | +| -------- | -------- | -------- | -------- | +| action | number | 是 | 编辑框属性。 | +| callback | AsyncCallback<boolean> | 是 | 回调函数。当功能键发送成功,err为undefined,data为true;否则为错误对象。 | + +**错误码:** + +以下错误码的详细介绍请参见[输入法框架错误码](../errorcodes/errcode-inputmethod-framework.md)。 + +| 错误码ID | 错误码信息 | +| -------- | -------------------------- | +| 12800003 | Input method client error. | + + **示例:** + +```js +try { + InputClient.sendKeyFunction(keyFunction, (err, result) => { + if (err) { + console.error('sendKeyFunction err: ' + JSON.stringify(err)JSON.stringify(err)); + return; + } + if (result) { + console.info('Success to sendKeyFunction. '); + } else { + console.error('Failed to sendKeyFunction. '); + } + }); +} catch (err) { + console.error('sendKeyFunction err: ' + JSON.stringify(err)); +} +``` + +### sendKeyFunction9+ + +sendKeyFunction(action:number): Promise<boolean> + +发送功能键。使用promise异步回调。 + +**系统能力:** SystemCapability.MiscServices.InputMethodFramework + +**参数:** + +| 参数名 | 类型 | 必填 | 说明 | +| -------- | -------- | -------- | -------- | +| action | number | 是 | 编辑框属性。 | + +**返回值:** + +| 类型 | 说明 | +| ------------------------------- | ------------------------------------------------------------ | +| Promise<boolean> | Promise对象。返回true表示功能键发送成功;返回false表示功能键发送失败。| + +**错误码:** + +以下错误码的详细介绍请参见[输入法框架错误码](../errorcodes/errcode-inputmethod-framework.md)。 + +| 错误码ID | 错误码信息 | +| -------- | -------------------------- | +| 12800003 | Input method client error. | + +**示例:** + +```js +try { + InputClient.sendKeyFunction(keyFunction).then((result) => { + if (result) { + console.info('Success to sendKeyFunction. '); + } else { + console.error('Failed to sendKeyFunction. '); + } + }).catch((err) => { + console.error('sendKeyFunction err:' + JSON.stringify(err)); + }); +} catch (err) { + console.error('sendKeyFunction err: ' + JSON.stringify(err)); +} +``` + +### getForward9+ + +getForward(length:number, callback: AsyncCallback<string>): void + +获取光标前固定长度的文本。使用callback异步回调。 + +**系统能力:** SystemCapability.MiscServices.InputMethodFramework + +**参数:** + +| 参数名 | 类型 | 必填 | 说明 | +| -------- | -------- | -------- | -------- | +| length | number | 是 | 文本长度。 | +| callback | AsyncCallback<string> | 是 | 回调函数。当光标前固定长度的文本获取成功,err为undefined,data为获取到的文本;否则为错误对象。 | + +**错误码:** + +以下错误码的详细介绍请参见[输入法框架错误码](../errorcodes/errcode-inputmethod-framework.md)。 + +| 错误码ID | 错误码信息 | +| -------- | ------------------------------ | +| 12800003 | Input method client error. | +| 12800006 | Input method controller error. | + +**示例:** + +```js +let length = 1; +try { + InputClient.getForward(length, (err, text) => { + if (err) { + console.error('getForward err: ' + JSON.stringify(err)); + return; + } + console.log('getForward result: ' + text); + }); +} catch (err) { + console.error('getForward err: ' + JSON.stringify(err)); +} +``` + +### getForward9+ + +getForward(length:number): Promise<string> + +获取光标前固定长度的文本。使用promise异步回调。 + +**系统能力:** SystemCapability.MiscServices.InputMethodFramework + +**参数:** + +| 参数名 | 类型 | 必填 | 说明 | +| -------- | -------- | -------- | -------- | +| length | number | 是 | 文本长度。 | + +**返回值:** + +| 类型 | 说明 | +| ------------------------------- | ------------------------------------------------------------ | +| Promise<string> | Promise对象,返回光标前固定长度的文本。 | + +**错误码:** + +以下错误码的详细介绍请参见[输入法框架错误码](../errorcodes/errcode-inputmethod-framework.md)。 + +| 错误码ID | 错误码信息 | +| -------- | ------------------------------ | +| 12800003 | Input method client error. | +| 12800006 | Input method controller error. | + +**示例:** + +```js +async function InputMethodAbility() { + let length = 1; + try { + await InputClient.getForward(length).then((text) => { + console.info('getForward resul: ' + text); + }).catch((err) => { + console.error('getForward err: ' + JSON.stringify(err)); + }); + } catch (err) { + console.error('getForward err: ' + JSON.stringify(err)); + } +} +``` + +### getBackward9+ + +getBackward(length:number, callback: AsyncCallback<string>): void + +获取光标后固定长度的文本。使用callback异步回调。 + +**系统能力:** SystemCapability.MiscServices.InputMethodFramework + +**参数:** + +| 参数名 | 类型 | 必填 | 说明 | +| -------- | -------- | -------- | -------- | +| length | number | 是 | 文本长度。 | +| callback | AsyncCallback<string> | 是 | 回调函数。当光标后固定长度的文本获取成功,err为undefined,data为获取到的文本;否则为错误对象。| + +**错误码:** + +以下错误码的详细介绍请参见[输入法框架错误码](../errorcodes/errcode-inputmethod-framework.md)。 + +| 错误码ID | 错误码信息 | +| -------- | ------------------------------ | +| 12800003 | Input method client error. | +| 12800006 | Input method controller error. | + +**示例:** + +```js +let length = 1; +try { + InputClient.getBackward(length, (err, text) => { + if (err) { + console.error('getBackward result: ' + JSON.stringify(err)); + return; + } + console.log('getBackward result---text: ' + text); + }); +} catch (err) { + console.error('getBackward result: ' + JSON.stringify(err)); +} +``` + +### getBackward9+ + +getBackward(length:number): Promise<string> + +获取光标后固定长度的文本。使用promise异步回调。 + +**系统能力:** SystemCapability.MiscServices.InputMethodFramework + +**参数:** + +| 参数名 | 类型 | 必填 | 说明 | +| -------- | -------- | -------- | -------- | +| length | number | 是 | 文本长度。 | + +**返回值:** + +| 类型 | 说明 | +| ------------------------------- | ------------------------------------------------------------ | +| Promise<string> | Promise对象,返回光标后固定长度的文本。 | + +**错误码:** + +以下错误码的详细介绍请参见[输入法框架错误码](../errorcodes/errcode-inputmethod-framework.md)。 + +| 错误码ID | 错误码信息 | +| -------- | ------------------------------ | +| 12800003 | Input method client error. | +| 12800006 | Input method controller error. | + +**示例:** + +```js +async function InputMethodAbility() { + let length = 1; + try { + await InputClient.getBackward(length).then((text) => { + console.info('getBackward result: ' + text); + }).catch((err) => { + console.error('getBackward err: ' + JSON.stringify(err)); + }); + } catch (err) { + console.error('getBackward err: ' + JSON.stringify(err)); + } +} +``` + +### deleteForward9+ + +deleteForward(length:number, callback: AsyncCallback<boolean>): void + +删除光标前固定长度的文本。使用callback异步回调。 + +**系统能力:** SystemCapability.MiscServices.InputMethodFramework + +**参数:** + +| 参数名 | 类型 | 必填 | 说明 | +| -------- | -------- | -------- | -------- | +| length | number | 是 | 文本长度。 | +| callback | AsyncCallback<boolean> | 是 | 回调函数。当光标前固定长度的文本删除成功,err为undefined,data为true;否则为错误对象。 | + +**错误码:** + +以下错误码的详细介绍请参见[输入法框架错误码](../errorcodes/errcode-inputmethod-framework.md)。 + +| 错误码ID | 错误码信息 | +| -------- | -------------------------- | +| 12800002 | Input method engine error. | +| 12800003 | Input method client error. | + +**示例:** + +```js +let length = 1; +try { + InputClient.deleteForward(length, (err, result) => { + if (err) { + console.error('deleteForward result: ' + JSON.stringify(err)); + return; + } + if (result) { + console.info('Success to deleteForward. '); + } else { + console.error('Failed to deleteForward. '); + } + }); +} catch (err) { + console.error('deleteForward result: ' + JSON.stringify(err)); +} +``` + +### deleteForward9+ + +deleteForward(length:number): Promise<boolean> + +删除光标前固定长度的文本。使用promise异步回调。 + +**系统能力:** SystemCapability.MiscServices.InputMethodFramework + +**参数:** + +| 参数名 | 类型 | 必填 | 说明 | +| ------ | ------ | ---- | ---------- | +| length | number | 是 | 文本长度。 | + +**返回值:** + +| 类型 | 说明 | +| ---------------------- | -------------- | +| Promise<boolean> | Promise对象。返回true表示删除光标前固定长度的文本成功;返回false表示删除光标前固定长度的文本失败。| + +**错误码:** + +以下错误码的详细介绍请参见[输入法框架错误码](../errorcodes/errcode-inputmethod-framework.md)。 + +| 错误码ID | 错误码信息 | +| -------- | -------------------------- | +| 12800002 | Input method engine error. | +| 12800003 | Input method client error. | + +**示例:** + +```js +async function InputMethodAbility() { + let length = 1; + try { + await InputClient.deleteForward(length).then((result) => { + if (result) { + console.info('Success to deleteForward. '); + } else { + console.error('Failed to deleteForward. '); + } + }).catch((err) => { + console.error('deleteForward err: ' + JSON.stringify(err)); + }); + } catch (err) { + console.error('deleteForward err: ' + JSON.stringify(err)); + } +} +``` + +### deleteBackward9+ + +deleteBackward(length:number, callback: AsyncCallback<boolean>): void + +删除光标后固定长度的文本。使用callback异步回调。 + +**系统能力:** SystemCapability.MiscServices.InputMethodFramework + +**参数:** + +| 参数名 | 类型 | 必填 | 说明 | +| -------- | ---------------------------- | ---- | -------------- | +| length | number | 是 | 文本长度。 | +| callback | AsyncCallback<boolean> | 是 | 回调函数。当光标后固定长度的文本删除成功,err为undefined,data为true;否则为错误对象。 | + +**错误码:** + +以下错误码的详细介绍请参见[输入法框架错误码](../errorcodes/errcode-inputmethod-framework.md)。 + +| 错误码ID | 错误码信息 | +| -------- | -------------------------- | +| 12800002 | Input method engine error. | +| 12800003 | Input method client error. | + +**示例:** + +```js +let length = 1; +try { + InputClient.deleteBackward(length, (err, result) => { + if (err) { + console.error('deleteBackward err: ' + JSON.stringify(err)); + return; + } + if (result) { + console.info('Success to deleteBackward. '); + } else { + console.error('Failed to deleteBackward. '); + } + }); +} catch (err) { + console.error('deleteBackward err: ' + JSON.stringify(err)); +} +``` + +### deleteBackward9+ + +deleteBackward(length:number): Promise<boolean> + +删除光标后固定长度的文本。使用callback异步回调。 + +**系统能力:** SystemCapability.MiscServices.InputMethodFramework + +**参数:** + +| 参数名 | 类型 | 必填 | 说明 | +| -------- | -------- | -------- | -------- | +| length | number | 是 | 文本长度。 | + +**返回值:** + +| 类型 | 说明 | +| ------------------------------- | ------------------------------------------------------------ | +| Promise<boolean> | Promise对象。返回true表示删除光标后固定长度的文本成功;返回false表示删除光标后固定长度的文本失败。 | + +**错误码:** + +以下错误码的详细介绍请参见[输入法框架错误码](../errorcodes/errcode-inputmethod-framework.md)。 + +| 错误码ID | 错误码信息 | +| -------- | -------------------------- | +| 12800002 | Input method engine error. | +| 12800003 | Input method client error. | + +**示例:** + +```js +async function InputMethodAbility() { + let length = 1; + await InputClient.deleteBackward(length).then((result) => { + if (result) { + console.info('Success to deleteBackward. '); + } else { + console.error('Failed to deleteBackward. '); + } + }).catch((err) => { + console.error('deleteBackward err: ' + JSON.stringify(err)); + }); +} +``` + +### insertText9+ + +insertText(text:string, callback: AsyncCallback<boolean>): void + +插入文本。使用callback异步回调。 + +**系统能力:** SystemCapability.MiscServices.InputMethodFramework + +**参数:** + +| 参数名 | 类型 | 必填 | 说明 | +| -------- | -------- | -------- | -------- | +| text | string | 是 | 文本。 | +| callback | AsyncCallback<boolean> | 是 | 回调函数。当文本插入成功,err为undefined,data为true;否则为错误对象。 | + +**错误码:** + +以下错误码的详细介绍请参见[输入法框架错误码](../errorcodes/errcode-inputmethod-framework.md)。 + +| 错误码ID | 错误码信息 | +| -------- | -------------------------- | +| 12800002 | Input method engine error. | +| 12800003 | Input method client error. | + +**示例:** + +```js +InputClient.insertText('test', (err, result) => { + if (err) { + console.error('insertText err: ' + JSON.stringify(err)); + return; + } + if (result) { + console.info('Success to insertText. '); + } else { + console.error('Failed to insertText. '); + } +}); +``` + +### insertText9+ + +insertText(text:string): Promise<boolean> + +插入文本。使用promise异步回调。 + +**系统能力:** SystemCapability.MiscServices.InputMethodFramework + +**参数:** + +| 参数名 | 类型 | 必填 | 说明 | +| -------- | -------- | -------- | -------- | +| text | string | 是 | 文本。 | + +**返回值:** + +| 类型 | 说明 | +| ------------------------------- | ------------------------------------------------------------ | +| Promise<boolean> | Promise对象。返回true表示插入文本成功;返回false表示插入文本失败。 | + +**错误码:** + +以下错误码的详细介绍请参见[输入法框架错误码](../errorcodes/errcode-inputmethod-framework.md)。 + +| 错误码ID | 错误码信息 | +| -------- | -------------------------- | +| 12800002 | Input method engine error. | +| 12800003 | Input method client error. | + +**示例:** + +```js +async function InputMethodAbility() { + try { + await InputClient.insertText('test').then((result) => { + if (result) { + console.info('Success to insertText. '); + } else { + console.error('Failed to insertText. '); + } + }).catch((err) => { + console.error('insertText err: ' + JSON.stringify(err)); + }); + } catch (e) { + console.error('insertText err: ' + JSON.stringify(err)); + } +} +``` + +### getEditorAttribute9+ + +getEditorAttribute(callback: AsyncCallback<EditorAttribute>): void + +获取编辑框属性值。使用callback异步回调。 + +**系统能力:** SystemCapability.MiscServices.InputMethodFramework + +**参数:** + +| 参数名 | 类型 | 必填 | 说明 | +| ------------------------------- | ------------------------------------------------------------ | ------------------------------------------------------------ | ------------------------------------------------------------ | +| callback | AsyncCallback<[EditorAttribute](#editorattribute)> | 是 | 回调函数。当编辑框属性值获取成功,err为undefined,data为编辑框属性值;否则为错误对象。| + +**错误码:** + +以下错误码的详细介绍请参见[输入法框架错误码](../errorcodes/errcode-inputmethod-framework.md)。 + +| 错误码ID | 错误码信息 | +| -------- | -------------------------- | +| 12800003 | Input method client error. | + +**示例:** + +```js +InputClient.getEditorAttribute((err, editorAttribute) => { + if (err) { + console.error('getEditorAttribute err: ' + JSON.stringify(err)); + return; + } + console.log('editorAttribute.inputPattern: ' + JSON.stringify(editorAttribute.inputPattern)); + console.log('editorAttribute.enterKeyType: ' + JSON.stringify(editorAttribute.enterKeyType)); +}); +``` + +### getEditorAttribute9+ + +getEditorAttribute(): Promise<EditorAttribute> + +获取编辑框属性值。使用promise异步回调。 + +**系统能力:** SystemCapability.MiscServices.InputMethodFramework + +**返回值:** + +| 类型 | 说明 | +| ------------------------------- | ------------------------------------------------------------ | +| Promise<[EditorAttribute](#editorattribute)> | Promise对象,返回编辑框属性值。 | + +**错误码:** + +以下错误码的详细介绍请参见[输入法框架错误码](../errorcodes/errcode-inputmethod-framework.md)。 + +| 错误码ID | 错误码信息 | +| -------- | -------------------------- | +| 12800003 | Input method client error. | + +**示例:** + +```js +async function InputMethodEngine() { + await InputClient.getEditorAttribute().then((editorAttribute) => { + console.info('editorAttribute.inputPattern: ' + JSON.stringify(editorAttribute.inputPattern)); + console.info('editorAttribute.enterKeyType: ' + JSON.stringify(editorAttribute.enterKeyType)); }).catch((err) => { - console.info('hideKeyboard promise err: ' + err.msg); + console.error('getEditorAttribute err: ' + JSON.stringify(err)); + }); +} +``` + +### moveCursor9+ + +moveCursor(direction: number, callback: AsyncCallback<void>): void + +移动光标。使用callback异步回调。 + +**系统能力:** SystemCapability.MiscServices.InputMethodFramework + +**参数:** + +| 参数名 | 类型 | 必填 | 说明 | +| --------- | ------------------------- | ---- | -------------- | +| direction | number | 是 | 光标移动方向。 | +| callback | AsyncCallback<void> | 是 | 回调函数。当光标移动成功,err为undefined,否则为错误对象。 | + +**错误码:** + +以下错误码的详细介绍请参见[输入法框架错误码](../errorcodes/errcode-inputmethod-framework.md)。 + +| 错误码ID | 错误码信息 | +| -------- | -------------------------- | +| 12800003 | Input method client error. | + +**示例:** + +```js +try { + InputClient.moveCursor(inputMethodAbility.CURSOR_xxx, (err) => { + if (err) { + console.error('moveCursor err: ' + JSON.stringify(err)); + return; + } + console.info('moveCursor success'); }); +} catch (err) { + console.error('moveCursor err: ' + JSON.stringify(err)); +} +``` + +### moveCursor9+ + +moveCursor(direction: number): Promise<void> + +移动光标。使用promise异步回调。 + +**系统能力:** SystemCapability.MiscServices.InputMethodFramework + +**参数:** + +| 参数名 | 类型 | 必填 | 说明 | +| --------- | ------ | ---- | -------------- | +| direction | number | 是 | 光标移动方向。 | + +**返回值:** + +| 类型 | 说明 | +| ------------------- | ------------------------- | +| Promise<void> | 无返回结果的Promise对象。 | + +**错误码:** + +以下错误码的详细介绍请参见[输入法框架错误码](../errorcodes/errcode-inputmethod-framework.md)。 + +| 错误码ID | 错误码信息 | +| -------- | -------------------------- | +| 12800003 | Input method client error. | + +**示例:** + +```js +async function InputMethodAbility() { + try { + await InputClient.moveCursor(inputMethodEngine.CURSOR_xxx).then((err) => { + if (err) { + console.log('moveCursor err: ' + JSON.stringify(err)); + return; + } + console.log('moveCursor success'); + }).catch((err) => { + console.error('moveCursor success err: ' + JSON.stringify(err)); + }); + } catch (err) { + console.log('moveCursor err: ' + JSON.stringify(err)); + } } ``` -## TextInputClient +## EditorAttribute + +编辑框属性值。 + +**系统能力:** SystemCapability.MiscServices.InputMethodFramework + +| 名称 | 参数类型 | 可读 | 可写 | 说明 | +| ------------ | -------- | ---- | ---- | ------------------ | +| enterKeyType | number | 是 | 否 | 编辑框的功能属性。 | +| inputPattern | number | 是 | 否 | 编辑框的文本属性。 | + +## KeyEvent + +按键属性值。 + +**系统能力:** SystemCapability.MiscServices.InputMethodFramework + +| 名称 | 参数类型 | 可读 | 可写 | 说明 | +| --------- | -------- | ---- | ---- | ------------ | +| keyCode | number | 是 | 否 | 按键的键值。 | +| keyAction | number | 是 | 否 | 按键的状态。 | -下列API示例中都需使用[inputStart](#inputStart)回调获取到TextInputClient实例,再通过此实例调用对应方法。 +## TextInputClient(deprecated) -### getForward +> **说明:** +> +> 从API version 8开始支持,API version 9开始废弃, 建议使用[InputClient](#inputclient9)替代。 + +下列API示例中都需使用[on('inputStart')](#oninputstart)回调获取到TextInputClient实例,再通过此实例调用对应方法。 + +### getForward(deprecated) getForward(length:number, callback: AsyncCallback<string>): void -获取光标前固定长度的文本。使用callback形式返回结果。参数个数为2,否则抛出异常。 +获取光标前固定长度的文本。使用callback异步回调。 -**系统能力**: SystemCapability.MiscServices.InputMethodFramework +> **说明:** +> +> 从API version 8开始支持,API version 9开始废弃, 建议使用[getForward](#getforward9)替代。 + +**系统能力:** SystemCapability.MiscServices.InputMethodFramework **参数:** | 参数名 | 类型 | 必填 | 说明 | | -------- | -------- | -------- | -------- | | length | number | 是 | 文本长度。 | -| callback | AsyncCallback<string> | 是 | 返回文本。 | +| callback | AsyncCallback<string> | 是 | 回调函数。当光标前固定长度的文本获取成功,err为undefined,data为获取到的文本;否则为错误对象。| **示例:** - ```js - var length = 1; - TextInputClient.getForward(length, (err, text) => { - if (err === undefined) { - console.error('getForward callback result---err: ' + err.msg); - return; - } - console.log('getForward callback result---text: ' + text); - }); - ``` +```js +let length = 1; +TextInputClient.getForward(length, (err, text) => { + if (err === undefined) { + console.error('getForward err: ' + JSON.stringify(err)); + return; + } + console.log('getForward result---text: ' + text); +}); +``` -### getForward +### getForward(deprecated) getForward(length:number): Promise<string> -获取光标前固定长度的文本。使用promise形式返回结果。参数个数为1,否则抛出异常。 +获取光标前固定长度的文本。使用promise异步回调。 + +> **说明:** +> +> 从API version 8开始支持,API version 9开始废弃, 建议使用[getForward](#getforward9)替代。 -**系统能力**: SystemCapability.MiscServices.InputMethodFramework +**系统能力:** SystemCapability.MiscServices.InputMethodFramework **参数:** @@ -606,56 +1701,64 @@ getForward(length:number): Promise<string> | 类型 | 说明 | | ------------------------------- | ------------------------------------------------------------ | -| Promise<string> | 返回文本。 | +| Promise<string> | Promise对象,返回光标前固定长度的文本。 | **示例:** - ```js - async function InputMethodEngine() { - var length = 1; - await TextInputClient.getForward(length).then((text) => { - console.info('getForward promise result---res: ' + text); - }).catch((err) => { - console.error('getForward promise err: ' + err.msg); - }); - } - ``` +```js +async function InputMethodEngine() { + let length = 1; + await TextInputClient.getForward(length).then((text) => { + console.info('getForward result---res: ' + text); + }).catch((err) => { + console.error('getForward err: ' + JSON.stringify(err)); + }); +} +``` -### getBackward +### getBackward(deprecated) getBackward(length:number, callback: AsyncCallback<string>): void -获取光标后固定长度的文本。使用callback形式返回结果。参数个数为2,否则抛出异常。 +获取光标后固定长度的文本。使用callback异步回调。 -**系统能力**: SystemCapability.MiscServices.InputMethodFramework +> **说明:** +> +> 从API version 8开始支持,API version 9开始废弃, 建议使用[getBackward](#getbackward9)替代。 + +**系统能力:** SystemCapability.MiscServices.InputMethodFramework **参数:** | 参数名 | 类型 | 必填 | 说明 | | -------- | -------- | -------- | -------- | | length | number | 是 | 文本长度。 | -| callback | AsyncCallback<string> | 是 | 返回文本。 | +| callback | AsyncCallback<string> | 是 | 回调函数。当光标后固定长度的文本获取成功,err为undefined,data为获取到的文本;否则为错误对象。 | **示例:** - ```js - var length = 1; - TextInputClient.getBackward(length, (err, text) => { - if (err === undefined) { - console.error('getBackward callback result---err: ' + err.msg); - return; - } - console.log('getBackward callback result---text: ' + text); - }); - ``` +```js +let length = 1; +TextInputClient.getBackward(length, (err, text) => { + if (err === undefined) { + console.error('getBackward err: ' + JSON.stringify(err)); + return; + } + console.log('getBackward result---text: ' + text); +}); +``` -### getBackward +### getBackward(deprecated) getBackward(length:number): Promise<string> -获取光标后固定长度的文本。使用promise形式返回结果。参数个数为1,否则抛出异常。 +获取光标后固定长度的文本。使用promise异步回调。 + +> **说明:** +> +> 从API version 8开始支持,API version 9开始废弃, 建议使用[getBackward](#getbackward9)替代。 -**系统能力**: SystemCapability.MiscServices.InputMethodFramework +**系统能力:** SystemCapability.MiscServices.InputMethodFramework **参数:** @@ -667,59 +1770,68 @@ getBackward(length:number): Promise<string> | 类型 | 说明 | | ------------------------------- | ------------------------------------------------------------ | -| Promise<string> | 返回文本。 | +| Promise<string> | Promise对象,返回光标后固定长度的文本。 | **示例:** - ```js - async function InputMethodEngine() { - var length = 1; - await TextInputClient.getBackward(length).then((text) => { - console.info('getBackward promise result---res: ' + text); - }).catch((err) => { - console.error('getBackward promise err: ' + err.msg); - }); - } - ``` +```js +async function InputMethodEngine() { + let length = 1; + await TextInputClient.getBackward(length).then((text) => { + console.info('getBackward result---res: ' + text); + }).catch((err) => { + console.error('getBackward err: ' + JSON.stringify(err)); + }); +} +``` -### deleteForward +### deleteForward(deprecated) deleteForward(length:number, callback: AsyncCallback<boolean>): void -删除光标前固定长度的文本。使用callback形式返回结果。参数个数为2,否则抛出异常。 +删除光标前固定长度的文本。使用callback异步回调。 -**系统能力**: SystemCapability.MiscServices.InputMethodFramework +> **说明:** +> +> 从API version 8开始支持,API version 9开始废弃, 建议使用[deleteForward](#deleteforward9)替代。 + +**系统能力:** SystemCapability.MiscServices.InputMethodFramework **参数:** | 参数名 | 类型 | 必填 | 说明 | | -------- | -------- | -------- | -------- | | length | number | 是 | 文本长度。 | -| callback | AsyncCallback<boolean> | 是 | 操作成功与否。 | +| callback | AsyncCallback<boolean> | 是 | 回调函数。当光标前固定长度的文本删除成功,err为undefined,data为true;否则为错误对象。 | **示例:** - ```js - var length = 1; - TextInputClient.deleteForward(length, (err, result) => { - if (err === undefined) { - console.error('deleteForward callback result---err: ' + err.msg); - return; - } - if (result) { - console.info('Success to deleteForward.(callback) '); - } else { - console.error('Failed to deleteForward.(callback) '); - } - }); - ``` -### deleteForward +```js +let length = 1; +TextInputClient.deleteForward(length, (err, result) => { + if (err === undefined) { + console.error('deleteForward err: ' + JSON.stringify(err)); + return; + } + if (result) { + console.info('Success to deleteForward. '); + } else { + console.error('Failed to deleteForward. '); + } +}); +``` + +### deleteForward(deprecated) deleteForward(length:number): Promise<boolean> -删除光标前固定长度的文本。使用promise形式返回结果。参数个数为1,否则抛出异常。 +删除光标前固定长度的文本。使用promise异步回调。 + +> **说明:** +> +> 从API version 8开始支持,API version 9开始废弃, 建议使用[deleteForward](#deleteforward9)替代。 -**系统能力**: SystemCapability.MiscServices.InputMethodFramework +**系统能力:** SystemCapability.MiscServices.InputMethodFramework **参数:** @@ -731,64 +1843,72 @@ deleteForward(length:number): Promise<boolean> | 类型 | 说明 | | ---------------------- | -------------- | -| Promise<boolean> | 操作成功与否。 | +| Promise<boolean> | Promise对象。返回true表示删除光标前固定长度的文本成功;返回false表示删除光标前固定长度的文本失败。| **示例:** ```js async function InputMethodEngine() { - var length = 1; + let length = 1; await TextInputClient.deleteForward(length).then((result) => { if (result) { - console.info('Success to deleteForward.(promise) '); + console.info('Success to deleteForward. '); } else { - console.error('Failed to deleteForward.(promise) '); + console.error('Failed to deleteForward. '); } }).catch((err) => { - console.error('deleteForward promise err: ' + err.msg); + console.error('deleteForward err: ' + JSON.stringify(err)); }); } ``` -### deleteBackward +### deleteBackward(deprecated) deleteBackward(length:number, callback: AsyncCallback<boolean>): void -删除光标后固定长度的文本。使用callback形式返回结果。参数个数为2,否则抛出异常。 +删除光标后固定长度的文本。使用callback异步回调。 -**系统能力**: SystemCapability.MiscServices.InputMethodFramework +> **说明:** +> +> 从API version 8开始支持,API version 9开始废弃, 建议使用[deleteBackward](#deletebackward9)替代。 + +**系统能力:** SystemCapability.MiscServices.InputMethodFramework **参数:** | 参数名 | 类型 | 必填 | 说明 | | -------- | ---------------------------- | ---- | -------------- | | length | number | 是 | 文本长度。 | -| callback | AsyncCallback<boolean> | 是 | 操作成功与否。 | +| callback | AsyncCallback<boolean> | 是 | 回调函数。当光标后固定长度的文本删除成功,err为undefined,data为true;否则为错误对象。| **示例:** ```js -var length = 1; +let length = 1; TextInputClient.deleteBackward(length, (err, result) => { if (err === undefined) { - console.error('deleteBackward callback result---err: ' + err.msg); + console.error('deleteBackward err: ' + JSON.stringify(err)); return; } if (result) { - console.info('Success to deleteBackward.(callback) '); + console.info('Success to deleteBackward. '); } else { - console.error('Failed to deleteBackward.(callback) '); + console.error('Failed to deleteBackward. '); } }); ``` -### deleteBackward +### deleteBackward(deprecated) deleteBackward(length:number): Promise<boolean> -删除光标后固定长度的文本。使用callback形式返回结果。参数个数为2,否则抛出异常。 +删除光标后固定长度的文本。使用callback异步回调。 + +> **说明:** +> +> 从API version 8开始支持,API version 9开始废弃, 建议使用[deleteBackward](#deletebackward9)替代。 -**系统能力**: SystemCapability.MiscServices.InputMethodFramework +**系统能力:** SystemCapability.MiscServices.InputMethodFramework **参数:** @@ -800,62 +1920,70 @@ deleteBackward(length:number): Promise<boolean> | 类型 | 说明 | | ------------------------------- | ------------------------------------------------------------ | -| Promise<boolean> | 操作成功与否。 | +| Promise<boolean> | Promise对象。返回true表示删除光标后固定长度的文本成功;返回false表示删除光标后固定长度的文本失败。| **示例:** ```js async function InputMethodEngine() { - var length = 1; + let length = 1; await TextInputClient.deleteBackward(length).then((result) => { if (result) { - console.info('Success to deleteBackward.(promise) '); + console.info('Success to deleteBackward. '); } else { - console.error('Failed to deleteBackward.(promise) '); + console.error('Failed to deleteBackward. '); } }).catch((err) => { - console.error('deleteBackward promise err: ' + err.msg); + console.error('deleteBackward err: ' + JSON.stringify(err)); }); } ``` -### sendKeyFunction +### sendKeyFunction(deprecated) sendKeyFunction(action:number, callback: AsyncCallback<boolean>): void -发送功能键。使用callback形式返回结果。参数个数为2,否则抛出异常。 +发送功能键。使用callback异步回调。 -**系统能力**: SystemCapability.MiscServices.InputMethodFramework +> **说明:** +> +> 从API version 8开始支持,API version 9开始废弃, 建议使用[sendKeyFunction](#sendkeyfunction9)替代。 + +**系统能力:** SystemCapability.MiscServices.InputMethodFramework **参数:** | 参数名 | 类型 | 必填 | 说明 | | -------- | -------- | -------- | -------- | | action | number | 是 | 编辑框属性。 | -| callback | AsyncCallback<boolean> | 是 | 操作成功与否。 | +| callback | AsyncCallback<boolean> | 是 | 回调函数。当功能键发送成功,err为undefined,data为true;否则为错误对象。 | **示例:** ```js TextInputClient.sendKeyFunction(keyFunction, (err, result) => { if (err === undefined) { - console.error('sendKeyFunction callback result---err: ' + err.msg); + console.error('sendKeyFunction err: ' + JSON.stringify(err)); return; } if (result) { - console.info('Success to sendKeyFunction.(callback) '); + console.info('Success to sendKeyFunction. '); } else { - console.error('Failed to sendKeyFunction.(callback) '); + console.error('Failed to sendKeyFunction. '); } }); ``` -### sendKeyFunction +### sendKeyFunction(deprecated) sendKeyFunction(action:number): Promise<boolean> -发送功能键。使用promise形式返回结果。参数个数为1,否则抛出异常。 +发送功能键。使用promise异步回调。 + +> **说明:** +> +> 从API version 8开始支持,API version 9开始废弃, 建议使用[sendKeyFunction](#sendkeyfunction9)替代。 -**系统能力**: SystemCapability.MiscServices.InputMethodFramework +**系统能力:** SystemCapability.MiscServices.InputMethodFramework **参数:** @@ -867,62 +1995,70 @@ sendKeyFunction(action:number): Promise<boolean> | 类型 | 说明 | | ------------------------------- | ------------------------------------------------------------ | -| Promise<boolean> | 操作成功与否。 | +| Promise<boolean> | Promise对象。返回true表示发送功能键成功;返回false表示发送功能键失败。 | **示例:** - ```js - async function InputMethodEngine() { - await client.sendKeyFunction(keyFunction).then((result) => { - if (result) { - console.info('Success to sendKeyFunction.(promise) '); - } else { - console.error('Failed to sendKeyFunction.(promise) '); - } - }).catch((err) => { - console.error('sendKeyFunction promise err:' + err.msg); - }); - } - ``` - -### insertText +```js +async function InputMethodEngine() { + await client.sendKeyFunction(keyFunction).then((result) => { + if (result) { + console.info('Success to sendKeyFunction. '); + } else { + console.error('Failed to sendKeyFunction. '); + } + }).catch((err) => { + console.error('sendKeyFunction err:' + JSON.stringify(err)); + }); +} +``` + +### insertText(deprecated) insertText(text:string, callback: AsyncCallback<boolean>): void -插入文本。使用callback形式返回结果。参数个数为2,否则抛出异常。 +插入文本。使用callback异步回调。 -**系统能力**: SystemCapability.MiscServices.InputMethodFramework +> **说明:** +> +> 从API version 8开始支持,API version 9开始废弃, 建议使用[insertText](#inserttext9)替代。 + +**系统能力:** SystemCapability.MiscServices.InputMethodFramework **参数:** | 参数名 | 类型 | 必填 | 说明 | | -------- | -------- | -------- | -------- | | text | string | 是 | 文本。 | -| callback | AsyncCallback<boolean> | 是 | 操作成功与否。 | +| callback | AsyncCallback<boolean> | 是 | 回调函数。当文本插入成功,err为undefined,data为true;否则为错误对象。 | **示例:** ```js TextInputClient.insertText('test', (err, result) => { if (err === undefined) { - console.error('insertText callback result---err: ' + err.msg); + console.error('insertText err: ' + JSON.stringify(err)); return; } if (result) { - console.info('Success to insertText.(callback) '); + console.info('Success to insertText. '); } else { - console.error('Failed to insertText.(callback) '); + console.error('Failed to insertText. '); } }); ``` -### insertText +### insertText(deprecated) insertText(text:string): Promise<boolean> -插入文本。使用promise形式返回结果。参数个数为1,否则抛出异常。 +插入文本。使用promise异步回调。 + +> **说明:** +> +> 从API version 8开始支持,API version 9开始废弃, 建议使用[insertText](#inserttext9)替代。 -**系统能力**: SystemCapability.MiscServices.InputMethodFramework +**系统能力:** SystemCapability.MiscServices.InputMethodFramework **参数:** @@ -934,155 +2070,82 @@ insertText(text:string): Promise<boolean> | 类型 | 说明 | | ------------------------------- | ------------------------------------------------------------ | -| Promise<boolean> | 操作成功与否。 | +| Promise<boolean> | Promise对象。返回true表示插入文本成功;返回false表示插入文本失败。 | **示例:** - ```js - async function InputMethodEngine() { - await TextInputClient.insertText('test').then((result) => { - if (result) { - console.info('Success to insertText.(promise) '); - } else { - console.error('Failed to insertText.(promise) '); - } - }).catch((err) => { - console.error('insertText promise err: ' + err.msg); - }); - } - ``` - -### getEditorAttribute +```js +async function InputMethodEngine() { + await TextInputClient.insertText('test').then((result) => { + if (result) { + console.info('Success to insertText. '); + } else { + console.error('Failed to insertText. '); + } + }).catch((err) => { + console.error('insertText err: ' + JSON.stringify(err)); + }); +} +``` + +### getEditorAttribute(deprecated) getEditorAttribute(callback: AsyncCallback<EditorAttribute>): void -获取编辑框属性值。使用callback形式返回结果。参数个数为1,否则抛出异常。 +获取编辑框属性值。使用callback异步回调。 -**系统能力**: SystemCapability.MiscServices.InputMethodFramework +> **说明:** +> +> 从API version 8开始支持,API version 9开始废弃, 建议使用[getEditorAttribute](#geteditorattribute9)替代。 + +**系统能力:** SystemCapability.MiscServices.InputMethodFramework **参数:** | 参数名 | 类型 | 必填 | 说明 | | ------------------------------- | ------------------------------------------------------------ | ------------------------------------------------------------ | ------------------------------------------------------------ | -| callback | AsyncCallback<[EditorAttribute](#EditorAttribute)> | 是 | 编辑框属性值。 | - -**示例:** - - ```js - TextInputClient.getEditorAttribute((err, editorAttribute) => { - if (err === undefined) { - console.error('getEditorAttribute callback result---err: ' + err.msg); - return; - } - console.log('editorAttribute.inputPattern(callback): ' + JSON.stringify(editorAttribute.inputPattern)); - console.log('editorAttribute.enterKeyType(callback): ' + JSON.stringify(editorAttribute.enterKeyType)); - }); - ``` - -### getEditorAttribute - -getEditorAttribute(): Promise<EditorAttribute> - -获取编辑框属性值。使用promise形式返回结果。参数个数为0,否则抛出异常。 - -**系统能力**: SystemCapability.MiscServices.InputMethodFramework - -**返回值:** - -| 类型 | 说明 | -| ------------------------------- | ------------------------------------------------------------ | -| Promise<[EditorAttribute](#EditorAttribute)> | 返回编辑框属性值。 | - -**示例:** - - ```js - async function InputMethodEngine() { - await TextInputClient.getEditorAttribute().then((editorAttribute) => { - console.info('editorAttribute.inputPattern(promise): ' + JSON.stringify(editorAttribute.inputPattern)); - console.info('editorAttribute.enterKeyType(promise): ' + JSON.stringify(editorAttribute.enterKeyType)); - }).catch((err) => { - console.error('getEditorAttribute promise err: ' + err.msg); - }); - } - ``` - -### moveCursor9+ - -moveCursor(direction: number, callback: AsyncCallback<void>): void - -移动光标。使用callback形式返回结果。参数个数为1,否则抛出异常。 - -**系统能力**: SystemCapability.MiscServices.InputMethodFramework - -**参数:** - -| 参数名 | 类型 | 必填 | 说明 | -| --------- | ------------------------- | ---- | -------------- | -| direction | number | 是 | 光标移动方向。 | -| callback | AsyncCallback<void> | 是 | 回调函数。 | +| callback | AsyncCallback<[EditorAttribute](#editorattribute)> | 是 | 回调函数。当编辑框的属性值获取成功,err为undefined,data为编辑框属性值;否则为错误对象。| **示例:** ```js -TextInputClient.moveCursor(inputMethodEngine.CURSOR_xxx, (err) => { +TextInputClient.getEditorAttribute((err, editorAttribute) => { if (err === undefined) { - console.error('moveCursor callback result---err: ' + err.msg); + console.error('getEditorAttribute err: ' + JSON.stringify(err)); return; } + console.log('editorAttribute.inputPattern: ' + JSON.stringify(editorAttribute.inputPattern)); + console.log('editorAttribute.enterKeyType: ' + JSON.stringify(editorAttribute.enterKeyType)); }); ``` -### moveCursor9+ - -moveCursor(direction: number): Promise<void> +### getEditorAttribute(deprecated) -移动光标。使用promise形式返回结果。参数个数为1,否则抛出异常。 +getEditorAttribute(): Promise<EditorAttribute> -**系统能力**: SystemCapability.MiscServices.InputMethodFramework +获取编辑框属性值。使用promise异步回调。 -**参数:** +> **说明:** +> +> 从API version 8开始支持,API version 9开始废弃, 建议使用[getEditorAttribute](#geteditorattribute9)替代。 -| 参数名 | 类型 | 必填 | 说明 | -| --------- | ------ | ---- | -------------- | -| direction | number | 是 | 光标移动方向。 | +**系统能力:** SystemCapability.MiscServices.InputMethodFramework -**返回值:** +**返回值:** -| 类型 | 说明 | -| ------------------- | ------------------------- | -| Promise<void> | 无返回结果的Promise对象。 | +| 类型 | 说明 | +| ------------------------------- | ------------------------------------------------------------ | +| Promise<[EditorAttribute](#editorattribute)> | Promise对象,返回编辑框属性值。 | **示例:** - ```js +```js async function InputMethodEngine() { - await TextInputClient.moveCursor(inputMethodEngine.CURSOR_xxx).then(async (err) => { - console.log('moveCursor success'); + await TextInputClient.getEditorAttribute().then((editorAttribute) => { + console.info('editorAttribute.inputPattern: ' + JSON.stringify(editorAttribute.inputPattern)); + console.info('editorAttribute.enterKeyType: ' + JSON.stringify(editorAttribute.enterKeyType)); }).catch((err) => { - console.error('moveCursor success err: ' + err.msg); + console.error('getEditorAttribute err: ' + JSON.stringify(err)); }); } - ``` - -## EditorAttribute - -编辑框属性值。 - -**系统能力**:以下各项对应的系统能力均为SystemCapability.MiscServices.InputMethodFramework - -| 名称 | 参数类型 | 可读 | 可写 | 说明 | -| ------------ | -------- | ---- | ---- | ------------------ | -| enterKeyType | number | 是 | 否 | 编辑框的功能属性。 | -| inputPattern | number | 是 | 否 | 编辑框的文本属性。 | - -## KeyEvent - -按键属性值。 - -**系统能力**:以下各项对应的系统能力均为SystemCapability.MiscServices.InputMethodFramework - -| 名称 | 参数类型 | 可读 | 可写 | 说明 | -| --------- | -------- | ---- | ---- | ------------ | -| keyCode | number | 是 | 否 | 按键的键值。 | -| keyAction | number | 是 | 否 | 按键的状态。 | - +``` \ No newline at end of file diff --git a/zh-cn/application-dev/reference/errorcodes/errcode-inputmethod-framework.md b/zh-cn/application-dev/reference/errorcodes/errcode-inputmethod-framework.md new file mode 100644 index 0000000000000000000000000000000000000000..1a1ff6b678814c19bcceb1ec491d27488c6e0477 --- /dev/null +++ b/zh-cn/application-dev/reference/errorcodes/errcode-inputmethod-framework.md @@ -0,0 +1,145 @@ +# 输入法框架错误码 + +## 12800001 包管理服务异常 + +**错误信息** + +Package manager error. + +**错误描述** + +当依赖包管理接口来获取一些信息失败时,系统会报此错误码。 + +**可能原因** + +在调用getInputMethods、listCurrentInputMethodSubtype等接口获取输入法及子类型的时候,由于获取包管理服务异常时会报错。 + +**处理步骤** + +无 + +## 12800002 输入法应用异常 + +**错误信息** + +Input method engine error. + +**错误描述** + +用户调用输入法应用接口失败时,系统会报此错误码。 + +**可能原因** + +在执行显示键盘、隐藏键盘等操作时,由于输入法应用进程死亡导致操作失败时会报错。 + +**处理步骤** + +查看输入法应用进程是否正常。例如再次在普通应用(微信、联系人等第三方应用)中点击对话框看键盘能否被正常拉起。 + +## 12800003 客户端应用异常 + +**错误信息** + +Input method client error. + +**错误描述** + +当三方应用(微信、设置、联系人等)的对话框等编辑控件调用显示键盘、隐藏键盘失败时,系统会报此错误码。 + +**可能原因** + +三方应用客户端服务异常导致输入法应用与三方应用客户端断链。 + +**处理步骤** + +重新将输入法应用与三方应用进行绑定:将三方应用后台进程杀死,重新启动三方应用,通过点击对话框等方式触发输入法键盘的显示,若键盘正常显示,则问题解决。 + +## 12800004 按键事件处理异常 + +**错误信息** + +Key event processing error. + +**错误描述** + +当按键事件异常时,系统会报此错误码。 + +**可能原因** + +按键事件分发、消费、监听异常时会报错。 + +**处理步骤** + +无 + +## 12800005 配置固化失败 + +**错误信息** + +Configuration persisting error. + +**错误描述** + +当保存配置失败时,系统会报此错误码。 + +**可能原因** + +当调用切换输入法接口的时候,会保存输入法的配置参数,系统参数配置模块异常导致参数保存失败时会报错。 + +**处理步骤** + +执行hdc shell param get persist.sys.default_ime查看默认输入法参数,若可查看,则系统参数配置模块正常,可重启设备进行尝试。 + +## 12800006 输入法控制器异常 + +**错误信息** + +Input method controller error. + +**错误描述** + +当获取到输入法控制器失败时,系统会报此错误码。 + +**可能原因** + +在调用getCotroller接口获取输入法控制器InputMethodController时发生异常时会报错。 + +**处理步骤** + +无。 + +## 12800007 输入法设置器异常 + +**错误信息** + +Input method settings extension error. + +**错误描述** + +当获取到输入法设置器发生错误时,系统会报此错误码。 + +**可能原因** + +在调用getSetting接口获取输入法设置器InputMethodSetting时发生异常时会报错。 + +**处理步骤** + +无。 + +## 12800008 输入法管理服务异常 + +**错误信息** + +Input method manager service error. + +**错误描述** + +获取输入法管理服务异常时,系统会报此错误码。 + +**可能原因** + +当调用[输入法框架](../apis/js-apis-inputmethod.md)中的任何接口都有可能由于依赖输入法管理服务,而服务找不到时发生此异常。 + +**处理步骤** + +通过ps -A|grep inputmethod查看是否存在输入法服务的进程号,如果存在,则服务正常。 \ No newline at end of file