提交 beb27013 编写于 作者: H Hollokin

输入法框架API资料补充

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