diff --git a/zh-cn/application-dev/reference/apis/Readme-CN.md b/zh-cn/application-dev/reference/apis/Readme-CN.md index 184a5d5467b37f4387fbacd33fe96c9a03763c80..532f240e1d032aaeb5198a5baf1eae1c7870a87a 100644 --- a/zh-cn/application-dev/reference/apis/Readme-CN.md +++ b/zh-cn/application-dev/reference/apis/Readme-CN.md @@ -81,6 +81,8 @@ - [WebGL](js-apis-webgl.md) - [WebGL2](js-apis-webgl2.md) - [屏幕截图](js-apis-screenshot.md) + - [输入法框架](js-apis-inputmethod.md) + - [输入法服务](js-apis-inputmethodengine.md) - DFX - [应用打点](js-apis-hiappevent.md) - [性能打点](js-apis-hitracemeter.md) diff --git a/zh-cn/application-dev/reference/apis/js-apis-inputmethod.md b/zh-cn/application-dev/reference/apis/js-apis-inputmethod.md new file mode 100644 index 0000000000000000000000000000000000000000..3824dc283144c6b377644699562dcc8256d682dd --- /dev/null +++ b/zh-cn/application-dev/reference/apis/js-apis-inputmethod.md @@ -0,0 +1,202 @@ +# 输入法框架 + +> ![icon-note.gif](public_sys-resources/icon-note.gif) **说明:** +> 本模块首批接口从API version 6开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 + + +## 导入模块 + +``` +import inputMethod from '@ohos.inputMethod'; +``` + +## inputMethod8+ + +常量值。 + +| 名称 | 参数类型 | 可读 | 可写 | 说明 | +| -------- | -------- | -------- | -------- | -------- | +| MAX_TYPE_NUM | number | 是 | 否 | 可支持的最大输入法个数。
**系统能力**: SystemCapability.MiscServices.InputMethod | + + +## InputMethodProperty8+ + +输入法应用属性。 + +| 名称 | 参数类型 | 可读 | 可写 | 说明 | +| -------- | -------- | -------- | -------- | -------- | +| packageName | string | 是 | 否 | 包名。
**系统能力**: SystemCapability.MiscServices.InputMethod | +| methodId | string | 是 | 否 | Ability名。
**系统能力**: SystemCapability.MiscServices.InputMethod | + +## inputMethod.getInputMethodController + +getInputMethodController(): InputMethodController + +获取客户端实例[InputMethodController](#InputMethodController)。 + +**系统能力**:SystemCapability.MiscServices.InputMethod + +- 返回值 + + | 类型 | 说明 | + | -------- | -------- | + | [InputMethodController](#InputMethodController) | 回调返回当前客户端实例。 | + +- 示例 + ``` + var InputMethodController = inputMethod.getInputMethodController(); + ``` +## inputMethod.getInputMethodSetting8+ + +getInputMethodSetting(): InputMethodSetting + +获取客户端设置实例[InputMethodSetting](#InputMethodSetting)。 + +**系统能力**: SystemCapability.MiscServices.InputMethod + +- 返回值 + + | 类型 | 说明 | + | ----------------------------------------- | ---------------------------- | + | [InputMethodSetting](#InputMethodSetting) | 回调返回当前客户端设置实例。 | + + +- 示例 + ``` + var InputMethodSetting = inputMethod.getInputMethodSetting(); + ``` + +## InputMethodController + +下列API示例中都需使用[getInputMethodController](#getInputMethodController)回调获取到InputMethodController实例,再通过此实例调用对应方法 + +### stopInput + +stopInput(callback: AsyncCallback<boolean>): void + +隐藏输入法。 + +**系统能力**:SystemCapability.MiscServices.InputMethod + +- 参数 + + | 参数名 | 类型 | 必填 | 说明 | + | -------- | -------- | -------- | -------- | + | callback | AsyncCallback<boolean> | 是 | 返回输入法隐藏是否成功。 | + +- 示例 + +``` + InputMethodController.stopInput((error)=>{ + console.info('stopInput'); + }); +``` + +### stopInput + +stopInput(): Promise<boolean> + +隐藏输入法。 + +**系统能力**: SystemCapability.MiscServices.InputMethod + +- 参数 + + | 参数名 | 类型 | 必填 | 说明 | + | -------- | -------- | -------- | -------- | + | callback | Promise<boolean> | 是 | 返回输入法隐藏是否成功。 | + +- 示例 + + +``` + var isSuccess = InputMethodController.stopInput(); + console.info('stopInput isSuccess = ' + isSuccess); +``` + +## InputMethodSetting + +下列API示例中都需使用[getInputMethodSetting](#getInputMethodSetting)回调获取到InputMethodSetting实例,再通过此实例调用对应方法 + +### listInputMethod8+ + +listInputMethod(callback: AsyncCallback<Array<InputMethodProperty>>): void + +查询已安装的输入法列表。 + +**系统能力**: SystemCapability.MiscServices.InputMethod + +- 返回值 + | 类型 | 说明 | + | ------------------------------- | ------------------------------------------------------------ | + | Array<[InputMethodProperty](#InputMethodProperty)> | 返回已安装输入法列表。 | + +- 示例 + ``` + InputMethodSetting.listInputMethod((properties)=>{ + var property = properties[i]; + console.info(property.packageName + "/" + property.methodId); + }); + ``` + +### listInputMethod8+ + +listInputMethod(): Promise<Array<InputMethodProperty>> + +查询已安装的输入法列表。 + +**系统能力**: SystemCapability.MiscServices.InputMethod + +- 返回值 + | 类型 | 说明 | + | ------------------------------- | ------------------------------------------------------------ | + | Array<[InputMethodProperty](#InputMethodProperty)> | 返回已安装输入法列表。 | + +- 示例 + ``` + var properties = InputMethodSetting.listInputMethod(); + for (var i = 0;i < properties.length; i++) { + var property = properties[i]; + console.info(property.packageName + "/" + property.methodId); + } + ``` + +### displayOptionalInputMethod8+ + +displayOptionalInputMethod(callback: AsyncCallback<void>): void + +显示输入法选择对话框。 + +**系统能力**: SystemCapability.MiscServices.InputMethod + +- 参数 + +| 参数名 | 类型 | 必填 | 说明 | +| -------- | -------- | -------- | -------- | +| callback | AsyncCallback<void> | 是 | 回调函数。 | + +- 示例 + ``` + InputMethodSetting.displayOptionalInputMethod(()=>{ + console.info('displayOptionalInputMethod is called'); + }); + ``` + +### displayOptionalInputMethod8+ + + displayOptionalInputMethod(): Promise<void> + + 显示输入法选择对话框。 + + **系统能力**: SystemCapability.MiscServices.InputMethod + +- 返回值 + +| 参数名 | 说明 | +| -------- | -------- | +| Promise<void> | 回调函数。 | + + - 示例 + ``` + InputMethodSetting.displayOptionalInputMethod(); + ``` \ 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 new file mode 100644 index 0000000000000000000000000000000000000000..6d7e7e6f8626ca18fc6b7eae1406fd8db4adc86e --- /dev/null +++ b/zh-cn/application-dev/reference/apis/js-apis-inputmethodengine.md @@ -0,0 +1,741 @@ +# 输入法服务 + +> ![icon-note.gif](public_sys-resources/icon-note.gif) **说明:** +> 本模块首批接口从API version 8开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 + +## 导入模块 + +``` +import inputMethodEngine from '@ohos.inputMethodEngine'; +``` + +## inputMethodEngine + +常量值。 + +| 名称 | 参数类型 | 可读 | 可写 | 说明 | +| -------- | -------- | -------- | -------- | -------- | +| ENTER_KEY_TYPE_UNSPECIFIED | number | 是 | 否 | 无功能键。
**系统能力**: SystemCapability.MiscServices.InputMethod | +| ENTER_KEY_TYPE_GO | number | 是 | 否 | “前往”功能键。
**系统能力**: SystemCapability.MiscServices.InputMethod | +| ENTER_KEY_TYPE_SEARCH | number | 是 | 否 | “搜索”功能键。
**系统能力**: SystemCapability.MiscServices.InputMethod | +| ENTER_KEY_TYPE_SEND | number | 是 | 否 | “发送”功能键。
**系统能力**: SystemCapability.MiscServices.InputMethod | +| ENTER_KEY_TYPE_NEXT | number | 是 | 否 | “下一个”功能键。
**系统能力**: SystemCapability.MiscServices.InputMethod | +| ENTER_KEY_TYPE_DONE | number | 是 | 否 | “回车”功能键。
**系统能力**: SystemCapability.MiscServices.InputMethod | +| ENTER_KEY_TYPE_PREVIOUS | number | 是 | 否 | “前一个”功能键。
**系统能力**: SystemCapability.MiscServices.InputMethod | +| PATTERN_NULL | number | 是 | 否 | 无特殊性编辑框。
**系统能力**: SystemCapability.MiscServices.InputMethod | +| PATTERN_TEXT | number | 是 | 否 | 文本编辑框。
**系统能力**: SystemCapability.MiscServices.InputMethod | +| PATTERN_NUMBER | number | 是 | 否 | 数字编辑框。
**系统能力**: SystemCapability.MiscServices.InputMethod | +| PATTERN_PHONE | number | 是 | 否 | 电话编辑框。
**系统能力**: SystemCapability.MiscServices.InputMethod | +| PATTERN_DATETIME | number | 是 | 否 | 日期编辑框。
**系统能力**: SystemCapability.MiscServices.InputMethod | +| PATTERN_EMAIL | number | 是 | 否 | 邮件编辑框。
**系统能力**: SystemCapability.MiscServices.InputMethod | +| PATTERN_URI | number | 是 | 否 | 超链接编辑框。
**系统能力**: SystemCapability.MiscServices.InputMethod | +| PATTERN_PASSWORD | number | 是 | 否 | 密码编辑框。
**系统能力**: SystemCapability.MiscServices.InputMethod | +| OPTION_ASCII | number | 是 | 否 | 允许输入ASCII值。
**系统能力**: SystemCapability.MiscServices.InputMethod | +| OPTION_NONE | number | 是 | 否 | 不指定编辑框输入属性。
**系统能力**: SystemCapability.MiscServices.InputMethod | +| OPTION_AUTO_CAP_CHARACTERS | number | 是 | 否 | 允许输入字符。
**系统能力**: SystemCapability.MiscServices.InputMethod | +| OPTION_AUTO_CAP_SENTENCES | number | 是 | 否 | 允许输入句子。
**系统能力**: SystemCapability.MiscServices.InputMethod | +| OPTION_AUTO_WORDS | number | 是 | 否 | 允许输入单词。
**系统能力**: SystemCapability.MiscServices.InputMethod | +| OPTION_MULTI_LINE | number | 是 | 否 | 允许输入多行。
**系统能力**: SystemCapability.MiscServices.InputMethod | +| OPTION_NO_FULLSCREEN | number | 是 | 否 | 半屏样式。
**系统能力**: SystemCapability.MiscServices.InputMethod | +| FLAG_SELECTING | number | 是 | 否 | 编辑框处于选择状态。
**系统能力**: SystemCapability.MiscServices.InputMethod | +| FLAG_SINGLE_LINE | number | 是 | 否 | 编辑框为单行。
**系统能力**: SystemCapability.MiscServices.InputMethod | +| DISPLAY_MODE_PART | number | 是 | 否 | 编辑框显示为半屏。
**系统能力**: SystemCapability.MiscServices.InputMethod | +| DISPLAY_MODE_FULL | number | 是 | 否 | 编辑框显示为全屏。
**系统能力**: SystemCapability.MiscServices.InputMethod | + +## inputMethodEngine.getInputMethodEngine + +getInputMethodEngine(): InputMethodEngine + +获取服务端实例[InputMethodEngine](#InputMethodEngine)。 + +**系统能力**: SystemCapability.MiscServices.InputMethod + +- 返回值 + + | 类型 | 说明 | + | --------------------------------------- | ------------ | + | [InputMethodEngine](#InputMethodEngine) | 服务端实例。 | + +- 示例 + + ``` + var InputMethodEngine = inputMethodEngine.getInputMethodEngine(); + ``` + +## inputMethodEngine.createKeyboardDelegate + +createKeyboardDelegate(): KeyboardDelegate + +获取客户端监听实例[KeyboardDelegate](#KeyboardDelegate)。 + +**系统能力**: SystemCapability.MiscServices.InputMethod + +- 返回值 + + | 类型 | 说明 | + | ------------------------------------- | ---------------- | + | [KeyboardDelegate](#KeyboardDelegate) | 客户端监听实例。 | + +- 示例 + + ``` + var KeyboardDelegate = inputMethodEngine.createKeyboardDelegate(); + ``` + +## InputMethodEngine + +下列API示例中都需使用[getInputMethodEngine](#getInputMethodEngine)回调获取到InputMethodEngine实例,再通过此实例调用对应方法。 + +### on('inputStart') + +on(type: 'inputStart', callback: (kbController: KeyboardController, textInputClient: TextInputClient) => void): void; + +订阅输入法绑定成功事件,使用callback输入法操作相关实例。 + +**系统能力**: SystemCapability.MiscServices.InputMethod + +- 参数: + +| 参数名 | 类型 | 必填 | 说明 | +| -------- | ------------------------------- | ---- | ------------------------------------------------------------ | +| type | string | 是 | 设置监听类型。
-type为‘inputStart’时表示订阅输入法绑定。 | +| callback | [KeyboardController](#KeyboardController), [TextInputClient](#TextInputClient) | 是 | 回调返回监听到的信息。 | + +- 示例: + + ``` + InputMethodEngine.on('inputStart', (kbController, textInputClient) => { + KeyboardController = kbController; + TextInputClient = textInputClient; + }); + ``` + +### off('inputStart') + +off(type: 'inputStart', callback?: (kbController: KeyboardController, textInputClient: TextInputClient) => void): void; + +取消订阅输入法绑定成功事件。 + +**系统能力**: SystemCapability.MiscServices.InputMethod + +- 参数: + + | 参数名 | 类型 | 必填 | 说明 | + | -------- | -------------------- | ---- | ------------------------ | + | type | string | 是 | 设置监听类型。
-type为‘inputStart’时表示订阅输入法绑定。 | + | callback | [KeyboardController](#KeyboardController), [TextInputClient](#TextInputClient) | 否 | 回调返回监听到的信息。 | + + + +- 示例: + + ``` + InputMethodEngine.off('inputStart'); + ``` + +### on('keyboardShow'|'keyboardHide') + +on(type: 'keyboardShow'|'keyboardHide', callback: () => void): void; + +订阅输入法事件。 + +**系统能力**: SystemCapability.MiscServices.InputMethod + +- 参数: + + | 参数名 | 类型 | 必填 | 说明 | + | -------- | ------ | ---- | ------------------------------------------------------------ | + | type | string | 是 | 设置监听类型。
- type为'keyboardShow',表示订阅输入法显示。
- type为'keyboardHide',表示订阅输入法隐藏。 | + | callback | void | 否 | 无返回值。 | + +- 示例: + + ``` + InputMethodEngine.on('keyboardShow', (err) => { + console.info('keyboardShow'); + }); + ``` + +### off('keyboardShow'|'keyboardHide') + +off(type: 'keyboardShow'|'keyboardHide', callback?: () => void): void; + +取消订阅输入法事件。 + +**系统能力**: SystemCapability.MiscServices.InputMethod + +- 参数: + + | 参数名 | 类型 | 必填 | 说明 | + | -------- | ------ | ---- | ------------------------------------------------------------ | + | type | string | 是 | 设置监听类型。
- type为'keyboardShow',表示订阅输入法显示。
- type为'keyboardHide',表示订阅输入法隐藏。 | + | callback | void | 否 | 无返回值。 | + +- 示例: + + ``` + InputMethodEngine.off('keyboardShow'); + ``` + + +## KeyboardDelegate + +下列API示例中都需使用[createKeyboardDelegate](#createKeyboardDelegate)回调获取到TextInputClient实例,再通过此实例调用对应方法。 + +### on('keyDown'|'keyUp') + +on(type: 'keyDown'|'keyUp', callback: (event: KeyEvent) => boolean): void; + +订阅硬键盘事件,使用callback回调按键信息。 + +**系统能力**: SystemCapability.MiscServices.InputMethod + +- 参数: + + | 参数名 | 类型 | 必填 | 说明 | + | -------- | ------------------------------- | ---- | ------------------------------------------------------------ | + | type | string | 是 | 设置监听类型。
- type为'keyDown',表示订阅硬键盘按下。
- type为'keyUp',表示订阅硬键盘抬起。 | + | callback | [KeyEvent](#KeyEvent) | 是 | 回调返回按键信息。 | + + + +- 示例: + + ``` + KeyboardDelegate.on('keyDown', (event) => { + console.info('keyDown'); + }); + ``` + +### off('keyDown'|'keyUp') + +off(type: 'keyDown'|'keyUp', callback?: (event: KeyEvent) => boolean): void; + +取消订阅硬键盘事件。 + +**系统能力**: SystemCapability.MiscServices.InputMethod + +- 参数: + + | 参数名 | 类型 | 必填 | 说明 | + | -------- | --------------------- | ---- | ------------------------------------------------------------ | + | type | string | 是 | 设置监听类型。
- type为'keyDown',表示订阅硬键盘按下。
- type为'keyUp',表示订阅硬键盘抬起。 | + | callback | [KeyEvent](#KeyEvent) | 否 | 回调返回监听到的信息。 | + +- 示例: + + ``` + KeyboardDelegate.off('keyDown'); + ``` + +### on('cursorContextChange') + +on(type: 'cursorContextChange', callback: (x: number, y:number, height:number) => void): void; + +订阅光标变化事件,使用callback返回光标信息。 + + **系统能力**: SystemCapability.MiscServices.InputMethod + + - 参数: + + | 参数名 | 类型 | 必填 | 说明 | + | -------- | ------ | ---- | ------------------------------------------------------------ | + | type | string | 是 | 光标变化事件。
-type为’cursorContextChange‘时,表示光标变化。 | + | callback | number | 是 | 回调返回监听到的信息。 | + + + + - 示例: + + ``` + KeyboardDelegate.on('cursorContextChange', (x, y, height) => { + console.info('cursorContextChange'); + }); + ``` + +### off('cursorContextChange') + +off(type: 'cursorContextChange', callback?: (x: number, y:number, height:number) => void): void; + +取消订阅光标变化事件。 + +**系统能力**: SystemCapability.MiscServices.InputMethod + + - 参数: + + | 参数名 | 类型 | 必填 | 说明 | + | -------- | -------------------- | ---- | ------------------------ | + | type | string | 是 | 光标变化事件。
-type为’cursorContextChange‘时,表示光标变化。 | + | callback | number | 否 | 回调返回监听到的信息。 | + + + - 示例: + + ``` + KeyboardDelegate.off('cursorContextChange'); + ``` +### on('selectionChange') + +on(type: 'selectionChange', callback: (oldBegin: number, oldEnd: number, newBegin: number, newEnd: number) => void): void; + +订阅文本选择变化事件,使用callback回调文本选择信息。 + +**系统能力**: SystemCapability.MiscServices.InputMethod + + - 参数: + + | 参数名 | 类型 | 必填 | 说明 | + | -------- | ------ | ---- | ------------------------------------------------------------ | + | type | string | 是 | 文本选择变化事件。
-type为’selectionChange‘时,表示选择文本变化。 | + | callback | number | 是 | 回调返回监听到的信息。 | + + - 示例: + + ``` + KeyboardDelegate.on('selectionChange', (oldBegin, oldEnd, newBegin, newEnd) => { + console.info('selectionChange'); + }); + ``` + +### off('selectionChange') + +off(type: 'selectionChange', callback?: (oldBegin: number, oldEnd: number, newBegin: number, newEnd: number) => void): void; + +取消订阅文本选择变化事件。 + +**系统能力**: SystemCapability.MiscServices.InputMethod + + - 参数: + + | 参数名 | 类型 | 必填 | 说明 | + | -------- | -------------------- | ---- | ------------------------ | + | type | string | 是 | 文本选择变化事件。
-type为’selectionChange‘时,表示选择文本变化。 | + | callback | number | 否 | 回调返回监听到的信息。 | + + - 示例: + + ``` + KeyboardDelegate.off('selectionChange'); + ``` + + +### on('textChange') + +on(type: 'textChange', callback: (text: string) => void): void; + +订阅文本变化事件,使用callback回调当前文本内容。 + +**系统能力**: SystemCapability.MiscServices.InputMethod + + - 参数: + + | 参数名 | 类型 | 必填 | 说明 | + | -------- | ------------------------------- | ---- | ------------------------------------------------------------ | + | type | string | 是 | 文本变化事件。
-type为’textChange‘时,表示当前文本变化。 | + | callback | string | 是 | 回调返回监听到的信息。 | + + - 示例: + + ``` + KeyboardDelegate.on('textChange', (text) => { + console.info('textChange'); + }); + ``` + +### off('textChange') + +off(type: 'textChange', callback?: (text: string) => void): void; + +取消订阅文本变化事件。 + +**系统能力**: SystemCapability.MiscServices.InputMethod + + - 参数: + + | 参数名 | 类型 | 必填 | 说明 | + | -------- | -------------------- | ---- | ------------------------ | + | type | string | 是 | 文本变化事件。
-type为’textChange‘时,表示当前文本变化。 | + | callback | string | 否 | 回调返回监听到的信息。 | + + - 示例: + + ``` + KeyboardDelegate.off('textChange'); + ``` + + + +## KeyboardController + +下列API示例中都需使用[inputStart](#inputStart)回调获取到KeyboardController实例,再通过此实例调用对应方法。 + +### hideKeyboard + +hideKeyboard(callback: AsyncCallback<void>): void + +隐藏输入法。 + +**系统能力**: SystemCapability.MiscServices.InputMethod + +- 示例 + + +``` + KeyboardController.hideKeyboard(()=>{ + }); +``` + +### hideKeyboard + +hideKeyboard(): Promise<void> + +隐藏输入法。 + +**系统能力**: SystemCapability.MiscServices.InputMethod + +- 示例 + + +``` + KeyboardController.hideKeyboard(); +``` + +## TextInputClient + +下列API示例中都需使用[inputStart](#inputStart)回调获取到TextInputClient实例,再通过此实例调用对应方法。 + +### getForward + +getForward(length:number, callback: AsyncCallback<string>): void + +获取光标前固定长度的文本。 + +**系统能力**: SystemCapability.MiscServices.InputMethod + +- 参数 + + | 参数名 | 类型 | 必填 | 说明 | + | -------- | -------- | -------- | -------- | + | length | number | 是 | 文本长度。 | + | callback | AsyncCallback<string> | 是 | 返回文本。 | + +- 示例 + ``` + var text = TextInputClient.getForward(5,(text) =>{ + console.info("text = " + text); + }); + ``` + +### getForward + +getForward(length:number): Promise<string> + +获取光标前固定长度的文本。 + +**系统能力**: SystemCapability.MiscServices.InputMethod + +- 参数 + + | 参数名 | 类型 | 必填 | 说明 | + | -------- | -------- | -------- | -------- | + | length | number | 是 | 文本长度。 | + +- 返回值 + ​ + | 类型 | 说明 | + | ------------------------------- | ------------------------------------------------------------ | + | Promise<string> | 返回文本。 | + + ​ + +- 示例 + ``` + var text = TextInputClient.getForward(5); + console.info("text = " + text); + ``` + +### getBackward + +getBackward(length:number, callback: AsyncCallback<string>): void + +获取光标后固定长度的文本。 + +**系统能力**: SystemCapability.MiscServices.InputMethod + +- 参数 + + | 参数名 | 类型 | 必填 | 说明 | + | -------- | -------- | -------- | -------- | + | length | number | 是 | 文本长度。 | + | callback | AsyncCallback<string> | 是 | 返回文本。 | + +- 示例 + ``` + var text = TextInputClient.getBackward(5,(text)=>{ + console.info("text = " + text); + }); + ``` + +### getBackward + +getBackward(length:number): Promise<string> + +获取光标后固定长度的文本。 + +**系统能力**: SystemCapability.MiscServices.InputMethod + +- 参数 + + | 参数名 | 类型 | 必填 | 说明 | + | -------- | -------- | -------- | -------- | + | length | number | 是 | 文本长度。 | + +- 返回值 + | 类型 | 说明 | + | ------------------------------- | ------------------------------------------------------------ | + | Promise<string> | 返回文本。 | + +- 示例 + ``` + var text = TextInputClient.getBackward(5); + console.info("text = " + text); + ``` + +### deleteForward + +deleteForward(length:number, callback: AsyncCallback<boolean>): void + +删除光标前固定长度的文本。 + +**系统能力**: SystemCapability.MiscServices.InputMethod + +- 参数 + + | 参数名 | 类型 | 必填 | 说明 | + | -------- | -------- | -------- | -------- | + | length | number | 是 | 文本长度。 | + | callback | AsyncCallback<boolean> | 是 | 操作成功与否。 | + +- 示例 + ``` + TextInputClient.deleteForward(5,(isSuccess)=>{ + console.info("isSuccess = " + isSuccess); + }); + ``` +### deleteForward + +deleteForward(length:number): Promise<boolean> + +删除光标前固定长度的文本。 + +**系统能力**: SystemCapability.MiscServices.InputMethod + +- 参数 + + | 参数名 | 类型 | 必填 | 说明 | + | -------- | -------- | -------- | -------- | + | length | number | 是 | 文本长度。 | + +- 返回值 + | 类型 | 说明 | + | ------------------------------- | ------------------------------------------------------------ | + | Promise<boolean> | 操作成功与否。 | + + - 示例 + ``` + var isSuccess = TextInputClient.deleteForward(5); + console.info("isSuccess = " + isSuccess); + ``` + +### deleteBackward + +deleteBackward(length:number, callback: AsyncCallback<boolean>): void + +删除光标后固定长度的文本。 + +**系统能力**: SystemCapability.MiscServices.InputMethod + + - 参数 + + | 参数名 | 类型 | 必填 | 说明 | + | -------- | -------- | -------- | -------- | + | length | number | 是 | 文本长度。 | + | callback | AsyncCallback<boolean> | 是 | 操作成功与否。 | + + - 示例 + ``` + TextInputClient.deleteBackward(5, (isSuccess)=>{ + console.info("isSuccess = " + isSuccess); + }); + ``` + +### deleteBackward + +deleteBackward(length:number): Promise<boolean> +删除光标后固定长度的文本。 + +**系统能力**: SystemCapability.MiscServices.InputMethod + +- 参数 + | 参数名 | 类型 | 必填 | 说明 | + | -------- | -------- | -------- | -------- | + | length | number | 是 | 文本长度。 | + +- 返回值 + | 类型 | 说明 | + | ------------------------------- | ------------------------------------------------------------ | + | Promise<boolean> | 操作成功与否。 | + +- 示例 + + ``` + var isSuccess = TextInputClient.deleteBackward(5); + console.info("isSuccess = " + isSuccess); + ``` +### sendKeyFunction + +sendKeyFunction(action:number, callback: AsyncCallback<boolean>): void + +发送功能键。 + +**系统能力**: SystemCapability.MiscServices.InputMethod + + - 参数 + + | 参数名 | 类型 | 必填 | 说明 | + | -------- | -------- | -------- | -------- | + | length | number | 是 | 文本长度。 | + | callback | AsyncCallback<boolean> | 是 | 操作成功与否。 | + + - 示例 + ``` + TextInputClient.sendKeyFunction(inputMethod.ENTER_KEY_TYPE_NEXT,(isSuccess)=>{ + console.info("isSuccess = " + isSuccess); + }); + ``` + +### sendKeyFunction + +sendKeyFunction(action:number): Promise<boolean> + +发送功能键。 + +**系统能力**: SystemCapability.MiscServices.InputMethod + +- 参数 + | 参数名 | 类型 | 必填 | 说明 | + | -------- | -------- | -------- | -------- | + | length | number | 是 | 文本长度。 | + +- 返回值 + | 类型 | 说明 | + | ------------------------------- | ------------------------------------------------------------ | + | Promise<boolean> | 操作成功与否。 | + +- 示例 + + ``` + var isSuccess = TextInputClient.sendKeyFunction(inputMethod.ENTER_KEY_TYPE_NEXT); + console.info("isSuccess = " + isSuccess); + ``` + +### insertText + +insertText(text:string, callback: AsyncCallback<boolean>): void + +插入文本。 + +**系统能力**: SystemCapability.MiscServices.InputMethod + +- 参数 + + | 参数名 | 类型 | 必填 | 说明 | + | -------- | -------- | -------- | -------- | + | text | string | 是 | 文本。 | + | callback | AsyncCallback<boolean> | 是 | 操作成功与否。 | + +- 示例 + ``` + TextInputClient.insertText("test", (isSuccess)=>{ + console.info("isSuccess = " + isSuccess); + }); + ``` + +### insertText + +insertText(text:string): Promise<boolean> +插入文本。 + +**系统能力**: SystemCapability.MiscServices.InputMethod + +- 参数 + | 参数名 | 类型 | 必填 | 说明 | + | -------- | -------- | -------- | -------- | + | text | string | 是 | 文本。 | + +- 返回值 + | 类型 | 说明 | + | ------------------------------- | ------------------------------------------------------------ | + | Promise<boolean> | 操作成功与否。 | + +- 示例 + + ``` + var isSuccess = TextInputClient.insertText("test"); + console.info("isSuccess = " + isSuccess); + ``` + +### getEditorAttribute + +getEditorAttribute(callback: AsyncCallback<EditorAttribute>): void + +获取编辑框属性[EditorAttribute](#EditorAttribute)实例。 + +**系统能力**: SystemCapability.MiscServices.InputMethod + +- 参数 + | 参数名 | 类型 | 必填 | 说明 | + | ------------------------------- | ------------------------------------------------------------ | ------------------------------------------------------------ | ------------------------------------------------------------ | + | callback | AsyncCallback<EditorAttribute> | 是 | 编辑框属性实例。 | + + - 示例 + ``` + TextInputClient.getEditorAttribute((EditorAttribute)=>{ + }); + ``` + +### getEditorAttribute + +getEditorAttribute(): Promise<EditorAttribute> +获取编辑框属性[EditorAttribute](#EditorAttribute)实例。 + +**系统能力**: SystemCapability.MiscServices.InputMethod + +- 返回值 + | 类型 | 说明 | + | ------------------------------- | ------------------------------------------------------------ | + | Promise<EditorAttribute> | 返回编辑框属性实例。 | + +- 示例 + ``` + var EditorAttribute = TextInputClient.getEditorAttribute(); + ``` + +## EditorAttribute + +编辑框属性值。 + +| 名称 | 参数类型 | 可读 | 可写 | 说明 | +| ------------ | -------- | ---- | ---- | ------------------------------------------------------------ | +| enterKeyType | number | 是 | 否 | 功能键属性。
**系统能力**: SystemCapability.MiscServices.InputMethod | +| inputPattern | number | 是 | 否 | 编辑框属性。
**系统能力**: SystemCapability.MiscServices.InputMethod | + +## KeyEvent + +按键属性值 + +| 名称 | 参数类型 | 可读 | 可写 | 说明 | +| --------- | -------- | ---- | ---- | ------------------------------------------------------------ | +| keyCode | number | 是 | 否 | 键值。
**系统能力**: SystemCapability.MiscServices.InputMethod | +| keyAction | number | 是 | 否 | 按键状态。
**系统能力**: SystemCapability.MiscServices.InputMethod | +