提交 beb27013 编写于 作者: H Hollokin

输入法框架API资料补充

Signed-off-by: NHollokin <taoyuxin2@huawei.com>
上级 d787319f
...@@ -4,8 +4,8 @@ InputMethodExtensionAbility模块,提供生态输入法应用开发者通过In ...@@ -4,8 +4,8 @@ InputMethodExtensionAbility模块,提供生态输入法应用开发者通过In
> **说明:** > **说明:**
> >
> 本模块首批接口从API version 9开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 > - 本模块首批接口从API version 9开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
> 本模块接口仅可在Stage模型下使用。 > - 本模块接口仅可在Stage模型下使用。
## 导入模块 ## 导入模块
...@@ -24,7 +24,7 @@ import InputMethodExtensionAbility from '@ohos.inputmethodextensionability'; ...@@ -24,7 +24,7 @@ import InputMethodExtensionAbility from '@ohos.inputmethodextensionability';
## InputMethodExtensionAbility.onCreate() ## InputMethodExtensionAbility.onCreate()
onCreate(want: Want): void; onCreate(want: Want): void
Extension生命周期回调,在拉起Extension输入法应用时调用,执行初始化输入法应用操作。 Extension生命周期回调,在拉起Extension输入法应用时调用,执行初始化输入法应用操作。
...@@ -38,18 +38,18 @@ Extension生命周期回调,在拉起Extension输入法应用时调用,执 ...@@ -38,18 +38,18 @@ Extension生命周期回调,在拉起Extension输入法应用时调用,执
**示例:** **示例:**
```js ```js
class InputMethodExt extends InputMethodExtensionAbility { class InputMethodExt extends InputMethodExtensionAbility {
onCreate(want) { onCreate(want) {
console.log('onCreate, want:' + want.abilityName); console.log('onCreate, want:' + want.abilityName);
} }
} }
``` ```
## InputMethodExtensionAbility.onDestroy() ## InputMethodExtensionAbility.onDestroy()
onDestroy(): void; onDestroy(): void
Extension生命周期回调,在销毁输入法应用时回调,执行资源清理等操作。 Extension生命周期回调,在销毁输入法应用时回调,执行资源清理等操作。
...@@ -57,83 +57,123 @@ Extension生命周期回调,在销毁输入法应用时回调,执行资源 ...@@ -57,83 +57,123 @@ Extension生命周期回调,在销毁输入法应用时回调,执行资源
**示例:** **示例:**
```js ```js
class InputMethodExt extends InputMethodExtensionAbility { class InputMethodExt extends InputMethodExtensionAbility {
onDestroy() { onDestroy() {
console.log('onDestroy'); console.log('onDestroy');
} }
} }
``` ```
## InputMethodExtensionAbility.onRequest() ## InputMethodExtensionAbility.onRequest()
onRequest(want: Want, startId: number): void; onRequest(want: Want, startId: number): void
Extension生命周期回调,在一个输入法extention开始时回调,执行输入法的相关操作。 Extension生命周期回调,在一个输入法extention开始时回调,执行输入法的相关操作。
**系统能力**:SystemCapability.MiscServices.InputMethodFramework **系统能力**:SystemCapability.MiscServices.InputMethodFramework
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| want | [Want](js-apis-application-Want.md) | 是 | 当前Extension相关的Want类型信息,包括ability名称、bundle名称等。 |
| startId | number | 是 | 返回拉起次数。首次拉起初始值返回1,多次之后自动递增。 |
**示例:** **示例:**
```js ```js
class InputMethodExt extends InputMethodExtensionAbility { class InputMethodExt extends InputMethodExtensionAbility {
onRequest() { onRequest(want, startId) {
console.log('onRequest, want:' + want.abilityName + 'startId:' + startId); console.log('onRequest, want:' + want.abilityName + 'startId:' + startId);
} }
} }
``` ```
## InputMethodExtensionAbility.onConnect() ## InputMethodExtensionAbility.onConnect()
onConnect(want: Want): rpc.RemoteObject; onConnect(want: Want): rpc.RemoteObject
Extension生命周期回调,在输入法extention首次连接输入法ability时回调。 Extension生命周期回调,在输入法extention首次连接输入法ability时回调。
**系统能力**:SystemCapability.MiscServices.InputMethodFramework **系统能力**:SystemCapability.MiscServices.InputMethodFramework
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| want | [Want](js-apis-application-Want.md) | 是 | 当前Extension相关的Want类型信息,包括ability名称、bundle名称等。 |
**返回值**
| 类型 | 说明 |
| ------------------------------- | ------------------------------------------------------------ |
| rpc.RemoteObject | 一个RemoteObject对象,用于和客户端进行通信。 |
**示例:** **示例:**
```js ```js
class InputMethodExt extends InputMethodExtensionAbility { import rpc from '@ohos.rpc'
onConnect() { class StubTest extends rpc.RemoteObject{
console.log('onConnect, want:' + want.abilityName); constructor(des) {
super(des);
} }
} onConnect(code, data, reply, option) {
``` }
}
class ServiceExt extends ServiceExtension {
onConnect(want) {
console.log('onConnect , want:' + want.abilityName);
return new StubTest("test");
}
}
```
## InputMethodExtensionAbility.onDisconnect() ## InputMethodExtensionAbility.onDisconnect()
onDisconnect(want: Want): rpc.RemoteObject; onDisconnect(want: Want): void
Extension生命周期回调,在所有连接在输入法extention上的ability都断开的时候回调。 Extension生命周期回调,在所有连接在输入法extention上的ability都断开的时候回调。
**系统能力**:SystemCapability.MiscServices.InputMethodFramework **系统能力**:SystemCapability.MiscServices.InputMethodFramework
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| want | [Want](js-apis-application-Want.md) | 是 | 当前Extension相关的Want类型信息,包括ability名称、bundle名称等。 |
**示例:** **示例:**
```js ```js
class InputMethodExt extends InputMethodExtensionAbility { class InputMethodExt extends InputMethodExtensionAbility {
onDisconnect() { onDisconnect(want) {
console.log('onDisconnect, want:' + want.abilityName); console.log('onDisconnect, want:' + want.abilityName);
} }
} }
``` ```
## InputMethodExtensionAbility.onReconnect() ## InputMethodExtensionAbility.onReconnect()
onReconnect(want: Want): rpc.RemoteObject; onReconnect(want: Want): void
Extension生命周期回调,在一个新的客户端去尝试连接输入法extention的时候回调(先前连接在extention上的客户端全部断开的情况下)。 Extension生命周期回调,在一个新的客户端去尝试连接输入法extention的时候回调(先前连接在extention上的客户端全部断开的情况下)。
**系统能力**:SystemCapability.MiscServices.InputMethodFramework **系统能力**:SystemCapability.MiscServices.InputMethodFramework
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| want | [Want](js-apis-application-Want.md) | 是 | 当前Extension相关的Want类型信息,包括ability名称、bundle名称等。 |
**示例:** **示例:**
```js ```js
class InputMethodExt extends InputMethodExtensionAbility { class InputMethodExt extends InputMethodExtensionAbility {
onReconnect() { onReconnect(want) {
console.log('onReconnect, want:' + want.abilityName); console.log('onReconnect, want:' + want.abilityName);
} }
} }
``` ```
...@@ -6,8 +6,8 @@ InputMethodExtensionContext模块提供InputMethodExtensionAbility具有的能 ...@@ -6,8 +6,8 @@ InputMethodExtensionContext模块提供InputMethodExtensionAbility具有的能
> **说明:** > **说明:**
> >
> 本模块首批接口从API version 9开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 > - 本模块首批接口从API version 9开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
> 本模块接口仅可在Stage模型下使用。 > - 本模块接口仅可在Stage模型下使用。
## 导入模块 ## 导入模块
...@@ -20,12 +20,12 @@ import InputMethodExtensionContext from '@ohos.inputmethodextensioncontext'; ...@@ -20,12 +20,12 @@ import InputMethodExtensionContext from '@ohos.inputmethodextensioncontext';
在使用InputMethodExtensionContext的功能前,需要通过InputMethodExtensionAbility子类实例获取。 在使用InputMethodExtensionContext的功能前,需要通过InputMethodExtensionAbility子类实例获取。
```js ```js
import InputMethodExtensionAbility from '@ohos.inputmethodextensionability'; import InputMethodExtensionAbility from '@ohos.inputmethodextensionability';
class MainAbility extends InputMethodExtensionAbility { class MainAbility extends InputMethodExtensionAbility {
onCreate() { onCreate() {
let context = this.context; let context = this.context;
} }
} }
``` ```
## InputMethodExtensionContext.startAbility ## InputMethodExtensionContext.startAbility
...@@ -45,15 +45,15 @@ startAbility(want: Want, callback: AsyncCallback&lt;void&gt;): void; ...@@ -45,15 +45,15 @@ startAbility(want: Want, callback: AsyncCallback&lt;void&gt;): void;
**示例:** **示例:**
```js ```js
let want = { let want = {
'bundleName': 'com.example.myapp', 'bundleName': 'com.example.myapp',
'abilityName': 'MyAbility' 'abilityName': 'MyAbility'
}; };
this.context.startAbility(want, (err) => { this.context.startAbility(want, (err) => {
console.log('startAbility result:' + JSON.stringify(err)); console.log('startAbility result:' + JSON.stringify(err));
}); });
``` ```
## InputMethodExtensionContext.startAbility ## InputMethodExtensionContext.startAbility
...@@ -78,18 +78,17 @@ startAbility(want: Want, options?: StartOptions): Promise\<void>; ...@@ -78,18 +78,17 @@ startAbility(want: Want, options?: StartOptions): Promise\<void>;
**示例:** **示例:**
```js ```js
let want = { let want = {
'bundleName': 'com.example.myapp', 'bundleName': 'com.example.myapp',
'abilityName': 'MyAbility' 'abilityName': 'MyAbility'
}; };
this.context.startAbility(want).then((data) => { this.context.startAbility(want).then((data) => {
console.log('success:' + JSON.stringify(data)); console.log('success:' + JSON.stringify(data));
}).catch((error) => { }).catch((error) => {
console.log('failed:' + JSON.stringify(error)); console.log('failed:' + JSON.stringify(error));
}); });
```
```
## InputMethodExtensionContext.startAbility ## InputMethodExtensionContext.startAbility
...@@ -109,19 +108,19 @@ startAbility(want: Want, options: StartOptions, callback: AsyncCallback&lt;void& ...@@ -109,19 +108,19 @@ startAbility(want: Want, options: StartOptions, callback: AsyncCallback&lt;void&
**示例:** **示例:**
```js ```js
var want = { let want = {
'deviceId': '', 'deviceId': '',
'bundleName': 'com.extreme.test', 'bundleName': 'com.extreme.test',
'abilityName': 'MainAbility' 'abilityName': 'MainAbility'
}; };
var options = { let options = {
windowMode: 0, windowMode: 0,
}; };
this.context.startAbility(want, options, (error) => { this.context.startAbility(want, options, (error) => {
console.log('error.code = ' + error.code) console.log('error.code = ' + error.code)
}) })
``` ```
## InputMethodExtensionContext.terminateSelf ## InputMethodExtensionContext.terminateSelf
...@@ -139,11 +138,11 @@ terminateSelf(callback: AsyncCallback&lt;void&gt;): void; ...@@ -139,11 +138,11 @@ terminateSelf(callback: AsyncCallback&lt;void&gt;): void;
**示例:** **示例:**
```js ```js
this.context.terminateSelf((err) => { this.context.terminateSelf((err) => {
console.log('terminateSelf result:' + JSON.stringify(err)); console.log('terminateSelf result:' + JSON.stringify(err));
}); });
``` ```
## InputMethodExtensionContext.terminateSelf ## InputMethodExtensionContext.terminateSelf
...@@ -161,10 +160,10 @@ terminateSelf(): Promise&lt;void&gt;; ...@@ -161,10 +160,10 @@ terminateSelf(): Promise&lt;void&gt;;
**示例:** **示例:**
```js ```js
this.context.terminateSelf().then((data) => { this.context.terminateSelf().then((data) => {
console.log('success:' + JSON.stringify(data)); console.log('success:' + JSON.stringify(data));
}).catch((error) => { }).catch((error) => {
console.log('failed:' + JSON.stringify(error)); console.log('failed:' + JSON.stringify(error));
}); });
``` ```
...@@ -11,7 +11,6 @@ ...@@ -11,7 +11,6 @@
``` ```
import inputMethod from '@ohos.inputmethod'; import inputMethod from '@ohos.inputmethod';
import InputMethodSubtype from './@ohos.inputMethodSubtype';
``` ```
## inputMethod<sup>8+</sup> ## inputMethod<sup>8+</sup>
...@@ -42,31 +41,6 @@ import InputMethodSubtype from './@ohos.inputMethodSubtype'; ...@@ -42,31 +41,6 @@ import InputMethodSubtype from './@ohos.inputMethodSubtype';
| iconId<sup>9+</sup> | number | 是 | 否 | 输入法图标id,非必填项。 | | iconId<sup>9+</sup> | number | 是 | 否 | 输入法图标id,非必填项。 |
| extra<sup>9+</sup> | object | 是 | 否 | 输入法其他信息,非必填项。 | | extra<sup>9+</sup> | object | 是 | 否 | 输入法其他信息,非必填项。 |
## inputMethod.getInputMethodController<sup>(deprecated)</sup>
getInputMethodController(): InputMethodController
获取客户端实例[InputMethodController](#inputmethodcontroller)
> **说明:**
> 从API version 9开始废弃, 建议使用[getController](#inputmethodgetcontroller9)替代
>
> 从 API version 6开始支持。
**系统能力**:SystemCapability.MiscServices.InputMethodFramework
**返回值:**
| 类型 | 说明 |
| ----------------------------------------------- | ------------------------ |
| [InputMethodController](#inputmethodcontroller) | 回调返回当前客户端实例。 |
**示例:**
```js
var InputMethodController = inputMethod.getInputMethodController();
```
## inputMethod.getController<sup>9+</sup> ## inputMethod.getController<sup>9+</sup>
getController(): InputMethodController getController(): InputMethodController
...@@ -84,33 +58,7 @@ getController(): InputMethodController ...@@ -84,33 +58,7 @@ getController(): InputMethodController
**示例:** **示例:**
```js ```js
var InputMethodController = inputMethod.getController(); let InputMethodController = inputMethod.getController();
```
## inputMethod.getInputMethodSetting<sup>(deprecated)</sup>
getInputMethodSetting(): InputMethodSetting
获取客户端设置实例[InputMethodSetting](#inputmethodsetting8)
> **说明:**
> 从API version 9开始废弃, 建议使用[getSetting](#inputmethodgetsetting9)替代
>
> 从 API version 6开始支持。
**系统能力**: SystemCapability.MiscServices.InputMethodFramework
**返回值:**
| 类型 | 说明 |
| ----------------------------------------- | ---------------------------- |
| [InputMethodSetting](#inputmethodsetting8) | 回调返回当前客户端设置实例。 |
**示例:**
```js
var InputMethodSetting = inputMethod.getInputMethodSetting();
``` ```
## inputMethod.getSetting<sup>9+</sup> ## inputMethod.getSetting<sup>9+</sup>
...@@ -131,7 +79,7 @@ getSetting(): InputMethodSetting ...@@ -131,7 +79,7 @@ getSetting(): InputMethodSetting
**示例:** **示例:**
```js ```js
var InputMethodSetting = inputMethod.getSetting(); let InputMethodSetting = inputMethod.getSetting();
``` ```
## inputMethod.switchInputMethod<sup>9+</sup> ## inputMethod.switchInputMethod<sup>9+</sup>
...@@ -227,7 +175,7 @@ getCurrentInputMethod(): InputMethodProperty ...@@ -227,7 +175,7 @@ getCurrentInputMethod(): InputMethodProperty
**示例:** **示例:**
```js ```js
var currentIme = inputMethod.getCurrentInputMethod(); let currentIme = inputMethod.getCurrentInputMethod();
``` ```
## inputMethod.switchCurrentInputMethodSubtype<sup>9+</sup> ## inputMethod.switchCurrentInputMethodSubtype<sup>9+</sup>
...@@ -328,7 +276,7 @@ getCurrentInputMethodSubtype(): InputMethodSubtype ...@@ -328,7 +276,7 @@ getCurrentInputMethodSubtype(): InputMethodSubtype
**示例:** **示例:**
```js ```js
var currentImeSubType = inputMethod.getCurrentInputMethodSubtype(); let currentImeSubType = inputMethod.getCurrentInputMethodSubtype();
``` ```
## inputMethod.switchCurrentInputMethodAndSubtype<sup>9+</sup> ## inputMethod.switchCurrentInputMethodAndSubtype<sup>9+</sup>
...@@ -420,78 +368,56 @@ try { ...@@ -420,78 +368,56 @@ try {
} }
``` ```
## InputMethodController ## inputMethod.getInputMethodController<sup>(deprecated)</sup>
下列API示例中都需使用[getController](##inputmethodgetcontroller9)回调获取到InputMethodController实例,再通过此实例调用对应方法。
### stopInput<sup>(deprecated)</sup>
stopInput(callback: AsyncCallback&lt;boolean&gt;): void getInputMethodController(): InputMethodController
隐藏输入法。使用callback形式返回结果。参数个数为1,否则抛出异常 获取客户端实例[InputMethodController](#inputmethodcontroller)
> **说明:** > **说明:**
> 从API version 9开始废弃, 建议使用[stopInputSession](#stopinputsession9)替代 > 从API version 6开始支持,从API version 9开始废弃, 建议使用[getController()](#inputmethodgetcontroller9)替代
>
> 从 API version 6开始支持。
**系统能力**:SystemCapability.MiscServices.InputMethodFramework **系统能力**:SystemCapability.MiscServices.InputMethodFramework
**参数:** **返回值:**
| 参数名 | 类型 | 必填 | 说明 | | 类型 | 说明 |
| -------- | -------- | -------- | -------- | | ----------------------------------------------- | ------------------------ |
| callback | AsyncCallback&lt;boolean&gt; | 是 | 返回输入法隐藏是否成功。 | | [InputMethodController](#inputmethodcontroller) | 回调返回当前客户端实例。 |
**示例:** **示例:**
```js ```js
InputMethodController.stopInput((error, result) => { let InputMethodController = inputMethod.getInputMethodController();
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<sup>(deprecated)</sup> ## inputMethod.getInputMethodSetting<sup>(deprecated)</sup>
stopInput(): Promise&lt;boolean&gt; getInputMethodSetting(): InputMethodSetting
隐藏输入法。使用promise形式返回结果。参数个数为0,否则抛出异常 获取客户端设置实例[InputMethodSetting](#inputmethodsetting8)
> **说明:** > **说明:**
> 从API version 9开始废弃, 建议使用[stopInputSession](#stopinputsession9)替代 > 从API version 6开始支持,从API version 9开始废弃, 建议使用[getSetting()](#inputmethodgetsetting9)替代
>
> 从 API version 6开始支持。
**系统能力**: SystemCapability.MiscServices.InputMethodFramework **系统能力**: SystemCapability.MiscServices.InputMethodFramework
**返回值:** **返回值:**
| 类型 | 说明 | | 类型 | 说明 |
| -------- | -------- | | ----------------------------------------- | ---------------------------- |
| Promise&lt;boolean&gt; | 返回输入法隐藏是否成功。 | | [InputMethodSetting](#inputmethodsetting8) | 回调返回当前客户端设置实例。 |
**示例:** **示例:**
```js ```js
InputMethodController.stopInput().then((result) => { let InputMethodSetting = inputMethod.getInputMethodSetting();
if (result) {
console.info('Success to stopInput.(promise)');
} else {
console.error('Failed to stopInput.(promise)');
}
}).catch((err) => {
console.error('stopInput promise err: ' + err);
})
``` ```
## InputMethodController
下列API示例中都需使用[getController](##inputmethodgetcontroller9)回调获取到InputMethodController实例,再通过此实例调用对应方法。
### stopInputSession<sup>9+</sup> ### stopInputSession<sup>9+</sup>
stopInputSession(callback: AsyncCallback&lt;boolean&gt;): void stopInputSession(callback: AsyncCallback&lt;boolean&gt;): void
...@@ -528,7 +454,7 @@ try { ...@@ -528,7 +454,7 @@ try {
### stopInputSession ### stopInputSession
stopInputSession(): Promise&lt;boolean&gt; stopInputSession(): Promise&lt;boolean&gt;<sup>9+</sup>
隐藏输入法。使用promise形式返回结果。 隐藏输入法。使用promise形式返回结果。
...@@ -658,6 +584,70 @@ InputMethodController.hideSoftKeyboard().then(async (err) => { ...@@ -658,6 +584,70 @@ InputMethodController.hideSoftKeyboard().then(async (err) => {
}); });
``` ```
### stopInput<sup>(deprecated)</sup>
stopInput(callback: AsyncCallback&lt;boolean&gt;): void
隐藏输入法。使用callback形式返回结果。参数个数为1,否则抛出异常。
> **说明:**
> 从API version 6开始支持,从API version 9开始废弃, 建议使用[stopInputSession()](#stopinputsession9)替代
**系统能力**:SystemCapability.MiscServices.InputMethodFramework
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| callback | AsyncCallback&lt;boolean&gt; | 是 | 返回输入法隐藏是否成功。 |
**示例:**
```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<sup>(deprecated)</sup>
stopInput(): Promise&lt;boolean&gt;
隐藏输入法。使用promise形式返回结果。参数个数为0,否则抛出异常。
> **说明:**
> 从API version 6开始支持,从API version 9开始废弃, 建议使用[stopInputSession()](#stopinputsession9)替代
**系统能力**: SystemCapability.MiscServices.InputMethodFramework
**返回值:**
| 类型 | 说明 |
| -------- | -------- |
| Promise&lt;boolean&gt; | 返回输入法隐藏是否成功。 |
**示例:**
```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);
})
```
## InputMethodSetting<sup>8+</sup> ## InputMethodSetting<sup>8+</sup>
下列API示例中都需使用[getSetting](#inputmethodgetsetting9)回调获取到InputMethodSetting实例,再通过此实例调用对应方法。 下列API示例中都需使用[getSetting](#inputmethodgetsetting9)回调获取到InputMethodSetting实例,再通过此实例调用对应方法。
...@@ -679,14 +669,14 @@ on(type: 'imeChange', callback: (inputMethodProperty: InputMethodProperty, input ...@@ -679,14 +669,14 @@ on(type: 'imeChange', callback: (inputMethodProperty: InputMethodProperty, input
**示例:** **示例:**
```js ```js
InputMethodEngine.on('imeChange', (inputMethodProperty, inputMethodSubtype) => { InputMethodEngine.on('imeChange', (inputMethodProperty, inputMethodSubtype) => {
InputMethodProperty = inputMethodProperty; InputMethodProperty = inputMethodProperty;
InputMethodSubtype = inputMethodSubtype; InputMethodSubtype = inputMethodSubtype;
}); });
``` ```
### off('imeChange')<a name="imeChange"></a><sup>9+</sup> ### off('imeChange')<sup>9+</sup>
on(type: 'imeChange', callback: (inputMethodProperty: InputMethodProperty, inputMethodSubtype: InputMethodSubtype) => void): void on(type: 'imeChange', callback: (inputMethodProperty: InputMethodProperty, inputMethodSubtype: InputMethodSubtype) => void): void
...@@ -703,9 +693,9 @@ on(type: 'imeChange', callback: (inputMethodProperty: InputMethodProperty, input ...@@ -703,9 +693,9 @@ on(type: 'imeChange', callback: (inputMethodProperty: InputMethodProperty, input
**示例:** **示例:**
```js ```js
InputMethodAbility.off('imeChange'); InputMethodAbility.off('imeChange');
``` ```
### listInputMethodSubtype<sup>9+</sup> ### listInputMethodSubtype<sup>9+</sup>
...@@ -903,6 +893,62 @@ try { ...@@ -903,6 +893,62 @@ try {
} }
``` ```
### showOptionalInputMethods<sup>9+</sup>
showOptionalInputMethods(callback: AsyncCallback&lt;void&gt;): void
显示输入法选择对话框。使用callback形式返回结果。参数个数为1,否则抛出异常。
**需要权限**: ohos.permission.CONNECT_IME_ABILITY
**系统能力**: SystemCapability.MiscServices.InputMethodFramework
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| callback | AsyncCallback&lt;void&gt; | 是 | 回调函数。 |
**示例:**
```js
try {
InputMethodSetting.showOptionalInputMethods((err) => {
if (err) {
console.error('showOptionalInputMethods failed: ' + JSON.stringify(err));
return;
}
console.info('showOptionalInputMethods success');
});
} catch (err) {
console.error('showOptionalInputMethods failed: ' + JSON.stringify(err));
}
```
### showOptionalInputMethods<sup>9+</sup>
showOptionalInputMethods(): Promise&lt;void&gt;
显示输入法选择对话框。使用promise形式返回结果。参数个数为0,否则抛出异常。
**系统能力**: SystemCapability.MiscServices.InputMethodFramework
**返回值:**
| 类型 | 说明 |
| -------- | -------- |
| Promise&lt;void&gt; | 无返回结果的Promise对象。 |
**示例:**
```js
InputMethodSetting.showOptionalInputMethods().then(() => {
console.info('displayOptionalInputMethod success.(promise)');
}).catch((err) => {
console.error('displayOptionalInputMethod promise err: ' + err);
})
```
### listInputMethod<sup>(deprecated)</sup> ### listInputMethod<sup>(deprecated)</sup>
listInputMethod(callback: AsyncCallback&lt;Array&lt;InputMethodProperty&gt;&gt;): void listInputMethod(callback: AsyncCallback&lt;Array&lt;InputMethodProperty&gt;&gt;): void
...@@ -910,9 +956,7 @@ listInputMethod(callback: AsyncCallback&lt;Array&lt;InputMethodProperty&gt;&gt;) ...@@ -910,9 +956,7 @@ listInputMethod(callback: AsyncCallback&lt;Array&lt;InputMethodProperty&gt;&gt;)
查询已安装的输入法列表。使用callback形式返回结果。参数个数为1,否则抛出异常。 查询已安装的输入法列表。使用callback形式返回结果。参数个数为1,否则抛出异常。
> **说明:** > **说明:**
> 从API version 9开始废弃, 建议使用[getInputMethods](#getinputmethods9)替代 > 从API version 8开始支持,从API version 9开始废弃, 建议使用[getInputMethods](#getinputmethods9)替代
>
> 从 API version 8开始支持。
**系统能力**: SystemCapability.MiscServices.InputMethodFramework **系统能力**: SystemCapability.MiscServices.InputMethodFramework
...@@ -941,9 +985,7 @@ listInputMethod(): Promise&lt;Array&lt;InputMethodProperty&gt;&gt; ...@@ -941,9 +985,7 @@ listInputMethod(): Promise&lt;Array&lt;InputMethodProperty&gt;&gt;
查询已安装的输入法列表。使用promise形式返回结果。参数个数为0,否则抛出异常。 查询已安装的输入法列表。使用promise形式返回结果。参数个数为0,否则抛出异常。
> **说明:** > **说明:**
> 从API version 9开始废弃, 建议使用[getInputMethods](#getinputmethods9-1)替代 > 从API version 8开始支持,从API version 9开始废弃, 建议使用[getInputMethods](#getinputmethods9-1)替代
>
> 从 API version 8开始支持。
**系统能力**: SystemCapability.MiscServices.InputMethodFramework **系统能力**: SystemCapability.MiscServices.InputMethodFramework
...@@ -970,9 +1012,7 @@ displayOptionalInputMethod(callback: AsyncCallback&lt;void&gt;): void ...@@ -970,9 +1012,7 @@ displayOptionalInputMethod(callback: AsyncCallback&lt;void&gt;): void
显示输入法选择对话框。使用callback形式返回结果。参数个数为1,否则抛出异常。 显示输入法选择对话框。使用callback形式返回结果。参数个数为1,否则抛出异常。
> **说明:** > **说明:**
> 从API version 9开始废弃, 建议使用[showOptionalInputMethods](#showoptionalinputmethods9)替代 > 从API version 8开始支持,从API version 9开始废弃, 建议使用[showOptionalInputMethods()](#showoptionalinputmethods9)替代
>
> 从 API version 8开始支持。
**系统能力**: SystemCapability.MiscServices.InputMethodFramework **系统能力**: SystemCapability.MiscServices.InputMethodFramework
...@@ -994,38 +1034,6 @@ InputMethodSetting.displayOptionalInputMethod((err) => { ...@@ -994,38 +1034,6 @@ InputMethodSetting.displayOptionalInputMethod((err) => {
}); });
``` ```
### showOptionalInputMethods<sup>9+</sup>
showOptionalInputMethods(callback: AsyncCallback&lt;void&gt;): void
显示输入法选择对话框。使用callback形式返回结果。参数个数为1,否则抛出异常。
**需要权限**: ohos.permission.CONNECT_IME_ABILITY
**系统能力**: SystemCapability.MiscServices.InputMethodFramework
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| callback | AsyncCallback&lt;void&gt; | 是 | 回调函数。 |
**示例:**
```js
try {
InputMethodSetting.showOptionalInputMethods((err) => {
if (err) {
console.error('showOptionalInputMethods failed: ' + JSON.stringify(err));
return;
}
console.info('showOptionalInputMethods success');
});
} catch (err) {
console.error('showOptionalInputMethods failed: ' + JSON.stringify(err));
}
```
### displayOptionalInputMethod<sup>(deprecated)</sup> ### displayOptionalInputMethod<sup>(deprecated)</sup>
displayOptionalInputMethod(): Promise&lt;void&gt; displayOptionalInputMethod(): Promise&lt;void&gt;
...@@ -1033,9 +1041,7 @@ displayOptionalInputMethod(): Promise&lt;void&gt; ...@@ -1033,9 +1041,7 @@ displayOptionalInputMethod(): Promise&lt;void&gt;
显示输入法选择对话框。使用promise形式返回结果。参数个数为0,否则抛出异常。 显示输入法选择对话框。使用promise形式返回结果。参数个数为0,否则抛出异常。
> **说明:** > **说明:**
> 从API version 9开始废弃, 建议使用[showOptionalInputMethods](#showoptionalinputmethods9-1)替代 > 从API version 8开始支持,API version 9开始废弃, 建议使用[showOptionalInputMethods()](#showoptionalinputmethods9-1)替代
>
> 从 API version 8开始支持。
**系统能力**: SystemCapability.MiscServices.InputMethodFramework **系统能力**: SystemCapability.MiscServices.InputMethodFramework
...@@ -1054,27 +1060,3 @@ InputMethodSetting.displayOptionalInputMethod().then(() => { ...@@ -1054,27 +1060,3 @@ InputMethodSetting.displayOptionalInputMethod().then(() => {
console.error('displayOptionalInputMethod promise err: ' + err); console.error('displayOptionalInputMethod promise err: ' + err);
}) })
``` ```
### showOptionalInputMethods<sup>9+</sup>
showOptionalInputMethods(): Promise&lt;void&gt;
显示输入法选择对话框。使用promise形式返回结果。参数个数为0,否则抛出异常。
**系统能力**: SystemCapability.MiscServices.InputMethodFramework
**返回值:**
| 类型 | 说明 |
| -------- | -------- |
| Promise&lt;void&gt; | 无返回结果的Promise对象。 |
**示例:**
```js
InputMethodSetting.showOptionalInputMethods().then(() => {
console.info('displayOptionalInputMethod success.(promise)');
}).catch((err) => {
console.error('displayOptionalInputMethod promise err: ' + err);
})
```
\ No newline at end of file
...@@ -51,82 +51,78 @@ import inputMethodEngine from '@ohos.inputmethodengine'; ...@@ -51,82 +51,78 @@ import inputMethodEngine from '@ohos.inputmethodengine';
| CURSOR_RIGHT<sup>9+</sup> | number | 是 | 否 | 光标右移。 | | CURSOR_RIGHT<sup>9+</sup> | number | 是 | 否 | 光标右移。 |
| WINDOW_TYPE_INPUT_METHOD_FLOAT<sup>9+</sup> | number | 是 | 否 | 输入法应用窗口风格标识。 | | WINDOW_TYPE_INPUT_METHOD_FLOAT<sup>9+</sup> | number | 是 | 否 | 输入法应用窗口风格标识。 |
## inputMethodEngine.getInputMethodEngine<a name="getInputMethodEngine"></a><sup>(deprecated)</sup> ## inputMethodEngine.getInputMethodAbility<a name="getInputMethodAbility"></a><sup>9+</sup>
getInputMethodEngine(): InputMethodEngine getInputMethodAbility(): InputMethodAbility
获取服务端实例。 获取服务端实例。
> **说明:**
> 从API version 9开始废弃, 建议使用[getInputMethodAbility](#getInputMethodAbility)替代
>
> 从 API version 8开始支持。
**系统能力**: SystemCapability.MiscServices.InputMethodFramework **系统能力**: SystemCapability.MiscServices.InputMethodFramework
**返回值:** **返回值:**
| 类型 | 说明 | | 类型 | 说明 |
| --------------------------------------- | ------------ | | --------------------------------------- | ------------ |
| [InputMethodEngine](#inputmethodengine-1) | 服务端实例。 | | [InputMethodAbility](#inputmethodability) | 服务端实例。 |
**示例:** **示例:**
```js ```js
var InputMethodEngine = inputMethodEngine.getInputMethodEngine(); let InputMethodAbility = inputMethodAbility.getInputMethodAbility();
``` ```
## inputMethodEngine.getInputMethodAbility<a name="getInputMethodAbility"></a><sup>9+</sup> ## inputMethodEngine.getKeyboardDelegate<a name="getKeyboardDelegate"></a><sup>9+</sup>
getInputMethodAbility(): InputMethodAbility getKeyboardDelegate(): KeyboardDelegate
获取服务端实例。 获取客户端监听实例。
**系统能力**: SystemCapability.MiscServices.InputMethodFramework **系统能力**: SystemCapability.MiscServices.InputMethodFramework
**返回值:** **返回值:**
| 类型 | 说明 | | 类型 | 说明 |
| --------------------------------------- | ------------ | | ------------------------------------- | ---------------- |
| [InputMethodAbility](#inputmethodability) | 服务端实例。 | | [KeyboardDelegate](#KeyboardDelegate) | 客户端监听实例。 |
**示例:** **示例:**
```js ```js
var InputMethodAbility = inputMethodAbility.getInputMethodAbility(); let KeyboardDelegate = inputMethodAbility.getKeyboardDelegate();
``` ```
## inputMethodEngine.createKeyboardDelegate<a name="createKeyboardDelegate"></a><sup>(deprecated)</sup> ## inputMethodEngine.getInputMethodEngine<a name="getInputMethodEngine"></a><sup>(deprecated)</sup>
createKeyboardDelegate(): KeyboardDelegate getInputMethodEngine(): InputMethodEngine
获取客户端监听实例。 获取服务端实例。
> **说明:** > **说明:**
> 从API version 9开始废弃, 建议使用[getKeyboardDelegate](#getKeyboardDelegate)替代 > 从API version 8开始支持,API version 9开始废弃, 建议使用[getInputMethodAbility()](#getInputMethodAbility)替代
>
> 从 API version 8开始支持。
**系统能力**: SystemCapability.MiscServices.InputMethodFramework **系统能力**: SystemCapability.MiscServices.InputMethodFramework
**返回值:** **返回值:**
| 类型 | 说明 | | 类型 | 说明 |
| ------------------------------------- | ---------------- | | --------------------------------------- | ------------ |
| [KeyboardDelegate](#KeyboardDelegate) | 客户端监听实例。 | | [InputMethodEngine](#inputmethodengine-1) | 服务端实例。 |
**示例:** **示例:**
```js ```js
var KeyboardDelegate = inputMethodEngine.createKeyboardDelegate(); let InputMethodEngine = inputMethodEngine.getInputMethodEngine();
``` ```
## inputMethodEngine.getKeyboardDelegate<a name="getKeyboardDelegate"></a><sup>9+</sup> ## inputMethodEngine.createKeyboardDelegate<a name="createKeyboardDelegate"></a><sup>(deprecated)</sup>
getKeyboardDelegate(): KeyboardDelegate createKeyboardDelegate(): KeyboardDelegate
获取客户端监听实例。 获取客户端监听实例。
> **说明:**
> 从API version 8开始支持,API version 9开始废弃, 建议使用[getKeyboardDelegate()](#getKeyboardDelegate)替代
**系统能力**: SystemCapability.MiscServices.InputMethodFramework **系统能力**: SystemCapability.MiscServices.InputMethodFramework
**返回值:** **返回值:**
...@@ -137,9 +133,9 @@ getKeyboardDelegate(): KeyboardDelegate ...@@ -137,9 +133,9 @@ getKeyboardDelegate(): KeyboardDelegate
**示例:** **示例:**
```js ```js
var KeyboardDelegate = inputMethodAbility.getKeyboardDelegate(); let KeyboardDelegate = inputMethodEngine.createKeyboardDelegate();
``` ```
## InputMethodEngine<a name="InputMethodEngine"></a> ## InputMethodEngine<a name="InputMethodEngine"></a>
...@@ -162,12 +158,12 @@ on(type: 'inputStart', callback: (kbController: KeyboardController, textInputCli ...@@ -162,12 +158,12 @@ on(type: 'inputStart', callback: (kbController: KeyboardController, textInputCli
**示例:** **示例:**
```js ```js
inputMethodEngine.getInputMethodEngine().on('inputStart', (kbController, textInputClient) => { inputMethodEngine.getInputMethodEngine().on('inputStart', (kbController, textInputClient) => {
KeyboardController = kbController; KeyboardController = kbController;
TextInputClient = textInputClient; TextInputClient = textInputClient;
}); });
``` ```
### off('inputStart') ### off('inputStart')
...@@ -188,11 +184,11 @@ off(type: 'inputStart', callback?: (kbController: KeyboardController, textInputC ...@@ -188,11 +184,11 @@ off(type: 'inputStart', callback?: (kbController: KeyboardController, textInputC
**示例:** **示例:**
```js ```js
inputMethodEngine.getInputMethodEngine().off('inputStart', (kbController, textInputClient) => { inputMethodEngine.getInputMethodEngine().off('inputStart', (kbController, textInputClient) => {
console.log('delete inputStart notification.'); console.log('delete inputStart notification.');
}); });
``` ```
### on('inputStop')<sup>9+</sup> ### on('inputStop')<sup>9+</sup>
...@@ -211,11 +207,11 @@ on(type: 'inputStop', callback: () => void): void ...@@ -211,11 +207,11 @@ on(type: 'inputStop', callback: () => void): void
**示例:** **示例:**
```js ```js
inputMethodEngine.getInputMethodEngine().on('inputStop', () => { inputMethodEngine.getInputMethodEngine().on('inputStop', () => {
console.log('inputMethodEngine inputStop'); console.log('inputMethodEngine inputStop');
}); });
``` ```
### off('inputStop')<sup>9+</sup> ### off('inputStop')<sup>9+</sup>
...@@ -234,11 +230,11 @@ off(type: 'inputStop', callback: () => void): void ...@@ -234,11 +230,11 @@ off(type: 'inputStop', callback: () => void): void
**示例:** **示例:**
```js ```js
inputMethodEngine.getInputMethodEngine().off('inputStop', () => { inputMethodEngine.getInputMethodEngine().off('inputStop', () => {
console.log('inputMethodEngine delete inputStop notification.'); console.log('inputMethodEngine delete inputStop notification.');
}); });
``` ```
### on('setCallingWindow')<sup>9+</sup> ### on('setCallingWindow')<sup>9+</sup>
...@@ -257,11 +253,11 @@ on(type: 'setCallingWindow', callback: (wid:number) => void): void ...@@ -257,11 +253,11 @@ on(type: 'setCallingWindow', callback: (wid:number) => void): void
**示例:** **示例:**
```js ```js
inputMethodEngine.getInputMethodEngine().on('setCallingWindow', (wid) => { inputMethodEngine.getInputMethodEngine().on('setCallingWindow', (wid) => {
console.log('inputMethodEngine setCallingWindow'); console.log('inputMethodEngine setCallingWindow');
}); });
``` ```
### off('setCallingWindow')<sup>9+</sup> ### off('setCallingWindow')<sup>9+</sup>
...@@ -280,11 +276,11 @@ off(type: 'setCallingWindow', callback: (wid:number) => void): void ...@@ -280,11 +276,11 @@ off(type: 'setCallingWindow', callback: (wid:number) => void): void
**示例:** **示例:**
```js ```js
inputMethodEngine.getInputMethodEngine().off('setCallingWindow', () => { inputMethodEngine.getInputMethodEngine().off('setCallingWindow', () => {
console.log('inputMethodEngine delete setCallingWindow notification.'); console.log('inputMethodEngine delete setCallingWindow notification.');
}); });
``` ```
### on('keyboardShow'|'keyboardHide') ### on('keyboardShow'|'keyboardHide')
...@@ -303,14 +299,14 @@ on(type: 'keyboardShow'|'keyboardHide', callback: () => void): void ...@@ -303,14 +299,14 @@ on(type: 'keyboardShow'|'keyboardHide', callback: () => void): void
**示例:** **示例:**
```js ```js
inputMethodEngine.getInputMethodEngine().on('keyboardShow', () => { inputMethodEngine.getInputMethodEngine().on('keyboardShow', () => {
console.log('inputMethodEngine keyboardShow.'); console.log('inputMethodEngine keyboardShow.');
}); });
inputMethodEngine.getInputMethodEngine().on('keyboardHide', () => { inputMethodEngine.getInputMethodEngine().on('keyboardHide', () => {
console.log('inputMethodEngine keyboardHide.'); console.log('inputMethodEngine keyboardHide.');
}); });
``` ```
### off('keyboardShow'|'keyboardHide') ### off('keyboardShow'|'keyboardHide')
...@@ -329,14 +325,14 @@ off(type: 'keyboardShow'|'keyboardHide', callback?: () => void): void ...@@ -329,14 +325,14 @@ off(type: 'keyboardShow'|'keyboardHide', callback?: () => void): void
**示例:** **示例:**
```js ```js
inputMethodEngine.getInputMethodEngine().off('keyboardShow', () => { inputMethodEngine.getInputMethodEngine().off('keyboardShow', () => {
console.log('inputMethodEngine delete keyboardShow notification.'); console.log('inputMethodEngine delete keyboardShow notification.');
}); });
inputMethodEngine.getInputMethodEngine().off('keyboardHide', () => { inputMethodEngine.getInputMethodEngine().off('keyboardHide', () => {
console.log('inputMethodEngine delete keyboardHide notification.'); console.log('inputMethodEngine delete keyboardHide notification.');
}); });
``` ```
## InputMethodAbility<a name="InputMethodAbility"></a> ## InputMethodAbility<a name="InputMethodAbility"></a>
...@@ -359,12 +355,12 @@ on(type: 'inputStart', callback: (kbController: KeyboardController, inputClient: ...@@ -359,12 +355,12 @@ on(type: 'inputStart', callback: (kbController: KeyboardController, inputClient:
**示例:** **示例:**
```js ```js
inputMethodEngine.getInputMethodAbility().on('inputStart', (kbController, inputClient) => { inputMethodEngine.getInputMethodAbility().on('inputStart', (kbController, inputClient) => {
KeyboardController = kbController; KeyboardController = kbController;
InputClient = inputClient; InputClient = inputClient;
}); });
``` ```
### off('inputStart')<sup>9+</sup> ### off('inputStart')<sup>9+</sup>
...@@ -383,11 +379,11 @@ off(type: 'inputStart', callback?: (kbController: KeyboardController, inputClien ...@@ -383,11 +379,11 @@ off(type: 'inputStart', callback?: (kbController: KeyboardController, inputClien
**示例:** **示例:**
```js ```js
inputMethodEngine.getInputMethodAbility().off('inputStart', (kbController, inputClient) => { inputMethodEngine.getInputMethodAbility().off('inputStart', (kbController, inputClient) => {
console.log('delete inputStart notification.'); console.log('delete inputStart notification.');
}); });
``` ```
### on('inputStop')<sup>9+</sup> ### on('inputStop')<sup>9+</sup>
...@@ -406,11 +402,11 @@ on(type: 'inputStop', callback: () => void): void ...@@ -406,11 +402,11 @@ on(type: 'inputStop', callback: () => void): void
**示例:** **示例:**
```js ```js
inputMethodEngine.getInputMethodAbility().on('inputStop', () => { inputMethodEngine.getInputMethodAbility().on('inputStop', () => {
console.log('inputMethodAbility inputStop'); console.log('inputMethodAbility inputStop');
}); });
``` ```
### off('inputStop')<sup>9+</sup> ### off('inputStop')<sup>9+</sup>
...@@ -429,11 +425,11 @@ off(type: 'inputStop', callback: () => void): void ...@@ -429,11 +425,11 @@ off(type: 'inputStop', callback: () => void): void
**示例:** **示例:**
```js ```js
inputMethodEngine.getInputMethodAbility().off('inputStop', () => { inputMethodEngine.getInputMethodAbility().off('inputStop', () => {
console.log('inputMethodAbility delete inputStop notification.'); console.log('inputMethodAbility delete inputStop notification.');
}); });
``` ```
### on('setCallingWindow')<sup>9+</sup> ### on('setCallingWindow')<sup>9+</sup>
...@@ -452,11 +448,11 @@ on(type: 'setCallingWindow', callback: (wid:number) => void): void ...@@ -452,11 +448,11 @@ on(type: 'setCallingWindow', callback: (wid:number) => void): void
**示例:** **示例:**
```js ```js
inputMethodEngine.getInputMethodAbility().on('setCallingWindow', (wid) => { inputMethodEngine.getInputMethodAbility().on('setCallingWindow', (wid) => {
console.log('inputMethodAbility setCallingWindow'); console.log('inputMethodAbility setCallingWindow');
}); });
``` ```
### off('setCallingWindow')<sup>9+</sup> ### off('setCallingWindow')<sup>9+</sup>
...@@ -475,11 +471,11 @@ off(type: 'setCallingWindow', callback: (wid:number) => void): void ...@@ -475,11 +471,11 @@ off(type: 'setCallingWindow', callback: (wid:number) => void): void
**示例:** **示例:**
```js ```js
inputMethodEngine.getInputMethodAbility().off('setCallingWindow', () => { inputMethodEngine.getInputMethodAbility().off('setCallingWindow', () => {
console.log('inputMethodAbility delete setCallingWindow notification.'); console.log('inputMethodAbility delete setCallingWindow notification.');
}); });
``` ```
### on('keyboardShow'|'keyboardHide')<sup>9+</sup> ### on('keyboardShow'|'keyboardHide')<sup>9+</sup>
...@@ -498,14 +494,14 @@ on(type: 'keyboardShow'|'keyboardHide', callback: () => void): void ...@@ -498,14 +494,14 @@ on(type: 'keyboardShow'|'keyboardHide', callback: () => void): void
**示例:** **示例:**
```js ```js
inputMethodEngine.getInputMethodAbility().on('keyboardShow', () => { inputMethodEngine.getInputMethodAbility().on('keyboardShow', () => {
console.log('InputMethodAbility keyboardShow.'); console.log('InputMethodAbility keyboardShow.');
}); });
inputMethodEngine.getInputMethodAbility().on('keyboardHide', () => { inputMethodEngine.getInputMethodAbility().on('keyboardHide', () => {
console.log('InputMethodAbility keyboardHide.'); console.log('InputMethodAbility keyboardHide.');
}); });
``` ```
### off('keyboardShow'|'keyboardHide')<sup>9+</sup> ### off('keyboardShow'|'keyboardHide')<sup>9+</sup>
...@@ -524,14 +520,14 @@ off(type: 'keyboardShow'|'keyboardHide', callback?: () => void): void ...@@ -524,14 +520,14 @@ off(type: 'keyboardShow'|'keyboardHide', callback?: () => void): void
**示例:** **示例:**
```js ```js
inputMethodEngine.getInputMethodAbility().off('keyboardShow', () => { inputMethodEngine.getInputMethodAbility().off('keyboardShow', () => {
console.log('InputMethodAbility delete keyboardShow notification.'); console.log('InputMethodAbility delete keyboardShow notification.');
}); });
inputMethodEngine.getInputMethodAbility().off('keyboardHide', () => { inputMethodEngine.getInputMethodAbility().off('keyboardHide', () => {
console.log('InputMethodAbility delete keyboardHide notification.'); console.log('InputMethodAbility delete keyboardHide notification.');
}); });
``` ```
### on('setSubtype')<sup>9+</sup> ### on('setSubtype')<sup>9+</sup>
...@@ -550,11 +546,11 @@ on(type: 'setSubtype', callback: (inputMethodSubtype: InputMethodSubtype) => voi ...@@ -550,11 +546,11 @@ on(type: 'setSubtype', callback: (inputMethodSubtype: InputMethodSubtype) => voi
**示例:** **示例:**
```js ```js
inputMethodEngine.getInputMethodAbility().on('setSubtype', (inputMethodSubtype) => { inputMethodEngine.getInputMethodAbility().on('setSubtype', (inputMethodSubtype) => {
console.log('InputMethodAbility setSubtype.'); console.log('InputMethodAbility setSubtype.');
}); });
``` ```
### off('setSubtype')<sup>9+</sup> ### off('setSubtype')<sup>9+</sup>
...@@ -573,11 +569,11 @@ off(type: 'setSubtype', callback?: () => void): void ...@@ -573,11 +569,11 @@ off(type: 'setSubtype', callback?: () => void): void
**示例:** **示例:**
```js ```js
inputMethodEngine.getInputMethodAbility().off('setSubtype', () => { inputMethodEngine.getInputMethodAbility().off('setSubtype', () => {
console.log('InputMethodAbility delete setSubtype notification.'); console.log('InputMethodAbility delete setSubtype notification.');
}); });
``` ```
## KeyboardDelegate<a name="KeyboardDelegate"></a> ## KeyboardDelegate<a name="KeyboardDelegate"></a>
...@@ -600,18 +596,18 @@ on(type: 'keyDown'|'keyUp', callback: (event: KeyEvent) => boolean): void ...@@ -600,18 +596,18 @@ on(type: 'keyDown'|'keyUp', callback: (event: KeyEvent) => boolean): void
**示例:** **示例:**
```js ```js
inputMethodEngine.getKeyboardDelegate().on('keyUp', (keyEvent) => { inputMethodEngine.getKeyboardDelegate().on('keyUp', (keyEvent) => {
console.info('inputMethodEngine keyCode.(keyUp):' + JSON.stringify(keyEvent.keyCode)); console.info('inputMethodEngine keyCode.(keyUp):' + JSON.stringify(keyEvent.keyCode));
console.info('inputMethodEngine keyAction.(keyUp):' + JSON.stringify(keyEvent.keyAction)); console.info('inputMethodEngine keyAction.(keyUp):' + JSON.stringify(keyEvent.keyAction));
return true; return true;
}); });
inputMethodEngine.getKeyboardDelegate().on('keyDown', (keyEvent) => { inputMethodEngine.getKeyboardDelegate().on('keyDown', (keyEvent) => {
console.info('inputMethodEngine keyCode.(keyDown):' + JSON.stringify(keyEvent.keyCode)); console.info('inputMethodEngine keyCode.(keyDown):' + JSON.stringify(keyEvent.keyCode));
console.info('inputMethodEngine keyAction.(keyDown):' + JSON.stringify(keyEvent.keyAction)); console.info('inputMethodEngine keyAction.(keyDown):' + JSON.stringify(keyEvent.keyAction));
return true; return true;
}); });
``` ```
### off('keyDown'|'keyUp') ### off('keyDown'|'keyUp')
...@@ -630,16 +626,16 @@ off(type: 'keyDown'|'keyUp', callback?: (event: KeyEvent) => boolean): void ...@@ -630,16 +626,16 @@ off(type: 'keyDown'|'keyUp', callback?: (event: KeyEvent) => boolean): void
**示例:** **示例:**
```js ```js
inputMethodEngine.getKeyboardDelegate().off('keyUp', (keyEvent) => { inputMethodEngine.getKeyboardDelegate().off('keyUp', (keyEvent) => {
console.log('delete keyUp notification.'); console.log('delete keyUp notification.');
return true; return true;
}); });
inputMethodEngine.getKeyboardDelegate().off('keyDown', (keyEvent) => { inputMethodEngine.getKeyboardDelegate().off('keyDown', (keyEvent) => {
console.log('delete keyDown notification.'); console.log('delete keyDown notification.');
return true; return true;
}); });
``` ```
### on('cursorContextChange') ### on('cursorContextChange')
...@@ -843,21 +839,90 @@ async function InputMethodEngine() { ...@@ -843,21 +839,90 @@ async function InputMethodEngine() {
} }
``` ```
## TextInputClient<a name="TextInputClient"></a>
下列API示例中都需使用[inputStart](#inputStart)回调获取到TextInputClient实例,再通过此实例调用对应方法。 ## InputClient<a name="InputClient "></a><sup>9+</sup>
### getForward<sup>(deprecated)</sup> 下列API示例中都需使用[inputStart](#inputStart9)回调获取到InputClient实例,再通过此实例调用对应方法。
### sendKeyFunction<sup>9+</sup>
sendKeyFunction(action:number, callback: AsyncCallback&lt;boolean&gt;): void
发送功能键。使用callback形式返回结果。参数个数为2,否则抛出异常。
**系统能力**: SystemCapability.MiscServices.InputMethodFramework
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| action | number | 是 | 编辑框属性。 |
| callback | AsyncCallback&lt;boolean&gt; | 是 | 操作成功与否。 |
**示例:**
```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.(callback) ');
} else {
console.error('Failed to sendKeyFunction.(callback) ');
}
});
} catch (err) {
console.error('sendKeyFunction err: ' + JSON.stringify(err));
}
```
### sendKeyFunction<sup>9+</sup>
sendKeyFunction(action:number): Promise&lt;boolean&gt;
发送功能键。使用promise形式返回结果。参数个数为1,否则抛出异常。
**系统能力**: SystemCapability.MiscServices.InputMethodFramework
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| action | number | 是 | 编辑框属性。 |
**返回值:**
| 类型 | 说明 |
| ------------------------------- | ------------------------------------------------------------ |
| Promise&lt;boolean&gt; | 操作成功与否。 |
**示例:**
```js
try {
InputClient.sendKeyFunction(keyFunction).then((result) => {
if (result) {
console.info('Success to sendKeyFunction.(callback) ');
} else {
console.error('Failed to sendKeyFunction.(callback) ');
}
}).catch((err) => {
console.error('sendKeyFunction promise err:' + JSON.stringify(err));
});
} catch (err) {
console.error('sendKeyFunction err: ' + JSON.stringify(err));
}
```
### getForward<sup>9+</sup>
getForward(length:number, callback: AsyncCallback&lt;string&gt;): void getForward(length:number, callback: AsyncCallback&lt;string&gt;): void
获取光标前固定长度的文本。使用callback形式返回结果。参数个数为2,否则抛出异常。 获取光标前固定长度的文本。使用callback形式返回结果。参数个数为2,否则抛出异常。
> **说明:**
> 从API version 9开始废弃, 建议使用[getForward](#getforward9)替代
>
> 从 API version 8开始支持。
**系统能力**: SystemCapability.MiscServices.InputMethodFramework **系统能力**: SystemCapability.MiscServices.InputMethodFramework
**参数:** **参数:**
...@@ -869,28 +934,27 @@ getForward(length:number, callback: AsyncCallback&lt;string&gt;): void ...@@ -869,28 +934,27 @@ getForward(length:number, callback: AsyncCallback&lt;string&gt;): void
**示例:** **示例:**
```js ```js
var length = 1; let length = 1;
TextInputClient.getForward(length, (err, text) => { try {
if (err === undefined) { InputClient.getForward(length, (err, text) => {
console.error('getForward callback result---err: ' + JSON.stringify(err)); if (err) {
return; console.error('getForward err: ' + JSON.stringify(err));
} return;
console.log('getForward callback result---text: ' + text); }
}); console.log('getForward callback result: ' + text);
``` });
} catch (err) {
console.error('getForward err: ' + JSON.stringify(err));
}
```
### getForward<sup>(deprecated)</sup> ### getForward<sup>9+</sup>
getForward(length:number): Promise&lt;string&gt; getForward(length:number): Promise&lt;string&gt;
获取光标前固定长度的文本。使用promise形式返回结果。参数个数为1,否则抛出异常。 获取光标前固定长度的文本。使用promise形式返回结果。参数个数为1,否则抛出异常。
> **说明:**
> 从API version 9开始废弃, 建议使用[getForward](#getforward9)替代
>
> 从 API version 8开始支持。
**系统能力**: SystemCapability.MiscServices.InputMethodFramework **系统能力**: SystemCapability.MiscServices.InputMethodFramework
**参数:** **参数:**
...@@ -907,28 +971,27 @@ getForward(length:number): Promise&lt;string&gt; ...@@ -907,28 +971,27 @@ getForward(length:number): Promise&lt;string&gt;
**示例:** **示例:**
```js ```js
async function InputMethodEngine() { async function InputMethodAbility() {
var length = 1; let length = 1;
await TextInputClient.getForward(length).then((text) => { try {
console.info('getForward promise result---res: ' + text); await InputClient.getForward(length).then((text) => {
}).catch((err) => { console.info('getForward promise resul: ' + text);
console.error('getForward promise err: ' + JSON.stringify(err)); }).catch((err) => {
}); console.error('getForward promise err: ' + JSON.stringify(err));
} });
``` } catch (err) {
console.error('getForward promise err: ' + JSON.stringify(err));
}
}
```
### getBackward<sup>(deprecated)</sup> ### getBackward<sup>9+</sup>
getBackward(length:number, callback: AsyncCallback&lt;string&gt;): void getBackward(length:number, callback: AsyncCallback&lt;string&gt;): void
获取光标后固定长度的文本。使用callback形式返回结果。参数个数为2,否则抛出异常。 获取光标后固定长度的文本。使用callback形式返回结果。参数个数为2,否则抛出异常。
> **说明:**
> 从API version 9开始废弃, 建议使用[getBackward](#getbackward9)替代
>
> 从 API version 8开始支持。
**系统能力**: SystemCapability.MiscServices.InputMethodFramework **系统能力**: SystemCapability.MiscServices.InputMethodFramework
**参数:** **参数:**
...@@ -940,28 +1003,27 @@ getBackward(length:number, callback: AsyncCallback&lt;string&gt;): void ...@@ -940,28 +1003,27 @@ getBackward(length:number, callback: AsyncCallback&lt;string&gt;): void
**示例:** **示例:**
```js ```js
var length = 1; let length = 1;
TextInputClient.getBackward(length, (err, text) => { try {
if (err === undefined) { InputClient.getBackward(length, (err, text) => {
console.error('getBackward callback result---err: ' + JSON.stringify(err)); if (err) {
return; console.error('getBackward callback result: ' + JSON.stringify(err));
} return;
console.log('getBackward callback result---text: ' + text); }
}); console.log('getBackward callback result---text: ' + text);
``` });
} catch (err) {
console.error('getBackward callback result: ' + JSON.stringify(err));
}
```
### getBackward<sup>(deprecated)</sup> ### getBackward<sup>9+</sup>
getBackward(length:number): Promise&lt;string&gt; getBackward(length:number): Promise&lt;string&gt;
获取光标后固定长度的文本。使用promise形式返回结果。参数个数为1,否则抛出异常。 获取光标后固定长度的文本。使用promise形式返回结果。参数个数为1,否则抛出异常。
> **说明:**
> 从API version 9开始废弃, 建议使用[getBackward](#getbackward9)替代
>
> 从 API version 8开始支持。
**系统能力**: SystemCapability.MiscServices.InputMethodFramework **系统能力**: SystemCapability.MiscServices.InputMethodFramework
**参数:** **参数:**
...@@ -978,28 +1040,27 @@ getBackward(length:number): Promise&lt;string&gt; ...@@ -978,28 +1040,27 @@ getBackward(length:number): Promise&lt;string&gt;
**示例:** **示例:**
```js ```js
async function InputMethodEngine() { async function InputMethodAbility() {
var length = 1; let length = 1;
await TextInputClient.getBackward(length).then((text) => { try {
console.info('getBackward promise result---res: ' + text); await InputClient.getBackward(length).then((text) => {
}).catch((err) => { console.info('getBackward promise result: ' + text);
console.error('getBackward promise err: ' + JSON.stringify(err)); }).catch((err) => {
}); console.error('getBackward promise err: ' + JSON.stringify(err));
} });
``` } catch (err) {
console.error('getBackward promise err: ' + JSON.stringify(err));
}
}
```
### deleteForward<sup>(deprecated)</sup> ### deleteForward<sup>9+</sup>
deleteForward(length:number, callback: AsyncCallback&lt;boolean&gt;): void deleteForward(length:number, callback: AsyncCallback&lt;boolean&gt;): void
删除光标前固定长度的文本。使用callback形式返回结果。参数个数为2,否则抛出异常。 删除光标前固定长度的文本。使用callback形式返回结果。参数个数为2,否则抛出异常。
> **说明:**
> 从API version 9开始废弃, 建议使用[deleteForward](#deleteforward9)替代
>
> 从 API version 8开始支持。
**系统能力**: SystemCapability.MiscServices.InputMethodFramework **系统能力**: SystemCapability.MiscServices.InputMethodFramework
**参数:** **参数:**
...@@ -1011,31 +1072,31 @@ deleteForward(length:number, callback: AsyncCallback&lt;boolean&gt;): void ...@@ -1011,31 +1072,31 @@ deleteForward(length:number, callback: AsyncCallback&lt;boolean&gt;): void
**示例:** **示例:**
```js ```js
var length = 1; let length = 1;
TextInputClient.deleteForward(length, (err, result) => { try {
if (err === undefined) { InputClient.deleteForward(length, (err, result) => {
console.error('deleteForward callback result---err: ' + JSON.stringify(err)); if (err) {
return; console.error('deleteForward callback result: ' + JSON.stringify(err));
} return;
if (result) { }
console.info('Success to deleteForward.(callback) '); if (result) {
} else { console.info('Success to deleteForward.(callback) ');
console.error('Failed to deleteForward.(callback) '); } else {
} console.error('Failed to deleteForward.(callback) ');
}); }
``` });
### deleteForward<sup>(deprecated)</sup> } catch (err) {
console.error('deleteForward callback result: ' + JSON.stringify(err));
}
```
### deleteForward<sup>9+</sup>
deleteForward(length:number): Promise&lt;boolean&gt; deleteForward(length:number): Promise&lt;boolean&gt;
删除光标前固定长度的文本。使用promise形式返回结果。参数个数为1,否则抛出异常。 删除光标前固定长度的文本。使用promise形式返回结果。参数个数为1,否则抛出异常。
> **说明:**
> 从API version 9开始废弃, 建议使用[deleteForward](#deleteforward9)替代
>
> 从 API version 8开始支持。
**系统能力**: SystemCapability.MiscServices.InputMethodFramework **系统能力**: SystemCapability.MiscServices.InputMethodFramework
**参数:** **参数:**
...@@ -1053,31 +1114,30 @@ deleteForward(length:number): Promise&lt;boolean&gt; ...@@ -1053,31 +1114,30 @@ deleteForward(length:number): Promise&lt;boolean&gt;
**示例:** **示例:**
```js ```js
async function InputMethodEngine() { async function InputMethodAbility() {
var length = 1; let length = 1;
await TextInputClient.deleteForward(length).then((result) => { try {
if (result) { await InputClient.deleteForward(length).then((result) => {
console.info('Success to deleteForward.(promise) '); if (result) {
} else { console.info('Success to deleteForward.(promise) ');
console.error('Failed to deleteForward.(promise) '); } else {
} console.error('Failed to deleteForward.(promise) ');
}).catch((err) => { }
}).catch((err) => {
console.error('deleteForward promise err: ' + JSON.stringify(err));
});
} catch (err) {
console.error('deleteForward promise err: ' + JSON.stringify(err)); console.error('deleteForward promise err: ' + JSON.stringify(err));
}); }
} }
``` ```
### deleteBackward<sup>(deprecated)</sup> ### deleteBackward<sup>9+</sup>
deleteBackward(length:number, callback: AsyncCallback&lt;boolean&gt;): void deleteBackward(length:number, callback: AsyncCallback&lt;boolean&gt;): void
删除光标后固定长度的文本。使用callback形式返回结果。参数个数为2,否则抛出异常。 删除光标后固定长度的文本。使用callback形式返回结果。参数个数为2,否则抛出异常。
> **说明:**
> 从API version 9开始废弃, 建议使用[deleteBackward](#deletebackward9)替代
>
> 从 API version 8开始支持。
**系统能力**: SystemCapability.MiscServices.InputMethodFramework **系统能力**: SystemCapability.MiscServices.InputMethodFramework
**参数:** **参数:**
...@@ -1090,31 +1150,30 @@ deleteBackward(length:number, callback: AsyncCallback&lt;boolean&gt;): void ...@@ -1090,31 +1150,30 @@ deleteBackward(length:number, callback: AsyncCallback&lt;boolean&gt;): void
**示例:** **示例:**
```js ```js
var length = 1; let length = 1;
TextInputClient.deleteBackward(length, (err, result) => { try {
if (err === undefined) { InputClient.deleteBackward(length, (err, result) => {
console.error('deleteBackward callback result---err: ' + JSON.stringify(err)); if (err) {
return; console.error('deleteBackward err: ' + JSON.stringify(err));
} return;
if (result) { }
console.info('Success to deleteBackward.(callback) '); if (result) {
} else { console.info('Success to deleteBackward.(callback) ');
console.error('Failed to deleteBackward.(callback) '); } else {
} console.error('Failed to deleteBackward.(callback) ');
}); }
});
} catch (err) {
console.error('deleteBackward err: ' + JSON.stringify(err));
}
``` ```
### deleteBackward<sup>(deprecated)</sup> ### deleteBackward<sup>9+</sup>
deleteBackward(length:number): Promise&lt;boolean&gt; deleteBackward(length:number): Promise&lt;boolean&gt;
删除光标后固定长度的文本。使用callback形式返回结果。参数个数为2,否则抛出异常。 删除光标后固定长度的文本。使用callback形式返回结果。参数个数为2,否则抛出异常。
> **说明:**
> 从API version 9开始废弃, 建议使用[deleteBackward](#deletebackward9)替代
>
> 从 API version 8开始支持。
**系统能力**: SystemCapability.MiscServices.InputMethodFramework **系统能力**: SystemCapability.MiscServices.InputMethodFramework
**参数:** **参数:**
...@@ -1132,9 +1191,9 @@ deleteBackward(length:number): Promise&lt;boolean&gt; ...@@ -1132,9 +1191,9 @@ deleteBackward(length:number): Promise&lt;boolean&gt;
**示例:** **示例:**
```js ```js
async function InputMethodEngine() { async function InputMethodAbility() {
var length = 1; let length = 1;
await TextInputClient.deleteBackward(length).then((result) => { await InputClient.deleteBackward(length).then((result) => {
if (result) { if (result) {
console.info('Success to deleteBackward.(promise) '); console.info('Success to deleteBackward.(promise) ');
} else { } else {
...@@ -1145,94 +1204,13 @@ async function InputMethodEngine() { ...@@ -1145,94 +1204,13 @@ async function InputMethodEngine() {
}); });
} }
``` ```
### sendKeyFunction<sup>(deprecated)</sup>
sendKeyFunction(action:number, callback: AsyncCallback&lt;boolean&gt;): void
发送功能键。使用callback形式返回结果。参数个数为2,否则抛出异常。
> **说明:**
> 从API version 9开始废弃, 建议使用[sendKeyFunction](#sendkeyfunction9)替代
>
> 从 API version 8开始支持。
**系统能力**: SystemCapability.MiscServices.InputMethodFramework
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| action | number | 是 | 编辑框属性。 |
| callback | AsyncCallback&lt;boolean&gt; | 是 | 操作成功与否。 |
**示例:**
```js
TextInputClient.sendKeyFunction(keyFunction, (err, result) => {
if (err === undefined) {
console.error('sendKeyFunction callback result---err: ' + JSON.stringify(err));
return;
}
if (result) {
console.info('Success to sendKeyFunction.(callback) ');
} else {
console.error('Failed to sendKeyFunction.(callback) ');
}
});
```
### sendKeyFunction<sup>(deprecated)</sup> ### insertText<sup>9+</sup>
sendKeyFunction(action:number): Promise&lt;boolean&gt;
发送功能键。使用promise形式返回结果。参数个数为1,否则抛出异常。
> **说明:**
> 从API version 9开始废弃, 建议使用[sendKeyFunction](#sendkeyfunction9)替代
>
> 从 API version 8开始支持。
**系统能力**: SystemCapability.MiscServices.InputMethodFramework
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| action | number | 是 | 编辑框属性。 |
**返回值:**
| 类型 | 说明 |
| ------------------------------- | ------------------------------------------------------------ |
| Promise&lt;boolean&gt; | 操作成功与否。 |
**示例:**
```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:' + JSON.stringify(err));
});
}
```
### insertText<sup>(deprecated)</sup>
insertText(text:string, callback: AsyncCallback&lt;boolean&gt;): void insertText(text:string, callback: AsyncCallback&lt;boolean&gt;): void
插入文本。使用callback形式返回结果。参数个数为2,否则抛出异常。 插入文本。使用callback形式返回结果。参数个数为2,否则抛出异常。
> **说明:**
> 从API version 9开始废弃, 建议使用[insertText](#inserttext9)替代
>
> 从 API version 8开始支持。
**系统能力**: SystemCapability.MiscServices.InputMethodFramework **系统能力**: SystemCapability.MiscServices.InputMethodFramework
**参数:** **参数:**
...@@ -1245,9 +1223,9 @@ insertText(text:string, callback: AsyncCallback&lt;boolean&gt;): void ...@@ -1245,9 +1223,9 @@ insertText(text:string, callback: AsyncCallback&lt;boolean&gt;): void
**示例:** **示例:**
```js ```js
TextInputClient.insertText('test', (err, result) => { InputClient.insertText('test', (err, result) => {
if (err === undefined) { if (err) {
console.error('insertText callback result---err: ' + JSON.stringify(err)); console.error('insertText err: ' + JSON.stringify(err));
return; return;
} }
if (result) { if (result) {
...@@ -1258,17 +1236,12 @@ TextInputClient.insertText('test', (err, result) => { ...@@ -1258,17 +1236,12 @@ TextInputClient.insertText('test', (err, result) => {
}); });
``` ```
### insertText<sup>(deprecated)</sup> ### insertText<sup>9+</sup>
insertText(text:string): Promise&lt;boolean&gt; insertText(text:string): Promise&lt;boolean&gt;
插入文本。使用promise形式返回结果。参数个数为1,否则抛出异常。 插入文本。使用promise形式返回结果。参数个数为1,否则抛出异常。
> **说明:**
> 从API version 9开始废弃, 建议使用[insertText](#inserttext9)替代
>
> 从 API version 8开始支持。
**系统能力**: SystemCapability.MiscServices.InputMethodFramework **系统能力**: SystemCapability.MiscServices.InputMethodFramework
**参数:** **参数:**
...@@ -1285,63 +1258,57 @@ insertText(text:string): Promise&lt;boolean&gt; ...@@ -1285,63 +1258,57 @@ insertText(text:string): Promise&lt;boolean&gt;
**示例:** **示例:**
```js ```js
async function InputMethodEngine() { async function InputMethodAbility() {
await TextInputClient.insertText('test').then((result) => { try {
if (result) { await InputClient.insertText('test').then((result) => {
console.info('Success to insertText.(promise) '); if (result) {
} else { console.info('Success to insertText.(promise) ');
console.error('Failed to insertText.(promise) '); } else {
} console.error('Failed to insertText.(promise) ');
}).catch((err) => { }
console.error('insertText promise err: ' + JSON.stringify(err)); }).catch((err) => {
}); console.error('insertText promise err: ' + JSON.stringify(err));
} });
``` } catch (e) {
console.error('insertText promise err: ' + JSON.stringify(err));
}
}
```
### getEditorAttribute<sup>(deprecated)</sup> ### getEditorAttribute<sup>9+</sup>
getEditorAttribute(callback: AsyncCallback&lt;EditorAttribute&gt;): void getEditorAttribute(callback: AsyncCallback&lt;EditorAttribute&gt;): void
获取编辑框属性值。使用callback形式返回结果。参数个数为1,否则抛出异常。 获取编辑框属性值。使用callback形式返回结果。参数个数为1,否则抛出异常。
> **说明:**
> 从API version 9开始废弃, 建议使用[getEditorAttribute](#geteditorattribute9)替代
>
> 从 API version 8开始支持。
**系统能力**: SystemCapability.MiscServices.InputMethodFramework **系统能力**: SystemCapability.MiscServices.InputMethodFramework
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| ------------------------------- | ------------------------------------------------------------ | ------------------------------------------------------------ | ------------------------------------------------------------ | | ------------------------------- | ------------------------------------------------------------ | ------------------------------------------------------------ | ------------------------------------------------------------ |
| callback | AsyncCallback&lt;[EditorAttribute](#editorattribute)&gt; | 是 | 编辑框属性值。 | | callback | AsyncCallback&lt;[EditorAttribute](#EditorAttribute)&gt; | 是 | 编辑框属性值。 |
**示例:** **示例:**
```js ```js
TextInputClient.getEditorAttribute((err, editorAttribute) => { InputClient.getEditorAttribute((err, editorAttribute) => {
if (err === undefined) { if (err) {
console.error('getEditorAttribute callback result---err: ' + JSON.stringify(err)); console.error('getEditorAttribute callback result---err: ' + JSON.stringify(err));
return; return;
} }
console.log('editorAttribute.inputPattern(callback): ' + JSON.stringify(editorAttribute.inputPattern)); console.log('editorAttribute.inputPattern(callback): ' + JSON.stringify(editorAttribute.inputPattern));
console.log('editorAttribute.enterKeyType(callback): ' + JSON.stringify(editorAttribute.enterKeyType)); console.log('editorAttribute.enterKeyType(callback): ' + JSON.stringify(editorAttribute.enterKeyType));
}); });
``` ```
### getEditorAttribute<sup>(deprecated)</sup> ### getEditorAttribute<sup>9+</sup>
getEditorAttribute(): Promise&lt;EditorAttribute&gt; getEditorAttribute(): Promise&lt;EditorAttribute&gt;
获取编辑框属性值。使用promise形式返回结果。参数个数为0,否则抛出异常。 获取编辑框属性值。使用promise形式返回结果。参数个数为0,否则抛出异常。
> **说明:**
> 从API version 9开始废弃, 建议使用[getEditorAttribute](#geteditorattribute9)替代
>
> 从 API version 8开始支持。
**系统能力**: SystemCapability.MiscServices.InputMethodFramework **系统能力**: SystemCapability.MiscServices.InputMethodFramework
**返回值:** **返回值:**
...@@ -1352,99 +1319,122 @@ getEditorAttribute(): Promise&lt;EditorAttribute&gt; ...@@ -1352,99 +1319,122 @@ getEditorAttribute(): Promise&lt;EditorAttribute&gt;
**示例:** **示例:**
```js ```js
async function InputMethodEngine() { async function InputMethodEngine() {
await TextInputClient.getEditorAttribute().then((editorAttribute) => { await InputClient.getEditorAttribute().then((editorAttribute) => {
console.info('editorAttribute.inputPattern(promise): ' + JSON.stringify(editorAttribute.inputPattern)); console.info('editorAttribute.inputPattern(promise): ' + JSON.stringify(editorAttribute.inputPattern));
console.info('editorAttribute.enterKeyType(promise): ' + JSON.stringify(editorAttribute.enterKeyType)); console.info('editorAttribute.enterKeyType(promise): ' + JSON.stringify(editorAttribute.enterKeyType));
}).catch((err) => { }).catch((err) => {
console.error('getEditorAttribute promise err: ' + JSON.stringify(err)); console.error('getEditorAttribute promise err: ' + JSON.stringify(err));
}); });
} }
``` ```
## InputClient<a name="InputClient "></a><sup>9+</sup>
下列API示例中都需使用[inputStart](#inputStart9)回调获取到InputClient实例,再通过此实例调用对应方法。
### sendKeyFunction<sup>9+</sup> ### moveCursor<sup>9+</sup>
sendKeyFunction(action:number, callback: AsyncCallback&lt;boolean&gt;): void moveCursor(direction: number, callback: AsyncCallback&lt;void&gt;): void
发送功能键。使用callback形式返回结果。参数个数为2,否则抛出异常。 移动光标。使用callback形式返回结果。参数个数为1,否则抛出异常。
**系统能力**: SystemCapability.MiscServices.InputMethodFramework **系统能力**: SystemCapability.MiscServices.InputMethodFramework
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- | | --------- | ------------------------- | ---- | -------------- |
| action | number | 是 | 编辑框属性。 | | direction | number | 是 | 光标移动方向。 |
| callback | AsyncCallback&lt;boolean&gt; | 是 | 操作成功与否。 | | callback | AsyncCallback&lt;void&gt; | 是 | 回调函数。 |
**示例:** **示例:**
```js ```js
try { try {
InputClient.sendKeyFunction(keyFunction, (err, result) => { InputClient.moveCursor(inputMethodAbility.CURSOR_xxx, (err) => {
if (err) { if (err) {
console.error('sendKeyFunction err: ' + JSON.stringify(err)JSON.stringify(err)); console.error('moveCursor err: ' + JSON.stringify(err));
return; return;
} }
if (result) { console.info('moveCursor success');
console.info('Success to sendKeyFunction.(callback) ');
} else {
console.error('Failed to sendKeyFunction.(callback) ');
}
}); });
} catch (err) { } catch (err) {
console.error('sendKeyFunction err: ' + JSON.stringify(err)); console.error('moveCursor err: ' + JSON.stringify(err));
} }
``` ```
### sendKeyFunction<sup>9+</sup> ### moveCursor<sup>9+</sup>
sendKeyFunction(action:number): Promise&lt;boolean&gt; moveCursor(direction: number): Promise&lt;void&gt;
发送功能键。使用promise形式返回结果。参数个数为1,否则抛出异常。 移动光标。使用promise形式返回结果。参数个数为1,否则抛出异常。
**系统能力**: SystemCapability.MiscServices.InputMethodFramework **系统能力**: SystemCapability.MiscServices.InputMethodFramework
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- | | --------- | ------ | ---- | -------------- |
| action | number | 是 | 编辑框属性。 | | direction | number | 是 | 光标移动方向。 |
**返回值:** **返回值:**
| 类型 | 说明 | | 类型 | 说明 |
| ------------------------------- | ------------------------------------------------------------ | | ------------------- | ------------------------- |
| Promise&lt;boolean&gt; | 操作成功与否。 | | Promise&lt;void&gt; | 无返回结果的Promise对象。 |
**示例:** **示例:**
```js ```js
try { async function InputMethodAbility() {
InputClient.sendKeyFunction(keyFunction).then((result) => { try {
if (result) { await InputClient.moveCursor(inputMethodEngine.CURSOR_xxx).then((err) => {
console.info('Success to sendKeyFunction.(callback) '); if (err) {
} else { console.log('moveCursor err: ' + JSON.stringify(err));
console.error('Failed to sendKeyFunction.(callback) '); return;
} }
}).catch((err) => { console.log('moveCursor success');
console.error('sendKeyFunction promise err:' + JSON.stringify(err)); }).catch((err) => {
}); console.error('moveCursor success err: ' + JSON.stringify(err));
} catch (err) { });
console.error('sendKeyFunction err: ' + JSON.stringify(err)); } catch (err) {
console.log('moveCursor err: ' + JSON.stringify(err));
}
} }
``` ```
### getForward<sup>9+</sup> ## EditorAttribute<a name="EditorAttribute"></a>
getForward(length:number, callback: AsyncCallback&lt;string&gt;): void 编辑框属性值。
获取光标前固定长度的文本。使用callback形式返回结果。参数个数为2,否则抛出异常。 **系统能力**:以下各项对应的系统能力均为SystemCapability.MiscServices.InputMethodFramework
| 名称 | 参数类型 | 可读 | 可写 | 说明 |
| ------------ | -------- | ---- | ---- | ------------------ |
| enterKeyType | number | 是 | 否 | 编辑框的功能属性。 |
| inputPattern | number | 是 | 否 | 编辑框的文本属性。 |
## KeyEvent<a name="KeyEvent"></a>
按键属性值。
**系统能力**:以下各项对应的系统能力均为SystemCapability.MiscServices.InputMethodFramework
| 名称 | 参数类型 | 可读 | 可写 | 说明 |
| --------- | -------- | ---- | ---- | ------------ |
| keyCode | number | 是 | 否 | 按键的键值。 |
| keyAction | number | 是 | 否 | 按键的状态。 |
## TextInputClient<a name="TextInputClient"></a>
下列API示例中都需使用[inputStart](#inputStart)回调获取到TextInputClient实例,再通过此实例调用对应方法。
### getForward<sup>(deprecated)</sup>
getForward(length:number, callback: AsyncCallback&lt;string&gt;): void
获取光标前固定长度的文本。使用callback形式返回结果。参数个数为2,否则抛出异常。
> **说明:**
> 从API version 8开始支持,API version 9开始废弃, 建议使用[getForward](#getforward9)替代
**系统能力**: SystemCapability.MiscServices.InputMethodFramework **系统能力**: SystemCapability.MiscServices.InputMethodFramework
...@@ -1457,27 +1447,26 @@ getForward(length:number, callback: AsyncCallback&lt;string&gt;): void ...@@ -1457,27 +1447,26 @@ getForward(length:number, callback: AsyncCallback&lt;string&gt;): void
**示例:** **示例:**
```js ```js
var length = 1; let length = 1;
try { TextInputClient.getForward(length, (err, text) => {
InputClient.getForward(length, (err, text) => { if (err === undefined) {
if (err) { console.error('getForward callback result---err: ' + JSON.stringify(err));
console.error('getForward err: ' + JSON.stringify(err)); return;
return; }
} console.log('getForward callback result---text: ' + text);
console.log('getForward callback result: ' + text); });
}); ```
} catch (err) {
console.error('getForward err: ' + JSON.stringify(err));
}
```
### getForward<sup>9+</sup> ### getForward<sup>(deprecated)</sup>
getForward(length:number): Promise&lt;string&gt; getForward(length:number): Promise&lt;string&gt;
获取光标前固定长度的文本。使用promise形式返回结果。参数个数为1,否则抛出异常。 获取光标前固定长度的文本。使用promise形式返回结果。参数个数为1,否则抛出异常。
> **说明:**
> 从API version 8开始支持,API version 9开始废弃, 建议使用[getForward](#getforward9)替代
**系统能力**: SystemCapability.MiscServices.InputMethodFramework **系统能力**: SystemCapability.MiscServices.InputMethodFramework
**参数:** **参数:**
...@@ -1494,27 +1483,26 @@ getForward(length:number): Promise&lt;string&gt; ...@@ -1494,27 +1483,26 @@ getForward(length:number): Promise&lt;string&gt;
**示例:** **示例:**
```js ```js
async function InputMethodAbility() { async function InputMethodEngine() {
var length = 1; let length = 1;
try { await TextInputClient.getForward(length).then((text) => {
await InputClient.getForward(length).then((text) => { console.info('getForward promise result---res: ' + text);
console.info('getForward promise resul: ' + text); }).catch((err) => {
}).catch((err) => { console.error('getForward promise err: ' + JSON.stringify(err));
console.error('getForward promise err: ' + JSON.stringify(err)); });
}); }
} catch (err) { ```
console.error('getForward promise err: ' + JSON.stringify(err));
}
}
```
### getBackward<sup>9+</sup> ### getBackward<sup>(deprecated)</sup>
getBackward(length:number, callback: AsyncCallback&lt;string&gt;): void getBackward(length:number, callback: AsyncCallback&lt;string&gt;): void
获取光标后固定长度的文本。使用callback形式返回结果。参数个数为2,否则抛出异常。 获取光标后固定长度的文本。使用callback形式返回结果。参数个数为2,否则抛出异常。
> **说明:**
> 从API version 8开始支持,API version 9开始废弃, 建议使用[getBackward](#getbackward9)替代
**系统能力**: SystemCapability.MiscServices.InputMethodFramework **系统能力**: SystemCapability.MiscServices.InputMethodFramework
**参数:** **参数:**
...@@ -1526,27 +1514,26 @@ getBackward(length:number, callback: AsyncCallback&lt;string&gt;): void ...@@ -1526,27 +1514,26 @@ getBackward(length:number, callback: AsyncCallback&lt;string&gt;): void
**示例:** **示例:**
```js ```js
var length = 1; let length = 1;
try { TextInputClient.getBackward(length, (err, text) => {
InputClient.getBackward(length, (err, text) => { if (err === undefined) {
if (err) { console.error('getBackward callback result---err: ' + JSON.stringify(err));
console.error('getBackward callback result: ' + JSON.stringify(err)); return;
return; }
} console.log('getBackward callback result---text: ' + text);
console.log('getBackward callback result---text: ' + text); });
}); ```
} catch (err) {
console.error('getBackward callback result: ' + JSON.stringify(err));
}
```
### getBackward<sup>9+</sup> ### getBackward<sup>(deprecated)</sup>
getBackward(length:number): Promise&lt;string&gt; getBackward(length:number): Promise&lt;string&gt;
获取光标后固定长度的文本。使用promise形式返回结果。参数个数为1,否则抛出异常。 获取光标后固定长度的文本。使用promise形式返回结果。参数个数为1,否则抛出异常。
> **说明:**
> 从API version 8开始支持,API version 9开始废弃, 建议使用[getBackward](#getbackward9)替代
**系统能力**: SystemCapability.MiscServices.InputMethodFramework **系统能力**: SystemCapability.MiscServices.InputMethodFramework
**参数:** **参数:**
...@@ -1563,27 +1550,26 @@ getBackward(length:number): Promise&lt;string&gt; ...@@ -1563,27 +1550,26 @@ getBackward(length:number): Promise&lt;string&gt;
**示例:** **示例:**
```js ```js
async function InputMethodAbility() { async function InputMethodEngine() {
var length = 1; let length = 1;
try { await TextInputClient.getBackward(length).then((text) => {
await InputClient.getBackward(length).then((text) => { console.info('getBackward promise result---res: ' + text);
console.info('getBackward promise result: ' + text); }).catch((err) => {
}).catch((err) => { console.error('getBackward promise err: ' + JSON.stringify(err));
console.error('getBackward promise err: ' + JSON.stringify(err)); });
}); }
} catch (err) { ```
console.error('getBackward promise err: ' + JSON.stringify(err));
}
}
```
### deleteForward<sup>9+</sup> ### deleteForward<sup>(deprecated)</sup>
deleteForward(length:number, callback: AsyncCallback&lt;boolean&gt;): void deleteForward(length:number, callback: AsyncCallback&lt;boolean&gt;): void
删除光标前固定长度的文本。使用callback形式返回结果。参数个数为2,否则抛出异常。 删除光标前固定长度的文本。使用callback形式返回结果。参数个数为2,否则抛出异常。
> **说明:**
> 从API version 8开始支持,API version 9开始废弃, 建议使用[deleteForward](#deleteforward9)替代
**系统能力**: SystemCapability.MiscServices.InputMethodFramework **系统能力**: SystemCapability.MiscServices.InputMethodFramework
**参数:** **参数:**
...@@ -1595,31 +1581,30 @@ deleteForward(length:number, callback: AsyncCallback&lt;boolean&gt;): void ...@@ -1595,31 +1581,30 @@ deleteForward(length:number, callback: AsyncCallback&lt;boolean&gt;): void
**示例:** **示例:**
```js ```js
var length = 1; let length = 1;
try { TextInputClient.deleteForward(length, (err, result) => {
InputClient.deleteForward(length, (err, result) => { if (err === undefined) {
if (err) { console.error('deleteForward callback result---err: ' + JSON.stringify(err));
console.error('deleteForward callback result: ' + JSON.stringify(err)); return;
return; }
} if (result) {
if (result) { console.info('Success to deleteForward.(callback) ');
console.info('Success to deleteForward.(callback) '); } else {
} else { console.error('Failed to deleteForward.(callback) ');
console.error('Failed to deleteForward.(callback) '); }
} });
}); ```
} catch (err) {
console.error('deleteForward callback result: ' + JSON.stringify(err));
}
```
### deleteForward<sup>9+</sup> ### deleteForward<sup>(deprecated)</sup>
deleteForward(length:number): Promise&lt;boolean&gt; deleteForward(length:number): Promise&lt;boolean&gt;
删除光标前固定长度的文本。使用promise形式返回结果。参数个数为1,否则抛出异常。 删除光标前固定长度的文本。使用promise形式返回结果。参数个数为1,否则抛出异常。
> **说明:**
> 从API version 8开始支持,API version 9开始废弃, 建议使用[deleteForward](#deleteforward9)替代
**系统能力**: SystemCapability.MiscServices.InputMethodFramework **系统能力**: SystemCapability.MiscServices.InputMethodFramework
**参数:** **参数:**
...@@ -1637,30 +1622,29 @@ deleteForward(length:number): Promise&lt;boolean&gt; ...@@ -1637,30 +1622,29 @@ deleteForward(length:number): Promise&lt;boolean&gt;
**示例:** **示例:**
```js ```js
async function InputMethodAbility() { async function InputMethodEngine() {
var length = 1; let length = 1;
try { await TextInputClient.deleteForward(length).then((result) => {
await InputClient.deleteForward(length).then((result) => { if (result) {
if (result) { console.info('Success to deleteForward.(promise) ');
console.info('Success to deleteForward.(promise) '); } else {
} else { console.error('Failed to deleteForward.(promise) ');
console.error('Failed to deleteForward.(promise) '); }
} }).catch((err) => {
}).catch((err) => {
console.error('deleteForward promise err: ' + JSON.stringify(err));
});
} catch (err) {
console.error('deleteForward promise err: ' + JSON.stringify(err)); console.error('deleteForward promise err: ' + JSON.stringify(err));
} });
} }
``` ```
### deleteBackward<sup>9+</sup> ### deleteBackward<sup>(deprecated)</sup>
deleteBackward(length:number, callback: AsyncCallback&lt;boolean&gt;): void deleteBackward(length:number, callback: AsyncCallback&lt;boolean&gt;): void
删除光标后固定长度的文本。使用callback形式返回结果。参数个数为2,否则抛出异常。 删除光标后固定长度的文本。使用callback形式返回结果。参数个数为2,否则抛出异常。
> **说明:**
> 从API version 8开始支持,API version 9开始废弃, 建议使用[deleteBackward](#deletebackward9)替代
**系统能力**: SystemCapability.MiscServices.InputMethodFramework **系统能力**: SystemCapability.MiscServices.InputMethodFramework
**参数:** **参数:**
...@@ -1673,30 +1657,29 @@ deleteBackward(length:number, callback: AsyncCallback&lt;boolean&gt;): void ...@@ -1673,30 +1657,29 @@ deleteBackward(length:number, callback: AsyncCallback&lt;boolean&gt;): void
**示例:** **示例:**
```js ```js
var length = 1; let length = 1;
try { TextInputClient.deleteBackward(length, (err, result) => {
InputClient.deleteBackward(length, (err, result) => { if (err === undefined) {
if (err) { console.error('deleteBackward callback result---err: ' + JSON.stringify(err));
console.error('deleteBackward err: ' + JSON.stringify(err)); return;
return; }
} if (result) {
if (result) { console.info('Success to deleteBackward.(callback) ');
console.info('Success to deleteBackward.(callback) '); } else {
} else { console.error('Failed to deleteBackward.(callback) ');
console.error('Failed to deleteBackward.(callback) '); }
} });
});
} catch (err) {
console.error('deleteBackward err: ' + JSON.stringify(err));
}
``` ```
### deleteBackward<sup>9+</sup> ### deleteBackward<sup>(deprecated)</sup>
deleteBackward(length:number): Promise&lt;boolean&gt; deleteBackward(length:number): Promise&lt;boolean&gt;
删除光标后固定长度的文本。使用callback形式返回结果。参数个数为2,否则抛出异常。 删除光标后固定长度的文本。使用callback形式返回结果。参数个数为2,否则抛出异常。
> **说明:**
> 从API version 8开始支持,API version 9开始废弃, 建议使用[deleteBackward](#deletebackward9)替代
**系统能力**: SystemCapability.MiscServices.InputMethodFramework **系统能力**: SystemCapability.MiscServices.InputMethodFramework
**参数:** **参数:**
...@@ -1714,9 +1697,9 @@ deleteBackward(length:number): Promise&lt;boolean&gt; ...@@ -1714,9 +1697,9 @@ deleteBackward(length:number): Promise&lt;boolean&gt;
**示例:** **示例:**
```js ```js
async function InputMethodAbility() { async function InputMethodEngine() {
var length = 1; let length = 1;
await InputClient.deleteBackward(length).then((result) => { await TextInputClient.deleteBackward(length).then((result) => {
if (result) { if (result) {
console.info('Success to deleteBackward.(promise) '); console.info('Success to deleteBackward.(promise) ');
} else { } else {
...@@ -1727,43 +1710,48 @@ async function InputMethodAbility() { ...@@ -1727,43 +1710,48 @@ async function InputMethodAbility() {
}); });
} }
``` ```
### sendKeyFunction<sup>(deprecated)</sup>
### insertText<sup>9+</sup> sendKeyFunction(action:number, callback: AsyncCallback&lt;boolean&gt;): void
insertText(text:string, callback: AsyncCallback&lt;boolean&gt;): void 发送功能键。使用callback形式返回结果。参数个数为2,否则抛出异常。
插入文本。使用callback形式返回结果。参数个数为2,否则抛出异常。 > **说明:**
> 从API version 8开始支持,API version 9开始废弃, 建议使用[sendKeyFunction](#sendkeyfunction9)替代
**系统能力**: SystemCapability.MiscServices.InputMethodFramework **系统能力**: SystemCapability.MiscServices.InputMethodFramework
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| text | string | 是 | 文本。 | | action | number | 是 | 编辑框属性。 |
| callback | AsyncCallback&lt;boolean&gt; | 是 | 操作成功与否。 | | callback | AsyncCallback&lt;boolean&gt; | 是 | 操作成功与否。 |
**示例:** **示例:**
```js ```js
InputClient.insertText('test', (err, result) => { TextInputClient.sendKeyFunction(keyFunction, (err, result) => {
if (err) { if (err === undefined) {
console.error('insertText err: ' + JSON.stringify(err)); console.error('sendKeyFunction callback result---err: ' + JSON.stringify(err));
return; return;
} }
if (result) { if (result) {
console.info('Success to insertText.(callback) '); console.info('Success to sendKeyFunction.(callback) ');
} else { } else {
console.error('Failed to insertText.(callback) '); console.error('Failed to sendKeyFunction.(callback) ');
} }
}); });
``` ```
### insertText<sup>9+</sup> ### sendKeyFunction<sup>(deprecated)</sup>
insertText(text:string): Promise&lt;boolean&gt; sendKeyFunction(action:number): Promise&lt;boolean&gt;
插入文本。使用promise形式返回结果。参数个数为1,否则抛出异常。 发送功能键。使用promise形式返回结果。参数个数为1,否则抛出异常。
> **说明:**
> 从API version 8开始支持,API version 9开始废弃, 建议使用[sendKeyFunction](#sendkeyfunction9)替代
**系统能力**: SystemCapability.MiscServices.InputMethodFramework **系统能力**: SystemCapability.MiscServices.InputMethodFramework
...@@ -1771,9 +1759,9 @@ insertText(text:string): Promise&lt;boolean&gt; ...@@ -1771,9 +1759,9 @@ insertText(text:string): Promise&lt;boolean&gt;
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| text | string | 是 | 文本。 | | action | number | 是 | 编辑框属性。 |
**返回值:** **返回值:**
| 类型 | 说明 | | 类型 | 说明 |
| ------------------------------- | ------------------------------------------------------------ | | ------------------------------- | ------------------------------------------------------------ |
...@@ -1781,168 +1769,149 @@ insertText(text:string): Promise&lt;boolean&gt; ...@@ -1781,168 +1769,149 @@ insertText(text:string): Promise&lt;boolean&gt;
**示例:** **示例:**
```js ```js
async function InputMethodAbility() { async function InputMethodEngine() {
try { await client.sendKeyFunction(keyFunction).then((result) => {
await InputClient.insertText('test').then((result) => { if (result) {
if (result) { console.info('Success to sendKeyFunction.(promise) ');
console.info('Success to insertText.(promise) '); } else {
} else { console.error('Failed to sendKeyFunction.(promise) ');
console.error('Failed to insertText.(promise) '); }
} }).catch((err) => {
}).catch((err) => { console.error('sendKeyFunction promise err:' + JSON.stringify(err));
console.error('insertText promise err: ' + JSON.stringify(err)); });
}); }
} catch (e) { ```
console.error('insertText promise err: ' + JSON.stringify(err));
}
}
```
### getEditorAttribute<sup>9+</sup> ### insertText<sup>(deprecated)</sup>
getEditorAttribute(callback: AsyncCallback&lt;EditorAttribute&gt;): void insertText(text:string, callback: AsyncCallback&lt;boolean&gt;): void
获取编辑框属性值。使用callback形式返回结果。参数个数为1,否则抛出异常。 插入文本。使用callback形式返回结果。参数个数为2,否则抛出异常。
> **说明:**
> 从API version 8开始支持,API version 9开始废弃, 建议使用[insertText](#inserttext9)替代
**系统能力**: SystemCapability.MiscServices.InputMethodFramework **系统能力**: SystemCapability.MiscServices.InputMethodFramework
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| ------------------------------- | ------------------------------------------------------------ | ------------------------------------------------------------ | ------------------------------------------------------------ | | -------- | -------- | -------- | -------- |
| callback | AsyncCallback&lt;[EditorAttribute](#EditorAttribute)&gt; | 是 | 编辑框属性值。 | | text | string | 是 | 文本。 |
| callback | AsyncCallback&lt;boolean&gt; | 是 | 操作成功与否。 |
**示例:** **示例:**
```js ```js
InputClient.getEditorAttribute((err, editorAttribute) => { TextInputClient.insertText('test', (err, result) => {
if (err) { if (err === undefined) {
console.error('getEditorAttribute callback result---err: ' + JSON.stringify(err)); console.error('insertText callback result---err: ' + JSON.stringify(err));
return; return;
} }
console.log('editorAttribute.inputPattern(callback): ' + JSON.stringify(editorAttribute.inputPattern)); if (result) {
console.log('editorAttribute.enterKeyType(callback): ' + JSON.stringify(editorAttribute.enterKeyType)); console.info('Success to insertText.(callback) ');
}); } else {
``` console.error('Failed to insertText.(callback) ');
}
### getEditorAttribute<sup>9+</sup> });
```
getEditorAttribute(): Promise&lt;EditorAttribute&gt;
获取编辑框属性值。使用promise形式返回结果。参数个数为0,否则抛出异常。
**系统能力**: SystemCapability.MiscServices.InputMethodFramework
**返回值:**
| 类型 | 说明 |
| ------------------------------- | ------------------------------------------------------------ |
| Promise&lt;[EditorAttribute](#editorattribute)&gt; | 返回编辑框属性值。 |
**示例:**
```js ### insertText<sup>(deprecated)</sup>
async function InputMethodEngine() {
await InputClient.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: ' + JSON.stringify(err));
});
}
```
### moveCursor<sup>9+</sup> insertText(text:string): Promise&lt;boolean&gt;
moveCursor(direction: number, callback: AsyncCallback&lt;void&gt;): void 插入文本。使用promise形式返回结果。参数个数为1,否则抛出异常。
移动光标。使用callback形式返回结果。参数个数为1,否则抛出异常。 > **说明:**
> 从API version 8开始支持,API version 9开始废弃, 建议使用[insertText](#inserttext9)替代
**系统能力**: SystemCapability.MiscServices.InputMethodFramework **系统能力**: SystemCapability.MiscServices.InputMethodFramework
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| --------- | ------------------------- | ---- | -------------- | | -------- | -------- | -------- | -------- |
| direction | number | 是 | 光标移动方向。 | | text | string | 是 | 文本。 |
| callback | AsyncCallback&lt;void&gt; | 是 | 回调函数。 |
**返回值:**
| 类型 | 说明 |
| ------------------------------- | ------------------------------------------------------------ |
| Promise&lt;boolean&gt; | 操作成功与否。 |
**示例:** **示例:**
```js ```js
try { async function InputMethodEngine() {
InputClient.moveCursor(inputMethodAbility.CURSOR_xxx, (err) => { await TextInputClient.insertText('test').then((result) => {
if (err) { if (result) {
console.error('moveCursor err: ' + JSON.stringify(err)); console.info('Success to insertText.(promise) ');
return; } else {
console.error('Failed to insertText.(promise) ');
} }
console.info('moveCursor success'); }).catch((err) => {
console.error('insertText promise err: ' + JSON.stringify(err));
}); });
} catch (err) {
console.error('moveCursor err: ' + JSON.stringify(err));
} }
``` ```
### moveCursor<sup>9+</sup> ### getEditorAttribute<sup>(deprecated)</sup>
moveCursor(direction: number): Promise&lt;void&gt; getEditorAttribute(callback: AsyncCallback&lt;EditorAttribute&gt;): void
移动光标。使用promise形式返回结果。参数个数为1,否则抛出异常。 获取编辑框属性值。使用callback形式返回结果。参数个数为1,否则抛出异常。
> **说明:**
> 从API version 8开始支持,API version 9开始废弃, 建议使用[getEditorAttribute](#geteditorattribute9)替代
**系统能力**: SystemCapability.MiscServices.InputMethodFramework **系统能力**: SystemCapability.MiscServices.InputMethodFramework
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| --------- | ------ | ---- | -------------- | | ------------------------------- | ------------------------------------------------------------ | ------------------------------------------------------------ | ------------------------------------------------------------ |
| direction | number | 是 | 光标移动方向。 | | callback | AsyncCallback&lt;[EditorAttribute](#editorattribute)&gt; | 是 | 编辑框属性值。 |
**返回值:**
| 类型 | 说明 |
| ------------------- | ------------------------- |
| Promise&lt;void&gt; | 无返回结果的Promise对象。 |
**示例:** **示例:**
```js ```js
async function InputMethodAbility() { TextInputClient.getEditorAttribute((err, editorAttribute) => {
try { if (err === undefined) {
await InputClient.moveCursor(inputMethodEngine.CURSOR_xxx).then((err) => { console.error('getEditorAttribute callback result---err: ' + JSON.stringify(err));
if (err) { return;
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));
} }
} console.log('editorAttribute.inputPattern(callback): ' + JSON.stringify(editorAttribute.inputPattern));
``` console.log('editorAttribute.enterKeyType(callback): ' + JSON.stringify(editorAttribute.enterKeyType));
});
```
## EditorAttribute<a name="EditorAttribute"></a> ### getEditorAttribute<sup>(deprecated)</sup>
编辑框属性值。 getEditorAttribute(): Promise&lt;EditorAttribute&gt;
**系统能力**:以下各项对应的系统能力均为SystemCapability.MiscServices.InputMethodFramework 获取编辑框属性值。使用promise形式返回结果。参数个数为0,否则抛出异常。
| 名称 | 参数类型 | 可读 | 可写 | 说明 | > **说明:**
| ------------ | -------- | ---- | ---- | ------------------ | > 从API version 8开始支持,API version 9开始废弃, 建议使用[getEditorAttribute](#geteditorattribute9)替代
| enterKeyType | number | 是 | 否 | 编辑框的功能属性。 |
| inputPattern | number | 是 | 否 | 编辑框的文本属性。 |
## KeyEvent<a name="KeyEvent"></a> **系统能力**: SystemCapability.MiscServices.InputMethodFramework
按键属性值。 **返回值:**
**系统能力**:以下各项对应的系统能力均为SystemCapability.MiscServices.InputMethodFramework | 类型 | 说明 |
| ------------------------------- | ------------------------------------------------------------ |
| Promise&lt;[EditorAttribute](#editorattribute)&gt; | 返回编辑框属性值。 |
| 名称 | 参数类型 | 可读 | 可写 | 说明 | **示例:**
| --------- | -------- | ---- | ---- | ------------ |
| keyCode | number | 是 | 否 | 按键的键值。 |
| keyAction | number | 是 | 否 | 按键的状态。 |
```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: ' + JSON.stringify(err));
});
}
```
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册