提交 64a00496 编写于 作者: M ma-shaoyin

Signed-off-by: ma-shaoyin <mashaoyin1@huawei.com>

 Changes to be committed:
上级 e8c503ba
...@@ -45,9 +45,9 @@ getInputMethodController(): InputMethodController ...@@ -45,9 +45,9 @@ getInputMethodController(): InputMethodController
**返回值:** **返回值:**
| 类型 | 说明 | | 类型 | 说明 |
| -------- | -------- | | ----------------------------------------------- | ------------------------ |
| [InputMethodController](#inputmethodcontroller) | 回调返回当前客户端实例。 | | [InputMethodController](#inputmethodcontroller) | 回调返回当前客户端实例。 |
**示例:** **示例:**
...@@ -79,7 +79,7 @@ getInputMethodSetting(): InputMethodSetting ...@@ -79,7 +79,7 @@ getInputMethodSetting(): InputMethodSetting
switchInputMethod(target: InputmethodProperty, callback: AsyncCallback&lt;boolean&gt;): void; switchInputMethod(target: InputmethodProperty, callback: AsyncCallback&lt;boolean&gt;): void;
切换输入法。此接口仅可在Stage模型下使用。 切换输入法。此接口仅可在Stage模型下使用。使用callback形式返回结果。参数个数为2,否则抛出异常。
**系统能力**:SystemCapability.Miscservices.InputMethodFramework **系统能力**:SystemCapability.Miscservices.InputMethodFramework
...@@ -102,7 +102,7 @@ switchInputMethod(target: InputmethodProperty, callback: AsyncCallback&lt;boolea ...@@ -102,7 +102,7 @@ switchInputMethod(target: InputmethodProperty, callback: AsyncCallback&lt;boolea
## inputMethod.switchInputMethod<sup>9+</sup> ## inputMethod.switchInputMethod<sup>9+</sup>
switchInputMethod(target: InputmethodProperty): Promise&lt;boolean&gt; switchInputMethod(target: InputmethodProperty): Promise&lt;boolean&gt;
切换输入法。此接口仅可在Stage模型下使用。 切换输入法。此接口仅可在Stage模型下使用。使用promise形式返回结果。参数个数为1,否则抛出异常。
**系统能力**: SystemCapability.Miscservices.InputMethodFramework **系统能力**: SystemCapability.Miscservices.InputMethodFramework
...@@ -133,7 +133,7 @@ switchInputMethod(target: InputmethodProperty): Promise&lt;boolean&gt; ...@@ -133,7 +133,7 @@ switchInputMethod(target: InputmethodProperty): Promise&lt;boolean&gt;
stopInput(callback: AsyncCallback&lt;boolean&gt;): void stopInput(callback: AsyncCallback&lt;boolean&gt;): void
隐藏输入法。 隐藏输入法。使用callback形式返回结果。参数个数为1,否则抛出异常。
**系统能力**:SystemCapability.MiscServices.InputMethodFramework **系统能力**:SystemCapability.MiscServices.InputMethodFramework
...@@ -146,16 +146,24 @@ stopInput(callback: AsyncCallback&lt;boolean&gt;): void ...@@ -146,16 +146,24 @@ stopInput(callback: AsyncCallback&lt;boolean&gt;): void
**示例:** **示例:**
```js ```js
InputMethodController.stopInput((error)=>{ inputMethodController.stopInput((err, result) => {
console.info('stopInput'); if (err == undefined) {
}); console.error("stopInput callback result---err: " + err.msg);
return;
}
if (result) {
console.info("Success to stopInput.(callback)");
} else {
console.info("Failed to stopInput.(callback)");
}
});
``` ```
### stopInput ### stopInput
stopInput(): Promise&lt;boolean&gt; stopInput(): Promise&lt;boolean&gt;
隐藏输入法。 隐藏输入法。使用promise形式返回结果。参数个数为0,否则抛出异常。
**系统能力**: SystemCapability.MiscServices.InputMethodFramework **系统能力**: SystemCapability.MiscServices.InputMethodFramework
...@@ -169,15 +177,22 @@ stopInput(): Promise&lt;boolean&gt; ...@@ -169,15 +177,22 @@ stopInput(): Promise&lt;boolean&gt;
```js ```js
var isSuccess = InputMethodController.stopInput(); await inputMethodController.stopInput().then((result)=>{
console.info('stopInput isSuccess = ' + isSuccess); if (result) {
console.info("Success to stopInput.(promise)");
} else {
console.info("Failed to stopInput.(promise)");
}
}).catch((err) => {
console.error("stopInput promise err: " + err.msg);
});
``` ```
### showSoftKeyboard<sup>9+</sup> ### ### showSoftKeyboard<sup>9+</sup> ###
showSoftKeyboard(callback: AsyncCallback&lt;void&gt;): void showSoftKeyboard(callback: AsyncCallback&lt;void&gt;): void
显示软键盘,使用callback异步回调。 显示软键盘,使用callback异步回调。参数个数为1,否则抛出异常。
**系统能力:** SystemCapability.MiscServices.InputMethodFramework **系统能力:** SystemCapability.MiscServices.InputMethodFramework
...@@ -204,7 +219,7 @@ InputMethodController.showSoftKeyboard((err) => { ...@@ -204,7 +219,7 @@ InputMethodController.showSoftKeyboard((err) => {
showSoftKeyboard(): Promise&lt;void&gt; showSoftKeyboard(): Promise&lt;void&gt;
显示软键盘,使用Promise异步回调。 显示软键盘,使用Promise异步回调。参数个数为0,否则抛出异常。
**系统能力:** SystemCapability.MiscServices.InputMethodFramework **系统能力:** SystemCapability.MiscServices.InputMethodFramework
...@@ -228,7 +243,7 @@ InputMethodController.showSoftKeyboard().then(async (err) => { ...@@ -228,7 +243,7 @@ InputMethodController.showSoftKeyboard().then(async (err) => {
hideSoftKeyboard(callback: AsyncCallback&lt;void&gt;): void hideSoftKeyboard(callback: AsyncCallback&lt;void&gt;): void
隐藏软键盘,使用callback异步回调。 隐藏软键盘,使用callback异步回调。参数个数为1,否则抛出异常。
**系统能力:** SystemCapability.MiscServices.InputMethodFramework **系统能力:** SystemCapability.MiscServices.InputMethodFramework
...@@ -255,7 +270,7 @@ InputMethodController.hideSoftKeyboard((err) => { ...@@ -255,7 +270,7 @@ InputMethodController.hideSoftKeyboard((err) => {
hideSoftKeyboard(): Promise&lt;void&gt; hideSoftKeyboard(): Promise&lt;void&gt;
隐藏软键盘,使用Promise异步回调。 隐藏软键盘,使用Promise异步回调。参数个数为0,否则抛出异常。
**系统能力:** SystemCapability.MiscServices.InputMethodFramework **系统能力:** SystemCapability.MiscServices.InputMethodFramework
...@@ -283,7 +298,7 @@ InputMethodController.hideSoftKeyboard().then(async (err) => { ...@@ -283,7 +298,7 @@ InputMethodController.hideSoftKeyboard().then(async (err) => {
listInputMethod(callback: AsyncCallback&lt;Array&lt;InputMethodProperty&gt;&gt;): void listInputMethod(callback: AsyncCallback&lt;Array&lt;InputMethodProperty&gt;&gt;): void
查询已安装的输入法列表。 查询已安装的输入法列表。使用callback形式返回结果。参数个数为1,否则抛出异常。
**系统能力**: SystemCapability.MiscServices.InputMethodFramework **系统能力**: SystemCapability.MiscServices.InputMethodFramework
...@@ -295,19 +310,20 @@ listInputMethod(callback: AsyncCallback&lt;Array&lt;InputMethodProperty&gt;&gt;) ...@@ -295,19 +310,20 @@ listInputMethod(callback: AsyncCallback&lt;Array&lt;InputMethodProperty&gt;&gt;)
**示例:** **示例:**
```js ```js
InputMethodSetting.listInputMethod((properties)=>{ inputMethodSetting.listInputMethod((err,data) => {
for (var i = 0;i < properties.length; i++) { if (err == undefined) {
var property = properties[i]; console.error("listInputMethod callback result---err: " + err.msg);
console.info(property.packageName + "/" + property.methodId); return;
} }
}); console.info("listInputMethod callback result---data: " + JSON.stringify(data));
});
``` ```
### listInputMethod ### listInputMethod
listInputMethod(): Array&lt;InputMethodProperty&gt; listInputMethod(): Promise<Array<InputMethodProperty>>;
查询已安装的输入法列表。 查询已安装的输入法列表。使用promise形式返回结果。参数个数为0,否则抛出异常。
**系统能力**: SystemCapability.MiscServices.InputMethodFramework **系统能力**: SystemCapability.MiscServices.InputMethodFramework
...@@ -319,18 +335,18 @@ listInputMethod(): Array&lt;InputMethodProperty&gt; ...@@ -319,18 +335,18 @@ listInputMethod(): Array&lt;InputMethodProperty&gt;
**示例:** **示例:**
```js ```js
var properties = InputMethodSetting.listInputMethod(); await inputMethodSetting.listInputMethod().then((data)=>{
for (var i = 0;i < properties.length; i++) { console.info("listInputMethod promise result---data: " + JSON.stringify(data));
var property = properties[i]; }).catch((err) => {
console.info(property.packageName + "/" + property.methodId); console.info("listInputMethod promise err:" + err.msg);
} });
``` ```
### displayOptionalInputMethod ### displayOptionalInputMethod
displayOptionalInputMethod(callback: AsyncCallback&lt;void&gt;): void displayOptionalInputMethod(callback: AsyncCallback&lt;void&gt;): void
显示输入法选择对话框。 显示输入法选择对话框。使用callback形式返回结果。参数个数为1,否则抛出异常。
**系统能力**: SystemCapability.MiscServices.InputMethodFramework **系统能力**: SystemCapability.MiscServices.InputMethodFramework
...@@ -343,16 +359,20 @@ displayOptionalInputMethod(callback: AsyncCallback&lt;void&gt;): void ...@@ -343,16 +359,20 @@ displayOptionalInputMethod(callback: AsyncCallback&lt;void&gt;): void
**示例:** **示例:**
```js ```js
InputMethodSetting.displayOptionalInputMethod(()=>{ inputMethodSetting.displayOptionalInputMethod((err) => {
console.info('displayOptionalInputMethod is called'); if (err == undefined) {
}); console.error("displayOptionalInputMethod callback---err: " + err.msg);
return;
}
console.info("displayOptionalInputMethod callback");
});
``` ```
### displayOptionalInputMethod ### displayOptionalInputMethod
displayOptionalInputMethod(): Promise&lt;void&gt; displayOptionalInputMethod(): Promise&lt;void&gt;
显示输入法选择对话框。 显示输入法选择对话框。使用promise形式返回结果。参数个数为0,否则抛出异常。
**系统能力**: SystemCapability.MiscServices.InputMethodFramework **系统能力**: SystemCapability.MiscServices.InputMethodFramework
...@@ -360,10 +380,14 @@ displayOptionalInputMethod(callback: AsyncCallback&lt;void&gt;): void ...@@ -360,10 +380,14 @@ displayOptionalInputMethod(callback: AsyncCallback&lt;void&gt;): void
| 类型 | 说明 | | 类型 | 说明 |
| -------- | -------- | | -------- | -------- |
| Promise&lt;void&gt; | 回调函数。 | | Promise&lt;void&gt; | 无返回结果的Promise对象。 |
**示例:** **示例:**
```js ```js
InputMethodSetting.displayOptionalInputMethod(); await inputMethodSetting.displayOptionalInputMethod().then(()=>{
console.info("displayOptionalInputMethod promise");
}).catch((err) => {
console.info("listInputMethod promise err: " + err.msg);
});
``` ```
\ No newline at end of file
...@@ -94,7 +94,7 @@ createKeyboardDelegate(): KeyboardDelegate ...@@ -94,7 +94,7 @@ createKeyboardDelegate(): KeyboardDelegate
on(type: 'inputStart', callback: (kbController: KeyboardController, textInputClient: TextInputClient) => void): void on(type: 'inputStart', callback: (kbController: KeyboardController, textInputClient: TextInputClient) => void): void
订阅输入法绑定成功事件,使用callback回调返回输入法操作相关实例。 订阅输入法绑定成功事件,使用callback回调返回输入法操作相关实例。参数个数为2,参数1为napi_string,参数2为napi_function,否则抛出异常。
**系统能力**: SystemCapability.MiscServices.InputMethodFramework **系统能力**: SystemCapability.MiscServices.InputMethodFramework
...@@ -118,7 +118,7 @@ on(type: 'inputStart', callback: (kbController: KeyboardController, textInputCli ...@@ -118,7 +118,7 @@ on(type: 'inputStart', callback: (kbController: KeyboardController, textInputCli
off(type: 'inputStart', callback?: (kbController: KeyboardController, textInputClient: TextInputClient) => void): void off(type: 'inputStart', callback?: (kbController: KeyboardController, textInputClient: TextInputClient) => void): void
取消订阅输入法绑定成功事件。 取消订阅输入法绑定成功事件。参数个数不为1或2抛出异常,若为1,参数不为napi_string抛出异常,若为2,参数1不为napi_string,参数2不为napi_function抛出异常。参数若为1,取消此类型所有监听,参数若为2,取消此类型当前监听。
**系统能力**: SystemCapability.MiscServices.InputMethodFramework **系统能力**: SystemCapability.MiscServices.InputMethodFramework
...@@ -134,14 +134,16 @@ off(type: 'inputStart', callback?: (kbController: KeyboardController, textInputC ...@@ -134,14 +134,16 @@ off(type: 'inputStart', callback?: (kbController: KeyboardController, textInputC
**示例:** **示例:**
```js ```js
InputMethodEngine.off('inputStart'); InputMethodEngine.off('inputStart', (kbController, textInputClient) => {
console.log("delete inputStart notification.");
});
``` ```
### on('keyboardShow'|'keyboardHide') ### on('keyboardShow'|'keyboardHide')
on(type: 'keyboardShow'|'keyboardHide', callback: () => void): void on(type: 'keyboardShow'|'keyboardHide', callback: () => void): void
订阅输入法事件。 订阅输入法事件。参数个数为2,参数1为napi_string,参数2为napi_function,否则抛出异常。
**系统能力**: SystemCapability.MiscServices.InputMethodFramework **系统能力**: SystemCapability.MiscServices.InputMethodFramework
...@@ -155,8 +157,11 @@ on(type: 'keyboardShow'|'keyboardHide', callback: () => void): void ...@@ -155,8 +157,11 @@ on(type: 'keyboardShow'|'keyboardHide', callback: () => void): void
**示例:** **示例:**
```js ```js
InputMethodEngine.on('keyboardShow', (err) => { InputMethodEngine.on('keyboardShow', () => {
console.info('keyboardShow'); console.log("inputMethodEngine keyboardShow.");
});
InputMethodEngine.on('keyboardHide', () => {
console.log("inputMethodEngine keyboardHide.");
}); });
``` ```
...@@ -164,7 +169,7 @@ on(type: 'keyboardShow'|'keyboardHide', callback: () => void): void ...@@ -164,7 +169,7 @@ on(type: 'keyboardShow'|'keyboardHide', callback: () => void): void
off(type: 'keyboardShow'|'keyboardHide', callback?: () => void): void off(type: 'keyboardShow'|'keyboardHide', callback?: () => void): void
取消订阅输入法事件。 取消订阅输入法事件。参数个数不为1或2抛出异常,若为1,参数不为napi_string抛出异常,若为2,参数1不为napi_string,参数2不为napi_function抛出异常。参数若为1,取消此类型所有监听,参数若为2,取消此类型当前监听。
**系统能力**: SystemCapability.MiscServices.InputMethodFramework **系统能力**: SystemCapability.MiscServices.InputMethodFramework
...@@ -178,7 +183,12 @@ off(type: 'keyboardShow'|'keyboardHide', callback?: () => void): void ...@@ -178,7 +183,12 @@ off(type: 'keyboardShow'|'keyboardHide', callback?: () => void): void
**示例:** **示例:**
```js ```js
InputMethodEngine.off('keyboardShow'); InputMethodEngine.off('keyboardShow', () => {
console.log("inputMethodEngine delete keyboardShow notification.");
});
InputMethodEngine.off('keyboardHide', () => {
console.log("inputMethodEngine delete keyboardHide notification.");
});
``` ```
...@@ -190,7 +200,7 @@ off(type: 'keyboardShow'|'keyboardHide', callback?: () => void): void ...@@ -190,7 +200,7 @@ off(type: 'keyboardShow'|'keyboardHide', callback?: () => void): void
on(type: 'keyDown'|'keyUp', callback: (event: KeyEvent) => boolean): void on(type: 'keyDown'|'keyUp', callback: (event: KeyEvent) => boolean): void
订阅硬键盘事件,使用callback回调返回按键信息。 订阅硬键盘事件,使用callback回调返回按键信息。参数个数为2,参数1为napi_string,参数2为napi_function,否则抛出异常。
**系统能力**: SystemCapability.MiscServices.InputMethodFramework **系统能力**: SystemCapability.MiscServices.InputMethodFramework
...@@ -206,8 +216,15 @@ on(type: 'keyDown'|'keyUp', callback: (event: KeyEvent) => boolean): void ...@@ -206,8 +216,15 @@ on(type: 'keyDown'|'keyUp', callback: (event: KeyEvent) => boolean): void
**示例:** **示例:**
```js ```js
KeyboardDelegate.on('keyDown', (event) => { KeyboardDelegate.on('keyUp', (keyEvent) => {
console.info('keyDown'); console.info("inputMethodEngine keyCode.(keyUp):" + JSON.stringify(keyEvent.keyCode));
console.info("inputMethodEngine keyAction.(keyUp):" + JSON.stringify(keyEvent.keyAction));
return true;
});
KeyboardDelegate.on('keyDown', (keyEvent) => {
console.info("inputMethodEngine keyCode.(keyDown):" + JSON.stringify(keyEvent.keyCode));
console.info("inputMethodEngine keyAction.(keyDown):" + JSON.stringify(keyEvent.keyAction));
return true;
}); });
``` ```
...@@ -215,7 +232,7 @@ on(type: 'keyDown'|'keyUp', callback: (event: KeyEvent) => boolean): void ...@@ -215,7 +232,7 @@ on(type: 'keyDown'|'keyUp', callback: (event: KeyEvent) => boolean): void
off(type: 'keyDown'|'keyUp', callback?: (event: KeyEvent) => boolean): void off(type: 'keyDown'|'keyUp', callback?: (event: KeyEvent) => boolean): void
取消订阅硬键盘事件。 取消订阅硬键盘事件。参数个数不为1或2抛出异常,若为1,参数不为napi_string抛出异常,若为2,参数1不为napi_string,参数2不为napi_function抛出异常。参数若为1,取消此类型所有监听,参数若为2,取消此类型当前监听。
**系统能力**: SystemCapability.MiscServices.InputMethodFramework **系统能力**: SystemCapability.MiscServices.InputMethodFramework
...@@ -229,14 +246,21 @@ off(type: 'keyDown'|'keyUp', callback?: (event: KeyEvent) => boolean): void ...@@ -229,14 +246,21 @@ off(type: 'keyDown'|'keyUp', callback?: (event: KeyEvent) => boolean): void
**示例:** **示例:**
```js ```js
KeyboardDelegate.off('keyDown'); KeyboardDelegate.off('keyUp', (keyEvent) => {
console.log("delete keyUp notification.");
return true;
});
KeyboardDelegate.off('keyDown', (keyEvent) => {
console.log("delete keyDown notification.");
return true;
});
``` ```
### on('cursorContextChange') ### on('cursorContextChange')
on(type: 'cursorContextChange', callback: (x: number, y:number, height:number) => void): void on(type: 'cursorContextChange', callback: (x: number, y:number, height:number) => void): void
订阅光标变化事件,使用callback回调返回光标信息。 订阅光标变化事件,使用callback回调返回光标信息。使用callback回调返回光标信息,使用callback回调返回按键信息。参数个数为2,参数1为napi_string,参数2为napi_function,否则抛出异常。
**系统能力**: SystemCapability.MiscServices.InputMethodFramework **系统能力**: SystemCapability.MiscServices.InputMethodFramework
...@@ -252,18 +276,18 @@ on(type: 'cursorContextChange', callback: (x: number, y:number, height:number) = ...@@ -252,18 +276,18 @@ on(type: 'cursorContextChange', callback: (x: number, y:number, height:number) =
**示例:** **示例:**
```js ```js
KeyboardDelegate.on('cursorContextChange', (x, y, height) => { KeyboardDelegate.on('cursorContextChange', (x, y, height) => {
console.info('cursorContextChange'); console.log("inputMethodEngine cursorContextChange x:" + x);
console.log("inputMethodEngine cursorContextChange y:" + y);
console.log("inputMethodEngine cursorContextChange height:" + height);
}); });
``` ```
### off('cursorContextChange') ### off('cursorContextChange')
off(type: 'cursorContextChange', callback?: (x: number, y:number, height:number) => void): void off(type: 'cursorContextChange', callback?: (x: number, y:number, height:number) => void): void
取消订阅光标变化事件。 取消订阅光标变化事件。参数个数不为1或2抛出异常,若为1,参数不为napi_string抛出异常,若为2,参数1不为napi_string,参数2不为napi_function抛出异常。参数若为1,取消此类型所有监听,参数若为2,取消此类型当前监听。
**系统能力**: SystemCapability.MiscServices.InputMethodFramework **系统能力**: SystemCapability.MiscServices.InputMethodFramework
...@@ -278,15 +302,15 @@ off(type: 'cursorContextChange', callback?: (x: number, y:number, height:number) ...@@ -278,15 +302,15 @@ off(type: 'cursorContextChange', callback?: (x: number, y:number, height:number)
**示例:** **示例:**
```js ```js
KeyboardDelegate.off('cursorContextChange', (x, y, height) => {
KeyboardDelegate.off('cursorContextChange'); console.log("delete cursorContextChange notification.");
});
``` ```
### on('selectionChange') ### on('selectionChange')
on(type: 'selectionChange', callback: (oldBegin: number, oldEnd: number, newBegin: number, newEnd: number) => void): void on(type: 'selectionChange', callback: (oldBegin: number, oldEnd: number, newBegin: number, newEnd: number) => void): void
订阅文本选择变化事件,使用callback回调返回文本选择信息。 订阅文本选择变化事件,使用callback回调返回文本选择信息,使用callback回调返回按键信息。参数个数为2,参数1为napi_string,参数2为napi_function,否则抛出异常
**系统能力**: SystemCapability.MiscServices.InputMethodFramework **系统能力**: SystemCapability.MiscServices.InputMethodFramework
...@@ -300,18 +324,19 @@ on(type: 'selectionChange', callback: (oldBegin: number, oldEnd: number, newBegi ...@@ -300,18 +324,19 @@ on(type: 'selectionChange', callback: (oldBegin: number, oldEnd: number, newBegi
**示例:** **示例:**
```js ```js
KeyboardDelegate.on('selectionChange', (oldBegin, oldEnd, newBegin, newEnd) => { KeyboardDelegate.on('selectionChange', (oldBegin, oldEnd, newBegin, newEnd) => {
console.info('selectionChange'); console.log("inputMethodEngine beforeEach selectionChange oldBegin:" + oldBegin);
console.log("inputMethodEngine beforeEach selectionChange oldEnd:" + oldEnd);
console.log("inputMethodEngine beforeEach selectionChange newBegin:" + newBegin);
console.log("inputMethodEngine beforeEach selectionChange newEnd:" + newEnd);
}); });
``` ```
### off('selectionChange') ### off('selectionChange')
off(type: 'selectionChange', callback?: (oldBegin: number, oldEnd: number, newBegin: number, newEnd: number) => void): void off(type: 'selectionChange', callback?: (oldBegin: number, oldEnd: number, newBegin: number, newEnd: number) => void): void
取消订阅文本选择变化事件。 取消订阅文本选择变化事件。参数个数不为1或2抛出异常,若为1,参数不为napi_string抛出异常,若为2,参数1不为napi_string,参数2不为napi_function抛出异常。参数若为1,取消此类型所有监听,参数若为2,取消此类型当前监听。
**系统能力**: SystemCapability.MiscServices.InputMethodFramework **系统能力**: SystemCapability.MiscServices.InputMethodFramework
...@@ -325,9 +350,9 @@ off(type: 'selectionChange', callback?: (oldBegin: number, oldEnd: number, newBe ...@@ -325,9 +350,9 @@ off(type: 'selectionChange', callback?: (oldBegin: number, oldEnd: number, newBe
**示例:** **示例:**
```js ```js
KeyboardDelegate.off('selectionChange', (oldBegin, oldEnd, newBegin, newEnd) => {
KeyboardDelegate.off('selectionChange'); console.log("delete selectionChange notification.");
});
``` ```
...@@ -335,7 +360,7 @@ KeyboardDelegate.off('selectionChange'); ...@@ -335,7 +360,7 @@ KeyboardDelegate.off('selectionChange');
on(type: 'textChange', callback: (text: string) => void): void on(type: 'textChange', callback: (text: string) => void): void
订阅文本变化事件,使用callback回调返回当前文本内容。 订阅文本变化事件,使用callback回调返回当前文本内容,使用callback回调返回按键信息。参数个数为2,参数1为napi_string,参数2为napi_function,否则抛出异常
**系统能力**: SystemCapability.MiscServices.InputMethodFramework **系统能力**: SystemCapability.MiscServices.InputMethodFramework
...@@ -349,18 +374,16 @@ on(type: 'textChange', callback: (text: string) => void): void ...@@ -349,18 +374,16 @@ on(type: 'textChange', callback: (text: string) => void): void
**示例:** **示例:**
```js ```js
KeyboardDelegate.on('textChange', (text) => { KeyboardDelegate.on('textChange', (text) => {
console.info('textChange'); console.log("inputMethodEngine textChange. text:" + text);
}); });
``` ```
### off('textChange') ### off('textChange')
off(type: 'textChange', callback?: (text: string) => void): void off(type: 'textChange', callback?: (text: string) => void): void
取消订阅文本变化事件。 取消订阅文本变化事件。参数个数不为1或2抛出异常,若为1,参数不为napi_string抛出异常,若为2,参数1不为napi_string,参数2不为napi_function抛出异常。参数若为1,取消此类型所有监听,参数若为2,取消此类型当前监听。
**系统能力**: SystemCapability.MiscServices.InputMethodFramework **系统能力**: SystemCapability.MiscServices.InputMethodFramework
...@@ -374,7 +397,9 @@ off(type: 'textChange', callback?: (text: string) => void): void ...@@ -374,7 +397,9 @@ off(type: 'textChange', callback?: (text: string) => void): void
**示例:** **示例:**
```js ```js
KeyboardDelegate.off('textChange'); keyboardDelegate.off('textChange', (text) => {
console.log("delete textChange notification. text:" + text);
});
``` ```
## KeyboardController<a name="KeyboardController"></a> ## KeyboardController<a name="KeyboardController"></a>
...@@ -385,7 +410,7 @@ KeyboardDelegate.off('textChange'); ...@@ -385,7 +410,7 @@ KeyboardDelegate.off('textChange');
hideKeyboard(callback: AsyncCallback&lt;void&gt;): void hideKeyboard(callback: AsyncCallback&lt;void&gt;): void
隐藏输入法。 隐藏输入法。使用callback形式返回结果。参数个数为1,否则抛出异常。
**系统能力**: SystemCapability.MiscServices.InputMethodFramework **系统能力**: SystemCapability.MiscServices.InputMethodFramework
...@@ -399,28 +424,37 @@ hideKeyboard(callback: AsyncCallback&lt;void&gt;): void ...@@ -399,28 +424,37 @@ hideKeyboard(callback: AsyncCallback&lt;void&gt;): void
```js ```js
KeyboardController.hideKeyboard(()=>{ KeyboardController.hideKeyboard((err) => {
}); if (err == undefined) {
console.error("hideKeyboard callback result---err: " + err.msg);
return;
}
console.log("hideKeyboard callback.");
});
``` ```
### hideKeyboard ### hideKeyboard
hideKeyboard(): Promise&lt;void&gt; hideKeyboard(): Promise&lt;void&gt;
隐藏输入法。 隐藏输入法。使用peomise形式返回结果。参数个数为0,否则抛出异常。
**系统能力**: SystemCapability.MiscServices.InputMethodFramework **系统能力**: SystemCapability.MiscServices.InputMethodFramework
**返回值:** **返回值:**
| 类型 | 说明 | | 类型 | 说明 |
| ---------------- | -------- | | ---------------- | ------------------------- |
| Promise&lt;void> | 回调函数 | | Promise&lt;void> | 无返回结果的Promise对象。 |
**示例:** **示例:**
```js ```js
KeyboardController.hideKeyboard(); await KeyboardController.hideKeyboard().then(() => {
console.info("hideKeyboard promise.");
}).catch((err) => {
console.info("hideKeyboard promise err: " + err.msg);
});
``` ```
## TextInputClient<a name="TextInputClient"></a> ## TextInputClient<a name="TextInputClient"></a>
...@@ -431,7 +465,7 @@ hideKeyboard(): Promise&lt;void&gt; ...@@ -431,7 +465,7 @@ hideKeyboard(): Promise&lt;void&gt;
getForward(length:number, callback: AsyncCallback&lt;string&gt;): void getForward(length:number, callback: AsyncCallback&lt;string&gt;): void
获取光标前固定长度的文本。 获取光标前固定长度的文本。使用callback形式返回结果。参数个数为2,否侧抛出异常。
**系统能力**: SystemCapability.MiscServices.InputMethodFramework **系统能力**: SystemCapability.MiscServices.InputMethodFramework
...@@ -445,16 +479,21 @@ getForward(length:number, callback: AsyncCallback&lt;string&gt;): void ...@@ -445,16 +479,21 @@ getForward(length:number, callback: AsyncCallback&lt;string&gt;): void
**示例:** **示例:**
```js ```js
TextInputClient.getForward(5,(text) =>{ var length = 1;
console.info("text = " + text); TextInputClient.getForward(length, (err, text) => {
}); if (err == undefined) {
console.error("getForward callback result---err: " + err.msg);
return;
}
console.log("getForward callback result---text: " + text);
});
``` ```
### getForward ### getForward
getForward(length:number): Promise&lt;string&gt; getForward(length:number): Promise&lt;string&gt;
获取光标前固定长度的文本。 获取光标前固定长度的文本。使用promise形式返回结果。参数个数为1,否侧抛出异常。
**系统能力**: SystemCapability.MiscServices.InputMethodFramework **系统能力**: SystemCapability.MiscServices.InputMethodFramework
...@@ -473,15 +512,19 @@ getForward(length:number): Promise&lt;string&gt; ...@@ -473,15 +512,19 @@ getForward(length:number): Promise&lt;string&gt;
**示例:** **示例:**
```js ```js
var text = TextInputClient.getForward(5); var length = 1;
console.info("text = " + text); await client.getForward(length).then((text) => {
console.info("getForward promise result---res: " + text);
}).catch((err) => {
console.error("getForward promise err: " + err.msg);
});
``` ```
### getBackward ### getBackward
getBackward(length:number, callback: AsyncCallback&lt;string&gt;): void getBackward(length:number, callback: AsyncCallback&lt;string&gt;): void
获取光标后固定长度的文本。 获取光标后固定长度的文本。使用callback形式返回结果。参数个数为2,否侧抛出异常。
**系统能力**: SystemCapability.MiscServices.InputMethodFramework **系统能力**: SystemCapability.MiscServices.InputMethodFramework
...@@ -495,8 +538,12 @@ getBackward(length:number, callback: AsyncCallback&lt;string&gt;): void ...@@ -495,8 +538,12 @@ getBackward(length:number, callback: AsyncCallback&lt;string&gt;): void
**示例:** **示例:**
```js ```js
TextInputClient.getBackward(5,(text)=>{ TextInputClient.getBackward(length, (err, text) => {
console.info("text = " + text); if (err == undefined) {
console.error("getBackward callback result---err: " + err.msg);
return;
}
console.log("getBackward callback result---text: " + text);
}); });
``` ```
...@@ -504,7 +551,7 @@ getBackward(length:number, callback: AsyncCallback&lt;string&gt;): void ...@@ -504,7 +551,7 @@ getBackward(length:number, callback: AsyncCallback&lt;string&gt;): void
getBackward(length:number): Promise&lt;string&gt; getBackward(length:number): Promise&lt;string&gt;
获取光标后固定长度的文本。 获取光标后固定长度的文本。使用promise形式返回结果。参数个数为1,否侧抛出异常。
**系统能力**: SystemCapability.MiscServices.InputMethodFramework **系统能力**: SystemCapability.MiscServices.InputMethodFramework
...@@ -523,15 +570,18 @@ getBackward(length:number): Promise&lt;string&gt; ...@@ -523,15 +570,18 @@ getBackward(length:number): Promise&lt;string&gt;
**示例:** **示例:**
```js ```js
var text = TextInputClient.getBackward(5); await TextInputClient.getBackward(length).then((text) => {
console.info("text = " + text); console.info("getBackward promise result---res: " + text);
}).catch((err) => {
console.error("getBackward promise err: " + err.msg);
});
``` ```
### deleteForward ### deleteForward
deleteForward(length:number, callback: AsyncCallback&lt;boolean&gt;): void deleteForward(length:number, callback: AsyncCallback&lt;boolean&gt;): void
删除光标前固定长度的文本。 删除光标前固定长度的文本。使用callback形式返回结果。参数个数为2,否侧抛出异常。
**系统能力**: SystemCapability.MiscServices.InputMethodFramework **系统能力**: SystemCapability.MiscServices.InputMethodFramework
...@@ -545,15 +595,23 @@ deleteForward(length:number, callback: AsyncCallback&lt;boolean&gt;): void ...@@ -545,15 +595,23 @@ deleteForward(length:number, callback: AsyncCallback&lt;boolean&gt;): void
**示例:** **示例:**
```js ```js
TextInputClient.deleteForward(5,(isSuccess)=>{ TextInputClient.deleteForward(length, (err, result) => {
console.info("isSuccess = " + isSuccess); if (err == undefined) {
console.error('deleteForward callback result---err: ' + err.msg);
return;
}
if (result) {
console.info("Success to deleteForward.(callback) ");
} else {
console.error("Failed to deleteForward.(callback) ");
}
}); });
``` ```
### deleteForward ### deleteForward
deleteForward(length:number): Promise&lt;boolean&gt; deleteForward(length:number): Promise&lt;boolean&gt;
删除光标前固定长度的文本。 删除光标前固定长度的文本。使用promise形式返回结果。参数个数为1,否侧抛出异常。
**系统能力**: SystemCapability.MiscServices.InputMethodFramework **系统能力**: SystemCapability.MiscServices.InputMethodFramework
...@@ -572,15 +630,22 @@ deleteForward(length:number): Promise&lt;boolean&gt; ...@@ -572,15 +630,22 @@ deleteForward(length:number): Promise&lt;boolean&gt;
**示例:** **示例:**
```js ```js
var isSuccess = TextInputClient.deleteForward(5); await TextInputClient.deleteForward(length).then((result) => {
console.info("isSuccess = " + isSuccess); if (result) {
console.info("Success to deleteForward.(promise) ");
} else {
console.error("Failed to deleteForward.(promise) ");
}
}).catch((err) => {
console.error("deleteForward promise err: " + err.msg);
});
``` ```
### deleteBackward ### deleteBackward
deleteBackward(length:number, callback: AsyncCallback&lt;boolean&gt;): void deleteBackward(length:number, callback: AsyncCallback&lt;boolean&gt;): void
删除光标后固定长度的文本。 删除光标后固定长度的文本。使用callback形式返回结果。参数个数为2,否侧抛出异常。
**系统能力**: SystemCapability.MiscServices.InputMethodFramework **系统能力**: SystemCapability.MiscServices.InputMethodFramework
...@@ -594,18 +659,24 @@ deleteBackward(length:number, callback: AsyncCallback&lt;boolean&gt;): void ...@@ -594,18 +659,24 @@ deleteBackward(length:number, callback: AsyncCallback&lt;boolean&gt;): void
**示例:** **示例:**
```js ```js
TextInputClient.deleteBackward(length, (err, result) => {
TextInputClient.deleteBackward(5, (isSuccess)=>{ if (err == undefined) {
console.info("isSuccess = " + isSuccess); console.error("deleteBackward callback result---err: " + err.msg);
return;
}
if (result) {
console.info("Success to deleteBackward.(callback) ");
} else {
console.error("Failed to deleteBackward.(callback) ");
}
}); });
``` ```
### deleteBackward ### deleteBackward
deleteBackward(length:number): Promise&lt;boolean&gt; deleteBackward(length:number): Promise&lt;boolean&gt;
删除光标后固定长度的文本。 删除光标后固定长度的文本。使用callback形式返回结果。参数个数为2,否侧抛出异常。
**系统能力**: SystemCapability.MiscServices.InputMethodFramework **系统能力**: SystemCapability.MiscServices.InputMethodFramework
...@@ -623,16 +694,21 @@ deleteBackward(length:number): Promise&lt;boolean&gt; ...@@ -623,16 +694,21 @@ deleteBackward(length:number): Promise&lt;boolean&gt;
**示例:** **示例:**
```js ```js
await TextInputClient.deleteBackward(length).then((result) => {
var isSuccess = TextInputClient.deleteBackward(5); if (result) {
console.info("isSuccess = " + isSuccess); console.info("Success to deleteBackward.(promise) ");
} else {
console.error("Failed to deleteBackward.(promise) ");
}
}).catch((err) => {
console.error("deleteBackward promise err: " + err.msg);
});
``` ```
### sendKeyFunction ### sendKeyFunction
sendKeyFunction(action:number, callback: AsyncCallback&lt;boolean&gt;): void sendKeyFunction(action:number, callback: AsyncCallback&lt;boolean&gt;): void
发送功能键。 发送功能键。使用callback形式返回结果。参数个数为2,否侧抛出异常。
**系统能力**: SystemCapability.MiscServices.InputMethodFramework **系统能力**: SystemCapability.MiscServices.InputMethodFramework
...@@ -646,18 +722,24 @@ sendKeyFunction(action:number, callback: AsyncCallback&lt;boolean&gt;): void ...@@ -646,18 +722,24 @@ sendKeyFunction(action:number, callback: AsyncCallback&lt;boolean&gt;): void
**示例:** **示例:**
```js ```js
TextInputClient.sendKeyFunction(keyFunction, (err, result) => {
TextInputClient.sendKeyFunction(inputMethod.ENTER_KEY_TYPE_NEXT,(isSuccess)=>{ if (err == undefined) {
console.info("isSuccess = " + isSuccess); console.error("sendKeyFunction callback result---err: " + err.msg);
return;
}
if (result) {
console.info("Success to sendKeyFunction.(callback) ");
} else {
console.error("Failed to sendKeyFunction.(callback) ");
}
}); });
``` ```
### sendKeyFunction ### sendKeyFunction
sendKeyFunction(action:number): Promise&lt;boolean&gt; sendKeyFunction(action:number): Promise&lt;boolean&gt;
发送功能键。 发送功能键。使用promise形式返回结果。参数个数为1,否侧抛出异常。
**系统能力**: SystemCapability.MiscServices.InputMethodFramework **系统能力**: SystemCapability.MiscServices.InputMethodFramework
...@@ -676,15 +758,22 @@ sendKeyFunction(action:number): Promise&lt;boolean&gt; ...@@ -676,15 +758,22 @@ sendKeyFunction(action:number): Promise&lt;boolean&gt;
**示例:** **示例:**
```js ```js
var isSuccess = TextInputClient.sendKeyFunction(inputMethod.ENTER_KEY_TYPE_NEXT); await client.sendKeyFunction(keyFunction).then((result) => {
console.info("isSuccess = " + isSuccess); if (result) {
console.info("Success to sendKeyFunction.(promise) ");
} else {
console.error("Failed to sendKeyFunction.(promise) ");
}
}).catch((err) => {
console.error("sendKeyFunction promise err:" + err.msg);
});
``` ```
### insertText ### insertText
insertText(text:string, callback: AsyncCallback&lt;boolean&gt;): void insertText(text:string, callback: AsyncCallback&lt;boolean&gt;): void
插入文本。 插入文本。使用callback形式返回结果。参数个数为2,否侧抛出异常。
**系统能力**: SystemCapability.MiscServices.InputMethodFramework **系统能力**: SystemCapability.MiscServices.InputMethodFramework
...@@ -698,18 +787,24 @@ insertText(text:string, callback: AsyncCallback&lt;boolean&gt;): void ...@@ -698,18 +787,24 @@ insertText(text:string, callback: AsyncCallback&lt;boolean&gt;): void
**示例:** **示例:**
```js ```js
TextInputClient.insertText('test', (err, result) => {
TextInputClient.insertText("test", (isSuccess)=>{ if (err == undefined) {
console.info("isSuccess = " + isSuccess); console.error("insertText callback result---err: " + err.msg);
return;
}
if (result) {
console.info("Success to insertText.(callback) ");
} else {
console.error("Failed to insertText.(callback) ");
}
}); });
``` ```
### insertText ### insertText
insertText(text:string): Promise&lt;boolean&gt; insertText(text:string): Promise&lt;boolean&gt;
插入文本。 插入文本。使用promise形式返回结果。参数个数为1,否侧抛出异常。
**系统能力**: SystemCapability.MiscServices.InputMethodFramework **系统能力**: SystemCapability.MiscServices.InputMethodFramework
...@@ -728,15 +823,22 @@ insertText(text:string): Promise&lt;boolean&gt; ...@@ -728,15 +823,22 @@ insertText(text:string): Promise&lt;boolean&gt;
**示例:** **示例:**
```js ```js
var isSuccess = TextInputClient.insertText("test"); await TextInputClient.insertText('test').then((result) => {
console.info("isSuccess = " + isSuccess); if (result) {
console.info("Success to insertText.(promise) ");
} else {
console.error("Failed to insertText.(promise) ");
}
}).catch((err) => {
console.error("insertText promise err: " + err.msg);
});
``` ```
### getEditorAttribute ### getEditorAttribute
getEditorAttribute(callback: AsyncCallback&lt;EditorAttribute&gt;): void getEditorAttribute(callback: AsyncCallback&lt;EditorAttribute&gt;): void
获取编辑框属性值。 获取编辑框属性值。使用callback形式返回结果。参数个数为1,否侧抛出异常。
**系统能力**: SystemCapability.MiscServices.InputMethodFramework **系统能力**: SystemCapability.MiscServices.InputMethodFramework
...@@ -749,15 +851,21 @@ getEditorAttribute(callback: AsyncCallback&lt;EditorAttribute&gt;): void ...@@ -749,15 +851,21 @@ getEditorAttribute(callback: AsyncCallback&lt;EditorAttribute&gt;): void
**示例:** **示例:**
```js ```js
TextInputClient.getEditorAttribute((EditorAttribute)=>{ TextInputClient.getEditorAttribute((err, editorAttribute) => {
}); if (err == undefined) {
console.error("getEditorAttribute callback result---err: " + err.msg);
return;
}
console.log("editorAttribute.inputPattern(callback): " + JSON.stringify(editorAttribute.inputPattern));
console.log("editorAttribute.enterKeyType(callback): " + JSON.stringify(editorAttribute.enterKeyType));
});
``` ```
### getEditorAttribute ### getEditorAttribute
getEditorAttribute(): EditorAttribute getEditorAttribute(): EditorAttribute
获取编辑框属性值。 获取编辑框属性值。使用promise形式返回结果。参数个数为0,否侧抛出异常。
**系统能力**: SystemCapability.MiscServices.InputMethodFramework **系统能力**: SystemCapability.MiscServices.InputMethodFramework
...@@ -770,7 +878,12 @@ getEditorAttribute(): EditorAttribute ...@@ -770,7 +878,12 @@ getEditorAttribute(): EditorAttribute
**示例:** **示例:**
```js ```js
var EditorAttribute = TextInputClient.getEditorAttribute(); await TextInputClient.getEditorAttribute().then((editorAttribute) => {
console.info("editorAttribute.inputPattern(promise): " + JSON.stringify(editorAttribute.inputPattern));
console.info("editorAttribute.enterKeyType(promise): " + JSON.stringify(editorAttribute.enterKeyType));
}).catch((err) => {
console.error("getEditorAttribute promise err: " + err.msg);
});
``` ```
## EditorAttribute<a name="EditorAttribute"></a> ## EditorAttribute<a name="EditorAttribute"></a>
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册