Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Docs
提交
beb27013
D
Docs
项目概览
OpenHarmony
/
Docs
大约 2 年 前同步成功
通知
161
Star
293
Fork
28
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
D
Docs
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
beb27013
编写于
10月 20, 2022
作者:
H
Hollokin
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
输入法框架API资料补充
Signed-off-by:
N
Hollokin
<
taoyuxin2@huawei.com
>
上级
d787319f
变更
4
显示空白变更内容
内联
并排
Showing
4 changed file
with
960 addition
and
970 deletion
+960
-970
zh-cn/application-dev/reference/apis/js-apis-inputmethod-extension-ability.md
...v/reference/apis/js-apis-inputmethod-extension-ability.md
+82
-42
zh-cn/application-dev/reference/apis/js-apis-inputmethod-extension-context.md
...v/reference/apis/js-apis-inputmethod-extension-context.md
+50
-51
zh-cn/application-dev/reference/apis/js-apis-inputmethod.md
zh-cn/application-dev/reference/apis/js-apis-inputmethod.md
+160
-178
zh-cn/application-dev/reference/apis/js-apis-inputmethodengine.md
...plication-dev/reference/apis/js-apis-inputmethodengine.md
+668
-699
未找到文件。
zh-cn/application-dev/reference/apis/js-apis-inputmethod-extension-ability.md
浏览文件 @
beb27013
...
@@ -4,8 +4,8 @@ InputMethodExtensionAbility模块,提供生态输入法应用开发者通过In
...
@@ -4,8 +4,8 @@ InputMethodExtensionAbility模块,提供生态输入法应用开发者通过In
> **说明:**
> **说明:**
>
>
> 本模块首批接口从API version 9开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
>
-
本模块首批接口从API version 9开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
> 本模块接口仅可在Stage模型下使用。
>
-
本模块接口仅可在Stage模型下使用。
## 导入模块
## 导入模块
...
@@ -24,7 +24,7 @@ import InputMethodExtensionAbility from '@ohos.inputmethodextensionability';
...
@@ -24,7 +24,7 @@ import InputMethodExtensionAbility from '@ohos.inputmethodextensionability';
## InputMethodExtensionAbility.onCreate()
## InputMethodExtensionAbility.onCreate()
onCreate(want: Want): void
;
onCreate(want: Want): void
Extension生命周期回调,在拉起Extension输入法应用时调用,执行初始化输入法应用操作。
Extension生命周期回调,在拉起Extension输入法应用时调用,执行初始化输入法应用操作。
...
@@ -38,18 +38,18 @@ Extension生命周期回调,在拉起Extension输入法应用时调用,执
...
@@ -38,18 +38,18 @@ Extension生命周期回调,在拉起Extension输入法应用时调用,执
**示例:**
**示例:**
```
js
```
js
class
InputMethodExt
extends
InputMethodExtensionAbility
{
class
InputMethodExt
extends
InputMethodExtensionAbility
{
onCreate
(
want
)
{
onCreate
(
want
)
{
console
.
log
(
'
onCreate, want:
'
+
want
.
abilityName
);
console
.
log
(
'
onCreate, want:
'
+
want
.
abilityName
);
}
}
}
}
```
```
## InputMethodExtensionAbility.onDestroy()
## InputMethodExtensionAbility.onDestroy()
onDestroy(): void
;
onDestroy(): void
Extension生命周期回调,在销毁输入法应用时回调,执行资源清理等操作。
Extension生命周期回调,在销毁输入法应用时回调,执行资源清理等操作。
...
@@ -57,83 +57,123 @@ Extension生命周期回调,在销毁输入法应用时回调,执行资源
...
@@ -57,83 +57,123 @@ Extension生命周期回调,在销毁输入法应用时回调,执行资源
**示例:**
**示例:**
```
js
```
js
class
InputMethodExt
extends
InputMethodExtensionAbility
{
class
InputMethodExt
extends
InputMethodExtensionAbility
{
onDestroy
()
{
onDestroy
()
{
console
.
log
(
'
onDestroy
'
);
console
.
log
(
'
onDestroy
'
);
}
}
}
}
```
```
## InputMethodExtensionAbility.onRequest()
## InputMethodExtensionAbility.onRequest()
onRequest(want: Want, startId: number): void
;
onRequest(want: Want, startId: number): void
Extension生命周期回调,在一个输入法extention开始时回调,执行输入法的相关操作。
Extension生命周期回调,在一个输入法extention开始时回调,执行输入法的相关操作。
**系统能力**
:SystemCapability.MiscServices.InputMethodFramework
**系统能力**
:SystemCapability.MiscServices.InputMethodFramework
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| want |
[
Want
](
js-apis-application-Want.md
)
| 是 | 当前Extension相关的Want类型信息,包括ability名称、bundle名称等。 |
| startId | number | 是 | 返回拉起次数。首次拉起初始值返回1,多次之后自动递增。 |
**示例:**
**示例:**
```
js
```
js
class
InputMethodExt
extends
InputMethodExtensionAbility
{
class
InputMethodExt
extends
InputMethodExtensionAbility
{
onRequest
()
{
onRequest
(
want
,
startId
)
{
console
.
log
(
'
onRequest, want:
'
+
want
.
abilityName
+
'
startId:
'
+
startId
);
console
.
log
(
'
onRequest, want:
'
+
want
.
abilityName
+
'
startId:
'
+
startId
);
}
}
}
}
```
```
## InputMethodExtensionAbility.onConnect()
## InputMethodExtensionAbility.onConnect()
onConnect(want: Want): rpc.RemoteObject
;
onConnect(want: Want): rpc.RemoteObject
Extension生命周期回调,在输入法extention首次连接输入法ability时回调。
Extension生命周期回调,在输入法extention首次连接输入法ability时回调。
**系统能力**
:SystemCapability.MiscServices.InputMethodFramework
**系统能力**
:SystemCapability.MiscServices.InputMethodFramework
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| want |
[
Want
](
js-apis-application-Want.md
)
| 是 | 当前Extension相关的Want类型信息,包括ability名称、bundle名称等。 |
**返回值**
| 类型 | 说明 |
| ------------------------------- | ------------------------------------------------------------ |
| rpc.RemoteObject | 一个RemoteObject对象,用于和客户端进行通信。 |
**示例:**
**示例:**
```
js
```
js
class
InputMethodExt
extends
InputMethodExtensionAbility
{
import
rpc
from
'
@ohos.rpc
'
onConnect
()
{
class
StubTest
extends
rpc
.
RemoteObject
{
console
.
log
(
'
onConnect, want:
'
+
want
.
abilityName
);
constructor
(
des
)
{
super
(
des
);
}
onConnect
(
code
,
data
,
reply
,
option
)
{
}
}
}
class
ServiceExt
extends
ServiceExtension
{
onConnect
(
want
)
{
console
.
log
(
'
onConnect , want:
'
+
want
.
abilityName
);
return
new
StubTest
(
"
test
"
);
}
}
```
}
```
## InputMethodExtensionAbility.onDisconnect()
## InputMethodExtensionAbility.onDisconnect()
onDisconnect(want: Want):
rpc.RemoteObject;
onDisconnect(want: Want):
void
Extension生命周期回调,在所有连接在输入法extention上的ability都断开的时候回调。
Extension生命周期回调,在所有连接在输入法extention上的ability都断开的时候回调。
**系统能力**
:SystemCapability.MiscServices.InputMethodFramework
**系统能力**
:SystemCapability.MiscServices.InputMethodFramework
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| want |
[
Want
](
js-apis-application-Want.md
)
| 是 | 当前Extension相关的Want类型信息,包括ability名称、bundle名称等。 |
**示例:**
**示例:**
```
js
```
js
class
InputMethodExt
extends
InputMethodExtensionAbility
{
class
InputMethodExt
extends
InputMethodExtensionAbility
{
onDisconnect
()
{
onDisconnect
(
want
)
{
console
.
log
(
'
onDisconnect, want:
'
+
want
.
abilityName
);
console
.
log
(
'
onDisconnect, want:
'
+
want
.
abilityName
);
}
}
}
}
```
```
## InputMethodExtensionAbility.onReconnect()
## InputMethodExtensionAbility.onReconnect()
onReconnect(want: Want):
rpc.RemoteObject;
onReconnect(want: Want):
void
Extension生命周期回调,在一个新的客户端去尝试连接输入法extention的时候回调(先前连接在extention上的客户端全部断开的情况下)。
Extension生命周期回调,在一个新的客户端去尝试连接输入法extention的时候回调(先前连接在extention上的客户端全部断开的情况下)。
**系统能力**
:SystemCapability.MiscServices.InputMethodFramework
**系统能力**
:SystemCapability.MiscServices.InputMethodFramework
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| want |
[
Want
](
js-apis-application-Want.md
)
| 是 | 当前Extension相关的Want类型信息,包括ability名称、bundle名称等。 |
**示例:**
**示例:**
```
js
```
js
class
InputMethodExt
extends
InputMethodExtensionAbility
{
class
InputMethodExt
extends
InputMethodExtensionAbility
{
onReconnect
()
{
onReconnect
(
want
)
{
console
.
log
(
'
onReconnect, want:
'
+
want
.
abilityName
);
console
.
log
(
'
onReconnect, want:
'
+
want
.
abilityName
);
}
}
}
}
```
```
zh-cn/application-dev/reference/apis/js-apis-inputmethod-extension-context.md
浏览文件 @
beb27013
...
@@ -6,8 +6,8 @@ InputMethodExtensionContext模块提供InputMethodExtensionAbility具有的能
...
@@ -6,8 +6,8 @@ InputMethodExtensionContext模块提供InputMethodExtensionAbility具有的能
> **说明:**
> **说明:**
>
>
> 本模块首批接口从API version 9开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
>
-
本模块首批接口从API version 9开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
> 本模块接口仅可在Stage模型下使用。
>
-
本模块接口仅可在Stage模型下使用。
## 导入模块
## 导入模块
...
@@ -20,12 +20,12 @@ import InputMethodExtensionContext from '@ohos.inputmethodextensioncontext';
...
@@ -20,12 +20,12 @@ import InputMethodExtensionContext from '@ohos.inputmethodextensioncontext';
在使用InputMethodExtensionContext的功能前,需要通过InputMethodExtensionAbility子类实例获取。
在使用InputMethodExtensionContext的功能前,需要通过InputMethodExtensionAbility子类实例获取。
```
js
```
js
import
InputMethodExtensionAbility
from
'
@ohos.inputmethodextensionability
'
;
import
InputMethodExtensionAbility
from
'
@ohos.inputmethodextensionability
'
;
class
MainAbility
extends
InputMethodExtensionAbility
{
class
MainAbility
extends
InputMethodExtensionAbility
{
onCreate
()
{
onCreate
()
{
let
context
=
this
.
context
;
let
context
=
this
.
context
;
}
}
}
}
```
```
## InputMethodExtensionContext.startAbility
## InputMethodExtensionContext.startAbility
...
@@ -45,15 +45,15 @@ startAbility(want: Want, callback: AsyncCallback<void>): void;
...
@@ -45,15 +45,15 @@ startAbility(want: Want, callback: AsyncCallback<void>): void;
**示例:**
**示例:**
```
js
```
js
let
want
=
{
let
want
=
{
'
bundleName
'
:
'
com.example.myapp
'
,
'
bundleName
'
:
'
com.example.myapp
'
,
'
abilityName
'
:
'
MyAbility
'
'
abilityName
'
:
'
MyAbility
'
};
};
this
.
context
.
startAbility
(
want
,
(
err
)
=>
{
this
.
context
.
startAbility
(
want
,
(
err
)
=>
{
console
.
log
(
'
startAbility result:
'
+
JSON
.
stringify
(
err
));
console
.
log
(
'
startAbility result:
'
+
JSON
.
stringify
(
err
));
});
});
```
```
## InputMethodExtensionContext.startAbility
## InputMethodExtensionContext.startAbility
...
@@ -78,18 +78,17 @@ startAbility(want: Want, options?: StartOptions): Promise\<void>;
...
@@ -78,18 +78,17 @@ startAbility(want: Want, options?: StartOptions): Promise\<void>;
**示例:**
**示例:**
```
js
```
js
let
want
=
{
let
want
=
{
'
bundleName
'
:
'
com.example.myapp
'
,
'
bundleName
'
:
'
com.example.myapp
'
,
'
abilityName
'
:
'
MyAbility
'
'
abilityName
'
:
'
MyAbility
'
};
};
this
.
context
.
startAbility
(
want
).
then
((
data
)
=>
{
this
.
context
.
startAbility
(
want
).
then
((
data
)
=>
{
console
.
log
(
'
success:
'
+
JSON
.
stringify
(
data
));
console
.
log
(
'
success:
'
+
JSON
.
stringify
(
data
));
}).
catch
((
error
)
=>
{
}).
catch
((
error
)
=>
{
console
.
log
(
'
failed:
'
+
JSON
.
stringify
(
error
));
console
.
log
(
'
failed:
'
+
JSON
.
stringify
(
error
));
});
});
```
```
## InputMethodExtensionContext.startAbility
## InputMethodExtensionContext.startAbility
...
@@ -109,19 +108,19 @@ startAbility(want: Want, options: StartOptions, callback: AsyncCallback<void&
...
@@ -109,19 +108,19 @@ startAbility(want: Want, options: StartOptions, callback: AsyncCallback<void&
**示例:**
**示例:**
```
js
```
js
var
want
=
{
let
want
=
{
'
deviceId
'
:
''
,
'
deviceId
'
:
''
,
'
bundleName
'
:
'
com.extreme.test
'
,
'
bundleName
'
:
'
com.extreme.test
'
,
'
abilityName
'
:
'
MainAbility
'
'
abilityName
'
:
'
MainAbility
'
};
};
var
options
=
{
let
options
=
{
windowMode
:
0
,
windowMode
:
0
,
};
};
this
.
context
.
startAbility
(
want
,
options
,
(
error
)
=>
{
this
.
context
.
startAbility
(
want
,
options
,
(
error
)
=>
{
console
.
log
(
'
error.code =
'
+
error
.
code
)
console
.
log
(
'
error.code =
'
+
error
.
code
)
})
})
```
```
## InputMethodExtensionContext.terminateSelf
## InputMethodExtensionContext.terminateSelf
...
@@ -139,11 +138,11 @@ terminateSelf(callback: AsyncCallback<void>): void;
...
@@ -139,11 +138,11 @@ terminateSelf(callback: AsyncCallback<void>): void;
**示例:**
**示例:**
```
js
```
js
this
.
context
.
terminateSelf
((
err
)
=>
{
this
.
context
.
terminateSelf
((
err
)
=>
{
console
.
log
(
'
terminateSelf result:
'
+
JSON
.
stringify
(
err
));
console
.
log
(
'
terminateSelf result:
'
+
JSON
.
stringify
(
err
));
});
});
```
```
## InputMethodExtensionContext.terminateSelf
## InputMethodExtensionContext.terminateSelf
...
@@ -161,10 +160,10 @@ terminateSelf(): Promise<void>;
...
@@ -161,10 +160,10 @@ terminateSelf(): Promise<void>;
**示例:**
**示例:**
```
js
```
js
this
.
context
.
terminateSelf
().
then
((
data
)
=>
{
this
.
context
.
terminateSelf
().
then
((
data
)
=>
{
console
.
log
(
'
success:
'
+
JSON
.
stringify
(
data
));
console
.
log
(
'
success:
'
+
JSON
.
stringify
(
data
));
}).
catch
((
error
)
=>
{
}).
catch
((
error
)
=>
{
console
.
log
(
'
failed:
'
+
JSON
.
stringify
(
error
));
console
.
log
(
'
failed:
'
+
JSON
.
stringify
(
error
));
});
});
```
```
zh-cn/application-dev/reference/apis/js-apis-inputmethod.md
浏览文件 @
beb27013
...
@@ -11,7 +11,6 @@
...
@@ -11,7 +11,6 @@
```
```
import inputMethod from '@ohos.inputmethod';
import inputMethod from '@ohos.inputmethod';
import InputMethodSubtype from './@ohos.inputMethodSubtype';
```
```
## inputMethod<sup>8+</sup>
## inputMethod<sup>8+</sup>
...
@@ -42,31 +41,6 @@ import InputMethodSubtype from './@ohos.inputMethodSubtype';
...
@@ -42,31 +41,6 @@ import InputMethodSubtype from './@ohos.inputMethodSubtype';
| iconId
<sup>
9+
</sup>
| number | 是 | 否 | 输入法图标id,非必填项。 |
| iconId
<sup>
9+
</sup>
| number | 是 | 否 | 输入法图标id,非必填项。 |
| extra
<sup>
9+
</sup>
| object | 是 | 否 | 输入法其他信息,非必填项。 |
| extra
<sup>
9+
</sup>
| object | 是 | 否 | 输入法其他信息,非必填项。 |
## inputMethod.getInputMethodController<sup>(deprecated)</sup>
getInputMethodController(): InputMethodController
获取客户端实例
[
InputMethodController
](
#inputmethodcontroller
)
。
> **说明:**
> 从API version 9开始废弃, 建议使用[getController](#inputmethodgetcontroller9)替代
>
> 从 API version 6开始支持。
**系统能力**
:SystemCapability.MiscServices.InputMethodFramework
**返回值:**
| 类型 | 说明 |
| ----------------------------------------------- | ------------------------ |
|
[
InputMethodController
](
#inputmethodcontroller
)
| 回调返回当前客户端实例。 |
**示例:**
```
js
var
InputMethodController
=
inputMethod
.
getInputMethodController
();
```
## inputMethod.getController<sup>9+</sup>
## inputMethod.getController<sup>9+</sup>
getController(): InputMethodController
getController(): InputMethodController
...
@@ -84,33 +58,7 @@ getController(): InputMethodController
...
@@ -84,33 +58,7 @@ getController(): InputMethodController
**示例:**
**示例:**
```
js
```
js
var
InputMethodController
=
inputMethod
.
getController
();
let
InputMethodController
=
inputMethod
.
getController
();
```
## inputMethod.getInputMethodSetting<sup>(deprecated)</sup>
getInputMethodSetting(): InputMethodSetting
获取客户端设置实例
[
InputMethodSetting
](
#inputmethodsetting8
)
。
> **说明:**
> 从API version 9开始废弃, 建议使用[getSetting](#inputmethodgetsetting9)替代
>
> 从 API version 6开始支持。
**系统能力**
: SystemCapability.MiscServices.InputMethodFramework
**返回值:**
| 类型 | 说明 |
| ----------------------------------------- | ---------------------------- |
|
[
InputMethodSetting
](
#inputmethodsetting8
)
| 回调返回当前客户端设置实例。 |
**示例:**
```
js
var
InputMethodSetting
=
inputMethod
.
getInputMethodSetting
();
```
```
## inputMethod.getSetting<sup>9+</sup>
## inputMethod.getSetting<sup>9+</sup>
...
@@ -131,7 +79,7 @@ getSetting(): InputMethodSetting
...
@@ -131,7 +79,7 @@ getSetting(): InputMethodSetting
**示例:**
**示例:**
```
js
```
js
var
InputMethodSetting
=
inputMethod
.
getSetting
();
let
InputMethodSetting
=
inputMethod
.
getSetting
();
```
```
## inputMethod.switchInputMethod<sup>9+</sup>
## inputMethod.switchInputMethod<sup>9+</sup>
...
@@ -227,7 +175,7 @@ getCurrentInputMethod(): InputMethodProperty
...
@@ -227,7 +175,7 @@ getCurrentInputMethod(): InputMethodProperty
**示例:**
**示例:**
```
js
```
js
var
currentIme
=
inputMethod
.
getCurrentInputMethod
();
let
currentIme
=
inputMethod
.
getCurrentInputMethod
();
```
```
## inputMethod.switchCurrentInputMethodSubtype<sup>9+</sup>
## inputMethod.switchCurrentInputMethodSubtype<sup>9+</sup>
...
@@ -328,7 +276,7 @@ getCurrentInputMethodSubtype(): InputMethodSubtype
...
@@ -328,7 +276,7 @@ getCurrentInputMethodSubtype(): InputMethodSubtype
**示例:**
**示例:**
```
js
```
js
var
currentImeSubType
=
inputMethod
.
getCurrentInputMethodSubtype
();
let
currentImeSubType
=
inputMethod
.
getCurrentInputMethodSubtype
();
```
```
## inputMethod.switchCurrentInputMethodAndSubtype<sup>9+</sup>
## inputMethod.switchCurrentInputMethodAndSubtype<sup>9+</sup>
...
@@ -420,78 +368,56 @@ try {
...
@@ -420,78 +368,56 @@ try {
}
}
```
```
## InputMethodController
## inputMethod.getInputMethodController<sup>(deprecated)</sup>
下列API示例中都需使用
[
getController
](
##inputmethodgetcontroller9
)
回调获取到InputMethodController实例,再通过此实例调用对应方法。
### stopInput<sup>(deprecated)</sup>
stopInput(callback: AsyncCallback
<
boolean
>
): void
getInputMethodController(): InputMethodController
隐藏输入法。使用callback形式返回结果。参数个数为1,否则抛出异常
。
获取客户端实例
[
InputMethodController
](
#inputmethodcontroller
)
。
> **说明:**
> **说明:**
> 从API version 9开始废弃, 建议使用[stopInputSession](#stopinputsession9)替代
> 从API version 6开始支持,从API version 9开始废弃, 建议使用[getController()](#inputmethodgetcontroller9)替代
>
> 从 API version 6开始支持。
**系统能力**
:SystemCapability.MiscServices.InputMethodFramework
**系统能力**
:SystemCapability.MiscServices.InputMethodFramework
**
参数
:**
**
返回值
:**
|
参数名 | 类型 | 必填 | 说明
|
|
类型 | 说明
|
| --------
| -------- | -------- |
-------- |
| --------
--------------------------------------- | ----------------
-------- |
|
callback | AsyncCallback
<
boolean
>
| 是 | 返回输入法隐藏是否成功
。 |
|
[
InputMethodController
](
#inputmethodcontroller
)
| 回调返回当前客户端实例
。 |
**示例:**
**示例:**
```
js
```
js
InputMethodController
.
stopInput
((
error
,
result
)
=>
{
let
InputMethodController
=
inputMethod
.
getInputMethodController
();
if
(
error
)
{
console
.
error
(
'
failed to stopInput because:
'
+
JSON
.
stringify
(
error
));
return
;
}
if
(
result
)
{
console
.
info
(
'
Success to stopInput.(callback)
'
);
}
else
{
console
.
error
(
'
Failed to stopInput.(callback)
'
);
}
});
```
```
##
# stopInput
<sup>(deprecated)</sup>
##
inputMethod.getInputMethodSetting
<sup>(deprecated)</sup>
stopInput(): Promise
<
boolean
>
getInputMethodSetting(): InputMethodSetting
隐藏输入法。使用promise形式返回结果。参数个数为0,否则抛出异常
。
获取客户端设置实例
[
InputMethodSetting
](
#inputmethodsetting8
)
。
> **说明:**
> **说明:**
> 从API version 9开始废弃, 建议使用[stopInputSession](#stopinputsession9)替代
> 从API version 6开始支持,从API version 9开始废弃, 建议使用[getSetting()](#inputmethodgetsetting9)替代
>
> 从 API version 6开始支持。
**系统能力**
: SystemCapability.MiscServices.InputMethodFramework
**系统能力**
: SystemCapability.MiscServices.InputMethodFramework
**返回值:**
**返回值:**
| 类型 | 说明 |
| 类型 | 说明 |
| --------
|
-------- |
| --------
--------------------------------- | --------------------
-------- |
|
Promise
<
boolean
>
| 返回输入法隐藏是否成功
。 |
|
[
InputMethodSetting
](
#inputmethodsetting8
)
| 回调返回当前客户端设置实例
。 |
**示例:**
**示例:**
```
js
```
js
InputMethodController
.
stopInput
().
then
((
result
)
=>
{
let
InputMethodSetting
=
inputMethod
.
getInputMethodSetting
();
if
(
result
)
{
console
.
info
(
'
Success to stopInput.(promise)
'
);
}
else
{
console
.
error
(
'
Failed to stopInput.(promise)
'
);
}
}).
catch
((
err
)
=>
{
console
.
error
(
'
stopInput promise err:
'
+
err
);
})
```
```
## InputMethodController
下列API示例中都需使用
[
getController
](
##inputmethodgetcontroller9
)
回调获取到InputMethodController实例,再通过此实例调用对应方法。
### stopInputSession<sup>9+</sup>
### stopInputSession<sup>9+</sup>
stopInputSession(callback: AsyncCallback
<
boolean
>
): void
stopInputSession(callback: AsyncCallback
<
boolean
>
): void
...
@@ -528,7 +454,7 @@ try {
...
@@ -528,7 +454,7 @@ try {
### stopInputSession
### stopInputSession
stopInputSession(): Promise
<
boolean
>
stopInputSession(): Promise
<
boolean
>
<sup>
9+
</sup>
隐藏输入法。使用promise形式返回结果。
隐藏输入法。使用promise形式返回结果。
...
@@ -658,6 +584,70 @@ InputMethodController.hideSoftKeyboard().then(async (err) => {
...
@@ -658,6 +584,70 @@ InputMethodController.hideSoftKeyboard().then(async (err) => {
});
});
```
```
### stopInput<sup>(deprecated)</sup>
stopInput(callback: AsyncCallback
<
boolean
>
): void
隐藏输入法。使用callback形式返回结果。参数个数为1,否则抛出异常。
> **说明:**
> 从API version 6开始支持,从API version 9开始废弃, 建议使用[stopInputSession()](#stopinputsession9)替代
**系统能力**
:SystemCapability.MiscServices.InputMethodFramework
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| callback | AsyncCallback
<
boolean
>
| 是 | 返回输入法隐藏是否成功。 |
**示例:**
```
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
<
boolean
>
隐藏输入法。使用promise形式返回结果。参数个数为0,否则抛出异常。
> **说明:**
> 从API version 6开始支持,从API version 9开始废弃, 建议使用[stopInputSession()](#stopinputsession9)替代
**系统能力**
: SystemCapability.MiscServices.InputMethodFramework
**返回值:**
| 类型 | 说明 |
| -------- | -------- |
| Promise
<
boolean
>
| 返回输入法隐藏是否成功。 |
**示例:**
```
js
InputMethodController
.
stopInput
().
then
((
result
)
=>
{
if
(
result
)
{
console
.
info
(
'
Success to stopInput.(promise)
'
);
}
else
{
console
.
error
(
'
Failed to stopInput.(promise)
'
);
}
}).
catch
((
err
)
=>
{
console
.
error
(
'
stopInput promise err:
'
+
err
);
})
```
## InputMethodSetting<sup>8+</sup>
## InputMethodSetting<sup>8+</sup>
下列API示例中都需使用
[
getSetting
](
#inputmethodgetsetting9
)
回调获取到InputMethodSetting实例,再通过此实例调用对应方法。
下列API示例中都需使用
[
getSetting
](
#inputmethodgetsetting9
)
回调获取到InputMethodSetting实例,再通过此实例调用对应方法。
...
@@ -679,14 +669,14 @@ on(type: 'imeChange', callback: (inputMethodProperty: InputMethodProperty, input
...
@@ -679,14 +669,14 @@ on(type: 'imeChange', callback: (inputMethodProperty: InputMethodProperty, input
**示例:**
**示例:**
```
js
```
js
InputMethodEngine
.
on
(
'
imeChange
'
,
(
inputMethodProperty
,
inputMethodSubtype
)
=>
{
InputMethodEngine
.
on
(
'
imeChange
'
,
(
inputMethodProperty
,
inputMethodSubtype
)
=>
{
InputMethodProperty
=
inputMethodProperty
;
InputMethodProperty
=
inputMethodProperty
;
InputMethodSubtype
=
inputMethodSubtype
;
InputMethodSubtype
=
inputMethodSubtype
;
});
});
```
```
### off('imeChange')<
a name="imeChange"></a><
sup>9+</sup>
### off('imeChange')<sup>9+</sup>
on(type: 'imeChange', callback: (inputMethodProperty: InputMethodProperty, inputMethodSubtype: InputMethodSubtype) => void): void
on(type: 'imeChange', callback: (inputMethodProperty: InputMethodProperty, inputMethodSubtype: InputMethodSubtype) => void): void
...
@@ -703,9 +693,9 @@ on(type: 'imeChange', callback: (inputMethodProperty: InputMethodProperty, input
...
@@ -703,9 +693,9 @@ on(type: 'imeChange', callback: (inputMethodProperty: InputMethodProperty, input
**示例:**
**示例:**
```
js
```
js
InputMethodAbility
.
off
(
'
imeChange
'
);
InputMethodAbility
.
off
(
'
imeChange
'
);
```
```
### listInputMethodSubtype<sup>9+</sup>
### listInputMethodSubtype<sup>9+</sup>
...
@@ -903,6 +893,62 @@ try {
...
@@ -903,6 +893,62 @@ try {
}
}
```
```
### showOptionalInputMethods<sup>9+</sup>
showOptionalInputMethods(callback: AsyncCallback
<
void
>
): void
显示输入法选择对话框。使用callback形式返回结果。参数个数为1,否则抛出异常。
**需要权限**
: ohos.permission.CONNECT_IME_ABILITY
**系统能力**
: SystemCapability.MiscServices.InputMethodFramework
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| callback | AsyncCallback
<
void
>
| 是 | 回调函数。 |
**示例:**
```
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
<
void
>
显示输入法选择对话框。使用promise形式返回结果。参数个数为0,否则抛出异常。
**系统能力**
: SystemCapability.MiscServices.InputMethodFramework
**返回值:**
| 类型 | 说明 |
| -------- | -------- |
| Promise
<
void
>
| 无返回结果的Promise对象。 |
**示例:**
```
js
InputMethodSetting
.
showOptionalInputMethods
().
then
(()
=>
{
console
.
info
(
'
displayOptionalInputMethod success.(promise)
'
);
}).
catch
((
err
)
=>
{
console
.
error
(
'
displayOptionalInputMethod promise err:
'
+
err
);
})
```
### listInputMethod<sup>(deprecated)</sup>
### listInputMethod<sup>(deprecated)</sup>
listInputMethod(callback: AsyncCallback
<
Array
<
InputMethodProperty
>>
): void
listInputMethod(callback: AsyncCallback
<
Array
<
InputMethodProperty
>>
): void
...
@@ -910,9 +956,7 @@ listInputMethod(callback: AsyncCallback<Array<InputMethodProperty>>)
...
@@ -910,9 +956,7 @@ listInputMethod(callback: AsyncCallback<Array<InputMethodProperty>>)
查询已安装的输入法列表。使用callback形式返回结果。参数个数为1,否则抛出异常。
查询已安装的输入法列表。使用callback形式返回结果。参数个数为1,否则抛出异常。
> **说明:**
> **说明:**
> 从API version 9开始废弃, 建议使用[getInputMethods](#getinputmethods9)替代
> 从API version 8开始支持,从API version 9开始废弃, 建议使用[getInputMethods](#getinputmethods9)替代
>
> 从 API version 8开始支持。
**系统能力**
: SystemCapability.MiscServices.InputMethodFramework
**系统能力**
: SystemCapability.MiscServices.InputMethodFramework
...
@@ -941,9 +985,7 @@ listInputMethod(): Promise<Array<InputMethodProperty>>
...
@@ -941,9 +985,7 @@ listInputMethod(): Promise<Array<InputMethodProperty>>
查询已安装的输入法列表。使用promise形式返回结果。参数个数为0,否则抛出异常。
查询已安装的输入法列表。使用promise形式返回结果。参数个数为0,否则抛出异常。
> **说明:**
> **说明:**
> 从API version 9开始废弃, 建议使用[getInputMethods](#getinputmethods9-1)替代
> 从API version 8开始支持,从API version 9开始废弃, 建议使用[getInputMethods](#getinputmethods9-1)替代
>
> 从 API version 8开始支持。
**系统能力**
: SystemCapability.MiscServices.InputMethodFramework
**系统能力**
: SystemCapability.MiscServices.InputMethodFramework
...
@@ -970,9 +1012,7 @@ displayOptionalInputMethod(callback: AsyncCallback<void>): void
...
@@ -970,9 +1012,7 @@ displayOptionalInputMethod(callback: AsyncCallback<void>): void
显示输入法选择对话框。使用callback形式返回结果。参数个数为1,否则抛出异常。
显示输入法选择对话框。使用callback形式返回结果。参数个数为1,否则抛出异常。
> **说明:**
> **说明:**
> 从API version 9开始废弃, 建议使用[showOptionalInputMethods](#showoptionalinputmethods9)替代
> 从API version 8开始支持,从API version 9开始废弃, 建议使用[showOptionalInputMethods()](#showoptionalinputmethods9)替代
>
> 从 API version 8开始支持。
**系统能力**
: SystemCapability.MiscServices.InputMethodFramework
**系统能力**
: SystemCapability.MiscServices.InputMethodFramework
...
@@ -994,38 +1034,6 @@ InputMethodSetting.displayOptionalInputMethod((err) => {
...
@@ -994,38 +1034,6 @@ InputMethodSetting.displayOptionalInputMethod((err) => {
});
});
```
```
### showOptionalInputMethods<sup>9+</sup>
showOptionalInputMethods(callback: AsyncCallback
<
void
>
): void
显示输入法选择对话框。使用callback形式返回结果。参数个数为1,否则抛出异常。
**需要权限**
: ohos.permission.CONNECT_IME_ABILITY
**系统能力**
: SystemCapability.MiscServices.InputMethodFramework
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| callback | AsyncCallback
<
void
>
| 是 | 回调函数。 |
**示例:**
```
js
try
{
InputMethodSetting
.
showOptionalInputMethods
((
err
)
=>
{
if
(
err
)
{
console
.
error
(
'
showOptionalInputMethods failed:
'
+
JSON
.
stringify
(
err
));
return
;
}
console
.
info
(
'
showOptionalInputMethods success
'
);
});
}
catch
(
err
)
{
console
.
error
(
'
showOptionalInputMethods failed:
'
+
JSON
.
stringify
(
err
));
}
```
### displayOptionalInputMethod<sup>(deprecated)</sup>
### displayOptionalInputMethod<sup>(deprecated)</sup>
displayOptionalInputMethod(): Promise
<
void
>
displayOptionalInputMethod(): Promise
<
void
>
...
@@ -1033,9 +1041,7 @@ displayOptionalInputMethod(): Promise<void>
...
@@ -1033,9 +1041,7 @@ displayOptionalInputMethod(): Promise<void>
显示输入法选择对话框。使用promise形式返回结果。参数个数为0,否则抛出异常。
显示输入法选择对话框。使用promise形式返回结果。参数个数为0,否则抛出异常。
> **说明:**
> **说明:**
> 从API version 9开始废弃, 建议使用[showOptionalInputMethods](#showoptionalinputmethods9-1)替代
> 从API version 8开始支持,API version 9开始废弃, 建议使用[showOptionalInputMethods()](#showoptionalinputmethods9-1)替代
>
> 从 API version 8开始支持。
**系统能力**
: SystemCapability.MiscServices.InputMethodFramework
**系统能力**
: SystemCapability.MiscServices.InputMethodFramework
...
@@ -1054,27 +1060,3 @@ InputMethodSetting.displayOptionalInputMethod().then(() => {
...
@@ -1054,27 +1060,3 @@ InputMethodSetting.displayOptionalInputMethod().then(() => {
console
.
error
(
'
displayOptionalInputMethod promise err:
'
+
err
);
console
.
error
(
'
displayOptionalInputMethod promise err:
'
+
err
);
})
})
```
```
### showOptionalInputMethods<sup>9+</sup>
showOptionalInputMethods(): Promise
<
void
>
显示输入法选择对话框。使用promise形式返回结果。参数个数为0,否则抛出异常。
**系统能力**
: SystemCapability.MiscServices.InputMethodFramework
**返回值:**
| 类型 | 说明 |
| -------- | -------- |
| Promise
<
void
>
| 无返回结果的Promise对象。 |
**示例:**
```
js
InputMethodSetting
.
showOptionalInputMethods
().
then
(()
=>
{
console
.
info
(
'
displayOptionalInputMethod success.(promise)
'
);
}).
catch
((
err
)
=>
{
console
.
error
(
'
displayOptionalInputMethod promise err:
'
+
err
);
})
```
\ No newline at end of file
zh-cn/application-dev/reference/apis/js-apis-inputmethodengine.md
浏览文件 @
beb27013
...
@@ -51,82 +51,78 @@ import inputMethodEngine from '@ohos.inputmethodengine';
...
@@ -51,82 +51,78 @@ import inputMethodEngine from '@ohos.inputmethodengine';
| CURSOR_RIGHT
<sup>
9+
</sup>
| number | 是 | 否 | 光标右移。 |
| CURSOR_RIGHT
<sup>
9+
</sup>
| number | 是 | 否 | 光标右移。 |
| WINDOW_TYPE_INPUT_METHOD_FLOAT
<sup>
9+
</sup>
| number | 是 | 否 | 输入法应用窗口风格标识。 |
| WINDOW_TYPE_INPUT_METHOD_FLOAT
<sup>
9+
</sup>
| number | 是 | 否 | 输入法应用窗口风格标识。 |
## inputMethodEngine.getInputMethod
Engine<a name="getInputMethodEngine"></a><sup>(deprecated)
</sup>
## inputMethodEngine.getInputMethod
Ability<a name="getInputMethodAbility"></a><sup>9+
</sup>
getInputMethod
Engine(): InputMethodEngine
getInputMethod
Ability(): InputMethodAbility
获取服务端实例。
获取服务端实例。
> **说明:**
> 从API version 9开始废弃, 建议使用[getInputMethodAbility](#getInputMethodAbility)替代
>
> 从 API version 8开始支持。
**系统能力**
: SystemCapability.MiscServices.InputMethodFramework
**系统能力**
: SystemCapability.MiscServices.InputMethodFramework
**返回值:**
**返回值:**
| 类型 | 说明 |
| 类型 | 说明 |
| --------------------------------------- | ------------ |
| --------------------------------------- | ------------ |
|
[
InputMethod
Engine
](
#inputmethodengine-1
)
| 服务端实例。 |
|
[
InputMethod
Ability
](
#inputmethodability
)
| 服务端实例。 |
**示例:**
**示例:**
```
js
```
js
var
InputMethodEngine
=
inputMethodEngine
.
getInputMethodEngine
();
let
InputMethodAbility
=
inputMethodAbility
.
getInputMethodAbility
();
```
```
## inputMethodEngine.get
InputMethodAbility<a name="getInputMethodAbility
"></a><sup>9+</sup>
## inputMethodEngine.get
KeyboardDelegate<a name="getKeyboardDelegate
"></a><sup>9+</sup>
get
InputMethodAbility(): InputMethodAbility
get
KeyboardDelegate(): KeyboardDelegate
获取
服务端
实例。
获取
客户端监听
实例。
**系统能力**
: SystemCapability.MiscServices.InputMethodFramework
**系统能力**
: SystemCapability.MiscServices.InputMethodFramework
**返回值:**
**返回值:**
| 类型 | 说明 |
| 类型 | 说明 |
| -------------------------------------
-- |
------------ |
| -------------------------------------
| ----
------------ |
|
[
InputMethodAbility
](
#inputmethodability
)
| 服务端
实例。 |
|
[
KeyboardDelegate
](
#KeyboardDelegate
)
| 客户端监听
实例。 |
**示例:**
**示例:**
```
js
```
js
var
InputMethodAbility
=
inputMethodAbility
.
getInputMethodAbility
();
let
KeyboardDelegate
=
inputMethodAbility
.
getKeyboardDelegate
();
```
```
## inputMethodEngine.
createKeyboardDelegate<a name="createKeyboardDelegat
e"></a><sup>(deprecated)</sup>
## inputMethodEngine.
getInputMethodEngine<a name="getInputMethodEngin
e"></a><sup>(deprecated)</sup>
createKeyboardDelegate(): KeyboardDelegat
e
getInputMethodEngine(): InputMethodEngin
e
获取
客户端监听
实例。
获取
服务端
实例。
> **说明:**
> **说明:**
> 从API version 9开始废弃, 建议使用[getKeyboardDelegate](#getKeyboardDelegate)替代
> 从API version 8开始支持,API version 9开始废弃, 建议使用[getInputMethodAbility()](#getInputMethodAbility)替代
>
> 从 API version 8开始支持。
**系统能力**
: SystemCapability.MiscServices.InputMethodFramework
**系统能力**
: SystemCapability.MiscServices.InputMethodFramework
**返回值:**
**返回值:**
| 类型 | 说明 |
| 类型 | 说明 |
| -------------------------------------
| ----
------------ |
| -------------------------------------
-- |
------------ |
|
[
KeyboardDelegate
](
#KeyboardDelegate
)
| 客户端监听
实例。 |
|
[
InputMethodEngine
](
#inputmethodengine-1
)
| 服务端
实例。 |
**示例:**
**示例:**
```
js
```
js
var
KeyboardDelegate
=
inputMethodEngine
.
createKeyboardDelegat
e
();
let
InputMethodEngine
=
inputMethodEngine
.
getInputMethodEngin
e
();
```
```
## inputMethodEngine.
getKeyboardDelegate<a name="getKeyboardDelegate"></a><sup>9+
</sup>
## inputMethodEngine.
createKeyboardDelegate<a name="createKeyboardDelegate"></a><sup>(deprecated)
</sup>
get
KeyboardDelegate(): KeyboardDelegate
create
KeyboardDelegate(): KeyboardDelegate
获取客户端监听实例。
获取客户端监听实例。
> **说明:**
> 从API version 8开始支持,API version 9开始废弃, 建议使用[getKeyboardDelegate()](#getKeyboardDelegate)替代
**系统能力**
: SystemCapability.MiscServices.InputMethodFramework
**系统能力**
: SystemCapability.MiscServices.InputMethodFramework
**返回值:**
**返回值:**
...
@@ -137,9 +133,9 @@ getKeyboardDelegate(): KeyboardDelegate
...
@@ -137,9 +133,9 @@ getKeyboardDelegate(): KeyboardDelegate
**示例:**
**示例:**
```
js
```
js
var
KeyboardDelegate
=
inputMethodAbility
.
get
KeyboardDelegate
();
let
KeyboardDelegate
=
inputMethodEngine
.
create
KeyboardDelegate
();
```
```
## InputMethodEngine<a name="InputMethodEngine"></a>
## InputMethodEngine<a name="InputMethodEngine"></a>
...
@@ -162,12 +158,12 @@ on(type: 'inputStart', callback: (kbController: KeyboardController, textInputCli
...
@@ -162,12 +158,12 @@ on(type: 'inputStart', callback: (kbController: KeyboardController, textInputCli
**示例:**
**示例:**
```
js
```
js
inputMethodEngine
.
getInputMethodEngine
().
on
(
'
inputStart
'
,
(
kbController
,
textInputClient
)
=>
{
inputMethodEngine
.
getInputMethodEngine
().
on
(
'
inputStart
'
,
(
kbController
,
textInputClient
)
=>
{
KeyboardController
=
kbController
;
KeyboardController
=
kbController
;
TextInputClient
=
textInputClient
;
TextInputClient
=
textInputClient
;
});
});
```
```
### off('inputStart')
### off('inputStart')
...
@@ -188,11 +184,11 @@ off(type: 'inputStart', callback?: (kbController: KeyboardController, textInputC
...
@@ -188,11 +184,11 @@ off(type: 'inputStart', callback?: (kbController: KeyboardController, textInputC
**示例:**
**示例:**
```
js
```
js
inputMethodEngine
.
getInputMethodEngine
().
off
(
'
inputStart
'
,
(
kbController
,
textInputClient
)
=>
{
inputMethodEngine
.
getInputMethodEngine
().
off
(
'
inputStart
'
,
(
kbController
,
textInputClient
)
=>
{
console
.
log
(
'
delete inputStart notification.
'
);
console
.
log
(
'
delete inputStart notification.
'
);
});
});
```
```
### on('inputStop')<sup>9+</sup>
### on('inputStop')<sup>9+</sup>
...
@@ -211,11 +207,11 @@ on(type: 'inputStop', callback: () => void): void
...
@@ -211,11 +207,11 @@ on(type: 'inputStop', callback: () => void): void
**示例:**
**示例:**
```
js
```
js
inputMethodEngine
.
getInputMethodEngine
().
on
(
'
inputStop
'
,
()
=>
{
inputMethodEngine
.
getInputMethodEngine
().
on
(
'
inputStop
'
,
()
=>
{
console
.
log
(
'
inputMethodEngine inputStop
'
);
console
.
log
(
'
inputMethodEngine inputStop
'
);
});
});
```
```
### off('inputStop')<sup>9+</sup>
### off('inputStop')<sup>9+</sup>
...
@@ -234,11 +230,11 @@ off(type: 'inputStop', callback: () => void): void
...
@@ -234,11 +230,11 @@ off(type: 'inputStop', callback: () => void): void
**示例:**
**示例:**
```
js
```
js
inputMethodEngine
.
getInputMethodEngine
().
off
(
'
inputStop
'
,
()
=>
{
inputMethodEngine
.
getInputMethodEngine
().
off
(
'
inputStop
'
,
()
=>
{
console
.
log
(
'
inputMethodEngine delete inputStop notification.
'
);
console
.
log
(
'
inputMethodEngine delete inputStop notification.
'
);
});
});
```
```
### on('setCallingWindow')<sup>9+</sup>
### on('setCallingWindow')<sup>9+</sup>
...
@@ -257,11 +253,11 @@ on(type: 'setCallingWindow', callback: (wid:number) => void): void
...
@@ -257,11 +253,11 @@ on(type: 'setCallingWindow', callback: (wid:number) => void): void
**示例:**
**示例:**
```
js
```
js
inputMethodEngine
.
getInputMethodEngine
().
on
(
'
setCallingWindow
'
,
(
wid
)
=>
{
inputMethodEngine
.
getInputMethodEngine
().
on
(
'
setCallingWindow
'
,
(
wid
)
=>
{
console
.
log
(
'
inputMethodEngine setCallingWindow
'
);
console
.
log
(
'
inputMethodEngine setCallingWindow
'
);
});
});
```
```
### off('setCallingWindow')<sup>9+</sup>
### off('setCallingWindow')<sup>9+</sup>
...
@@ -280,11 +276,11 @@ off(type: 'setCallingWindow', callback: (wid:number) => void): void
...
@@ -280,11 +276,11 @@ off(type: 'setCallingWindow', callback: (wid:number) => void): void
**示例:**
**示例:**
```
js
```
js
inputMethodEngine
.
getInputMethodEngine
().
off
(
'
setCallingWindow
'
,
()
=>
{
inputMethodEngine
.
getInputMethodEngine
().
off
(
'
setCallingWindow
'
,
()
=>
{
console
.
log
(
'
inputMethodEngine delete setCallingWindow notification.
'
);
console
.
log
(
'
inputMethodEngine delete setCallingWindow notification.
'
);
});
});
```
```
### on('keyboardShow'|'keyboardHide')
### on('keyboardShow'|'keyboardHide')
...
@@ -303,14 +299,14 @@ on(type: 'keyboardShow'|'keyboardHide', callback: () => void): void
...
@@ -303,14 +299,14 @@ on(type: 'keyboardShow'|'keyboardHide', callback: () => void): void
**示例:**
**示例:**
```
js
```
js
inputMethodEngine
.
getInputMethodEngine
().
on
(
'
keyboardShow
'
,
()
=>
{
inputMethodEngine
.
getInputMethodEngine
().
on
(
'
keyboardShow
'
,
()
=>
{
console
.
log
(
'
inputMethodEngine keyboardShow.
'
);
console
.
log
(
'
inputMethodEngine keyboardShow.
'
);
});
});
inputMethodEngine
.
getInputMethodEngine
().
on
(
'
keyboardHide
'
,
()
=>
{
inputMethodEngine
.
getInputMethodEngine
().
on
(
'
keyboardHide
'
,
()
=>
{
console
.
log
(
'
inputMethodEngine keyboardHide.
'
);
console
.
log
(
'
inputMethodEngine keyboardHide.
'
);
});
});
```
```
### off('keyboardShow'|'keyboardHide')
### off('keyboardShow'|'keyboardHide')
...
@@ -329,14 +325,14 @@ off(type: 'keyboardShow'|'keyboardHide', callback?: () => void): void
...
@@ -329,14 +325,14 @@ off(type: 'keyboardShow'|'keyboardHide', callback?: () => void): void
**示例:**
**示例:**
```
js
```
js
inputMethodEngine
.
getInputMethodEngine
().
off
(
'
keyboardShow
'
,
()
=>
{
inputMethodEngine
.
getInputMethodEngine
().
off
(
'
keyboardShow
'
,
()
=>
{
console
.
log
(
'
inputMethodEngine delete keyboardShow notification.
'
);
console
.
log
(
'
inputMethodEngine delete keyboardShow notification.
'
);
});
});
inputMethodEngine
.
getInputMethodEngine
().
off
(
'
keyboardHide
'
,
()
=>
{
inputMethodEngine
.
getInputMethodEngine
().
off
(
'
keyboardHide
'
,
()
=>
{
console
.
log
(
'
inputMethodEngine delete keyboardHide notification.
'
);
console
.
log
(
'
inputMethodEngine delete keyboardHide notification.
'
);
});
});
```
```
## InputMethodAbility<a name="InputMethodAbility"></a>
## InputMethodAbility<a name="InputMethodAbility"></a>
...
@@ -359,12 +355,12 @@ on(type: 'inputStart', callback: (kbController: KeyboardController, inputClient:
...
@@ -359,12 +355,12 @@ on(type: 'inputStart', callback: (kbController: KeyboardController, inputClient:
**示例:**
**示例:**
```
js
```
js
inputMethodEngine
.
getInputMethodAbility
().
on
(
'
inputStart
'
,
(
kbController
,
inputClient
)
=>
{
inputMethodEngine
.
getInputMethodAbility
().
on
(
'
inputStart
'
,
(
kbController
,
inputClient
)
=>
{
KeyboardController
=
kbController
;
KeyboardController
=
kbController
;
InputClient
=
inputClient
;
InputClient
=
inputClient
;
});
});
```
```
### off('inputStart')<sup>9+</sup>
### off('inputStart')<sup>9+</sup>
...
@@ -383,11 +379,11 @@ off(type: 'inputStart', callback?: (kbController: KeyboardController, inputClien
...
@@ -383,11 +379,11 @@ off(type: 'inputStart', callback?: (kbController: KeyboardController, inputClien
**示例:**
**示例:**
```
js
```
js
inputMethodEngine
.
getInputMethodAbility
().
off
(
'
inputStart
'
,
(
kbController
,
inputClient
)
=>
{
inputMethodEngine
.
getInputMethodAbility
().
off
(
'
inputStart
'
,
(
kbController
,
inputClient
)
=>
{
console
.
log
(
'
delete inputStart notification.
'
);
console
.
log
(
'
delete inputStart notification.
'
);
});
});
```
```
### on('inputStop')<sup>9+</sup>
### on('inputStop')<sup>9+</sup>
...
@@ -406,11 +402,11 @@ on(type: 'inputStop', callback: () => void): void
...
@@ -406,11 +402,11 @@ on(type: 'inputStop', callback: () => void): void
**示例:**
**示例:**
```
js
```
js
inputMethodEngine
.
getInputMethodAbility
().
on
(
'
inputStop
'
,
()
=>
{
inputMethodEngine
.
getInputMethodAbility
().
on
(
'
inputStop
'
,
()
=>
{
console
.
log
(
'
inputMethodAbility inputStop
'
);
console
.
log
(
'
inputMethodAbility inputStop
'
);
});
});
```
```
### off('inputStop')<sup>9+</sup>
### off('inputStop')<sup>9+</sup>
...
@@ -429,11 +425,11 @@ off(type: 'inputStop', callback: () => void): void
...
@@ -429,11 +425,11 @@ off(type: 'inputStop', callback: () => void): void
**示例:**
**示例:**
```
js
```
js
inputMethodEngine
.
getInputMethodAbility
().
off
(
'
inputStop
'
,
()
=>
{
inputMethodEngine
.
getInputMethodAbility
().
off
(
'
inputStop
'
,
()
=>
{
console
.
log
(
'
inputMethodAbility delete inputStop notification.
'
);
console
.
log
(
'
inputMethodAbility delete inputStop notification.
'
);
});
});
```
```
### on('setCallingWindow')<sup>9+</sup>
### on('setCallingWindow')<sup>9+</sup>
...
@@ -452,11 +448,11 @@ on(type: 'setCallingWindow', callback: (wid:number) => void): void
...
@@ -452,11 +448,11 @@ on(type: 'setCallingWindow', callback: (wid:number) => void): void
**示例:**
**示例:**
```
js
```
js
inputMethodEngine
.
getInputMethodAbility
().
on
(
'
setCallingWindow
'
,
(
wid
)
=>
{
inputMethodEngine
.
getInputMethodAbility
().
on
(
'
setCallingWindow
'
,
(
wid
)
=>
{
console
.
log
(
'
inputMethodAbility setCallingWindow
'
);
console
.
log
(
'
inputMethodAbility setCallingWindow
'
);
});
});
```
```
### off('setCallingWindow')<sup>9+</sup>
### off('setCallingWindow')<sup>9+</sup>
...
@@ -475,11 +471,11 @@ off(type: 'setCallingWindow', callback: (wid:number) => void): void
...
@@ -475,11 +471,11 @@ off(type: 'setCallingWindow', callback: (wid:number) => void): void
**示例:**
**示例:**
```
js
```
js
inputMethodEngine
.
getInputMethodAbility
().
off
(
'
setCallingWindow
'
,
()
=>
{
inputMethodEngine
.
getInputMethodAbility
().
off
(
'
setCallingWindow
'
,
()
=>
{
console
.
log
(
'
inputMethodAbility delete setCallingWindow notification.
'
);
console
.
log
(
'
inputMethodAbility delete setCallingWindow notification.
'
);
});
});
```
```
### on('keyboardShow'|'keyboardHide')<sup>9+</sup>
### on('keyboardShow'|'keyboardHide')<sup>9+</sup>
...
@@ -498,14 +494,14 @@ on(type: 'keyboardShow'|'keyboardHide', callback: () => void): void
...
@@ -498,14 +494,14 @@ on(type: 'keyboardShow'|'keyboardHide', callback: () => void): void
**示例:**
**示例:**
```
js
```
js
inputMethodEngine
.
getInputMethodAbility
().
on
(
'
keyboardShow
'
,
()
=>
{
inputMethodEngine
.
getInputMethodAbility
().
on
(
'
keyboardShow
'
,
()
=>
{
console
.
log
(
'
InputMethodAbility keyboardShow.
'
);
console
.
log
(
'
InputMethodAbility keyboardShow.
'
);
});
});
inputMethodEngine
.
getInputMethodAbility
().
on
(
'
keyboardHide
'
,
()
=>
{
inputMethodEngine
.
getInputMethodAbility
().
on
(
'
keyboardHide
'
,
()
=>
{
console
.
log
(
'
InputMethodAbility keyboardHide.
'
);
console
.
log
(
'
InputMethodAbility keyboardHide.
'
);
});
});
```
```
### off('keyboardShow'|'keyboardHide')<sup>9+</sup>
### off('keyboardShow'|'keyboardHide')<sup>9+</sup>
...
@@ -524,14 +520,14 @@ off(type: 'keyboardShow'|'keyboardHide', callback?: () => void): void
...
@@ -524,14 +520,14 @@ off(type: 'keyboardShow'|'keyboardHide', callback?: () => void): void
**示例:**
**示例:**
```
js
```
js
inputMethodEngine
.
getInputMethodAbility
().
off
(
'
keyboardShow
'
,
()
=>
{
inputMethodEngine
.
getInputMethodAbility
().
off
(
'
keyboardShow
'
,
()
=>
{
console
.
log
(
'
InputMethodAbility delete keyboardShow notification.
'
);
console
.
log
(
'
InputMethodAbility delete keyboardShow notification.
'
);
});
});
inputMethodEngine
.
getInputMethodAbility
().
off
(
'
keyboardHide
'
,
()
=>
{
inputMethodEngine
.
getInputMethodAbility
().
off
(
'
keyboardHide
'
,
()
=>
{
console
.
log
(
'
InputMethodAbility delete keyboardHide notification.
'
);
console
.
log
(
'
InputMethodAbility delete keyboardHide notification.
'
);
});
});
```
```
### on('setSubtype')<sup>9+</sup>
### on('setSubtype')<sup>9+</sup>
...
@@ -550,11 +546,11 @@ on(type: 'setSubtype', callback: (inputMethodSubtype: InputMethodSubtype) => voi
...
@@ -550,11 +546,11 @@ on(type: 'setSubtype', callback: (inputMethodSubtype: InputMethodSubtype) => voi
**示例:**
**示例:**
```
js
```
js
inputMethodEngine
.
getInputMethodAbility
().
on
(
'
setSubtype
'
,
(
inputMethodSubtype
)
=>
{
inputMethodEngine
.
getInputMethodAbility
().
on
(
'
setSubtype
'
,
(
inputMethodSubtype
)
=>
{
console
.
log
(
'
InputMethodAbility setSubtype.
'
);
console
.
log
(
'
InputMethodAbility setSubtype.
'
);
});
});
```
```
### off('setSubtype')<sup>9+</sup>
### off('setSubtype')<sup>9+</sup>
...
@@ -573,11 +569,11 @@ off(type: 'setSubtype', callback?: () => void): void
...
@@ -573,11 +569,11 @@ off(type: 'setSubtype', callback?: () => void): void
**示例:**
**示例:**
```
js
```
js
inputMethodEngine
.
getInputMethodAbility
().
off
(
'
setSubtype
'
,
()
=>
{
inputMethodEngine
.
getInputMethodAbility
().
off
(
'
setSubtype
'
,
()
=>
{
console
.
log
(
'
InputMethodAbility delete setSubtype notification.
'
);
console
.
log
(
'
InputMethodAbility delete setSubtype notification.
'
);
});
});
```
```
## KeyboardDelegate<a name="KeyboardDelegate"></a>
## KeyboardDelegate<a name="KeyboardDelegate"></a>
...
@@ -600,18 +596,18 @@ on(type: 'keyDown'|'keyUp', callback: (event: KeyEvent) => boolean): void
...
@@ -600,18 +596,18 @@ on(type: 'keyDown'|'keyUp', callback: (event: KeyEvent) => boolean): void
**示例:**
**示例:**
```
js
```
js
inputMethodEngine
.
getKeyboardDelegate
().
on
(
'
keyUp
'
,
(
keyEvent
)
=>
{
inputMethodEngine
.
getKeyboardDelegate
().
on
(
'
keyUp
'
,
(
keyEvent
)
=>
{
console
.
info
(
'
inputMethodEngine keyCode.(keyUp):
'
+
JSON
.
stringify
(
keyEvent
.
keyCode
));
console
.
info
(
'
inputMethodEngine keyCode.(keyUp):
'
+
JSON
.
stringify
(
keyEvent
.
keyCode
));
console
.
info
(
'
inputMethodEngine keyAction.(keyUp):
'
+
JSON
.
stringify
(
keyEvent
.
keyAction
));
console
.
info
(
'
inputMethodEngine keyAction.(keyUp):
'
+
JSON
.
stringify
(
keyEvent
.
keyAction
));
return
true
;
return
true
;
});
});
inputMethodEngine
.
getKeyboardDelegate
().
on
(
'
keyDown
'
,
(
keyEvent
)
=>
{
inputMethodEngine
.
getKeyboardDelegate
().
on
(
'
keyDown
'
,
(
keyEvent
)
=>
{
console
.
info
(
'
inputMethodEngine keyCode.(keyDown):
'
+
JSON
.
stringify
(
keyEvent
.
keyCode
));
console
.
info
(
'
inputMethodEngine keyCode.(keyDown):
'
+
JSON
.
stringify
(
keyEvent
.
keyCode
));
console
.
info
(
'
inputMethodEngine keyAction.(keyDown):
'
+
JSON
.
stringify
(
keyEvent
.
keyAction
));
console
.
info
(
'
inputMethodEngine keyAction.(keyDown):
'
+
JSON
.
stringify
(
keyEvent
.
keyAction
));
return
true
;
return
true
;
});
});
```
```
### off('keyDown'|'keyUp')
### off('keyDown'|'keyUp')
...
@@ -630,16 +626,16 @@ off(type: 'keyDown'|'keyUp', callback?: (event: KeyEvent) => boolean): void
...
@@ -630,16 +626,16 @@ off(type: 'keyDown'|'keyUp', callback?: (event: KeyEvent) => boolean): void
**示例:**
**示例:**
```
js
```
js
inputMethodEngine
.
getKeyboardDelegate
().
off
(
'
keyUp
'
,
(
keyEvent
)
=>
{
inputMethodEngine
.
getKeyboardDelegate
().
off
(
'
keyUp
'
,
(
keyEvent
)
=>
{
console
.
log
(
'
delete keyUp notification.
'
);
console
.
log
(
'
delete keyUp notification.
'
);
return
true
;
return
true
;
});
});
inputMethodEngine
.
getKeyboardDelegate
().
off
(
'
keyDown
'
,
(
keyEvent
)
=>
{
inputMethodEngine
.
getKeyboardDelegate
().
off
(
'
keyDown
'
,
(
keyEvent
)
=>
{
console
.
log
(
'
delete keyDown notification.
'
);
console
.
log
(
'
delete keyDown notification.
'
);
return
true
;
return
true
;
});
});
```
```
### on('cursorContextChange')
### on('cursorContextChange')
...
@@ -843,53 +839,51 @@ async function InputMethodEngine() {
...
@@ -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
<
string
>
): void
### sendKeyFunction<sup>9+</sup>
获取光标前固定长度的文本。使用callback形式返回结果。参数个数为2,否则抛出异常。
sendKeyFunction(action:number, callback: AsyncCallback
<
boolean
>
): void
> **说明:**
发送功能键。使用callback形式返回结果。参数个数为2,否则抛出异常。
> 从API version 9开始废弃, 建议使用[getForward](#getforward9)替代
>
> 从 API version 8开始支持。
**系统能力**
: SystemCapability.MiscServices.InputMethodFramework
**系统能力**
: SystemCapability.MiscServices.InputMethodFramework
**参数:**
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| -------- | -------- | -------- | -------- |
|
length | number | 是 | 文本长度
。 |
|
action | number | 是 | 编辑框属性
。 |
| callback | AsyncCallback
<
string
>
| 是 | 返回文本
。 |
| callback | AsyncCallback
<
boolean
>
| 是 | 操作成功与否
。 |
**示例:**
**示例:**
```
js
```
js
var
length
=
1
;
try
{
TextInputClient
.
getForward
(
length
,
(
err
,
tex
t
)
=>
{
InputClient
.
sendKeyFunction
(
keyFunction
,
(
err
,
resul
t
)
=>
{
if
(
err
===
undefined
)
{
if
(
err
)
{
console
.
error
(
'
getForward callback result---err:
'
+
JSON
.
stringify
(
err
));
console
.
error
(
'
sendKeyFunction err:
'
+
JSON
.
stringify
(
err
)
JSON
.
stringify
(
err
));
return
;
return
;
}
}
console
.
log
(
'
getForward callback result---text:
'
+
text
);
if
(
result
)
{
console
.
info
(
'
Success to sendKeyFunction.(callback)
'
);
}
else
{
console
.
error
(
'
Failed to sendKeyFunction.(callback)
'
);
}
});
});
```
}
catch
(
err
)
{
console
.
error
(
'
sendKeyFunction err:
'
+
JSON
.
stringify
(
err
));
### getForward<sup>(deprecated)</sup>
}
```
getForward(length:number): Promise
<
string
>
### sendKeyFunction<sup>9+</sup>
获取光标前固定长度的文本。使用promise形式返回结果。参数个数为1,否则抛出异常。
sendKeyFunction(action:number): Promise
<
boolean
>
> **说明:**
发送功能键。使用promise形式返回结果。参数个数为1,否则抛出异常。
> 从API version 9开始废弃, 建议使用[getForward](#getforward9)替代
>
> 从 API version 8开始支持。
**系统能力**
: SystemCapability.MiscServices.InputMethodFramework
**系统能力**
: SystemCapability.MiscServices.InputMethodFramework
...
@@ -897,37 +891,37 @@ getForward(length:number): Promise<string>
...
@@ -897,37 +891,37 @@ getForward(length:number): Promise<string>
| 参数名 | 类型 | 必填 | 说明 |
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| -------- | -------- | -------- | -------- |
|
length | number | 是 | 文本长度
。 |
|
action | number | 是 | 编辑框属性
。 |
**返回值:**
**返回值:**
| 类型 | 说明 |
| 类型 | 说明 |
| ------------------------------- | ------------------------------------------------------------ |
| ------------------------------- | ------------------------------------------------------------ |
| Promise
<
string
>
| 返回文本
。 |
| Promise
<
boolean
>
| 操作成功与否
。 |
**示例:**
**示例:**
```
js
```
js
async
function
InputMethodEngine
()
{
try
{
var
length
=
1
;
InputClient
.
sendKeyFunction
(
keyFunction
).
then
((
result
)
=>
{
await
TextInputClient
.
getForward
(
length
).
then
((
text
)
=>
{
if
(
result
)
{
console
.
info
(
'
getForward promise result---res:
'
+
text
);
console
.
info
(
'
Success to sendKeyFunction.(callback)
'
);
}
else
{
console
.
error
(
'
Failed to sendKeyFunction.(callback)
'
);
}
}).
catch
((
err
)
=>
{
}).
catch
((
err
)
=>
{
console
.
error
(
'
getForward promise err:
'
+
JSON
.
stringify
(
err
));
console
.
error
(
'
sendKeyFunction promise err:
'
+
JSON
.
stringify
(
err
));
});
});
}
}
catch
(
err
)
{
```
console
.
error
(
'
sendKeyFunction err:
'
+
JSON
.
stringify
(
err
));
}
### getBackward<sup>(deprecated)</sup>
```
getBackward(length:number, callback: AsyncCallback
<
string
>
): void
### getForward<sup>9+</sup>
获取光标后固定长度的文本。使用callback形式返回结果。参数个数为2,否则抛出异常。
getForward(length:number, callback: AsyncCallback
<
string
>
): void
> **说明:**
获取光标前固定长度的文本。使用callback形式返回结果。参数个数为2,否则抛出异常。
> 从API version 9开始废弃, 建议使用[getBackward](#getbackward9)替代
>
> 从 API version 8开始支持。
**系统能力**
: SystemCapability.MiscServices.InputMethodFramework
**系统能力**
: SystemCapability.MiscServices.InputMethodFramework
...
@@ -940,27 +934,26 @@ getBackward(length:number, callback: AsyncCallback<string>): void
...
@@ -940,27 +934,26 @@ getBackward(length:number, callback: AsyncCallback<string>): void
**示例:**
**示例:**
```
js
```
js
var
length
=
1
;
let
length
=
1
;
TextInputClient
.
getBackward
(
length
,
(
err
,
text
)
=>
{
try
{
if
(
err
===
undefined
)
{
InputClient
.
getForward
(
length
,
(
err
,
text
)
=>
{
console
.
error
(
'
getBackward callback result---err:
'
+
JSON
.
stringify
(
err
));
if
(
err
)
{
console
.
error
(
'
getForward err:
'
+
JSON
.
stringify
(
err
));
return
;
return
;
}
}
console
.
log
(
'
getBackward callback result---tex
t:
'
+
text
);
console
.
log
(
'
getForward callback resul
t:
'
+
text
);
});
});
```
}
catch
(
err
)
{
console
.
error
(
'
getForward err:
'
+
JSON
.
stringify
(
err
));
### getBackward<sup>(deprecated)</sup>
}
```
getBackward(length:number): Promise
<
string
>
### getForward<sup>9+</sup>
获取光标后固定长度的文本。使用promise形式返回结果。参数个数为1,否则抛出异常。
getForward(length:number): Promise
<
string
>
> **说明:**
获取光标前固定长度的文本。使用promise形式返回结果。参数个数为1,否则抛出异常。
> 从API version 9开始废弃, 建议使用[getBackward](#getbackward9)替代
>
> 从 API version 8开始支持。
**系统能力**
: SystemCapability.MiscServices.InputMethodFramework
**系统能力**
: SystemCapability.MiscServices.InputMethodFramework
...
@@ -978,27 +971,26 @@ getBackward(length:number): Promise<string>
...
@@ -978,27 +971,26 @@ getBackward(length:number): Promise<string>
**示例:**
**示例:**
```
js
```
js
async
function
InputMethodEngine
()
{
async
function
InputMethodAbility
()
{
var
length
=
1
;
let
length
=
1
;
await
TextInputClient
.
getBackward
(
length
).
then
((
text
)
=>
{
try
{
console
.
info
(
'
getBackward promise result---res:
'
+
text
);
await
InputClient
.
getForward
(
length
).
then
((
text
)
=>
{
console
.
info
(
'
getForward promise resul:
'
+
text
);
}).
catch
((
err
)
=>
{
}).
catch
((
err
)
=>
{
console
.
error
(
'
getBack
ward promise err:
'
+
JSON
.
stringify
(
err
));
console
.
error
(
'
getFor
ward promise err:
'
+
JSON
.
stringify
(
err
));
});
});
}
catch
(
err
)
{
console
.
error
(
'
getForward promise err:
'
+
JSON
.
stringify
(
err
));
}
}
```
}
```
### deleteForward<sup>(deprecated)</sup>
deleteForward(length:number, callback: AsyncCallback
<
boolean
>
): void
### getBackward<sup>9+</sup>
删除光标前固定长度的文本。使用callback形式返回结果。参数个数为2,否则抛出异常。
getBackward(length:number, callback: AsyncCallback
<
string
>
): void
> **说明:**
获取光标后固定长度的文本。使用callback形式返回结果。参数个数为2,否则抛出异常。
> 从API version 9开始废弃, 建议使用[deleteForward](#deleteforward9)替代
>
> 从 API version 8开始支持。
**系统能力**
: SystemCapability.MiscServices.InputMethodFramework
**系统能力**
: SystemCapability.MiscServices.InputMethodFramework
...
@@ -1007,190 +999,180 @@ deleteForward(length:number, callback: AsyncCallback<boolean>): void
...
@@ -1007,190 +999,180 @@ deleteForward(length:number, callback: AsyncCallback<boolean>): void
| 参数名 | 类型 | 必填 | 说明 |
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| -------- | -------- | -------- | -------- |
| length | number | 是 | 文本长度。 |
| length | number | 是 | 文本长度。 |
| callback | AsyncCallback
<
boolean
>
| 是 | 操作成功与否
。 |
| callback | AsyncCallback
<
string
>
| 是 | 返回文本
。 |
**示例:**
**示例:**
```
js
```
js
var
length
=
1
;
let
length
=
1
;
TextInputClient
.
deleteForward
(
length
,
(
err
,
result
)
=>
{
try
{
if
(
err
===
undefined
)
{
InputClient
.
getBackward
(
length
,
(
err
,
text
)
=>
{
console
.
error
(
'
deleteForward callback result---err:
'
+
JSON
.
stringify
(
err
));
if
(
err
)
{
console
.
error
(
'
getBackward callback result:
'
+
JSON
.
stringify
(
err
));
return
;
return
;
}
}
if
(
result
)
{
console
.
log
(
'
getBackward callback result---text:
'
+
text
);
console
.
info
(
'
Success to deleteForward.(callback)
'
);
}
else
{
console
.
error
(
'
Failed to deleteForward.(callback)
'
);
}
});
});
```
}
catch
(
err
)
{
### deleteForward<sup>(deprecated)</sup>
console
.
error
(
'
getBackward callback result:
'
+
JSON
.
stringify
(
err
));
}
```
deleteForward(length:number): Promise
<
boolean
>
### getBackward<sup>9+</sup>
删除光标前固定长度的文本。使用promise形式返回结果。参数个数为1,否则抛出异常。
getBackward(length:number): Promise
<
string
>
> **说明:**
获取光标后固定长度的文本。使用promise形式返回结果。参数个数为1,否则抛出异常。
> 从API version 9开始废弃, 建议使用[deleteForward](#deleteforward9)替代
>
> 从 API version 8开始支持。
**系统能力**
: SystemCapability.MiscServices.InputMethodFramework
**系统能力**
: SystemCapability.MiscServices.InputMethodFramework
**参数:**
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| 参数名 | 类型 | 必填 | 说明 |
| ------
| ------ | ---- | --
-------- |
| ------
-- | -------- | -------- |
-------- |
| length | number | 是 | 文本长度。 |
| length | number | 是 | 文本长度。 |
**返回值:**
**返回值:**
| 类型 | 说明 |
| 类型 | 说明 |
| ----------------------
|
-------------- |
| ----------------------
--------- | ----------------------------------------------
-------------- |
| Promise
<
boolean
>
| 操作成功与否。
|
| Promise
<
string
>
| 返回文本。
|
**示例:**
**示例:**
```
js
```
js
async
function
InputMethodEngine
()
{
async
function
InputMethodAbility
()
{
var
length
=
1
;
let
length
=
1
;
await
TextInputClient
.
deleteForward
(
length
).
then
((
result
)
=>
{
try
{
if
(
result
)
{
await
InputClient
.
getBackward
(
length
).
then
((
text
)
=>
{
console
.
info
(
'
Success to deleteForward.(promise)
'
);
console
.
info
(
'
getBackward promise result:
'
+
text
);
}
else
{
console
.
error
(
'
Failed to deleteForward.(promise)
'
);
}
}).
catch
((
err
)
=>
{
}).
catch
((
err
)
=>
{
console
.
error
(
'
deleteFor
ward promise err:
'
+
JSON
.
stringify
(
err
));
console
.
error
(
'
getBack
ward promise err:
'
+
JSON
.
stringify
(
err
));
});
});
}
catch
(
err
)
{
console
.
error
(
'
getBackward promise err:
'
+
JSON
.
stringify
(
err
));
}
}
}
```
```
### deleteBackward<sup>(deprecated)</sup>
### deleteForward<sup>9+</sup>
deleteBackward(length:number, callback: AsyncCallback
<
boolean
>
): void
删除光标后固定长度的文本。使用callback形式返回结果。参数个数为2,否则抛出异常。
deleteForward(length:number, callback: AsyncCallback
<
boolean
>
): void
> **说明:**
删除光标前固定长度的文本。使用callback形式返回结果。参数个数为2,否则抛出异常。
> 从API version 9开始废弃, 建议使用[deleteBackward](#deletebackward9)替代
>
> 从 API version 8开始支持。
**系统能力**
: SystemCapability.MiscServices.InputMethodFramework
**系统能力**
: SystemCapability.MiscServices.InputMethodFramework
**参数:**
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| 参数名 | 类型 | 必填 | 说明 |
| -------- | --------
-------------------- | ---- | ------
-------- |
| -------- | --------
| -------- |
-------- |
| length | number | 是 | 文本长度。 |
| length | number | 是 | 文本长度。 |
| callback | AsyncCallback
<
boolean
>
| 是 | 操作成功与否。 |
| callback | AsyncCallback
<
boolean
>
| 是 | 操作成功与否。 |
**示例:**
**示例:**
```
js
```
js
var
length
=
1
;
let
length
=
1
;
TextInputClient
.
deleteBackward
(
length
,
(
err
,
result
)
=>
{
try
{
if
(
err
===
undefined
)
{
InputClient
.
deleteForward
(
length
,
(
err
,
result
)
=>
{
console
.
error
(
'
deleteBackward callback result---err:
'
+
JSON
.
stringify
(
err
));
if
(
err
)
{
console
.
error
(
'
deleteForward callback result:
'
+
JSON
.
stringify
(
err
));
return
;
return
;
}
}
if
(
result
)
{
if
(
result
)
{
console
.
info
(
'
Success to deleteBack
ward.(callback)
'
);
console
.
info
(
'
Success to deleteFor
ward.(callback)
'
);
}
else
{
}
else
{
console
.
error
(
'
Failed to deleteBack
ward.(callback)
'
);
console
.
error
(
'
Failed to deleteFor
ward.(callback)
'
);
}
}
});
});
}
catch
(
err
)
{
console
.
error
(
'
deleteForward callback result:
'
+
JSON
.
stringify
(
err
));
}
```
```
### deleteBackward<sup>(deprecated)</sup>
### deleteForward<sup>9+</sup>
deleteBackward(length:number): Promise
<
boolean
>
删除光标后固定长度的文本。使用callback形式返回结果。参数个数为2,否则抛出异常。
deleteForward(length:number): Promise
<
boolean
>
> **说明:**
删除光标前固定长度的文本。使用promise形式返回结果。参数个数为1,否则抛出异常。
> 从API version 9开始废弃, 建议使用[deleteBackward](#deletebackward9)替代
>
> 从 API version 8开始支持。
**系统能力**
: SystemCapability.MiscServices.InputMethodFramework
**系统能力**
: SystemCapability.MiscServices.InputMethodFramework
**参数:**
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| 参数名 | 类型 | 必填 | 说明 |
| ------
-- | -------- | -------- |
-------- |
| ------
| ------ | ---- | --
-------- |
| length | number | 是 | 文本长度。 |
| length | number | 是 | 文本长度。 |
**返回值:**
**返回值:**
| 类型 | 说明 |
| 类型 | 说明 |
| ----------------------
--------- | ----------------------------------------------
-------------- |
| ----------------------
|
-------------- |
| Promise
<
boolean
>
| 操作成功与否。 |
| Promise
<
boolean
>
| 操作成功与否。 |
**示例:**
**示例:**
```
js
```
js
async
function
InputMethodEngine
()
{
async
function
InputMethodAbility
()
{
var
length
=
1
;
let
length
=
1
;
await
TextInputClient
.
deleteBackward
(
length
).
then
((
result
)
=>
{
try
{
await
InputClient
.
deleteForward
(
length
).
then
((
result
)
=>
{
if
(
result
)
{
if
(
result
)
{
console
.
info
(
'
Success to deleteBack
ward.(promise)
'
);
console
.
info
(
'
Success to deleteFor
ward.(promise)
'
);
}
else
{
}
else
{
console
.
error
(
'
Failed to deleteBack
ward.(promise)
'
);
console
.
error
(
'
Failed to deleteFor
ward.(promise)
'
);
}
}
}).
catch
((
err
)
=>
{
}).
catch
((
err
)
=>
{
console
.
error
(
'
deleteBack
ward promise err:
'
+
JSON
.
stringify
(
err
));
console
.
error
(
'
deleteFor
ward promise err:
'
+
JSON
.
stringify
(
err
));
});
});
}
catch
(
err
)
{
console
.
error
(
'
deleteForward promise err:
'
+
JSON
.
stringify
(
err
));
}
}
}
```
```
### sendKeyFunction<sup>(deprecated)</sup>
sendKeyFunction(action:number, callback: AsyncCallback
<
boolean
>
): void
### deleteBackward<sup>9+</sup>
发送功能键。使用callback形式返回结果。参数个数为2,否则抛出异常。
deleteBackward(length:number, callback: AsyncCallback
<
boolean
>
): void
> **说明:**
删除光标后固定长度的文本。使用callback形式返回结果。参数个数为2,否则抛出异常。
> 从API version 9开始废弃, 建议使用[sendKeyFunction](#sendkeyfunction9)替代
>
> 从 API version 8开始支持。
**系统能力**
: SystemCapability.MiscServices.InputMethodFramework
**系统能力**
: SystemCapability.MiscServices.InputMethodFramework
**参数:**
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| 参数名 | 类型 | 必填 | 说明 |
| -------- | --------
| -------- |
-------- |
| -------- | --------
-------------------- | ---- | ------
-------- |
|
action | number | 是 | 编辑框属性。
|
|
length | number | 是 | 文本长度。
|
| callback | AsyncCallback
<
boolean
>
| 是 | 操作成功与否。 |
| callback | AsyncCallback
<
boolean
>
| 是 | 操作成功与否。 |
**示例:**
**示例:**
```
js
```
js
TextInputClient
.
sendKeyFunction
(
keyFunction
,
(
err
,
result
)
=>
{
let
length
=
1
;
if
(
err
===
undefined
)
{
try
{
console
.
error
(
'
sendKeyFunction callback result---err:
'
+
JSON
.
stringify
(
err
));
InputClient
.
deleteBackward
(
length
,
(
err
,
result
)
=>
{
if
(
err
)
{
console
.
error
(
'
deleteBackward err:
'
+
JSON
.
stringify
(
err
));
return
;
return
;
}
}
if
(
result
)
{
if
(
result
)
{
console
.
info
(
'
Success to sendKeyFunction
.(callback)
'
);
console
.
info
(
'
Success to deleteBackward
.(callback)
'
);
}
else
{
}
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>
### deleteBackward<sup>9+</sup>
sendKeyFunction(action:number): Promise
<
boolean
>
发送功能键。使用promise形式返回结果。参数个数为1,否则抛出异常。
deleteBackward(length:number): Promise
<
boolean
>
> **说明:**
删除光标后固定长度的文本。使用callback形式返回结果。参数个数为2,否则抛出异常。
> 从API version 9开始废弃, 建议使用[sendKeyFunction](#sendkeyfunction9)替代
>
> 从 API version 8开始支持。
**系统能力**
: SystemCapability.MiscServices.InputMethodFramework
**系统能力**
: SystemCapability.MiscServices.InputMethodFramework
...
@@ -1198,7 +1180,7 @@ sendKeyFunction(action:number): Promise<boolean>
...
@@ -1198,7 +1180,7 @@ sendKeyFunction(action:number): Promise<boolean>
| 参数名 | 类型 | 必填 | 说明 |
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| -------- | -------- | -------- | -------- |
|
action | number | 是 | 编辑框属性
。 |
|
length | number | 是 | 文本长度
。 |
**返回值:**
**返回值:**
...
@@ -1208,31 +1190,27 @@ sendKeyFunction(action:number): Promise<boolean>
...
@@ -1208,31 +1190,27 @@ sendKeyFunction(action:number): Promise<boolean>
**示例:**
**示例:**
```
js
```
js
async
function
InputMethodEngine
()
{
async
function
InputMethodAbility
()
{
await
client
.
sendKeyFunction
(
keyFunction
).
then
((
result
)
=>
{
let
length
=
1
;
await
InputClient
.
deleteBackward
(
length
).
then
((
result
)
=>
{
if
(
result
)
{
if
(
result
)
{
console
.
info
(
'
Success to sendKeyFunction
.(promise)
'
);
console
.
info
(
'
Success to deleteBackward
.(promise)
'
);
}
else
{
}
else
{
console
.
error
(
'
Failed to sendKeyFunction
.(promise)
'
);
console
.
error
(
'
Failed to deleteBackward
.(promise)
'
);
}
}
}).
catch
((
err
)
=>
{
}).
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
<
boolean
>
): void
insertText(text:string, callback: AsyncCallback
<
boolean
>
): void
插入文本。使用callback形式返回结果。参数个数为2,否则抛出异常。
插入文本。使用callback形式返回结果。参数个数为2,否则抛出异常。
> **说明:**
> 从API version 9开始废弃, 建议使用[insertText](#inserttext9)替代
>
> 从 API version 8开始支持。
**系统能力**
: SystemCapability.MiscServices.InputMethodFramework
**系统能力**
: SystemCapability.MiscServices.InputMethodFramework
**参数:**
**参数:**
...
@@ -1245,9 +1223,9 @@ insertText(text:string, callback: AsyncCallback<boolean>): void
...
@@ -1245,9 +1223,9 @@ insertText(text:string, callback: AsyncCallback<boolean>): void
**示例:**
**示例:**
```
js
```
js
Text
InputClient
.
insertText
(
'
test
'
,
(
err
,
result
)
=>
{
InputClient
.
insertText
(
'
test
'
,
(
err
,
result
)
=>
{
if
(
err
===
undefined
)
{
if
(
err
)
{
console
.
error
(
'
insertText
callback result---
err:
'
+
JSON
.
stringify
(
err
));
console
.
error
(
'
insertText err:
'
+
JSON
.
stringify
(
err
));
return
;
return
;
}
}
if
(
result
)
{
if
(
result
)
{
...
@@ -1258,17 +1236,12 @@ TextInputClient.insertText('test', (err, result) => {
...
@@ -1258,17 +1236,12 @@ TextInputClient.insertText('test', (err, result) => {
});
});
```
```
### insertText<sup>
(deprecated)
</sup>
### insertText<sup>
9+
</sup>
insertText(text:string): Promise
<
boolean
>
insertText(text:string): Promise
<
boolean
>
插入文本。使用promise形式返回结果。参数个数为1,否则抛出异常。
插入文本。使用promise形式返回结果。参数个数为1,否则抛出异常。
> **说明:**
> 从API version 9开始废弃, 建议使用[insertText](#inserttext9)替代
>
> 从 API version 8开始支持。
**系统能力**
: SystemCapability.MiscServices.InputMethodFramework
**系统能力**
: SystemCapability.MiscServices.InputMethodFramework
**参数:**
**参数:**
...
@@ -1285,9 +1258,10 @@ insertText(text:string): Promise<boolean>
...
@@ -1285,9 +1258,10 @@ insertText(text:string): Promise<boolean>
**示例:**
**示例:**
```
js
```
js
async
function
InputMethodEngine
()
{
async
function
InputMethodAbility
()
{
await
TextInputClient
.
insertText
(
'
test
'
).
then
((
result
)
=>
{
try
{
await
InputClient
.
insertText
(
'
test
'
).
then
((
result
)
=>
{
if
(
result
)
{
if
(
result
)
{
console
.
info
(
'
Success to insertText.(promise)
'
);
console
.
info
(
'
Success to insertText.(promise)
'
);
}
else
{
}
else
{
...
@@ -1296,52 +1270,45 @@ insertText(text:string): Promise<boolean>
...
@@ -1296,52 +1270,45 @@ insertText(text:string): Promise<boolean>
}).
catch
((
err
)
=>
{
}).
catch
((
err
)
=>
{
console
.
error
(
'
insertText promise err:
'
+
JSON
.
stringify
(
err
));
console
.
error
(
'
insertText promise err:
'
+
JSON
.
stringify
(
err
));
});
});
}
catch
(
e
)
{
console
.
error
(
'
insertText promise err:
'
+
JSON
.
stringify
(
err
));
}
}
```
}
```
### getEditorAttribute<sup>
(deprecated)
</sup>
### getEditorAttribute<sup>
9+
</sup>
getEditorAttribute(callback: AsyncCallback
<
EditorAttribute
>
): void
getEditorAttribute(callback: AsyncCallback
<
EditorAttribute
>
): void
获取编辑框属性值。使用callback形式返回结果。参数个数为1,否则抛出异常。
获取编辑框属性值。使用callback形式返回结果。参数个数为1,否则抛出异常。
> **说明:**
> 从API version 9开始废弃, 建议使用[getEditorAttribute](#geteditorattribute9)替代
>
> 从 API version 8开始支持。
**系统能力**
: SystemCapability.MiscServices.InputMethodFramework
**系统能力**
: SystemCapability.MiscServices.InputMethodFramework
**参数:**
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| 参数名 | 类型 | 必填 | 说明 |
| ------------------------------- | ------------------------------------------------------------ | ------------------------------------------------------------ | ------------------------------------------------------------ |
| ------------------------------- | ------------------------------------------------------------ | ------------------------------------------------------------ | ------------------------------------------------------------ |
| callback | AsyncCallback
<
[EditorAttribute](#
editora
ttribute)
>
| 是 | 编辑框属性值。 |
| callback | AsyncCallback
<
[EditorAttribute](#
EditorA
ttribute)
>
| 是 | 编辑框属性值。 |
**示例:**
**示例:**
```
js
```
js
Text
InputClient
.
getEditorAttribute
((
err
,
editorAttribute
)
=>
{
InputClient
.
getEditorAttribute
((
err
,
editorAttribute
)
=>
{
if
(
err
===
undefined
)
{
if
(
err
)
{
console
.
error
(
'
getEditorAttribute callback result---err:
'
+
JSON
.
stringify
(
err
));
console
.
error
(
'
getEditorAttribute callback result---err:
'
+
JSON
.
stringify
(
err
));
return
;
return
;
}
}
console
.
log
(
'
editorAttribute.inputPattern(callback):
'
+
JSON
.
stringify
(
editorAttribute
.
inputPattern
));
console
.
log
(
'
editorAttribute.inputPattern(callback):
'
+
JSON
.
stringify
(
editorAttribute
.
inputPattern
));
console
.
log
(
'
editorAttribute.enterKeyType(callback):
'
+
JSON
.
stringify
(
editorAttribute
.
enterKeyType
));
console
.
log
(
'
editorAttribute.enterKeyType(callback):
'
+
JSON
.
stringify
(
editorAttribute
.
enterKeyType
));
});
});
```
```
### getEditorAttribute<sup>
(deprecated)
</sup>
### getEditorAttribute<sup>
9+
</sup>
getEditorAttribute(): Promise
<
EditorAttribute
>
getEditorAttribute(): Promise
<
EditorAttribute
>
获取编辑框属性值。使用promise形式返回结果。参数个数为0,否则抛出异常。
获取编辑框属性值。使用promise形式返回结果。参数个数为0,否则抛出异常。
> **说明:**
> 从API version 9开始废弃, 建议使用[getEditorAttribute](#geteditorattribute9)替代
>
> 从 API version 8开始支持。
**系统能力**
: SystemCapability.MiscServices.InputMethodFramework
**系统能力**
: SystemCapability.MiscServices.InputMethodFramework
**返回值:**
**返回值:**
...
@@ -1352,101 +1319,124 @@ getEditorAttribute(): Promise<EditorAttribute>
...
@@ -1352,101 +1319,124 @@ getEditorAttribute(): Promise<EditorAttribute>
**示例:**
**示例:**
```
js
```
js
async
function
InputMethodEngine
()
{
async
function
InputMethodEngine
()
{
await
Text
InputClient
.
getEditorAttribute
().
then
((
editorAttribute
)
=>
{
await
InputClient
.
getEditorAttribute
().
then
((
editorAttribute
)
=>
{
console
.
info
(
'
editorAttribute.inputPattern(promise):
'
+
JSON
.
stringify
(
editorAttribute
.
inputPattern
));
console
.
info
(
'
editorAttribute.inputPattern(promise):
'
+
JSON
.
stringify
(
editorAttribute
.
inputPattern
));
console
.
info
(
'
editorAttribute.enterKeyType(promise):
'
+
JSON
.
stringify
(
editorAttribute
.
enterKeyType
));
console
.
info
(
'
editorAttribute.enterKeyType(promise):
'
+
JSON
.
stringify
(
editorAttribute
.
enterKeyType
));
}).
catch
((
err
)
=>
{
}).
catch
((
err
)
=>
{
console
.
error
(
'
getEditorAttribute promise err:
'
+
JSON
.
stringify
(
err
));
console
.
error
(
'
getEditorAttribute promise err:
'
+
JSON
.
stringify
(
err
));
});
});
}
}
```
```
## InputClient<a name="InputClient "></a><sup>9+</sup>
下列API示例中都需使用
[
inputStart
](
#inputStart9
)
回调获取到InputClient实例,再通过此实例调用对应方法。
###
sendKeyFunction
<sup>9+</sup>
###
moveCursor
<sup>9+</sup>
sendKeyFunction(action:number, callback: AsyncCallback
<
boolean
>
): void
moveCursor(direction: number, callback: AsyncCallback
<
void
>
): void
发送功能键。使用callback形式返回结果。参数个数为2
,否则抛出异常。
移动光标。使用callback形式返回结果。参数个数为1
,否则抛出异常。
**系统能力**
: SystemCapability.MiscServices.InputMethodFramework
**系统能力**
: SystemCapability.MiscServices.InputMethodFramework
**参数:**
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| 参数名 | 类型 | 必填 | 说明 |
| --------
| -------- | -------- |
-------- |
| --------
- | ------------------------- | ---- | ------
-------- |
|
action | number | 是 | 编辑框属性
。 |
|
direction | number | 是 | 光标移动方向
。 |
| callback
| AsyncCallback
<
boolean
>
| 是 | 操作成功与否。
|
| callback
| AsyncCallback
<
void
>
| 是 | 回调函数。
|
**示例:**
**示例:**
```
js
```
js
try
{
try
{
InputClient
.
sendKeyFunction
(
keyFunction
,
(
err
,
result
)
=>
{
InputClient
.
moveCursor
(
inputMethodAbility
.
CURSOR_xxx
,
(
err
)
=>
{
if
(
err
)
{
if
(
err
)
{
console
.
error
(
'
sendKeyFunction err:
'
+
JSON
.
stringify
(
err
)
JSON
.
stringify
(
err
));
console
.
error
(
'
moveCursor err:
'
+
JSON
.
stringify
(
err
));
return
;
return
;
}
}
if
(
result
)
{
console
.
info
(
'
moveCursor success
'
);
console
.
info
(
'
Success to sendKeyFunction.(callback)
'
);
}
else
{
console
.
error
(
'
Failed to sendKeyFunction.(callback)
'
);
}
});
});
}
catch
(
err
)
{
}
catch
(
err
)
{
console
.
error
(
'
sendKeyFunction
err:
'
+
JSON
.
stringify
(
err
));
console
.
error
(
'
moveCursor
err:
'
+
JSON
.
stringify
(
err
));
}
}
```
```
###
sendKeyFunction
<sup>9+</sup>
###
moveCursor
<sup>9+</sup>
sendKeyFunction(action:number): Promise
<
boolean
>
moveCursor(direction: number): Promise
<
void
>
发送功能键
。使用promise形式返回结果。参数个数为1,否则抛出异常。
移动光标
。使用promise形式返回结果。参数个数为1,否则抛出异常。
**系统能力**
: SystemCapability.MiscServices.InputMethodFramework
**系统能力**
: SystemCapability.MiscServices.InputMethodFramework
**参数:**
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| 参数名 | 类型 | 必填 | 说明 |
| --------
| -------- | -------- |
-------- |
| --------
- | ------ | ---- | ------
-------- |
|
action | number | 是 | 编辑框属性
。 |
|
direction | number | 是 | 光标移动方向
。 |
**返回值:**
**返回值:**
| 类型 | 说明 |
| 类型 | 说明 |
| -------------------
------------ | -----------------------------------
------------------------- |
| -------------------
|
------------------------- |
| Promise
<
boolean
>
| 操作成功与否。
|
| Promise
<
void
>
| 无返回结果的Promise对象。
|
**示例:**
**示例:**
```
js
```
js
try
{
async
function
InputMethodAbility
()
{
InputClient
.
sendKeyFunction
(
keyFunction
).
then
((
result
)
=>
{
try
{
if
(
result
)
{
await
InputClient
.
moveCursor
(
inputMethodEngine
.
CURSOR_xxx
).
then
((
err
)
=>
{
console
.
info
(
'
Success to sendKeyFunction.(callback)
'
);
if
(
err
)
{
}
else
{
console
.
log
(
'
moveCursor err:
'
+
JSON
.
stringify
(
err
));
console
.
error
(
'
Failed to sendKeyFunction.(callback)
'
)
;
return
;
}
}
console
.
log
(
'
moveCursor success
'
);
}).
catch
((
err
)
=>
{
}).
catch
((
err
)
=>
{
console
.
error
(
'
sendKeyFunction promise err:
'
+
JSON
.
stringify
(
err
));
console
.
error
(
'
moveCursor success err:
'
+
JSON
.
stringify
(
err
));
});
});
}
catch
(
err
)
{
}
catch
(
err
)
{
console
.
error
(
'
sendKeyFunction err:
'
+
JSON
.
stringify
(
err
));
console
.
log
(
'
moveCursor err:
'
+
JSON
.
stringify
(
err
));
}
}
}
```
```
##
# getForward<sup>9+</sup
>
##
EditorAttribute<a name="EditorAttribute"></a
>
getForward(length:number, callback: AsyncCallback
<
string
>
): 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
<
string
>
): void
获取光标前固定长度的文本。使用callback形式返回结果。参数个数为2,否则抛出异常。
> **说明:**
> 从API version 8开始支持,API version 9开始废弃, 建议使用[getForward](#getforward9)替代
**系统能力**
: SystemCapability.MiscServices.InputMethodFramework
**参数:**
**参数:**
...
@@ -1457,27 +1447,26 @@ getForward(length:number, callback: AsyncCallback<string>): void
...
@@ -1457,27 +1447,26 @@ getForward(length:number, callback: AsyncCallback<string>): void
**示例:**
**示例:**
```
js
```
js
var
length
=
1
;
let
length
=
1
;
try
{
TextInputClient
.
getForward
(
length
,
(
err
,
text
)
=>
{
InputClient
.
getForward
(
length
,
(
err
,
text
)
=>
{
if
(
err
===
undefined
)
{
if
(
err
)
{
console
.
error
(
'
getForward callback result---err:
'
+
JSON
.
stringify
(
err
));
console
.
error
(
'
getForward err:
'
+
JSON
.
stringify
(
err
));
return
;
return
;
}
}
console
.
log
(
'
getForward callback result:
'
+
text
);
console
.
log
(
'
getForward callback result---text:
'
+
text
);
});
});
}
catch
(
err
)
{
```
console
.
error
(
'
getForward err:
'
+
JSON
.
stringify
(
err
));
}
```
### getForward<sup>
9+
</sup>
### getForward<sup>
(deprecated)
</sup>
getForward(length:number): Promise
<
string
>
getForward(length:number): Promise
<
string
>
获取光标前固定长度的文本。使用promise形式返回结果。参数个数为1,否则抛出异常。
获取光标前固定长度的文本。使用promise形式返回结果。参数个数为1,否则抛出异常。
> **说明:**
> 从API version 8开始支持,API version 9开始废弃, 建议使用[getForward](#getforward9)替代
**系统能力**
: SystemCapability.MiscServices.InputMethodFramework
**系统能力**
: SystemCapability.MiscServices.InputMethodFramework
**参数:**
**参数:**
...
@@ -1494,27 +1483,26 @@ getForward(length:number): Promise<string>
...
@@ -1494,27 +1483,26 @@ getForward(length:number): Promise<string>
**示例:**
**示例:**
```
js
```
js
async
function
InputMethodAbility
()
{
async
function
InputMethodEngine
()
{
var
length
=
1
;
let
length
=
1
;
try
{
await
TextInputClient
.
getForward
(
length
).
then
((
text
)
=>
{
await
InputClient
.
getForward
(
length
).
then
((
text
)
=>
{
console
.
info
(
'
getForward promise result---res:
'
+
text
);
console
.
info
(
'
getForward promise resul:
'
+
text
);
}).
catch
((
err
)
=>
{
}).
catch
((
err
)
=>
{
console
.
error
(
'
getForward promise err:
'
+
JSON
.
stringify
(
err
));
console
.
error
(
'
getForward promise err:
'
+
JSON
.
stringify
(
err
));
});
});
}
catch
(
err
)
{
}
console
.
error
(
'
getForward promise err:
'
+
JSON
.
stringify
(
err
));
```
}
}
```
### getBackward<sup>
9+
</sup>
### getBackward<sup>
(deprecated)
</sup>
getBackward(length:number, callback: AsyncCallback
<
string
>
): void
getBackward(length:number, callback: AsyncCallback
<
string
>
): void
获取光标后固定长度的文本。使用callback形式返回结果。参数个数为2,否则抛出异常。
获取光标后固定长度的文本。使用callback形式返回结果。参数个数为2,否则抛出异常。
> **说明:**
> 从API version 8开始支持,API version 9开始废弃, 建议使用[getBackward](#getbackward9)替代
**系统能力**
: SystemCapability.MiscServices.InputMethodFramework
**系统能力**
: SystemCapability.MiscServices.InputMethodFramework
**参数:**
**参数:**
...
@@ -1526,27 +1514,26 @@ getBackward(length:number, callback: AsyncCallback<string>): void
...
@@ -1526,27 +1514,26 @@ getBackward(length:number, callback: AsyncCallback<string>): void
**示例:**
**示例:**
```
js
```
js
var
length
=
1
;
let
length
=
1
;
try
{
TextInputClient
.
getBackward
(
length
,
(
err
,
text
)
=>
{
InputClient
.
getBackward
(
length
,
(
err
,
text
)
=>
{
if
(
err
===
undefined
)
{
if
(
err
)
{
console
.
error
(
'
getBackward callback result---err:
'
+
JSON
.
stringify
(
err
));
console
.
error
(
'
getBackward callback result:
'
+
JSON
.
stringify
(
err
));
return
;
return
;
}
}
console
.
log
(
'
getBackward callback result---text:
'
+
text
);
console
.
log
(
'
getBackward callback result---text:
'
+
text
);
});
});
}
catch
(
err
)
{
```
console
.
error
(
'
getBackward callback result:
'
+
JSON
.
stringify
(
err
));
}
```
### getBackward<sup>
9+
</sup>
### getBackward<sup>
(deprecated)
</sup>
getBackward(length:number): Promise
<
string
>
getBackward(length:number): Promise
<
string
>
获取光标后固定长度的文本。使用promise形式返回结果。参数个数为1,否则抛出异常。
获取光标后固定长度的文本。使用promise形式返回结果。参数个数为1,否则抛出异常。
> **说明:**
> 从API version 8开始支持,API version 9开始废弃, 建议使用[getBackward](#getbackward9)替代
**系统能力**
: SystemCapability.MiscServices.InputMethodFramework
**系统能力**
: SystemCapability.MiscServices.InputMethodFramework
**参数:**
**参数:**
...
@@ -1563,27 +1550,26 @@ getBackward(length:number): Promise<string>
...
@@ -1563,27 +1550,26 @@ getBackward(length:number): Promise<string>
**示例:**
**示例:**
```
js
```
js
async
function
InputMethodAbility
()
{
async
function
InputMethodEngine
()
{
var
length
=
1
;
let
length
=
1
;
try
{
await
TextInputClient
.
getBackward
(
length
).
then
((
text
)
=>
{
await
InputClient
.
getBackward
(
length
).
then
((
text
)
=>
{
console
.
info
(
'
getBackward promise result---res:
'
+
text
);
console
.
info
(
'
getBackward promise result:
'
+
text
);
}).
catch
((
err
)
=>
{
}).
catch
((
err
)
=>
{
console
.
error
(
'
getBackward promise err:
'
+
JSON
.
stringify
(
err
));
console
.
error
(
'
getBackward promise err:
'
+
JSON
.
stringify
(
err
));
});
});
}
catch
(
err
)
{
}
console
.
error
(
'
getBackward promise err:
'
+
JSON
.
stringify
(
err
));
```
}
}
```
### deleteForward<sup>
9+
</sup>
### deleteForward<sup>
(deprecated)
</sup>
deleteForward(length:number, callback: AsyncCallback
<
boolean
>
): void
deleteForward(length:number, callback: AsyncCallback
<
boolean
>
): void
删除光标前固定长度的文本。使用callback形式返回结果。参数个数为2,否则抛出异常。
删除光标前固定长度的文本。使用callback形式返回结果。参数个数为2,否则抛出异常。
> **说明:**
> 从API version 8开始支持,API version 9开始废弃, 建议使用[deleteForward](#deleteforward9)替代
**系统能力**
: SystemCapability.MiscServices.InputMethodFramework
**系统能力**
: SystemCapability.MiscServices.InputMethodFramework
**参数:**
**参数:**
...
@@ -1595,12 +1581,11 @@ deleteForward(length:number, callback: AsyncCallback<boolean>): void
...
@@ -1595,12 +1581,11 @@ deleteForward(length:number, callback: AsyncCallback<boolean>): void
**示例:**
**示例:**
```
js
```
js
var
length
=
1
;
let
length
=
1
;
try
{
TextInputClient
.
deleteForward
(
length
,
(
err
,
result
)
=>
{
InputClient
.
deleteForward
(
length
,
(
err
,
result
)
=>
{
if
(
err
===
undefined
)
{
if
(
err
)
{
console
.
error
(
'
deleteForward callback result---err:
'
+
JSON
.
stringify
(
err
));
console
.
error
(
'
deleteForward callback result:
'
+
JSON
.
stringify
(
err
));
return
;
return
;
}
}
if
(
result
)
{
if
(
result
)
{
...
@@ -1608,18 +1593,18 @@ try {
...
@@ -1608,18 +1593,18 @@ try {
}
else
{
}
else
{
console
.
error
(
'
Failed to deleteForward.(callback)
'
);
console
.
error
(
'
Failed to deleteForward.(callback)
'
);
}
}
});
});
}
catch
(
err
)
{
```
console
.
error
(
'
deleteForward callback result:
'
+
JSON
.
stringify
(
err
));
}
```
### deleteForward<sup>
9+
</sup>
### deleteForward<sup>
(deprecated)
</sup>
deleteForward(length:number): Promise
<
boolean
>
deleteForward(length:number): Promise
<
boolean
>
删除光标前固定长度的文本。使用promise形式返回结果。参数个数为1,否则抛出异常。
删除光标前固定长度的文本。使用promise形式返回结果。参数个数为1,否则抛出异常。
> **说明:**
> 从API version 8开始支持,API version 9开始废弃, 建议使用[deleteForward](#deleteforward9)替代
**系统能力**
: SystemCapability.MiscServices.InputMethodFramework
**系统能力**
: SystemCapability.MiscServices.InputMethodFramework
**参数:**
**参数:**
...
@@ -1637,10 +1622,9 @@ deleteForward(length:number): Promise<boolean>
...
@@ -1637,10 +1622,9 @@ deleteForward(length:number): Promise<boolean>
**示例:**
**示例:**
```
js
```
js
async
function
InputMethodAbility
()
{
async
function
InputMethodEngine
()
{
var
length
=
1
;
let
length
=
1
;
try
{
await
TextInputClient
.
deleteForward
(
length
).
then
((
result
)
=>
{
await
InputClient
.
deleteForward
(
length
).
then
((
result
)
=>
{
if
(
result
)
{
if
(
result
)
{
console
.
info
(
'
Success to deleteForward.(promise)
'
);
console
.
info
(
'
Success to deleteForward.(promise)
'
);
}
else
{
}
else
{
...
@@ -1649,18 +1633,18 @@ async function InputMethodAbility() {
...
@@ -1649,18 +1633,18 @@ async function InputMethodAbility() {
}).
catch
((
err
)
=>
{
}).
catch
((
err
)
=>
{
console
.
error
(
'
deleteForward promise err:
'
+
JSON
.
stringify
(
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
<
boolean
>
): void
deleteBackward(length:number, callback: AsyncCallback
<
boolean
>
): void
删除光标后固定长度的文本。使用callback形式返回结果。参数个数为2,否则抛出异常。
删除光标后固定长度的文本。使用callback形式返回结果。参数个数为2,否则抛出异常。
> **说明:**
> 从API version 8开始支持,API version 9开始废弃, 建议使用[deleteBackward](#deletebackward9)替代
**系统能力**
: SystemCapability.MiscServices.InputMethodFramework
**系统能力**
: SystemCapability.MiscServices.InputMethodFramework
**参数:**
**参数:**
...
@@ -1673,11 +1657,10 @@ deleteBackward(length:number, callback: AsyncCallback<boolean>): void
...
@@ -1673,11 +1657,10 @@ deleteBackward(length:number, callback: AsyncCallback<boolean>): void
**示例:**
**示例:**
```
js
```
js
var
length
=
1
;
let
length
=
1
;
try
{
TextInputClient
.
deleteBackward
(
length
,
(
err
,
result
)
=>
{
InputClient
.
deleteBackward
(
length
,
(
err
,
result
)
=>
{
if
(
err
===
undefined
)
{
if
(
err
)
{
console
.
error
(
'
deleteBackward callback result---err:
'
+
JSON
.
stringify
(
err
));
console
.
error
(
'
deleteBackward err:
'
+
JSON
.
stringify
(
err
));
return
;
return
;
}
}
if
(
result
)
{
if
(
result
)
{
...
@@ -1685,18 +1668,18 @@ try {
...
@@ -1685,18 +1668,18 @@ try {
}
else
{
}
else
{
console
.
error
(
'
Failed to deleteBackward.(callback)
'
);
console
.
error
(
'
Failed to deleteBackward.(callback)
'
);
}
}
});
});
}
catch
(
err
)
{
console
.
error
(
'
deleteBackward err:
'
+
JSON
.
stringify
(
err
));
}
```
```
### deleteBackward<sup>
9+
</sup>
### deleteBackward<sup>
(deprecated)
</sup>
deleteBackward(length:number): Promise
<
boolean
>
deleteBackward(length:number): Promise
<
boolean
>
删除光标后固定长度的文本。使用callback形式返回结果。参数个数为2,否则抛出异常。
删除光标后固定长度的文本。使用callback形式返回结果。参数个数为2,否则抛出异常。
> **说明:**
> 从API version 8开始支持,API version 9开始废弃, 建议使用[deleteBackward](#deletebackward9)替代
**系统能力**
: SystemCapability.MiscServices.InputMethodFramework
**系统能力**
: SystemCapability.MiscServices.InputMethodFramework
**参数:**
**参数:**
...
@@ -1714,9 +1697,9 @@ deleteBackward(length:number): Promise<boolean>
...
@@ -1714,9 +1697,9 @@ deleteBackward(length:number): Promise<boolean>
**示例:**
**示例:**
```
js
```
js
async
function
InputMethod
Ability
()
{
async
function
InputMethod
Engine
()
{
var
length
=
1
;
let
length
=
1
;
await
InputClient
.
deleteBackward
(
length
).
then
((
result
)
=>
{
await
Text
InputClient
.
deleteBackward
(
length
).
then
((
result
)
=>
{
if
(
result
)
{
if
(
result
)
{
console
.
info
(
'
Success to deleteBackward.(promise)
'
);
console
.
info
(
'
Success to deleteBackward.(promise)
'
);
}
else
{
}
else
{
...
@@ -1727,43 +1710,48 @@ async function InputMethodAbility() {
...
@@ -1727,43 +1710,48 @@ async function InputMethodAbility() {
});
});
}
}
```
```
### sendKeyFunction<sup>(deprecated)</sup>
### insertText<sup>9+</sup>
sendKeyFunction(action:number, callback: AsyncCallback
<
boolean
>
): void
insertText(text:string, callback: AsyncCallback
<
boolean
>
): void
发送功能键。使用callback形式返回结果。参数个数为2,否则抛出异常。
插入文本。使用callback形式返回结果。参数个数为2,否则抛出异常。
> **说明:**
> 从API version 8开始支持,API version 9开始废弃, 建议使用[sendKeyFunction](#sendkeyfunction9)替代
**系统能力**
: SystemCapability.MiscServices.InputMethodFramework
**系统能力**
: SystemCapability.MiscServices.InputMethodFramework
**参数:**
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| -------- | -------- | -------- | -------- |
|
text | string | 是 | 文本
。 |
|
action | number | 是 | 编辑框属性
。 |
| callback | AsyncCallback
<
boolean
>
| 是 | 操作成功与否。 |
| callback | AsyncCallback
<
boolean
>
| 是 | 操作成功与否。 |
**示例:**
**示例:**
```
js
```
js
InputClient
.
insertText
(
'
test
'
,
(
err
,
result
)
=>
{
TextInputClient
.
sendKeyFunction
(
keyFunction
,
(
err
,
result
)
=>
{
if
(
err
)
{
if
(
err
===
undefined
)
{
console
.
error
(
'
insertText
err:
'
+
JSON
.
stringify
(
err
));
console
.
error
(
'
sendKeyFunction callback result---
err:
'
+
JSON
.
stringify
(
err
));
return
;
return
;
}
}
if
(
result
)
{
if
(
result
)
{
console
.
info
(
'
Success to
insertText
.(callback)
'
);
console
.
info
(
'
Success to
sendKeyFunction
.(callback)
'
);
}
else
{
}
else
{
console
.
error
(
'
Failed to
insertText
.(callback)
'
);
console
.
error
(
'
Failed to
sendKeyFunction
.(callback)
'
);
}
}
});
});
```
```
###
insertText<sup>9+
</sup>
###
sendKeyFunction<sup>(deprecated)
</sup>
insertText(text:string
): Promise
<
boolean
>
sendKeyFunction(action:number
): Promise
<
boolean
>
插入文本。使用promise形式返回结果。参数个数为1,否则抛出异常。
发送功能键。使用promise形式返回结果。参数个数为1,否则抛出异常。
> **说明:**
> 从API version 8开始支持,API version 9开始废弃, 建议使用[sendKeyFunction](#sendkeyfunction9)替代
**系统能力**
: SystemCapability.MiscServices.InputMethodFramework
**系统能力**
: SystemCapability.MiscServices.InputMethodFramework
...
@@ -1771,7 +1759,7 @@ insertText(text:string): Promise<boolean>
...
@@ -1771,7 +1759,7 @@ insertText(text:string): Promise<boolean>
| 参数名 | 类型 | 必填 | 说明 |
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| -------- | -------- | -------- | -------- |
|
text | string | 是 | 文本
。 |
|
action | number | 是 | 编辑框属性
。 |
**返回值:**
**返回值:**
...
@@ -1781,168 +1769,149 @@ insertText(text:string): Promise<boolean>
...
@@ -1781,168 +1769,149 @@ insertText(text:string): Promise<boolean>
**示例:**
**示例:**
```
js
```
js
async
function
InputMethodAbility
()
{
async
function
InputMethodEngine
()
{
try
{
await
client
.
sendKeyFunction
(
keyFunction
).
then
((
result
)
=>
{
await
InputClient
.
insertText
(
'
test
'
).
then
((
result
)
=>
{
if
(
result
)
{
if
(
result
)
{
console
.
info
(
'
Success to insertText
.(promise)
'
);
console
.
info
(
'
Success to sendKeyFunction
.(promise)
'
);
}
else
{
}
else
{
console
.
error
(
'
Failed to insertText
.(promise)
'
);
console
.
error
(
'
Failed to sendKeyFunction
.(promise)
'
);
}
}
}).
catch
((
err
)
=>
{
}).
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
<
EditorAttribute
>
): void
insertText(text:string, callback: AsyncCallback
<
boolean
>
): void
获取编辑框属性值。使用callback形式返回结果。参数个数为1,否则抛出异常。
插入文本。使用callback形式返回结果。参数个数为2,否则抛出异常。
> **说明:**
> 从API version 8开始支持,API version 9开始废弃, 建议使用[insertText](#inserttext9)替代
**系统能力**
: SystemCapability.MiscServices.InputMethodFramework
**系统能力**
: SystemCapability.MiscServices.InputMethodFramework
**参数:**
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| 参数名 | 类型 | 必填 | 说明 |
| ------------------------------- | ------------------------------------------------------------ | ------------------------------------------------------------ | ------------------------------------------------------------ |
| -------- | -------- | -------- | -------- |
| callback | AsyncCallback
<
[EditorAttribute](#EditorAttribute)
>
| 是 | 编辑框属性值。 |
| text | string | 是 | 文本。 |
| callback | AsyncCallback
<
boolean
>
| 是 | 操作成功与否。 |
**示例:**
**示例:**
```
js
```
js
InputClient
.
getEditorAttribute
((
err
,
editorAttribute
)
=>
{
TextInputClient
.
insertText
(
'
test
'
,
(
err
,
result
)
=>
{
if
(
err
)
{
if
(
err
===
undefined
)
{
console
.
error
(
'
getEditorAttribute
callback result---err:
'
+
JSON
.
stringify
(
err
));
console
.
error
(
'
insertText
callback result---err:
'
+
JSON
.
stringify
(
err
));
return
;
return
;
}
}
console
.
log
(
'
editorAttribute.inputPattern(callback):
'
+
JSON
.
stringify
(
editorAttribute
.
inputPattern
));
if
(
result
)
{
console
.
log
(
'
editorAttribute.enterKeyType(callback):
'
+
JSON
.
stringify
(
editorAttribute
.
enterKeyType
));
console
.
info
(
'
Success to insertText.(callback)
'
);
});
}
else
{
```
console
.
error
(
'
Failed to insertText.(callback)
'
);
}
});
```
###
getEditorAttribute<sup>9+
</sup>
###
insertText<sup>(deprecated)
</sup>
getEditorAttribute(): Promise
<
EditorAttribute
>
insertText(text:string): Promise
<
boolean
>
获取编辑框属性值。使用promise形式返回结果。参数个数为0,否则抛出异常。
插入文本。使用promise形式返回结果。参数个数为1,否则抛出异常。
> **说明:**
> 从API version 8开始支持,API version 9开始废弃, 建议使用[insertText](#inserttext9)替代
**系统能力**
: SystemCapability.MiscServices.InputMethodFramework
**系统能力**
: SystemCapability.MiscServices.InputMethodFramework
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| text | string | 是 | 文本。 |
**返回值:**
**返回值:**
| 类型 | 说明 |
| 类型 | 说明 |
| ------------------------------- | ------------------------------------------------------------ |
| ------------------------------- | ------------------------------------------------------------ |
| Promise
<
[EditorAttribute](#editorattribute)
>
| 返回编辑框属性值。
|
| Promise
<
boolean
>
| 操作成功与否。
|
**示例:**
**示例:**
```
js
```
js
async
function
InputMethodEngine
()
{
async
function
InputMethodEngine
()
{
await
InputClient
.
getEditorAttribute
().
then
((
editorAttribute
)
=>
{
await
TextInputClient
.
insertText
(
'
test
'
).
then
((
result
)
=>
{
console
.
info
(
'
editorAttribute.inputPattern(promise):
'
+
JSON
.
stringify
(
editorAttribute
.
inputPattern
));
if
(
result
)
{
console
.
info
(
'
editorAttribute.enterKeyType(promise):
'
+
JSON
.
stringify
(
editorAttribute
.
enterKeyType
));
console
.
info
(
'
Success to insertText.(promise)
'
);
}
else
{
console
.
error
(
'
Failed to insertText.(promise)
'
);
}
}).
catch
((
err
)
=>
{
}).
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
<
void
>
): void
getEditorAttribute(callback: AsyncCallback
<
EditorAttribute
>
): void
移动光标。使用callback形式返回结果。参数个数为1,否则抛出异常。
获取编辑框属性值。使用callback形式返回结果。参数个数为1,否则抛出异常。
> **说明:**
> 从API version 8开始支持,API version 9开始废弃, 建议使用[getEditorAttribute](#geteditorattribute9)替代
**系统能力**
: SystemCapability.MiscServices.InputMethodFramework
**系统能力**
: SystemCapability.MiscServices.InputMethodFramework
**参数:**
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| 参数名 | 类型 | 必填 | 说明 |
| --------- | ------------------------- | ---- | -------------- |
| ------------------------------- | ------------------------------------------------------------ | ------------------------------------------------------------ | ------------------------------------------------------------ |
| direction | number | 是 | 光标移动方向。 |
| callback | AsyncCallback
<
[EditorAttribute](#editorattribute)
>
| 是 | 编辑框属性值。 |
| callback | AsyncCallback
<
void
>
| 是 | 回调函数。 |
**示例:**
**示例:**
```
js
```
js
try
{
TextInputClient
.
getEditorAttribute
((
err
,
editorAttribute
)
=>
{
InputClient
.
moveCursor
(
inputMethodAbility
.
CURSOR_xxx
,
(
err
)
=>
{
if
(
err
===
undefined
)
{
if
(
err
)
{
console
.
error
(
'
getEditorAttribute callback result---err:
'
+
JSON
.
stringify
(
err
));
console
.
error
(
'
moveCursor err:
'
+
JSON
.
stringify
(
err
));
return
;
return
;
}
}
console
.
info
(
'
moveCursor success
'
);
console
.
log
(
'
editorAttribute.inputPattern(callback):
'
+
JSON
.
stringify
(
editorAttribute
.
inputPattern
));
});
console
.
log
(
'
editorAttribute.enterKeyType(callback):
'
+
JSON
.
stringify
(
editorAttribute
.
enterKeyType
));
}
catch
(
err
)
{
});
console
.
error
(
'
moveCursor err:
'
+
JSON
.
stringify
(
err
));
}
```
```
### moveCursor<sup>9+</sup>
### getEditorAttribute<sup>(deprecated)</sup>
moveCursor(direction: number): Promise
<
void
>
移动光标。使用promise形式返回结果。参数个数为1,否则抛出异常。
getEditorAttribute(): Promise
<
EditorAttribute
>
**系统能力**
: SystemCapability.MiscServices.InputMethodFramework
获取编辑框属性值。使用promise形式返回结果。参数个数为0,否则抛出异常。
**参数:**
> **说明:**
> 从API version 8开始支持,API version 9开始废弃, 建议使用[getEditorAttribute](#geteditorattribute9)替代
| 参数名 | 类型 | 必填 | 说明 |
**系统能力**
: SystemCapability.MiscServices.InputMethodFramework
| --------- | ------ | ---- | -------------- |
| direction | number | 是 | 光标移动方向。 |
**返回值:**
**返回值:**
| 类型 | 说明 |
| 类型 | 说明 |
| -------------------
|
------------------------- |
| -------------------
------------ | -----------------------------------
------------------------- |
| Promise
<
void
>
| 无返回结果的Promise对象。
|
| Promise
<
[EditorAttribute](#editorattribute)
>
| 返回编辑框属性值。
|
**示例:**
**示例:**
```
js
```
js
async
function
InputMethodAbility
()
{
async
function
InputMethodEngine
()
{
try
{
await
TextInputClient
.
getEditorAttribute
().
then
((
editorAttribute
)
=>
{
await
InputClient
.
moveCursor
(
inputMethodEngine
.
CURSOR_xxx
).
then
((
err
)
=>
{
console
.
info
(
'
editorAttribute.inputPattern(promise):
'
+
JSON
.
stringify
(
editorAttribute
.
inputPattern
));
if
(
err
)
{
console
.
info
(
'
editorAttribute.enterKeyType(promise):
'
+
JSON
.
stringify
(
editorAttribute
.
enterKeyType
));
console
.
log
(
'
moveCursor err:
'
+
JSON
.
stringify
(
err
));
return
;
}
console
.
log
(
'
moveCursor success
'
);
}).
catch
((
err
)
=>
{
}).
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
));
}
}
}
```
```
\ No newline at end of file
## EditorAttribute<a name="EditorAttribute"></a>
编辑框属性值。
**系统能力**
:以下各项对应的系统能力均为SystemCapability.MiscServices.InputMethodFramework
| 名称 | 参数类型 | 可读 | 可写 | 说明 |
| ------------ | -------- | ---- | ---- | ------------------ |
| enterKeyType | number | 是 | 否 | 编辑框的功能属性。 |
| inputPattern | number | 是 | 否 | 编辑框的文本属性。 |
## KeyEvent<a name="KeyEvent"></a>
按键属性值。
**系统能力**
:以下各项对应的系统能力均为SystemCapability.MiscServices.InputMethodFramework
| 名称 | 参数类型 | 可读 | 可写 | 说明 |
| --------- | -------- | ---- | ---- | ------------ |
| keyCode | number | 是 | 否 | 按键的键值。 |
| keyAction | number | 是 | 否 | 按键的状态。 |
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录