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 9ae4dc93477c7b3d9ce24f13eaf195d508310f05..7442c05d9062d1d6d83207f90ad860bfe1b170b9 100644 --- a/zh-cn/application-dev/reference/apis/js-apis-inputmethod.md +++ b/zh-cn/application-dev/reference/apis/js-apis-inputmethod.md @@ -31,14 +31,14 @@ import inputMethod from '@ohos.inputmethod'; | 名称 | 类型 | 可读 | 可写 | 说明 | | -------- | -------- | -------- | -------- | -------- | -| name9+ | string | 是 | 否 | 输入法内部名称。 | -| id9+ | string | 是 | 否 | 输入法唯一标识。 | -| label9+ | string | 是 | 否 | 输入法对外显示名称。 | -| icon9+ | string | 是 | 否 | 输入法图标数据。 | -| iconId9+ | number | 是 | 否 | 输入法图标资源号。 | -| extra9+ | object | 是 | 否 | 输入法扩展信息。 | -| packageName(deprecated) | string | 是 | 否 | 输入法包名。
**说明:** 从API version 8开始支持,从API version 9开始废弃,建议使用name替代。 | -| methodId(deprecated) | string | 是 | 否 | 输入法唯一标识。
**说明:** 从API version 8开始支持,从API version 9开始废弃,建议使用id替代。 | +| name9+ | string | 是 | 否 | 输入法内部名称。必填。| +| id9+ | string | 是 | 否 | 输入法唯一标识。必填。| +| label9+ | string | 是 | 否 | 输入法对外显示名称。 非必填。| +| icon9+ | string | 是 | 否 | 输入法图标数据。非必填。 | +| iconId9+ | number | 是 | 否 | 输入法图标资源号。非必填。 | +| extra9+ | object | 是 | 是 | 输入法扩展信息。 必填。| +| packageName(deprecated) | string | 是 | 否 | 输入法包名。必填。
**说明:** 从API version 8开始支持,从API version 9开始废弃,建议使用name替代。 | +| methodId(deprecated) | string | 是 | 否 | 输入法唯一标识。必填。
**说明:** 从API version 8开始支持,从API version 9开始废弃,建议使用id替代。 | ## inputMethod.getController9+ @@ -102,7 +102,7 @@ switchInputMethod(target: InputMethodProperty, callback: AsyncCallback<boolea 切换输入法。使用callback异步回调。 -**需要权限:** ohos.permission.CONNECT_IME_ABILITY +**需要权限:** ohos.permission.CONNECT_IME_ABILITY,仅系统应用可用。 **系统能力:** SystemCapability.MiscServices.InputMethodFramework @@ -120,25 +120,33 @@ switchInputMethod(target: InputMethodProperty, callback: AsyncCallback<boolea | 错误码ID | 错误信息 | | -------- | -------------------------------------- | | 12800005 | Configuration persisting error. | -| 12800008 | Input method settings extension error. | +| 12800008 | Input method manager service error. | **示例:** ```js +let im = inputMethod.getCurrentInputMethod(); +let prop = { + packageName: im.packageName, + methodId: im.methodId, + name: im.packageName, + id: im.methodId, + extra: {} +} try{ - inputMethod.switchInputMethod({packageName:'com.example.kikakeyboard', methodId:'com.example.kikakeyboard', extra: {}}, (err, result) => { - if (err) { - console.error('switchInputMethod err: ' + JSON.stringify(err)); + inputMethod.switchInputMethod(prop, (err, result) => { + if (err !== undefined) { + console.error('Failed to switchInputMethod: ' + JSON.stringify(err)); return; } if (result) { - console.info('Success to switchInputMethod.(callback)'); + console.info('Succeeded in switching inputmethod.'); } else { - console.error('Failed to switchInputMethod.(callback)'); + console.error('Failed to switchInputMethod.'); } }); } catch(err) { - console.error('switchInputMethod err: ' + JSON.stringify(err)); + console.error('Failed to switchInputMethod: ' + JSON.stringify(err)); } ``` ## inputMethod.switchInputMethod9+ @@ -146,7 +154,7 @@ switchInputMethod(target: InputMethodProperty): Promise<boolean> 切换输入法。使用promise异步回调。 -**需要权限:** ohos.permission.CONNECT_IME_ABILITY +**需要权限:** ohos.permission.CONNECT_IME_ABILITY,仅系统应用可用。 **系统能力:** SystemCapability.MiscServices.InputMethodFramework @@ -169,23 +177,31 @@ switchInputMethod(target: InputMethodProperty): Promise<boolean> | 错误码ID | 错误信息 | | -------- | -------------------------------------- | | 12800005 | Configuration persisting error. | -| 12800008 | Input method settings extension error. | +| 12800008 | Input method manager service error. | **示例:** ```js +let im = inputMethod.getCurrentInputMethod(); +let prop = { + packageName: im.packageName, + methodId: im.methodId, + name: im.packageName, + id: im.methodId, + extra: {} +} try { - inputMethod.switchInputMethod({packageName:'com.example.kikakeyboard', methodId:'com.example.kikakeyboard', extra: {}}).then((result) => { + inputMethod.switchInputMethod(prop).then((result) => { if (result) { - console.info('Success to switchInputMethod.'); + console.info('Succeeded in switching inputmethod.'); } else { console.error('Failed to switchInputMethod.'); } }).catch((err) => { - console.error('switchInputMethod err: ' + JSON.stringify(err)); + console.error('Failed to switchInputMethod: ' + JSON.stringify(err)); }) } catch(err) { - console.error('switchInputMethod err: ' + JSON.stringify(err)); + console.error('Failed to switchInputMethod: ' + JSON.stringify(err)); } ``` @@ -215,7 +231,7 @@ switchCurrentInputMethodSubtype(target: InputMethodSubtype, callback: AsyncCallb 在当前输入法应用内切换子类型。使用callback异步回调。 -**需要权限:** ohos.permission.CONNECT_IME_ABILITY +**需要权限:** ohos.permission.CONNECT_IME_ABILITY,仅系统应用可用。 **系统能力:** SystemCapability.MiscServices.InputMethodFramework @@ -233,36 +249,35 @@ switchCurrentInputMethodSubtype(target: InputMethodSubtype, callback: AsyncCallb | 错误码ID | 错误信息 | | -------- | -------------------------------------- | | 12800005 | Configuration persisting error. | -| 12800008 | Input method settings extension error. | +| 12800008 | Input method manager service error. | **示例:** ```js -let inputMethodSubtype = { - id: "com.example.kikakeyboard", - label: "ServiceExtAbility", - name: "", - mode: "upper", - locale: "", - language: "", - icon: "", - iconId: 0, - extra: {} -} try { - inputMethod.switchCurrentInputMethodSubtype(inputMethodSubtype, (err, result) => { - if (err) { - console.error('switchCurrentInputMethodSubtype err: ' + JSON.stringify(err)); + inputMethod.switchCurrentInputMethodSubtype({ + id: "com.example.kikakeyboard", + label: "ServiceExtAbility", + name: "", + mode: "upper", + locale: "", + language: "", + icon: "", + iconId: 0, + extra: {} + }, (err, result) => { + if (err !== undefined) { + console.error('Failed to switchCurrentInputMethodSubtype: ' + JSON.stringify(err)); return; } if (result) { - console.info('Success to switchCurrentInputMethodSubtype.(callback)'); + console.info('Succeeded in switching currentInputMethodSubtype.'); } else { - console.error('Failed to switchCurrentInputMethodSubtype.(callback)'); + console.error('Failed to switchCurrentInputMethodSubtype'); } }); } catch(err) { - console.error('switchCurrentInputMethodSubtype err: ' + JSON.stringify(err)); + console.error('Failed to switchCurrentInputMethodSubtype: ' + JSON.stringify(err)); } ``` @@ -272,7 +287,7 @@ switchCurrentInputMethodSubtype(target: InputMethodSubtype): Promise<boolean& 在当前输入法应用内切换子类型。使用promise异步回调。 -**需要权限:** ohos.permission.CONNECT_IME_ABILITY +**需要权限:** ohos.permission.CONNECT_IME_ABILITY,仅系统应用可用。 **系统能力:** SystemCapability.MiscServices.InputMethodFramework @@ -295,34 +310,33 @@ switchCurrentInputMethodSubtype(target: InputMethodSubtype): Promise<boolean& | 错误码ID | 错误信息 | | -------- | -------------------------------------- | | 12800005 | Configuration persisting error. | -| 12800008 | Input method settings extension error. | +| 12800008 | Input method manager service error. | **示例:** ```js -let inputMethodSubtype = { - id: "com.example.kikakeyboard", - label: "ServiceExtAbility", - name: "", - mode: "upper", - locale: "", - language: "", - icon: "", - iconId: 0, - extra: {} -} try { - inputMethod.switchCurrentInputMethodSubtype(inputMethodSubtype).then((result) => { + inputMethod.switchCurrentInputMethodSubtype({ + id: "com.example.kikakeyboard", + label: "ServiceExtAbility", + name: "", + mode: "upper", + locale: "", + language: "", + icon: "", + iconId: 0, + extra: {} + }).then((result) => { if (result) { - console.info('Success to switchCurrentInputMethodSubtype.'); + console.info('Succeeded in switching currentInputMethodSubtype.'); } else { console.error('Failed to switchCurrentInputMethodSubtype.'); } }).catch((err) => { - console.error('switchCurrentInputMethodSubtype err: ' + JSON.stringify(err)); + console.error('Failed to switchCurrentInputMethodSubtype: ' + JSON.stringify(err)); }) } catch(err) { - console.error('switchCurrentInputMethodSubtype err: ' + JSON.stringify(err)); + console.error('Failed to switchCurrentInputMethodSubtype: ' + JSON.stringify(err)); } ``` @@ -352,7 +366,7 @@ switchCurrentInputMethodAndSubtype(inputMethodProperty: InputMethodProperty, inp 切换至指定输入法应用的指定子类型,用于跨输入法应用切换子类型。使用callback异步回调。 -**需要权限:** ohos.permission.CONNECT_IME_ABILITY +**需要权限:** ohos.permission.CONNECT_IME_ABILITY,仅系统应用可用。 **系统能力:** SystemCapability.MiscServices.InputMethodFramework @@ -371,41 +385,43 @@ switchCurrentInputMethodAndSubtype(inputMethodProperty: InputMethodProperty, inp | 错误码ID | 错误信息 | | -------- | -------------------------------------- | | 12800005 | Configuration persisting error. | -| 12800008 | Input method settings extension error. | +| 12800008 | Input method manager service error. | **示例:** ```js +let im = inputMethod.getCurrentInputMethod(); let inputMethodProperty = { - packageName: "com.example.kikakeyboard", - methodId: "ServiceExtAbility", - extra: {} -} -let inputMethodSubProperty = { - id: "com.example.kikakeyboard", - label: "ServiceExtAbility", - name: "", - mode: "upper", - locale: "", - language: "", - icon: "", - iconId: 0, + packageName: im.packageName, + methodId: im.methodId, + name: im.packageName, + id: im.methodId, extra: {} } try { - inputMethod.switchCurrentInputMethodAndSubtype(inputMethodProperty, inputMethodSubProperty, (err,result) => { - if (err) { - console.error('switchCurrentInputMethodAndSubtype err: ' + JSON.stringify(err)); + inputMethod.switchCurrentInputMethodAndSubtype(inputMethodProperty, { + id: "com.example.kikakeyboard", + label: "ServiceExtAbility", + name: "", + mode: "upper", + locale: "", + language: "", + icon: "", + iconId: 0, + extra: {} + }, (err,result) => { + if (err !== undefined) { + console.error('Failed to switchCurrentInputMethodAndSubtype: ' + JSON.stringify(err)); return; } if (result) { - console.info('Success to switchCurrentInputMethodAndSubtype.(callback)'); + console.info('Succeeded in switching currentInputMethodAndSubtype.'); } else { - console.error('Failed to switchCurrentInputMethodAndSubtype.(callback)'); + console.error('Failed to switchCurrentInputMethodAndSubtype.'); } }); } catch (err) { - console.error('switchCurrentInputMethodAndSubtype err: ' + JSON.stringify(err)); + console.error('Failed to switchCurrentInputMethodAndSubtype: ' + JSON.stringify(err)); } ``` @@ -415,7 +431,7 @@ switchCurrentInputMethodAndSubtype(inputMethodProperty: InputMethodProperty, inp 切换至指定输入法应用的指定子类型,用于跨输入法应用切换子类型。使用promise异步回调。 -**需要权限:** ohos.permission.CONNECT_IME_ABILITY +**需要权限:** ohos.permission.CONNECT_IME_ABILITY,仅系统应用可用。 **系统能力:** SystemCapability.MiscServices.InputMethodFramework @@ -439,39 +455,41 @@ switchCurrentInputMethodAndSubtype(inputMethodProperty: InputMethodProperty, inp | 错误码ID | 错误信息 | | -------- | -------------------------------------- | | 12800005 | Configuration persisting error. | -| 12800008 | Input method settings extension error. | +| 12800008 | Input method manager service error. | **示例:** ```js +let im = inputMethod.getCurrentInputMethod(); let inputMethodProperty = { - packageName: "com.example.kikakeyboard", - methodId: "ServiceExtAbility", - extra: {} -} -let inputMethodSubProperty = { - id: "com.example.kikakeyboard", - label: "ServiceExtAbility", - name: "", - mode: "upper", - locale: "", - language: "", - icon: "", - iconId: 0, + packageName: im.packageName, + methodId: im.methodId, + name: im.packageName, + id: im.methodId, extra: {} } try { - inputMethod.switchCurrentInputMethodAndSubtype(inputMethodProperty, inputMethodSubProperty).then((result) => { + inputMethod.switchCurrentInputMethodAndSubtype(inputMethodProperty, { + id: im.packageName, + label: im.methodId, + name: "", + mode: "upper", + locale: "", + language: "", + icon: "", + iconId: 0, + extra: {} + }).then((result) => { if (result) { - console.info('Success to switchCurrentInputMethodAndSubtype.'); + console.info('Succeeded in switching currentInputMethodAndSubtype.'); } else { console.error('Failed to switchCurrentInputMethodAndSubtype.'); } }).catch((err) => { - console.error('switchCurrentInputMethodAndSubtype err: ' + err); + console.error('Failed to switchCurrentInputMethodAndSubtype: ' + JSON.stringify(err)); }) } catch(err) { - console.error('switchCurrentInputMethodAndSubtype err: ' + err); + console.error('Failed to switchCurrentInputMethodAndSubtype: ' + JSON.stringify(err)); } ``` @@ -548,25 +566,25 @@ stopInputSession(callback: AsyncCallback<boolean>): void | 错误码ID | 错误信息 | | -------- | -------------------------------------- | | 12800003 | Input method client error. | -| 12800008 | Input method settings extension error. | +| 12800008 | Input method manager service error. | **示例:** ```js try { inputMethodController.stopInputSession((error, result) => { - if (error) { - console.error('stopInputSession err: ' + JSON.stringify(error)); + if (error !== undefined) { + console.error('Failed to stopInputSession: ' + JSON.stringify(error)); return; } if (result) { - console.info('Success to stopInputSession.(callback)'); + console.info('Succeeded in stopping inputSession.'); } else { - console.error('Failed to stopInputSession.(callback)'); + console.error('Failed to stopInputSession.'); } }); } catch(error) { - console.error('stopInputSession err: ' + JSON.stringify(error)); + console.error('Failed to stopInputSession: ' + JSON.stringify(error)); } ``` @@ -591,7 +609,7 @@ stopInputSession(): Promise<boolean> | 错误码ID | 错误信息 | | -------- | -------------------------------------- | | 12800003 | Input method client error. | -| 12800008 | Input method settings extension error. | +| 12800008 | Input method manager service error. | **示例:** @@ -599,15 +617,15 @@ stopInputSession(): Promise<boolean> try { inputMethodController.stopInputSession().then((result) => { if (result) { - console.info('Success to stopInputSession.'); + console.info('Succeeded in stopping inputSession.'); } else { console.error('Failed to stopInputSession.'); } }).catch((err) => { - console.error('stopInputSession err: ' + JSON.stringify(err)); + console.error('Failed to stopInputSession: ' + JSON.stringify(err)); }) } catch(err) { - console.error('stopInputSession err: ' + JSON.stringify(err)); + console.error('Failed to stopInputSession: ' + JSON.stringify(err)); } ``` @@ -617,7 +635,7 @@ showSoftKeyboard(callback: AsyncCallback<void>): void 显示软键盘。需要与输入框绑定使用。当点击输入框后,才可通过该接口的调用显示出当前输入法的软键盘。使用callback异步回调。 -**需要权限:** ohos.permission.CONNECT_IME_ABILITY +**需要权限:** ohos.permission.CONNECT_IME_ABILITY,仅系统应用可用。 **系统能力:** SystemCapability.MiscServices.InputMethodFramework @@ -634,16 +652,16 @@ showSoftKeyboard(callback: AsyncCallback<void>): void | 错误码ID | 错误信息 | | -------- | -------------------------------------- | | 12800003 | Input method client error. | -| 12800008 | Input method settings extension error. | +| 12800008 | Input method manager service error. | **示例:** ```js inputMethodController.showSoftKeyboard((err) => { if (err === undefined) { - console.info('showSoftKeyboard success'); + console.info('Succeeded in showing softKeyboard.'); } else { - console.error('showSoftKeyboard failed because : ' + JSON.stringify(err)); + console.error('Failed to showSoftKeyboard: ' + JSON.stringify(err)); } }) ``` @@ -654,7 +672,7 @@ showSoftKeyboard(): Promise<void> 显示软键盘。需要与输入框绑定使用。当点击输入框后,才可通过该接口的调用显示出当前输入法的软键盘。使用Promise异步回调。 -**需要权限:** ohos.permission.CONNECT_IME_ABILITY +**需要权限:** ohos.permission.CONNECT_IME_ABILITY,仅系统应用可用。 **系统能力:** SystemCapability.MiscServices.InputMethodFramework @@ -671,15 +689,15 @@ showSoftKeyboard(): Promise<void> | 错误码ID | 错误信息 | | -------- | -------------------------------------- | | 12800003 | Input method client error. | -| 12800008 | Input method settings extension error. | +| 12800008 | Input method manager service error. | **示例:** ```js -inputMethodController.showSoftKeyboard().then(async (err) => { - console.log('showSoftKeyboard success'); +inputMethodController.showSoftKeyboard().then(() => { + console.log('Succeeded in showing softKeyboard.'); }).catch((err) => { - console.error('showSoftKeyboard err: ' + JSON.stringify(err)); + console.error('Failed to showSoftKeyboard: ' + JSON.stringify(err)); }); ``` @@ -689,7 +707,7 @@ hideSoftKeyboard(callback: AsyncCallback<void>): void 隐藏软键盘。需要与输入框绑定使用。点击输入框后,才可以使用该接口的调用隐藏软键盘。使用callback异步回调。 -**需要权限:** ohos.permission.CONNECT_IME_ABILITY +**需要权限:** ohos.permission.CONNECT_IME_ABILITY,仅系统应用可用。 **系统能力:** SystemCapability.MiscServices.InputMethodFramework @@ -706,16 +724,16 @@ hideSoftKeyboard(callback: AsyncCallback<void>): void | 错误码ID | 错误信息 | | -------- | -------------------------------------- | | 12800003 | Input method client error. | -| 12800008 | Input method settings extension error. | +| 12800008 | Input method manager service error. | **示例:** ```js inputMethodController.hideSoftKeyboard((err) => { if (err === undefined) { - console.info('hideSoftKeyboard success'); + console.info('Succeeded in hiding softKeyboard.'); } else { - console.error('hideSoftKeyboard failed because : ' + JSON.stringify(err)); + console.error('Failed to hideSoftKeyboard: ' + JSON.stringify(err)); } }) ``` @@ -726,7 +744,7 @@ hideSoftKeyboard(): Promise<void> 隐藏软键盘。需要与输入框绑定使用。点击输入框后,才可以使用该接口的调用隐藏软键盘。使用Promise异步回调。 -**需要权限:** ohos.permission.CONNECT_IME_ABILITY +**需要权限:** ohos.permission.CONNECT_IME_ABILITY,仅系统应用可用。 **系统能力:** SystemCapability.MiscServices.InputMethodFramework @@ -743,15 +761,15 @@ hideSoftKeyboard(): Promise<void> | 错误码ID | 错误信息 | | -------- | -------------------------------------- | | 12800003 | Input method client error. | -| 12800008 | Input method settings extension error. | +| 12800008 | Input method manager service error. | **示例:** ```js -inputMethodController.hideSoftKeyboard().then(async (err) => { - console.log('hideSoftKeyboard success'); +inputMethodController.hideSoftKeyboard().then(() => { + console.log('Succeeded in hiding softKeyboard.'); }).catch((err) => { - console.error('hideSoftKeyboard err: ' + JSON.stringify(err)); + console.error('Failed to hideSoftKeyboard: ' + JSON.stringify(err)); }); ``` @@ -777,14 +795,14 @@ stopInput(callback: AsyncCallback<boolean>): void ```js inputMethodController.stopInput((error, result) => { - if (error) { - console.error('failed to stopInput because: ' + JSON.stringify(error)); + if (error !== undefined) { + console.error('Failed to stopInput: ' + JSON.stringify(error)); return; } if (result) { - console.info('Success to stopInput.(callback)'); + console.info('Succeeded in stopping input.'); } else { - console.error('Failed to stopInput.(callback)'); + console.error('Failed to stopInput.'); } }); ``` @@ -812,12 +830,12 @@ stopInput(): Promise<boolean> ```js inputMethodController.stopInput().then((result) => { if (result) { - console.info('Success to stopInput.'); + console.info('Succeeded in stopping input.'); } else { console.error('Failed to stopInput.'); } }).catch((err) => { - console.error('stopInput err: ' + err); + console.error('Failed to stopInput: ' + err); }) ``` @@ -891,26 +909,28 @@ listInputMethodSubtype(inputMethodProperty: InputMethodProperty, callback: Async | 错误码ID | 错误信息 | | -------- | -------------------------------------- | | 12800001 | Package manager error. | -| 12800008 | Input method settings extension error. | +| 12800008 | Input method manager service error. | **示例:** ```js let inputMethodProperty = { - packageName:'com.example.kikakeyboard', - methodId:'com.example.kikakeyboard', + packageName: 'com.example.kikakeyboard', + methodId: 'com.example.kikakeyboard', + name: 'com.example.kikakeyboard', + id: 'com.example.kikakeyboard', extra:{} } try { inputMethodSetting.listInputMethodSubtype(inputMethodProperty, (err,data) => { - if (err) { - console.error('listInputMethodSubtype failed: ' + JSON.stringify(err)); + if (err !== undefined) { + console.error('Failed to listInputMethodSubtype: ' + JSON.stringify(err)); return; } - console.log('listInputMethodSubtype success'); + console.log('Succeeded in listing inputMethodSubtype.'); }); } catch (err) { - console.error('listInputMethodSubtype failed: ' + JSON.stringify(err)); + console.error('Failed to listInputMethodSubtype: ' + JSON.stringify(err)); } ``` @@ -941,24 +961,26 @@ listInputMethodSubtype(inputMethodProperty: InputMethodProperty): Promise<Arr | 错误码ID | 错误信息 | | -------- | -------------------------------------- | | 12800001 | Package manager error. | -| 12800008 | Input method settings extension error. | +| 12800008 | Input method manager service error. | **示例:** ```js let inputMethodProperty = { - packageName:'com.example.kikakeyboard', - methodId:'com.example.kikakeyboard', + packageName: 'com.example.kikakeyboard', + methodId: 'com.example.kikakeyboard', + name: 'com.example.kikakeyboard', + id: 'com.example.kikakeyboard', extra:{} } try { inputMethodSetting.listInputMethodSubtype(inputMethodProperty).then((data) => { - console.info('listInputMethodSubtype success'); + console.info('Succeeded in listing inputMethodSubtype.'); }).catch((err) => { - console.error('listInputMethodSubtype err: ' + JSON.stringify(err)); + console.error('Failed to listInputMethodSubtype: ' + JSON.stringify(err)); }) } catch(err) { - console.error('listInputMethodSubtype err: ' + JSON.stringify(err)); + console.error('Failed to listInputMethodSubtype: ' + JSON.stringify(err)); } ``` @@ -983,21 +1005,21 @@ listCurrentInputMethodSubtype(callback: AsyncCallback<Array<InputMethodSub | 错误码ID | 错误信息 | | -------- | -------------------------------------- | | 12800001 | Package manager error. | -| 12800008 | Input method settings extension error. | +| 12800008 | Input method manager service error. | **示例:** ```js try { inputMethodSetting.listCurrentInputMethodSubtype((err, data) => { - if (err) { - console.error('listCurrentInputMethodSubtype failed: ' + JSON.stringify(err)); + if (err !== undefined) { + console.error('Failed to listCurrentInputMethodSubtype: ' + JSON.stringify(err)); return; } - console.log('listCurrentInputMethodSubtype success'); + console.log('Succeeded in listing currentInputMethodSubtype.'); }); } catch(err) { - console.error('listCurrentInputMethodSubtype err: ' + JSON.stringify(err)); + console.error('Failed to listCurrentInputMethodSubtype: ' + JSON.stringify(err)); } ``` @@ -1022,19 +1044,19 @@ listCurrentInputMethodSubtype(): Promise<Array<InputMethodSubtype>> | 错误码ID | 错误信息 | | -------- | -------------------------------------- | | 12800001 | Package manager error. | -| 12800008 | Input method settings extension error. | +| 12800008 | Input method manager service error. | **示例:** ```js try { inputMethodSetting.listCurrentInputMethodSubtype().then((data) => { - console.info('listCurrentInputMethodSubtype success'); + console.info('Succeeded in listing currentInputMethodSubtype.'); }).catch((err) => { - console.error('listCurrentInputMethodSubtype err: ' + err); + console.error('Failed to listCurrentInputMethodSubtype: ' + JSON.stringify(err)); }) } catch(err) { - console.error('listCurrentInputMethodSubtype err: ' + JSON.stringify(err)); + console.error('Failed to listCurrentInputMethodSubtype: ' + JSON.stringify(err)); } ``` @@ -1060,21 +1082,21 @@ getInputMethods(enable: boolean, callback: AsyncCallback<Array<InputMethod | 错误码ID | 错误信息 | | -------- | -------------------------------------- | | 12800001 | Package manager error. | -| 12800008 | Input method settings extension error. | +| 12800008 | Input method manager service error. | **示例:** ```js try { inputMethodSetting.getInputMethods(true, (err,data) => { - if (err) { - console.error('getInputMethods failed: ' + JSON.stringify(err)); + if (err !== undefined) { + console.error('Failed to getInputMethods: ' + JSON.stringify(err)); return; } - console.log('getInputMethods success'); + console.log('Succeeded in getting inputMethods.'); }); } catch (err) { - console.error('getInputMethods failed: ' + JSON.stringify(err)); + console.error('Failed to getInputMethods: ' + JSON.stringify(err)); } ``` @@ -1099,7 +1121,7 @@ getInputMethods(enable: boolean): Promise<Array<InputMethodProperty>> | 错误码ID | 错误信息 | | -------- | -------------------------------------- | | 12800001 | Package manager error. | -| 12800008 | Input method settings extension error. | +| 12800008 | Input method manager service error. | **返回值:** @@ -1112,12 +1134,12 @@ getInputMethods(enable: boolean): Promise<Array<InputMethodProperty>> ```js try { inputMethodSetting.getInputMethods(true).then((data) => { - console.info('getInputMethods success'); + console.info('Succeeded in getting inputMethods.'); }).catch((err) => { - console.error('getInputMethods err: ' + JSON.stringify(err)); + console.error('Failed to getInputMethods: ' + JSON.stringify(err)); }) } catch(err) { - console.error('getInputMethods err: ' + JSON.stringify(err)); + console.error('Failed to getInputMethods: ' + JSON.stringify(err)); } ``` @@ -1127,7 +1149,7 @@ showOptionalInputMethods(callback: AsyncCallback<boolean>): void 显示输入法选择对话框。使用callback异步回调。 -**需要权限:** ohos.permission.CONNECT_IME_ABILITY +**需要权限:** ohos.permission.CONNECT_IME_ABILITY,仅系统应用可用。 **系统能力:** SystemCapability.MiscServices.InputMethodFramework @@ -1143,21 +1165,21 @@ showOptionalInputMethods(callback: AsyncCallback<boolean>): void | 错误码ID | 错误信息 | | -------- | -------------------------------------- | -| 12800008 | Input method settings extension error. | +| 12800008 | Input method manager service error. | **示例:** ```js try { inputMethodSetting.showOptionalInputMethods((err, data) => { - if (err) { - console.error('showOptionalInputMethods failed: ' + JSON.stringify(err)); + if (err !== undefined) { + console.error('Failed to showOptionalInputMethods: ' + JSON.stringify(err)); return; } - console.info('showOptionalInputMethods success'); + console.info('Succeeded in showing optionalInputMethods.'); }); } catch (err) { - console.error('showOptionalInputMethods failed: ' + JSON.stringify(err)); + console.error('Failed to showOptionalInputMethods: ' + JSON.stringify(err)); } ``` @@ -1167,7 +1189,7 @@ showOptionalInputMethods(): Promise<boolean> 显示输入法选择对话框。使用promise异步回调。 -**需要权限:** ohos.permission.CONNECT_IME_ABILITY +**需要权限:** ohos.permission.CONNECT_IME_ABILITY,仅系统应用可用。 **系统能力:** SystemCapability.MiscServices.InputMethodFramework @@ -1183,15 +1205,15 @@ showOptionalInputMethods(): Promise<boolean> | 错误码ID | 错误信息 | | -------- | -------------------------------------- | -| 12800008 | Input method settings extension error. | +| 12800008 | Input method manager service error. | **示例:** ```js inputMethodSetting.showOptionalInputMethods().then((data) => { - console.info('displayOptionalInputMethod success.'); + console.info('Succeeded in showing optionalInputMethods.'); }).catch((err) => { - console.error('displayOptionalInputMethod err: ' + err); + console.error('Failed to showOptionalInputMethods: ' + JSON.stringify(err)); }) ``` @@ -1217,11 +1239,11 @@ listInputMethod(callback: AsyncCallback<Array<InputMethodProperty>>) ```js inputMethodSetting.listInputMethod((err,data) => { - if (err) { - console.error('listInputMethod failed because: ' + JSON.stringify(err)); + if (err !== undefined) { + console.error('Failed to listInputMethod: ' + JSON.stringify(err)); return; } - console.log('listInputMethod success'); + console.log('Succeeded in listing inputMethod.'); }); ``` @@ -1247,9 +1269,9 @@ listInputMethod(): Promise<Array<InputMethodProperty>> ```js inputMethodSetting.listInputMethod().then((data) => { - console.info('listInputMethod success'); + console.info('Succeeded in listing inputMethod.'); }).catch((err) => { - console.error('listInputMethod err: ' + JSON.stringify(err)); + console.error('Failed to listInputMethod: ' + JSON.stringify(err)); }) ``` @@ -1275,11 +1297,11 @@ displayOptionalInputMethod(callback: AsyncCallback<void>): void ```js inputMethodSetting.displayOptionalInputMethod((err) => { - if (err) { - console.error('displayOptionalInputMethod failed because: ' + JSON.stringify(err)); + if (err !== undefined) { + console.error('Failed to displayOptionalInputMethod: ' + JSON.stringify(err)); return; } - console.info('displayOptionalInputMethod success'); + console.info('Succeeded in displaying optionalInputMethod.'); }); ``` @@ -1305,8 +1327,8 @@ displayOptionalInputMethod(): Promise<void> ```js inputMethodSetting.displayOptionalInputMethod().then(() => { - console.info('displayOptionalInputMethod success'); + console.info('Succeeded in displaying optionalInputMethod.'); }).catch((err) => { - console.error('displayOptionalInputMethod err: ' + err); + console.error('Failed to displayOptionalInputMethod: ' + JSON.stringify(err)); }) ``` diff --git a/zh-cn/application-dev/reference/apis/js-apis-inputmethodengine.md b/zh-cn/application-dev/reference/apis/js-apis-inputmethodengine.md index bed21d742581d4a9f2f7f0b7d31deae71af176bc..52a0b3f5b93fe1c7ff35bbfd328f5dde8e96b23c 100644 --- a/zh-cn/application-dev/reference/apis/js-apis-inputmethodengine.md +++ b/zh-cn/application-dev/reference/apis/js-apis-inputmethodengine.md @@ -137,7 +137,7 @@ createKeyboardDelegate(): KeyboardDelegate **示例:** ```js -let KeyboardDelegate = inputMethodEngine.createKeyboardDelegate(); +let keyboardDelegate = inputMethodEngine.createKeyboardDelegate(); ``` ## InputMethodEngine @@ -162,9 +162,9 @@ on(type: 'inputStart', callback: (kbController: KeyboardController, textInputCli **示例:** ```js -inputMethodEngine.getInputMethodEngine().on('inputStart', (kbController, textInputClient) => { - KeyboardController = kbController; - TextInputClient = textInputClient; +inputMethodEngine.getInputMethodEngine().on('inputStart', (kbController, textClient) => { + let keyboardController = kbController; + let textInputClient = textClient; }); ``` @@ -235,12 +235,8 @@ off(type: 'keyboardShow'|'keyboardHide', callback?: () => void): void **示例:** ```js -inputMethodEngine.getInputMethodEngine().off('keyboardShow', () => { - console.log('inputMethodEngine delete keyboardShow notification.'); -}); -inputMethodEngine.getInputMethodEngine().off('keyboardHide', () => { - console.log('inputMethodEngine delete keyboardHide notification.'); -}); +inputMethodEngine.getInputMethodEngine().off('keyboardShow'); +inputMethodEngine.getInputMethodEngine().off('keyboardHide'); ``` ## InputMethodAbility @@ -265,9 +261,9 @@ on(type: 'inputStart', callback: (kbController: KeyboardController, inputClient: **示例:** ```js -inputMethodEngine.getInputMethodAbility().on('inputStart', (kbController, inputClient) => { - KeyboardController = kbController; - InputClient = inputClient; +inputMethodEngine.getInputMethodAbility().on('inputStart', (kbController, client) => { + let keyboardController = kbController; + let inputClient = client; }); ``` @@ -289,9 +285,7 @@ off(type: 'inputStart', callback?: (kbController: KeyboardController, inputClien **示例:** ```js -inputMethodEngine.getInputMethodAbility().off('inputStart', (kbController, inputClient) => { - console.log('delete inputStart notification.'); -}); +inputMethodEngine.getInputMethodAbility().off('inputStart'); ``` ### on('inputStop')9+ @@ -492,7 +486,7 @@ inputMethodEngine.getInputMethodAbility().off('setSubtype', () => { on(type: 'keyDown'|'keyUp', callback: (event: KeyEvent) => boolean): void -订阅硬键盘事件。使用callback异步回调。 +订阅硬键盘(即物理键盘)事件。使用callback异步回调。 **系统能力:** SystemCapability.MiscServices.InputMethodFramework @@ -522,7 +516,7 @@ inputMethodEngine.getKeyboardDelegate().on('keyDown', (keyEvent) => { off(type: 'keyDown'|'keyUp', callback?: (event: KeyEvent) => boolean): void -取消订阅硬键盘事件。使用callback异步回调。 +取消订阅硬键盘(即物理键盘)事件。使用callback异步回调。 **系统能力:** SystemCapability.MiscServices.InputMethodFramework @@ -602,14 +596,14 @@ on(type: 'selectionChange', callback: (oldBegin: number, oldEnd: number, newBegi **系统能力:** SystemCapability.MiscServices.InputMethodFramework - **参数:** +**参数:** | 参数名 | 类型 | 必填 | 说明 | | -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | | type | string | 是 | 文本选择变化事件。
- type为’selectionChange‘时,表示选择文本变化。 | | callback | (oldBegin: number, oldEnd: number, newBegin: number, newEnd: number) => void | 是 | 回调函数,返回文本选择信息。
- oldBegin为变化之前被选中文本的起始下标。
- oldEnd为变化之前被选中文本的终止下标。
- newBegin为变化之后被选中文本的起始下标。
- newEnd为变化之后被选中文本的终止下标。 | - **示例:** +**示例:** ```js inputMethodEngine.getKeyboardDelegate().on('selectionChange', (oldBegin, oldEnd, newBegin, newEnd) => { @@ -652,14 +646,14 @@ on(type: 'textChange', callback: (text: string) => void): void **系统能力:** SystemCapability.MiscServices.InputMethodFramework - **参数:** +**参数:** | 参数名 | 类型 | 必填 | 说明 | | -------- | ------ | ---- | ------------------------------------------------------------ | | type | string | 是 | 文本变化事件。
- type为’textChange‘时,表示订阅文本变化事件。 | | callback | (text: string) => void | 是 | 回调函数,返回订阅的文本内容。 | - **示例:** +**示例:** ```js inputMethodEngine.getKeyboardDelegate().on('textChange', (text) => { @@ -719,12 +713,12 @@ hide(callback: AsyncCallback<void>): void **示例:** ```js -KeyboardController.hide((err) => { - if (err === undefined) { - console.error('hide err: ' + JSON.stringify(err)); +keyboardController.hide((err) => { + if (err !== undefined) { + console.error('Failed to hide keyboard: ' + JSON.stringify(err)); return; } - console.log('hide success.'); + console.log('Succeeded in hiding keyboard.'); }); ``` @@ -753,10 +747,10 @@ hide(): Promise<void> **示例:** ```js -KeyboardController.hide().then(() => { - console.info('hide success.'); +keyboardController.hide().then(() => { + console.info('Succeeded in hiding keyboard.'); }).catch((err) => { - console.info('hide err: ' + JSON.stringify(err)); + console.info('Failed to hide keyboard: ' + JSON.stringify(err)); }); ``` @@ -781,12 +775,12 @@ hideKeyboard(callback: AsyncCallback<void>): void **示例:** ```js -KeyboardController.hideKeyboard((err) => { - if (err === undefined) { - console.error('hideKeyboard err: ' + JSON.stringify(err)); +keyboardController.hideKeyboard((err) => { + if (err !== undefined) { + console.error('Failed to hide Keyboard: ' + JSON.stringify(err)); return; } - console.log('hideKeyboard success.'); + console.log('Succeeded in hiding keyboard.'); }); ``` @@ -811,10 +805,10 @@ hideKeyboard(): Promise<void> **示例:** ```js -KeyboardController.hideKeyboard().then(() => { - console.info('hideKeyboard success.'); +keyboardController.hideKeyboard().then(() => { + console.info('Succeeded in hiding keyboard.'); }).catch((err) => { - console.info('hideKeyboard err: ' + JSON.stringify(err)); + console.info('Failed to hide Keyboard: ' + JSON.stringify(err)); }); ``` @@ -850,13 +844,13 @@ sendKeyFunction(action:number, callback: AsyncCallback<boolean>): void ```js let action = 1; try { - InputClient.sendKeyFunction(action, (err, result) => { - if (err) { - console.error('sendKeyFunction err: ' + JSON.stringify(err)); + inputClient.sendKeyFunction(action, (err, result) => { + if (err !== undefined) { + console.error('Failed to sendKeyFunction: ' + JSON.stringify(err)); return; } if (result) { - console.info('Success to sendKeyFunction. '); + console.info('Succeeded in sending key function. '); } else { console.error('Failed to sendKeyFunction. '); } @@ -899,17 +893,17 @@ sendKeyFunction(action: number): Promise<boolean> ```js let action = 1; try { - InputClient.sendKeyFunction(action).then((result) => { + inputClient.sendKeyFunction(action).then((result) => { if (result) { - console.info('Success to sendKeyFunction. '); + console.info('Succeeded in sending key function. '); } else { console.error('Failed to sendKeyFunction. '); } }).catch((err) => { - console.error('sendKeyFunction err:' + JSON.stringify(err)); + console.error('Failed to sendKeyFunction:' + JSON.stringify(err)); }); } catch (err) { - console.error('sendKeyFunction err: ' + JSON.stringify(err)); + console.error('Failed to sendKeyFunction: ' + JSON.stringify(err)); } ``` @@ -942,15 +936,15 @@ getForward(length:number, callback: AsyncCallback<string>): void ```js let length = 1; try { - InputClient.getForward(length, (err, text) => { - if (err) { - console.error('getForward err: ' + JSON.stringify(err)); + inputClient.getForward(length, (err, text) => { + if (err !== undefined) { + console.error('Failed to getForward: ' + JSON.stringify(err)); return; } - console.log('getForward result: ' + text); + console.log('Succeeded in getting forward, text: ' + text); }); } catch (err) { - console.error('getForward err: ' + JSON.stringify(err)); + console.error('Failed to getForward: ' + JSON.stringify(err)); } ``` @@ -988,13 +982,13 @@ getForward(length:number): Promise<string> ```js let length = 1; try { - InputClient.getForward(length).then((text) => { - console.info('getForward resul: ' + text); + inputClient.getForward(length).then((text) => { + console.info('Succeeded in getting forward, text: ' + text); }).catch((err) => { - console.error('getForward err: ' + JSON.stringify(err)); + console.error('Failed to getForward: ' + JSON.stringify(err)); }); } catch (err) { - console.error('getForward err: ' + JSON.stringify(err)); + console.error('Failed to getForward: ' + JSON.stringify(err)); } ``` @@ -1027,15 +1021,15 @@ getBackward(length:number, callback: AsyncCallback<string>): void ```js let length = 1; try { - InputClient.getBackward(length, (err, text) => { - if (err) { - console.error('getBackward result: ' + JSON.stringify(err)); + inputClient.getBackward(length, (err, text) => { + if (err !== undefined) { + console.error('Failed to getForward: ' + JSON.stringify(err)); return; } - console.log('getBackward result---text: ' + text); + console.log('Succeeded in getting backward, text: ' + text); }); } catch (err) { - console.error('getBackward result: ' + JSON.stringify(err)); + console.error('Failed to getForward: ' + JSON.stringify(err)); } ``` @@ -1073,13 +1067,13 @@ getBackward(length:number): Promise<string> ```js let length = 1; try { - InputClient.getBackward(length).then((text) => { - console.info('getBackward result: ' + text); + inputClient.getBackward(length).then((text) => { + console.info('Succeeded in getting backward, text: ' + text); }).catch((err) => { - console.error('getBackward err: ' + JSON.stringify(err)); + console.error('Failed to getForward: ' + JSON.stringify(err)); }); } catch (err) { - console.error('getBackward err: ' + JSON.stringify(err)); + console.error('Failed to getForward: ' + JSON.stringify(err)); } ``` @@ -1112,19 +1106,19 @@ deleteForward(length:number, callback: AsyncCallback<boolean>): void ```js let length = 1; try { - InputClient.deleteForward(length, (err, result) => { - if (err) { - console.error('deleteForward result: ' + JSON.stringify(err)); + inputClient.deleteForward(length, (err, result) => { + if (err !== undefined) { + console.error('Failed to delete forward: ' + JSON.stringify(err)); return; } if (result) { - console.info('Success to deleteForward. '); + console.info('Succeeded in deleting forward. '); } else { - console.error('Failed to deleteForward. '); + console.error('Failed to delete forward: ' + JSON.stringify(err)); } }); } catch (err) { - console.error('deleteForward result: ' + JSON.stringify(err)); + console.error('Failed to delete forward: ' + JSON.stringify(err)); } ``` @@ -1162,17 +1156,17 @@ deleteForward(length:number): Promise<boolean> ```js let length = 1; try { - InputClient.deleteForward(length).then((result) => { + inputClient.deleteForward(length).then((result) => { if (result) { - console.info('Success to deleteForward. '); + console.info('Succeeded in deleting forward. '); } else { - console.error('Failed to deleteForward. '); + console.error('Failed to delete Forward. '); } }).catch((err) => { - console.error('deleteForward err: ' + JSON.stringify(err)); + console.error('Failed to delete Forward: ' + JSON.stringify(err)); }); } catch (err) { - console.error('deleteForward err: ' + JSON.stringify(err)); + console.error('Failed to delete Forward: ' + JSON.stringify(err)); } ``` @@ -1205,15 +1199,15 @@ deleteBackward(length:number, callback: AsyncCallback<boolean>): void ```js let length = 1; try { - InputClient.deleteBackward(length, (err, result) => { - if (err) { - console.error('deleteBackward err: ' + JSON.stringify(err)); + inputClient.deleteBackward(length, (err, result) => { + if (err !== undefined) { + console.error('Failed to delete Backward: ' + JSON.stringify(err)); return; } if (result) { - console.info('Success to deleteBackward. '); + console.info('Succeeded in deleting backward. '); } else { - console.error('Failed to deleteBackward. '); + console.error('Failed to delete Backward: ' + JSON.stringify(err)); } }); } catch (err) { @@ -1254,14 +1248,14 @@ deleteBackward(length:number): Promise<boolean> ```js let length = 1; -InputClient.deleteBackward(length).then((result) => { +inputClient.deleteBackward(length).then((result) => { if (result) { - console.info('Success to deleteBackward. '); + console.info('Succeeded in deleting backward. '); } else { console.error('Failed to deleteBackward. '); } }).catch((err) => { - console.error('deleteBackward err: ' + JSON.stringify(err)); + console.error('Failed to deleteBackward: ' + JSON.stringify(err)); }); ``` @@ -1292,13 +1286,13 @@ insertText(text:string, callback: AsyncCallback<boolean>): void **示例:** ```js -InputClient.insertText('test', (err, result) => { - if (err) { - console.error('insertText err: ' + JSON.stringify(err)); +inputClient.insertText('test', (err, result) => { + if (err !== undefined) { + console.error('Failed to insertText: ' + JSON.stringify(err)); return; } if (result) { - console.info('Success to insertText. '); + console.info('Succeeded in inserting text. '); } else { console.error('Failed to insertText. '); } @@ -1338,17 +1332,17 @@ insertText(text:string): Promise<boolean> ```js try { - InputClient.insertText('test').then((result) => { + inputClient.insertText('test').then((result) => { if (result) { - console.info('Success to insertText. '); + console.info('Succeeded in inserting text. '); } else { console.error('Failed to insertText. '); } }).catch((err) => { - console.error('insertText err: ' + JSON.stringify(err)); + console.error('Failed to insertText: ' + JSON.stringify(err)); }); } catch (err) { - console.error('insertText err: ' + JSON.stringify(err)); + console.error('Failed to insertText: ' + JSON.stringify(err)); } ``` @@ -1377,9 +1371,9 @@ getEditorAttribute(callback: AsyncCallback<EditorAttribute>): void **示例:** ```js -InputClient.getEditorAttribute((err, editorAttribute) => { - if (err) { - console.error('getEditorAttribute err: ' + JSON.stringify(err)); +inputClient.getEditorAttribute((err, editorAttribute) => { + if (err !== undefined) { + console.error('Failed to getEditorAttribute: ' + JSON.stringify(err)); return; } console.log('editorAttribute.inputPattern: ' + JSON.stringify(editorAttribute.inputPattern)); @@ -1412,11 +1406,11 @@ getEditorAttribute(): Promise<EditorAttribute> **示例:** ```js -InputClient.getEditorAttribute().then((editorAttribute) => { +inputClient.getEditorAttribute().then((editorAttribute) => { console.info('editorAttribute.inputPattern: ' + JSON.stringify(editorAttribute.inputPattern)); console.info('editorAttribute.enterKeyType: ' + JSON.stringify(editorAttribute.enterKeyType)); }).catch((err) => { - console.error('getEditorAttribute err: ' + JSON.stringify(err)); + console.error('Failed to getEditorAttribute: ' + JSON.stringify(err)); }); ``` @@ -1447,15 +1441,15 @@ moveCursor(direction: number, callback: AsyncCallback<void>): void ```js try { - InputClient.moveCursor(inputMethodEngine.CURSOR_xxx, (err) => { - if (err) { - console.error('moveCursor err: ' + JSON.stringify(err)); + inputClient.moveCursor(inputMethodEngine.CURSOR_UP, (err) => { + if (err !== undefined) { + console.error('Failed to moveCursor: ' + JSON.stringify(err)); return; } - console.info('moveCursor success'); + console.info('Succeeded in moving cursor.'); }); } catch (err) { - console.error('moveCursor err: ' + JSON.stringify(err)); + console.error('Failed to moveCursor: ' + JSON.stringify(err)); } ``` @@ -1491,13 +1485,13 @@ moveCursor(direction: number): Promise<void> ```js try { - InputClient.moveCursor(inputMethodEngine.CURSOR_UP).then(() => { - console.log('moveCursor success'); + inputClient.moveCursor(inputMethodEngine.CURSOR_UP).then(() => { + console.log('Succeeded in moving cursor.'); }).catch((err) => { - console.error('moveCursor success err: ' + JSON.stringify(err)); + console.error('Failed to moveCursor: ' + JSON.stringify(err)); }); } catch (err) { - console.log('moveCursor err: ' + JSON.stringify(err)); + console.log('Failed to moveCursor: ' + JSON.stringify(err)); } ``` @@ -1554,12 +1548,12 @@ getForward(length:number, callback: AsyncCallback<string>): void ```js let length = 1; -TextInputClient.getForward(length, (err, text) => { - if (err === undefined) { - console.error('getForward err: ' + JSON.stringify(err)); +textInputClient.getForward(length, (err, text) => { + if (err !== undefined) { + console.error('Failed to getForward: ' + JSON.stringify(err)); return; } - console.log('getForward result---text: ' + text); + console.log('Succeeded in getting forward, text: ' + text); }); ``` @@ -1591,10 +1585,10 @@ getForward(length:number): Promise<string> ```js let length = 1; -TextInputClient.getForward(length).then((text) => { - console.info('getForward result: ' + JSON.stringify(text)); +textInputClient.getForward(length).then((text) => { + console.info('Succeeded in getting forward, text: ' + text); }).catch((err) => { - console.error('getForward err: ' + JSON.stringify(err)); + console.error('Failed to getForward: ' + JSON.stringify(err)); }); ``` @@ -1621,12 +1615,12 @@ getBackward(length:number, callback: AsyncCallback<string>): void ```js let length = 1; -TextInputClient.getBackward(length, (err, text) => { - if (err === undefined) { - console.error('getBackward err: ' + JSON.stringify(err)); +textInputClient.getBackward(length, (err, text) => { + if (err !== undefined) { + console.error('Failed to getBackward: ' + JSON.stringify(err)); return; } - console.log('getBackward result---text: ' + text); + console.log('Succeeded in getting borward, text: ' + text); }); ``` @@ -1658,10 +1652,10 @@ getBackward(length:number): Promise<string> ```js let length = 1; -TextInputClient.getBackward(length).then((text) => { - console.info('getBackward result: ' + JSON.stringify(text)); +textInputClient.getBackward(length).then((text) => { + console.info('Succeeded in getting backward: ' + JSON.stringify(text)); }).catch((err) => { - console.error('getBackward err: ' + JSON.stringify(err)); + console.error('Failed to getBackward: ' + JSON.stringify(err)); }); ``` @@ -1688,13 +1682,13 @@ deleteForward(length:number, callback: AsyncCallback<boolean>): void ```js let length = 1; -TextInputClient.deleteForward(length, (err, result) => { - if (err === undefined) { - console.error('deleteForward err: ' + JSON.stringify(err)); +textInputClient.deleteForward(length, (err, result) => { + if (err !== undefined) { + console.error('Failed to deleteForward: ' + JSON.stringify(err)); return; } if (result) { - console.info('Success to deleteForward. '); + console.info('Succeeded in deleting forward. '); } else { console.error('Failed to deleteForward. '); } @@ -1729,14 +1723,14 @@ deleteForward(length:number): Promise<boolean> ```js let length = 1; -TextInputClient.deleteForward(length).then((result) => { +textInputClient.deleteForward(length).then((result) => { if (result) { - console.info('Succeed in deleting forward. '); + console.info('Succeeded in deleting forward. '); } else { console.error('Failed to delete forward. '); } }).catch((err) => { - console.error('Failed to delete forward err: ' + JSON.stringify(err)); + console.error('Failed to delete forward: ' + JSON.stringify(err)); }); ``` @@ -1763,13 +1757,13 @@ deleteBackward(length:number, callback: AsyncCallback<boolean>): void ```js let length = 1; -TextInputClient.deleteBackward(length, (err, result) => { - if (err === undefined) { - console.error('deleteBackward err: ' + JSON.stringify(err)); +textInputClient.deleteBackward(length, (err, result) => { + if (err !== undefined) { + console.error('Failed to delete backward: ' + JSON.stringify(err)); return; } if (result) { - console.info('Success to deleteBackward. '); + console.info('Succeeded in deleting backward. '); } else { console.error('Failed to deleteBackward. '); } @@ -1804,14 +1798,14 @@ deleteBackward(length:number): Promise<boolean> ```js let length = 1; -TextInputClient.deleteBackward(length).then((result) => { +textInputClient.deleteBackward(length).then((result) => { if (result) { - console.info('Success to deleteBackward. '); + console.info('Succeeded in deleting backward. '); } else { console.error('Failed to deleteBackward. '); } }).catch((err) => { - console.error('deleteBackward err: ' + JSON.stringify(err)); + console.error('Failed to deleteBackward: ' + JSON.stringify(err)); }); ``` ### sendKeyFunction(deprecated) @@ -1837,13 +1831,13 @@ sendKeyFunction(action: number, callback: AsyncCallback<boolean>): void ```js let action = 1; -TextInputClient.sendKeyFunction(action, (err, result) => { - if (err === undefined) { - console.error('sendKeyFunction err: ' + JSON.stringify(err)); +textInputClient.sendKeyFunction(action, (err, result) => { + if (err !== undefined) { + console.error('Failed to sendKeyFunction: ' + JSON.stringify(err)); return; } if (result) { - console.info('Success to sendKeyFunction. '); + console.info('Succeeded in sending key function. '); } else { console.error('Failed to sendKeyFunction. '); } @@ -1878,14 +1872,14 @@ sendKeyFunction(action: number): Promise<boolean> ```js let action = 1; -TextInputClient.sendKeyFunction(action).then((result) => { +textInputClient.sendKeyFunction(action).then((result) => { if (result) { - console.info('Success to sendKeyFunction. '); + console.info('Succeeded in sending key function. '); } else { console.error('Failed to sendKeyFunction. '); } }).catch((err) => { - console.error('sendKeyFunction err:' + JSON.stringify(err)); + console.error('Failed to sendKeyFunction:' + JSON.stringify(err)); }); ``` @@ -1911,13 +1905,13 @@ insertText(text:string, callback: AsyncCallback<boolean>): void **示例:** ```js -TextInputClient.insertText('test', (err, result) => { - if (err === undefined) { - console.error('insertText err: ' + JSON.stringify(err)); +textInputClient.insertText('test', (err, result) => { + if (err !== undefined) { + console.error('Failed to insertText: ' + JSON.stringify(err)); return; } if (result) { - console.info('Success to insertText. '); + console.info('Succeeded in inserting text. '); } else { console.error('Failed to insertText. '); } @@ -1951,14 +1945,14 @@ insertText(text:string): Promise<boolean> **示例:** ```js -TextInputClient.insertText('test').then((result) => { +textInputClient.insertText('test').then((result) => { if (result) { - console.info('Success to insertText. '); + console.info('Succeeded in inserting text. '); } else { console.error('Failed to insertText. '); } }).catch((err) => { - console.error('insertText err: ' + JSON.stringify(err)); + console.error('Failed to insertText: ' + JSON.stringify(err)); }); ``` @@ -1983,9 +1977,9 @@ getEditorAttribute(callback: AsyncCallback<EditorAttribute>): void **示例:** ```js -TextInputClient.getEditorAttribute((err, editorAttribute) => { - if (err === undefined) { - console.error('getEditorAttribute err: ' + JSON.stringify(err)); +textInputClient.getEditorAttribute((err, editorAttribute) => { + if (err !== undefined) { + console.error('Failed to getEditorAttribute: ' + JSON.stringify(err)); return; } console.log('editorAttribute.inputPattern: ' + JSON.stringify(editorAttribute.inputPattern)); @@ -2014,10 +2008,10 @@ getEditorAttribute(): Promise<EditorAttribute> **示例:** ```js -TextInputClient.getEditorAttribute().then((editorAttribute) => { +textInputClient.getEditorAttribute().then((editorAttribute) => { console.info('editorAttribute.inputPattern: ' + JSON.stringify(editorAttribute.inputPattern)); console.info('editorAttribute.enterKeyType: ' + JSON.stringify(editorAttribute.enterKeyType)); }).catch((err) => { - console.error('getEditorAttribute err: ' + JSON.stringify(err)); + console.error('Failed to getEditorAttribute: ' + JSON.stringify(err)); }); ``` \ No newline at end of file