Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Docs
提交
534e97ce
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看板
提交
534e97ce
编写于
10月 12, 2022
作者:
H
Hollokin
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
错误码异常处理及输入法子类型API接口资料添加
Signed-off-by:
N
Hollokin
<
taoyuxin2@huawei.com
>
上级
bb190769
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
1537 addition
and
48 deletion
+1537
-48
zh-cn/application-dev/reference/apis/js-apis-inputmethod-extension-ability.md
...v/reference/apis/js-apis-inputmethod-extension-ability.md
+73
-0
zh-cn/application-dev/reference/apis/js-apis-inputmethod.md
zh-cn/application-dev/reference/apis/js-apis-inputmethod.md
+482
-23
zh-cn/application-dev/reference/apis/js-apis-inputmethodengine.md
...plication-dev/reference/apis/js-apis-inputmethodengine.md
+826
-25
zh-cn/application-dev/reference/apis/js-apis-inputmethodsubtype.md
...lication-dev/reference/apis/js-apis-inputmethodsubtype.md
+24
-0
zh-cn/application-dev/reference/errorcodes/errcode-InputMethodFramework.md
...-dev/reference/errorcodes/errcode-InputMethodFramework.md
+132
-0
未找到文件。
zh-cn/application-dev/reference/apis/js-apis-inputmethod-extension-ability.md
浏览文件 @
534e97ce
...
...
@@ -64,3 +64,76 @@ Extension生命周期回调,在销毁输入法应用时回调,执行资源
}
}
```
## InputMethodExtensionAbility.onRequest()
onRequest(want: Want, startId: number): void;
Extension生命周期回调,在开始执行输入法应用时回调,执行输入法的相关操作。
**系统能力**
:SystemCapability.MiscServices.InputMethodFramework
**示例:**
```
js
class
InputMethodExt
extends
InputMethodExtensionAbility
{
onRequest
()
{
console
.
log
(
'
onRequest, want:
'
+
want
.
abilityName
+
'
startId:
'
+
startId
);
}
}
```
## InputMethodExtensionAbility.onConnect()
onConnect(want: Want): rpc.RemoteObject;
Extension生命周期回调,在首次链接输入法ability时回调。
**系统能力**
:SystemCapability.MiscServices.InputMethodFramework
**示例:**
```
js
class
InputMethodExt
extends
InputMethodExtensionAbility
{
onConnect
()
{
console
.
log
(
'
onConnect, want:
'
+
want
.
abilityName
);
}
}
```
## InputMethodExtensionAbility.onDisconnect()
onDisconnect(want: Want): rpc.RemoteObject;
Extension生命周期回调,在所有链接在输入法extention上的ability都断开的时候回调。
**系统能力**
:SystemCapability.MiscServices.InputMethodFramework
**示例:**
```
js
class
InputMethodExt
extends
InputMethodExtensionAbility
{
onDisconnect
()
{
console
.
log
(
'
onDisconnect, want:
'
+
want
.
abilityName
);
}
}
```
## InputMethodExtensionAbility.onReconnect()
onReconnect(want: Want): rpc.RemoteObject;
Extension生命周期回调,在一个新的客户端去尝试连接输入法extention的时候回调(先前连接在extention上的客户端全部断开的情况下)。
**系统能力**
:SystemCapability.MiscServices.InputMethodFramework
**示例:**
```
js
class
InputMethodExt
extends
InputMethodExtensionAbility
{
onReconnect
()
{
console
.
log
(
'
onReconnect, want:
'
+
want
.
abilityName
);
}
}
```
zh-cn/application-dev/reference/apis/js-apis-inputmethod.md
浏览文件 @
534e97ce
...
...
@@ -2,7 +2,7 @@
本模块提供对输入法框架的管理,包括隐藏输入法、查询已安装的输入法列表和显示输入法选择对话框。
> **说明:**
>

**说明:**
>
> 本模块首批接口从API version 6开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
...
...
@@ -32,15 +32,22 @@ import inputMethod from '@ohos.inputmethod';
| 名称 | 参数类型 | 可读 | 可写 | 说明 |
| -------- | -------- | -------- | -------- | -------- |
| packageName | string | 是 | 否 | 包名。 |
| methodId | string | 是 | 否 | Ability名。 |
| packageName
<sup>
deprecated
</sup>
| string | 是 | 否 | 包名。 |
| methodId
<sup>
deprecated
</sup>
| string | 是 | 否 | Ability名。 |
| name
<sup>
9+
</sup>
| string | 是 | 否 | 包名。 |
| id
<sup>
9+
</sup>
| string | 是 | 否 | Ability名。 |
## inputMethod.getInputMethodController
## inputMethod.getInputMethodController
<sup>deprecated</sup>
getInputMethodController(): InputMethodController
获取客户端实例
[
InputMethodController
](
#inputmethodcontroller
)
。
> **说明:**
> 从API version 9开始废弃, 建议使用[getController](#getController)替代
>
> 从 API version 6开始支持。
**系统能力**
:SystemCapability.MiscServices.InputMethodFramework
**返回值:**
...
...
@@ -55,6 +62,26 @@ getInputMethodController(): InputMethodController
var
InputMethodController
=
inputMethod
.
getInputMethodController
();
```
## inputMethod.getController<sup>9+</sup>
getController(): InputMethodController
获取客户端实例
[
InputMethodController
](
#inputmethodcontroller
)
。
**系统能力**
:SystemCapability.MiscServices.InputMethodFramework
**返回值:**
| 类型 | 说明 |
| ----------------------------------------------- | ------------------------ |
|
[
InputMethodController
](
#inputmethodcontroller
)
| 回调返回当前客户端实例。 |
**示例:**
```
js
var
InputMethodController
=
inputMethod
.
getController
();
```
## inputMethod.getInputMethodSetting<sup>8+</sup>
getInputMethodSetting(): InputMethodSetting
...
...
@@ -75,12 +102,36 @@ getInputMethodSetting(): InputMethodSetting
```
js
var
InputMethodSetting
=
inputMethod
.
getInputMethodSetting
();
```
## inputMethod.getSetting<sup>9+</sup>
getSetting(): InputMethodSetting
获取客户端设置实例
[
InputMethodSetting
](
#inputmethodsetting8
)
。
**系统能力**
: SystemCapability.MiscServices.InputMethodFramework
**返回值:**
| 类型 | 说明 |
| ----------------------------------------- | ---------------------------- |
|
[
InputMethodSetting
](
#inputmethodsetting8
)
| 回调返回当前客户端设置实例。 |
**示例:**
```
js
var
InputMethodSetting
=
inputMethod
.
getSetting
();
```
## inputMethod.switchInputMethod<sup>9+</sup>
switchInputMethod(target: InputMethodProperty, callback: AsyncCallback
<
boolean
>
): void
切换输入法。此接口仅可在Stage模型下使用。使用callback形式返回结果。参数个数为2,否则抛出异常。
**需要权限**
: ohos.permission.CONNECT_IME_ABILITY
**系统能力**
:SystemCapability.MiscServices.InputMethodFramework
**参数:**
...
...
@@ -111,6 +162,8 @@ switchInputMethod(target: InputMethodProperty): Promise<boolean>
切换输入法。此接口仅可在Stage模型下使用。使用promise形式返回结果。参数个数为1,否则抛出异常。
**需要权限**
: ohos.permission.CONNECT_IME_ABILITY
**系统能力**
: SystemCapability.MiscServices.InputMethodFramework
**参数:**
...
...
@@ -127,7 +180,6 @@ switchInputMethod(target: InputMethodProperty): Promise<boolean>
**示例:**
```
js
inputMethod
.
switchInputMethod
({
packageName
:
'
com.example.kikakeyboard
'
,
methodId
:
'
com.example.kikakeyboard
'
}).
then
((
result
)
=>
{
if
(
result
)
{
...
...
@@ -139,6 +191,7 @@ inputMethod.switchInputMethod({packageName:'com.example.kikakeyboard', methodId:
console
.
error
(
'
switchInputMethod promise err:
'
+
err
);
})
```
## inputMethod.getCurrentInputMethod<sup>9+</sup>
getCurrentInputMethod(): InputMethodProperty
...
...
@@ -155,16 +208,165 @@ getCurrentInputMethod(): InputMethodProperty
**示例:**
```
js
var
currentIme
=
inputMethod
.
getCurrentInputMethod
();
```
## inputMethod.switchCurrentInputMethodSubtype<sup>9+</sup>
switchCurrentInputMethodSubtype(target: InputMethodSubtype, callback: AsyncCallback
<boolean>
): void
选择当前的输入法子类型。
**需要权限**
: ohos.permission.CONNECT_IME_ABILITY
**系统能力**
: SystemCapability.MiscServices.InputMethodFramework
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
|target |
[
InputMethodSubtype
](
#InputMethodSubtype
)
| 是 | 传入要切换的目标输入法子类型。 |
| callback | AsyncCallback
<
boolean
>
| 是 | 返回输入法子类型切换是否成功。 |
**示例:**
```
js
inputMethod
.
switchCurrentInputMethodSubtype
(
subType
,(
err
,
result
)
=>
{
if
(
err
)
{
console
.
error
(
'
switchCurrentInputMethodSubtype err:
'
+
JSON
.
stringify
(
err
));
return
;
}
if
(
result
)
{
console
.
info
(
'
Success to switchCurrentInputMethodSubtype.(callback)
'
);
}
else
{
console
.
error
(
'
Failed to switchCurrentInputMethodSubtype.(callback)
'
);
}
});
```
## inputMethod.switchCurrentInputMethodSubtype<sup>9+</sup>
switchCurrentInputMethodSubtype(target: InputMethodSubtype): Promise
<
boolean
>
切换输入法子类型。此接口仅可在Stage模型下使用。使用promise形式返回结果。参数个数为1,否则抛出异常。
**需要权限**
: ohos.permission.CONNECT_IME_ABILITY
**系统能力**
: SystemCapability.MiscServices.InputMethodFramework
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
|target |
[
InputMethodSubtype
](
#InputMethodSubtype
)
| 是 | 传入要切换的目标输入法子类型。 |
**示例:**
```
js
inputMethod
.
switchCurrentInputMethodSubtype
(
subType
).
then
((
result
)
=>
{
if
(
result
)
{
console
.
info
(
'
Success to switchCurrentInputMethodSubtype.(promise)
'
);
}
else
{
console
.
error
(
'
Failed to switchCurrentInputMethodSubtype.(promise)
'
);
}
}).
catch
((
err
)
=>
{
console
.
error
(
'
switchCurrentInputMethodSubtype promise err:
'
+
err
);
})
```
## inputMethod.getCurrentInputMethodSubtype<sup>9+</sup>
getCurrentInputMethodSubtype(): InputMethodSubtype
获取当前输入法子类型。
**需要权限**
: ohos.permission.CONNECT_IME_ABILITY
**系统能力**
: SystemCapability.MiscServices.InputMethodFramework
**返回值:**
| 类型 | 说明 |
| -------------------------------------------- | ------------------------ |
|
[
InputMethodSubtype
](
#InputMethodSubtype
)
| 返回当前输入法子类型对象。 |
**示例:**
```
js
var
currentImeSubType
=
inputMethod
.
getCurrentInputMethodSubtype
();
```
## inputMethod.switchCurrentInputMethodAndSubtype<sup>9+</sup>
switchCurrentInputMethodAndSubtype(inputMethodProperty: InputMethodProperty, inputMethodSubtype: InputMethodSubtype, callback: AsyncCallback
<boolean>
): void
选择输入法和子类型。
**需要权限**
: ohos.permission.CONNECT_IME_ABILITY
**系统能力**
: SystemCapability.MiscServices.InputMethodFramework
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
|inputMethodProperty |
[
InputMethodProperty
](
#InputMethodProperty
)
| 是 | 传入要切换的目标输入法。 |
|inputMethodSubtype |
[
inputMethodSubtype
](
#InputMethodSubtype
)
| 是 | 传入要切换的目标输入法子类型。 |
| callback | AsyncCallback
<
boolean
>
| 是 | 返回输入法和子类型切换是否成功。 |
**示例:**
```
js
inputMethod
.
switchCurrentInputMethodAndSubtype
(
property
,
subType
,(
err
,
result
)
=>
{
if
(
err
)
{
console
.
error
(
'
switchCurrentInputMethodAndSubtype err:
'
+
JSON
.
stringify
(
err
));
return
;
}
if
(
result
)
{
console
.
info
(
'
Success to switchCurrentInputMethodAndSubtype.(callback)
'
);
}
else
{
console
.
error
(
'
Failed to switchCurrentInputMethodAndSubtype.(callback)
'
);
}
});
```
## inputMethod.switchCurrentInputMethodAndSubtype<sup>9+</sup>
switchCurrentInputMethodAndSubtype(inputMethodProperty: InputMethodProperty, inputMethodSubtype: InputMethodSubtype, ): Promise
<
boolean
>
切换输入法子类型。此接口仅可在Stage模型下使用。使用promise形式返回结果。参数个数为1,否则抛出异常。
**需要权限**
: ohos.permission.CONNECT_IME_ABILITY
**系统能力**
: SystemCapability.MiscServices.InputMethodFramework
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
|inputMethodProperty |
[
InputMethodProperty
](
#InputMethodProperty
)
| 是 | 传入要切换的目标输入法。 |
|inputMethodSubtype |
[
inputMethodSubtype
](
#InputMethodSubtype
)
| 是 | 传入要切换的目标输入法子类型。 |
**示例:**
```
js
inputMethod
.
switchCurrentInputMethodAndSubtype
(
property
,
subType
).
then
((
result
)
=>
{
if
(
result
)
{
console
.
info
(
'
Success to switchCurrentInputMethodAndSubtype.(promise)
'
);
}
else
{
console
.
error
(
'
Failed to switchCurrentInputMethodAndSubtype.(promise)
'
);
}
}).
catch
((
err
)
=>
{
console
.
error
(
'
switchCurrentInputMethodAndSubtype promise err:
'
+
err
);
})
```
## InputMethodController
下列API示例中都需使用
[
getInputMethodController
](
#inputmethodgetinputmethodcontroller
)
回调获取到InputMethodController实例,再通过此实例调用对应方法。
### stopInput
### stopInput
<sup>deprecated</sup>
stopInput(callback: AsyncCallback
<
boolean
>
): void
...
...
@@ -194,7 +396,7 @@ InputMethodController.stopInput((error, result) => {
});
```
### stopInput
### stopInput
<sup>deprecated</sup>
stopInput(): Promise
<
boolean
>
...
...
@@ -223,6 +425,65 @@ InputMethodController.stopInput().then((result) => {
})
```
### stopInputSession<sup>9+</sup>
stopInputSession(callback: AsyncCallback
<
boolean
>
): void
隐藏输入法。使用callback形式返回结果。参数个数为1,否则抛出异常。
**系统能力**
:SystemCapability.MiscServices.InputMethodFramework
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| callback | AsyncCallback
<
boolean
>
| 是 | 返回输入法隐藏是否成功。 |
**示例:**
```
js
InputMethodController
.
stopInputSession
((
error
,
result
)
=>
{
if
(
error
)
{
console
.
error
(
'
failed to stopInputSession because:
'
+
JSON
.
stringify
(
error
));
return
;
}
if
(
result
)
{
console
.
info
(
'
Success to stopInputSession.(callback)
'
);
}
else
{
console
.
error
(
'
Failed to stopInputSession.(callback)
'
);
}
});
```
### stopInputSession
stopInputSession(): Promise
<
boolean
>
隐藏输入法。使用promise形式返回结果。参数个数为0,否则抛出异常。
**系统能力**
: SystemCapability.MiscServices.InputMethodFramework
**返回值:**
| 类型 | 说明 |
| -------- | -------- |
| Promise
<
boolean
>
| 返回输入法隐藏是否成功。 |
**示例:**
```
js
InputMethodController
.
stopInputSession
().
then
((
result
)
=>
{
if
(
result
)
{
console
.
info
(
'
Success to stopInputSession.(promise)
'
);
}
else
{
console
.
error
(
'
Failed to stopInputSession.(promise)
'
);
}
}).
catch
((
err
)
=>
{
console
.
error
(
'
stopInputSession promise err:
'
+
err
);
})
```
### showSoftKeyboard<sup>9+</sup> ###
showSoftKeyboard(callback: AsyncCallback
<
void
>
): void
...
...
@@ -329,9 +590,155 @@ InputMethodController.hideSoftKeyboard().then(async (err) => {
下列API示例中都需使用
[
getInputMethodSetting
](
#inputmethodgetinputmethodcontroller
)
回调获取到InputMethodSetting实例,再通过此实例调用对应方法。
### listInputMethod<sup>9+</sup>
### on('imeChange')<a name="imeChange"></a>
on(type: 'imeChange', callback: (inputMethodProperty: InputMethodProperty, inputMethodSubtype: InputMethodSubtype) => void): void
订阅输入法及子类型变化监听事件,使用callback回调返回变化了的输入法及子类型的相关实例。参数个数为3,参数1和参数2为napi_object,参数3为napi_function,否则抛出异常。
**系统能力**
: SystemCapability.MiscServices.InputMethodFramework
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | ------------------------------- | ---- | ------------------------------------------------------------ |
| type | string | 是 | 设置监听类型。
<br/>
-type为‘imeChange’时表示订阅输入法及子类型变化监听事件。 |
| callback |
[
inputMethodProperty
](
#InputMethodProperty
)
,
[
inputMethodSubtype
](
#InputMethodSubtype
)
| 是 | 回调返回输入法及子类型相关实例。 |
**示例:**
```
js
InputMethodEngine
.
on
(
'
imeChange
'
,
(
inputMethodProperty
,
inputMethodSubtype
)
=>
{
InputMethodProperty
=
inputMethodProperty
;
InputMethodSubtype
=
inputMethodSubtype
;
});
```
### off('imeChange')<a name="imeChange"></a>
on(type: 'imeChange', callback: (inputMethodProperty: InputMethodProperty, inputMethodSubtype: InputMethodSubtype) => void): void
取消订阅输入法及子类型变化监听事件,使用callback回调返回取消订阅的输入法及子类型的相关实例。必选参数个数为1,参数1为string,可选参数2为napi_function,否则抛出异常。
**系统能力**
: SystemCapability.MiscServices.InputMethodFramework
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | ------------------------------- | ---- | ------------------------------------------------------------ |
| type | string | 是 | 设置监听类型。
<br/>
-type为‘imeChange’时表示取消订阅输入法及子类型变化监听事件。 |
| callback |
[
inputMethodProperty
](
#InputMethodProperty
)
,
[
inputMethodSubtype
](
#InputMethodSubtype
)
| 否 | 回调返回输入法及子类型相关实例。 |
**示例:**
```
js
InputMethodAbility
.
off
(
'
imeChange
'
);
```
### listInputMethodSubtype<sup>9+</sup>
listInputMethodSubtype(inputMethodProperty: InputMethodProperty, callback: AsyncCallback
<
Array
<
InputMethodSubtype
>>
): void
查询已安装的输入法子类型列表。使用callback形式返回结果。参数个数为2,否则抛出异常。
**系统能力**
: SystemCapability.MiscServices.InputMethodFramework
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------------------------------------------------- | ---- | ---------------------- |
| inputMethodProperty | InputMethodProperty| 是 | 要查询的输入法子类型的输入法属性
| callback | Array
<
[
InputMethodSubtype
](
#InputMethodSubtype
)
>
| 是 | 返回已安装输入法列表。 |
**示例:**
```
js
InputMethodSetting
.
listInputMethodSubtype
({
"
name
"
:
''
,
"
id
"
:
''
},
(
err
,
data
)
=>
{
if
(
err
)
{
console
.
error
(
'
listInputMethod failed because:
'
+
JSON
.
stringify
(
err
));
return
;
}
console
.
log
(
'
listInputMethod success
'
);
});
```
### listInputMethodSubtype<sup>9+</sup>
listInputMethodSubtype(inputMethodProperty: InputMethodProperty): Promise
<
Array
<
InputMethodSubtype
>>
查询已安装的满足条件的输入法子类型列表。使用promise形式返回结果。参数个数为1,否则抛出异常。
**系统能力**
: SystemCapability.MiscServices.InputMethodFramework
**返回值:**
| 类型 | 说明 |
| ----------------------------------------------------------- | ---------------------- |
| Promise
<Array
<[
InputMethodSubtype
](
#InputMethodSubtype
)
>
> | 返回已安装输入法子类型列表。 |
**示例:**
```
js
InputMethodSetting
.
listInputMethodSubtype
().
then
((
data
)
=>
{
console
.
info
(
'
listInputMethodSubtype success
'
);
}).
catch
((
err
)
=>
{
console
.
error
(
'
listInputMethodSubtype promise err:
'
+
err
);
})
```
### listCurrentInputMethodSubtype<sup>9+</sup>
listCurrentInputMethodSubtype(callback: AsyncCallback
<
Array
<
InputMethodSubtype
>>
): void
listInputMethod(enable: boolean, callback: AsyncCallback
<
Array
<
InputMethodProperty
>>
): void
查询当前输入法的子类型列表。使用callback形式返回结果。参数个数为1,否则抛出异常。
**系统能力**
: SystemCapability.MiscServices.InputMethodFramework
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------------------------------------------------- | ---- | ---------------------- |
| callback | Array
<
[
InputMethodSubtype
](
#InputMethodSubtype
)
>
| 是 | 返回当前输入法的子类型列表。 |
**示例:**
```
js
InputMethodSetting
.
listCurrentInputMethodSubtype
((
err
,
data
)
=>
{
if
(
err
)
{
console
.
error
(
'
listCurrentInputMethodSubtype failed because:
'
+
JSON
.
stringify
(
err
));
return
;
}
console
.
log
(
'
listCurrentInputMethodSubtype success
'
);
});
```
### listCurrentInputMethodSubtype<sup>9+</sup>
listCurrentInputMethodSubtype(): Promise
<
Array
<
InputMethodSubtype
>>
查询当前输入法的子类型列表。使用promise形式返回结果。
**系统能力**
: SystemCapability.MiscServices.InputMethodFramework
**返回值:**
| 类型 | 说明 |
| ----------------------------------------------------------- | ---------------------- |
| Promise
<Array
<[
InputMethodSubtype
](
#InputMethodSubtype
)
>
> | 返回当前输入法的子类型列表。 |
**示例:**
```
js
InputMethodSetting
.
listCurrentInputMethodSubtype
().
then
((
data
)
=>
{
console
.
info
(
'
listCurrentInputMethodSubtype success
'
);
}).
catch
((
err
)
=>
{
console
.
error
(
'
listCurrentInputMethodSubtype promise err:
'
+
err
);
})
```
### getInputMethods<sup>9+</sup>
getInputMethods(enable: boolean, callback: AsyncCallback
<
Array
<
InputMethodProperty
>>
): void
获取已激活/未激活输入法列表。参数enable取true,返回已激活输入法列表,取false返回未激活输入法列表。使用callback形式返回结果。参数个数为2,否则抛出异常。
...
...
@@ -347,18 +754,18 @@ listInputMethod(enable: boolean, callback: AsyncCallback<Array<InputMethod
**示例:**
```
js
InputMethodSetting
.
listInputMethod
(
true
,
(
err
,
data
)
=>
{
InputMethodSetting
.
getInputMethods
(
true
,
(
err
,
data
)
=>
{
if
(
err
)
{
console
.
error
(
'
listInputMethod
failed because:
'
+
JSON
.
stringify
(
err
));
console
.
error
(
'
getInputMethods
failed because:
'
+
JSON
.
stringify
(
err
));
return
;
}
console
.
log
(
'
listInputMethod
success
'
);
console
.
log
(
'
getInputMethods
success
'
);
});
```
###
listInputMethod
<sup>9+</sup>
###
getInputMethods
<sup>9+</sup>
listInputMethod
(enable: boolean): Promise
<
Array
<
InputMethodProperty
>>
getInputMethods
(enable: boolean): Promise
<
Array
<
InputMethodProperty
>>
获取已激活/未激活输入法列表。参数enable取true返回已激活输入法列表,取false返回未激活输入法列表。使用promise形式返回结果。参数个数为0,否则抛出异常。
...
...
@@ -379,14 +786,14 @@ listInputMethod(enable: boolean): Promise<Array<InputMethodProperty>>
**示例:**
```
js
InputMethodSetting
.
listInputMethod
(
true
).
then
((
data
)
=>
{
console
.
info
(
'
listInputMethod
success
'
);
InputMethodSetting
.
getInputMethods
(
true
).
then
((
data
)
=>
{
console
.
info
(
'
getInputMethods
success
'
);
}).
catch
((
err
)
=>
{
console
.
error
(
'
listInputMethod
promise err:
'
+
err
);
console
.
error
(
'
getInputMethods
promise err:
'
+
err
);
})
```
### listInputMethod
### listInputMethod
<sup>deprecated</sup>
listInputMethod(callback: AsyncCallback
<
Array
<
InputMethodProperty
>>
): void
...
...
@@ -412,7 +819,7 @@ InputMethodSetting.listInputMethod((err,data) => {
});
```
### listInputMethod
### listInputMethod
<sup>deprecated</sup>
listInputMethod(): Promise
<
Array
<
InputMethodProperty
>>
...
...
@@ -436,7 +843,7 @@ InputMethodSetting.listInputMethod().then((data) => {
})
```
### displayOptionalInputMethod
### displayOptionalInputMethod
<sup>deprecated</sup>
displayOptionalInputMethod(callback: AsyncCallback
<
void
>
): void
...
...
@@ -462,9 +869,61 @@ 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
InputMethodSetting
.
showOptionalInputMethods
((
err
)
=>
{
if
(
err
)
{
console
.
error
(
'
showOptionalInputMethods failed because:
'
+
JSON
.
stringify
(
err
));
return
;
}
console
.
info
(
'
showOptionalInputMethods success
'
);
});
```
### displayOptionalInputMethod
displayOptionalInputMethod(): Promise
<
void
>
displayOptionalInputMethod(): Promise
<
void
>
显示输入法选择对话框。使用promise形式返回结果。参数个数为0,否则抛出异常。
**系统能力**
: SystemCapability.MiscServices.InputMethodFramework
**返回值:**
| 类型 | 说明 |
| -------- | -------- |
| Promise
<
void
>
| 无返回结果的Promise对象。 |
**示例:**
```
js
InputMethodSetting
.
displayOptionalInputMethod
().
then
(()
=>
{
console
.
info
(
'
displayOptionalInputMethod success.(promise)
'
);
}).
catch
((
err
)
=>
{
console
.
error
(
'
displayOptionalInputMethod promise err:
'
+
err
);
})
```
### showOptionalInputMethods<sup>9+</sup>
showOptionalInputMethods(): Promise
<
void
>
显示输入法选择对话框。使用promise形式返回结果。参数个数为0,否则抛出异常。
...
...
@@ -479,7 +938,7 @@ InputMethodSetting.displayOptionalInputMethod((err) => {
**示例:**
```
js
InputMethodSetting
.
displayOptionalInputMethod
().
then
(()
=>
{
InputMethodSetting
.
showOptionalInputMethods
().
then
(()
=>
{
console
.
info
(
'
displayOptionalInputMethod success.(promise)
'
);
}).
catch
((
err
)
=>
{
console
.
error
(
'
displayOptionalInputMethod promise err:
'
+
err
);
...
...
zh-cn/application-dev/reference/apis/js-apis-inputmethodengine.md
浏览文件 @
534e97ce
...
...
@@ -51,7 +51,7 @@ import inputMethodEngine from '@ohos.inputmethodengine';
| CURSOR_RIGHT
<sup>
9+
</sup>
| number | 是 | 否 | 光标右移。 |
| WINDOW_TYPE_INPUT_METHOD_FLOAT
<sup>
9+
</sup>
| number | 是 | 否 | 输入法应用窗口风格标识。 |
## inputMethodEngine.getInputMethodEngine<a name="getInputMethodEngine"></a>
## inputMethodEngine.getInputMethodEngine<a name="getInputMethodEngine"></a>
<sup>deprecated</sup>
getInputMethodEngine(): InputMethodEngine
...
...
@@ -71,7 +71,27 @@ getInputMethodEngine(): InputMethodEngine
var
InputMethodEngine
=
inputMethodEngine
.
getInputMethodEngine
();
```
## inputMethodEngine.createKeyboardDelegate<a name="createKeyboardDelegate"></a>
## inputMethodAbility.getInputMethodAbility<a name="getInputMethodAbility"></a>
getInputMethodAbility(): InputMethodAbility
获取服务端实例。
**系统能力**
: SystemCapability.MiscServices.InputMethodFramework
**返回值:**
| 类型 | 说明 |
| --------------------------------------- | ------------ |
|
[
InputMethodAbility
](
#InputMethodAbility
)
| 服务端实例。 |
**示例:**
```
js
var
InputMethodAbility
=
inputMethodAbility
.
getInputMethodAbility
();
```
## inputMethodEngine.createKeyboardDelegate<a name="createKeyboardDelegate"></a><sup>deprecated</sup>
createKeyboardDelegate(): KeyboardDelegate
...
...
@@ -91,6 +111,26 @@ createKeyboardDelegate(): KeyboardDelegate
var
KeyboardDelegate
=
inputMethodEngine
.
createKeyboardDelegate
();
```
## inputMethodAbility.getKeyboardDelegate<a name="getKeyboardDelegate"></a>
getKeyboardDelegate(): KeyboardDelegate
获取客户端监听实例。
**系统能力**
: SystemCapability.MiscServices.InputMethodFramework
**返回值:**
| 类型 | 说明 |
| ------------------------------------- | ---------------- |
|
[
KeyboardDelegate
](
#KeyboardDelegate
)
| 客户端监听实例。 |
**示例:**
```
js
var
KeyboardDelegate
=
inputMethodAbility
.
getKeyboardDelegate
();
```
## InputMethodEngine<a name="InputMethodEngine"></a>
下列API示例中都需使用
[
getInputMethodEngine
](
#getInputMethodEngine
)
回调获取到InputMethodEngine实例,再通过此实例调用对应方法。
...
...
@@ -288,6 +328,246 @@ off(type: 'keyboardShow'|'keyboardHide', callback?: () => void): void
});
```
## InputMethodAbility<a name="InputMethodAbility"></a>
下列API示例中都需使用
[
getInputMethodEngine
](
#getInputMethodEngine
)
回调获取到InputMethodEngine实例,再通过此实例调用对应方法。
### on('inputStart')<a name="inputStart"></a><sup>9+</sup>
on(type: 'inputStart', callback: (kbController: KeyboardController, inputClient: InputClient) => void): void
订阅输入法绑定成功事件,使用callback回调返回输入法操作相关实例。参数个数为2,参数1为napi_string,参数2为napi_function,否则抛出异常。
**系统能力**
: SystemCapability.MiscServices.InputMethodFramework
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | ------------------------------- | ---- | ------------------------------------------------------------ |
| type | string | 是 | 设置监听类型。
<br/>
-type为‘inputStart’时表示订阅输入法绑定。 |
| callback |
[
KeyboardController
](
#KeyboardController
)
,
[
InputClient
](
#InputClient
)
| 是 | 回调返回输入法操作相关实例。 |
**示例:**
```
js
InputMethodAbility
.
on
(
'
inputStart
'
,
(
kbController
,
inputClient
)
=>
{
KeyboardController
=
kbController
;
InputClient
=
inputClient
;
});
```
### off('inputStart')<sup>9+</sup>
off(type: 'inputStart', callback?: (kbController: KeyboardController, inputClient: InputClient) => void): void
取消订阅输入法绑定成功事件。参数个数不为1或2抛出异常。若为1,参数不为napi_string抛出异常;若为2,参数1不为napi_string,参数2不为napi_function抛出异常。参数若为1,取消此类型所有监听;参数若为2,取消此类型当前监听。
**系统能力**
: SystemCapability.MiscServices.InputMethodFramework
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------------------- | ---- | ------------------------ |
| type | string | 是 | 设置监听类型。
<br/>
-type为‘inputStart’时表示订阅输入法绑定。 |
| callback |
[
KeyboardController
](
#KeyboardController
)
,
[
InputClient
](
#InputClient
)
| 否 | 回调返回输入法操作相关实例。 |
**示例:**
```
js
InputMethodAbility
.
off
(
'
inputStart
'
,
(
kbController
,
inputClient
)
=>
{
console
.
log
(
'
delete inputStart notification.
'
);
});
```
### on('inputStop')<sup>9+</sup>
on(type: 'inputStop', callback: () => void): void
订阅停止输入法应用事件,使用callback回调。
**系统能力**
: SystemCapability.MiscServices.InputMethodFramework
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | ------ | ---- | ------------------------------------------------------------ |
| type | string | 是 | 设置监听类型。
<br/>
-type为‘inputStop’时表示订阅停止输入法应用事件。 |
| callback | void | 是 | 回调函数。 |
**示例:**
```
js
InputMethodAbility
.
getInputMethodAbility
().
on
(
'
inputStop
'
,
()
=>
{
console
.
log
(
'
inputMethodAbility inputStop
'
);
});
```
### off('inputStop')<sup>9+</sup>
off(type: 'inputStop', callback: () => void): void
取消订阅停止输入法应用事件。使用callback回调。
**系统能力**
: SystemCapability.MiscServices.InputMethodFramework
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | ------ | ---- | ------------------------------------------------------------ |
| type | string | 是 | 设置监听类型。
<br/>
-type为‘inputStop’时表示订阅停止输入法应用事件。 |
| callback | void | 是 | 回调函数。 |
**示例:**
```
js
InputMethodAbility
.
getInputMethodAbility
().
off
(
'
inputStop
'
,
()
=>
{
console
.
log
(
'
inputMethodAbility delete inputStop notification.
'
);
});
```
### on('setCallingWindow')<sup>9+</sup>
on(type: 'setCallingWindow', callback: (wid:number) => void): void
订阅设置调用窗口事件,使用callback回调。
**系统能力**
: SystemCapability.MiscServices.InputMethodFramework
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | ------ | ---- | ------------------------------------------------------------ |
| type | string | 是 | 设置监听类型。
<br/>
-type为‘setCallingWindow’时表示订阅设置调用窗口事件。 |
| callback | number | 是 | 调用方window id。 |
**示例:**
```
js
InputMethodAbility
.
getInputMethodAbility
().
on
(
'
setCallingWindow
'
,
(
wid
)
=>
{
console
.
log
(
'
inputMethodAbility setCallingWindow
'
);
});
```
### off('setCallingWindow')<sup>9+</sup>
off(type: 'setCallingWindow', callback: (wid:number) => void): void
取消订阅设置调用窗口事件。使用callback回调。
**系统能力**
: SystemCapability.MiscServices.InputMethodFramework
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | ------ | ---- | ------------------------------------------------------------ |
| type | string | 是 | 设置监听类型。
<br/>
-type为‘setCallingWindow’时表示订阅设置调用窗口事件。 |
| callback | number | 是 | 调用方window id。 |
**示例:**
```
js
InputMethodAbility
.
getInputMethodAbility
().
off
(
'
setCallingWindow
'
,
()
=>
{
console
.
log
(
'
inputMethodAbility delete setCallingWindow notification.
'
);
});
```
### on('keyboardShow'|'keyboardHide')<sup>9+</sup>
on(type: 'keyboardShow'|'keyboardHide', callback: () => void): void
订阅输入法事件。参数个数为2,参数1为napi_string,参数2为napi_function,否则抛出异常。
**系统能力**
: SystemCapability.MiscServices.InputMethodFramework
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | ------ | ---- | ------------------------------------------------------------ |
| type | string | 是 | 设置监听类型。
<br/>
-
type为'keyboardShow',表示订阅输入法显示。
<br/>
-
type为'keyboardHide',表示订阅输入法隐藏。 |
| callback | void | 否 | 回调函数。 |
**示例:**
```
js
InputMethodAbility
.
on
(
'
keyboardShow
'
,
()
=>
{
console
.
log
(
'
InputMethodAbility keyboardShow.
'
);
});
InputMethodAbility
.
on
(
'
keyboardHide
'
,
()
=>
{
console
.
log
(
'
InputMethodAbility keyboardHide.
'
);
});
```
### off('keyboardShow'|'keyboardHide')<sup>9+</sup>
off(type: 'keyboardShow'|'keyboardHide', callback?: () => void): void
取消订阅输入法事件。参数个数不为1或2抛出异常。若为1,参数不为napi_string抛出异常;若为2,参数1不为napi_string,参数2不为napi_function抛出异常。参数若为1,取消此类型所有监听;参数若为2,取消此类型当前监听。
**系统能力**
: SystemCapability.MiscServices.InputMethodFramework
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | ------ | ---- | ------------------------------------------------------------ |
| type | string | 是 | 设置监听类型。
<br/>
-
type为'keyboardShow',表示订阅输入法显示。
<br/>
-
type为'keyboardHide',表示订阅输入法隐藏。 |
| callback | void | 否 | 回调函数。 |
**示例:**
```
js
InputMethodAbility
.
off
(
'
keyboardShow
'
,
()
=>
{
console
.
log
(
'
InputMethodAbility delete keyboardShow notification.
'
);
});
InputMethodAbility
.
off
(
'
keyboardHide
'
,
()
=>
{
console
.
log
(
'
InputMethodAbility delete keyboardHide notification.
'
);
});
```
### on('setSubtype')<sup>9+</sup>
on(type: 'setSubtype', callback: (inputMethodSubtype: InputMethodSubtype) => void): void
订阅设置输入法子类型事件。参数个数为2,参数1为napi_string,参数2为napi_function,否则抛出异常。
**系统能力**
: SystemCapability.MiscServices.InputMethodFramework
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | ------ | ---- | ------------------------------------------------------------ |
| type | string | 是 | 设置监听类型。
<br/>
-
type为'setSubtype',表示订阅输入法显示。
<br/>
-
type为'keyboardHide',表示订阅输入法隐藏。 |
| callback | InputMethodSubtype | 是 | 调用方的输入法子类型。 |
**示例:**
```
js
InputMethodAbility
.
on
(
'
setSubtype
'
,
(
inputMethodSubtype
)
=>
{
console
.
log
(
'
InputMethodAbility setSubtype.
'
);
});
```
### off('setSubtype')<sup>9+</sup>
off(type: 'setSubtype', callback?: () => void): void
取消订阅输入法子类型事件。参数个数不为1或2抛出异常。若为1,参数不为napi_string抛出异常;若为2,参数1不为napi_string,参数2不为napi_function抛出异常。参数若为1,取消此类型所有监听;参数若为2,取消此类型当前监听。
**系统能力**
: SystemCapability.MiscServices.InputMethodFramework
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | ------ | ---- | ------------------------------------------------------------ |
| type | string | 是 | 设置监听类型。
<br/>
-
type为'setSubtype',表示订阅输入法显示。
<br/>
-
type为'keyboardHide',表示订阅输入法隐藏。 |
| callback | InputMethodSubtype | 是 | 调用方的输入法子类型。 |
**示例:**
```
js
InputMethodAbility
.
off
(
'
setSubtype
'
,
()
=>
{
console
.
log
(
'
InputMethodAbility delete setSubtype notification.
'
);
});
```
## KeyboardDelegate<a name="KeyboardDelegate"></a>
...
...
@@ -560,12 +840,17 @@ async function InputMethodEngine() {
下列API示例中都需使用
[
inputStart
](
#inputStart
)
回调获取到TextInputClient实例,再通过此实例调用对应方法。
### getForward
### getForward
<sup>deprecated</sup>
getForward(length:number, callback: AsyncCallback
<
string
>
): void
获取光标前固定长度的文本。使用callback形式返回结果。参数个数为2,否则抛出异常。
> **说明:**
> 从API version 9开始废弃, 建议使用[InputClient.getForward](#InputClient.getForward)替代
>
> 从 API version 8开始支持。
**系统能力**
: SystemCapability.MiscServices.InputMethodFramework
**参数:**
...
...
@@ -588,12 +873,17 @@ getForward(length:number, callback: AsyncCallback<string>): void
});
```
### getForward
### getForward
<sup>deprecated</sup>
getForward(length:number): Promise
<
string
>
获取光标前固定长度的文本。使用promise形式返回结果。参数个数为1,否则抛出异常。
> **说明:**
> 从API version 9开始废弃, 建议使用[InputClient.getForward](#InputClient.getForward)替代
>
> 从 API version 8开始支持。
**系统能力**
: SystemCapability.MiscServices.InputMethodFramework
**参数:**
...
...
@@ -621,12 +911,17 @@ getForward(length:number): Promise<string>
}
```
### getBackward
### getBackward
<sup>deprecated</sup>
getBackward(length:number, callback: AsyncCallback
<
string
>
): void
获取光标后固定长度的文本。使用callback形式返回结果。参数个数为2,否则抛出异常。
> **说明:**
> 从API version 9开始废弃, 建议使用[InputClient.getBackward](#InputClient.getBackward)替代
>
> 从 API version 8开始支持。
**系统能力**
: SystemCapability.MiscServices.InputMethodFramework
**参数:**
...
...
@@ -649,12 +944,17 @@ getBackward(length:number, callback: AsyncCallback<string>): void
});
```
### getBackward
### getBackward
<sup>deprecated</sup>
getBackward(length:number): Promise
<
string
>
获取光标后固定长度的文本。使用promise形式返回结果。参数个数为1,否则抛出异常。
> **说明:**
> 从API version 9开始废弃, 建议使用[InputClient.getBackward](#InputClient.getBackward)替代
>
> 从 API version 8开始支持。
**系统能力**
: SystemCapability.MiscServices.InputMethodFramework
**参数:**
...
...
@@ -682,12 +982,17 @@ getBackward(length:number): Promise<string>
}
```
### deleteForward
### deleteForward
<sup>deprecated</sup>
deleteForward(length:number, callback: AsyncCallback
<
boolean
>
): void
删除光标前固定长度的文本。使用callback形式返回结果。参数个数为2,否则抛出异常。
> **说明:**
> 从API version 9开始废弃, 建议使用[InputClient.deleteForward](#InputClient.deleteForward)替代
>
> 从 API version 8开始支持。
**系统能力**
: SystemCapability.MiscServices.InputMethodFramework
**参数:**
...
...
@@ -713,12 +1018,17 @@ deleteForward(length:number, callback: AsyncCallback<boolean>): void
}
});
```
### deleteForward
### deleteForward
<sup>deprecated</sup>
deleteForward(length:number): Promise
<
boolean
>
删除光标前固定长度的文本。使用promise形式返回结果。参数个数为1,否则抛出异常。
> **说明:**
> 从API version 9开始废弃, 建议使用[InputClient.deleteForward](#InputClient.deleteForward)替代
>
> 从 API version 8开始支持。
**系统能力**
: SystemCapability.MiscServices.InputMethodFramework
**参数:**
...
...
@@ -750,12 +1060,17 @@ async function InputMethodEngine() {
}
```
### deleteBackward
### deleteBackward
<sup>deprecated</sup>
deleteBackward(length:number, callback: AsyncCallback
<
boolean
>
): void
删除光标后固定长度的文本。使用callback形式返回结果。参数个数为2,否则抛出异常。
> **说明:**
> 从API version 9开始废弃, 建议使用[InputClient.deleteBackward](#InputClient.deleteBackward)替代
>
> 从 API version 8开始支持。
**系统能力**
: SystemCapability.MiscServices.InputMethodFramework
**参数:**
...
...
@@ -782,12 +1097,17 @@ TextInputClient.deleteBackward(length, (err, result) => {
});
```
### deleteBackward
### deleteBackward
<sup>deprecated</sup>
deleteBackward(length:number): Promise
<
boolean
>
删除光标后固定长度的文本。使用callback形式返回结果。参数个数为2,否则抛出异常。
> **说明:**
> 从API version 9开始废弃, 建议使用[InputClient.deleteBackward](#InputClient.deleteBackward)替代
>
> 从 API version 8开始支持。
**系统能力**
: SystemCapability.MiscServices.InputMethodFramework
**参数:**
...
...
@@ -818,12 +1138,17 @@ async function InputMethodEngine() {
});
}
```
### sendKeyFunction
### sendKeyFunction
<sup>deprecated</sup>
sendKeyFunction(action:number, callback: AsyncCallback
<
boolean
>
): void
发送功能键。使用callback形式返回结果。参数个数为2,否则抛出异常。
> **说明:**
> 从API version 9开始废弃, 建议使用[InputClient.sendKeyFunction](#InputClient.sendKeyFunction)替代
>
> 从 API version 8开始支持。
**系统能力**
: SystemCapability.MiscServices.InputMethodFramework
**参数:**
...
...
@@ -849,12 +1174,17 @@ TextInputClient.sendKeyFunction(keyFunction, (err, result) => {
});
```
### sendKeyFunction
### sendKeyFunction
<sup>deprecated</sup>
sendKeyFunction(action:number): Promise
<
boolean
>
发送功能键。使用promise形式返回结果。参数个数为1,否则抛出异常。
> **说明:**
> 从API version 9开始废弃, 建议使用[InputClient.sendKeyFunction](#InputClient.sendKeyFunction)替代
>
> 从 API version 8开始支持。
**系统能力**
: SystemCapability.MiscServices.InputMethodFramework
**参数:**
...
...
@@ -885,12 +1215,17 @@ sendKeyFunction(action:number): Promise<boolean>
}
```
### insertText
### insertText
<sup>deprecated</sup>
insertText(text:string, callback: AsyncCallback
<
boolean
>
): void
插入文本。使用callback形式返回结果。参数个数为2,否则抛出异常。
> **说明:**
> 从API version 9开始废弃, 建议使用[InputClient.insertText](#InputClient.insertText)替代
>
> 从 API version 8开始支持。
**系统能力**
: SystemCapability.MiscServices.InputMethodFramework
**参数:**
...
...
@@ -916,12 +1251,17 @@ TextInputClient.insertText('test', (err, result) => {
});
```
### insertText
### insertText
<sup>deprecated</sup>
insertText(text:string): Promise
<
boolean
>
插入文本。使用promise形式返回结果。参数个数为1,否则抛出异常。
> **说明:**
> 从API version 9开始废弃, 建议使用[InputClient.insertText](#InputClient.insertText)替代
>
> 从 API version 8开始支持。
**系统能力**
: SystemCapability.MiscServices.InputMethodFramework
**参数:**
...
...
@@ -952,12 +1292,17 @@ insertText(text:string): Promise<boolean>
}
```
### getEditorAttribute
### getEditorAttribute
<sup>deprecated</sup>
getEditorAttribute(callback: AsyncCallback
<
EditorAttribute
>
): void
获取编辑框属性值。使用callback形式返回结果。参数个数为1,否则抛出异常。
> **说明:**
> 从API version 9开始废弃, 建议使用[InputClient.getEditorAttribute](#InputClient.getEditorAttribute)替代
>
> 从 API version 8开始支持。
**系统能力**
: SystemCapability.MiscServices.InputMethodFramework
**参数:**
...
...
@@ -979,12 +1324,17 @@ getEditorAttribute(callback: AsyncCallback<EditorAttribute>): void
});
```
### getEditorAttribute
### getEditorAttribute
<sup>deprecated</sup>
getEditorAttribute(): Promise
<
EditorAttribute
>
获取编辑框属性值。使用promise形式返回结果。参数个数为0,否则抛出异常。
> **说明:**
> 从API version 9开始废弃, 建议使用[InputClient.getEditorAttribute](#InputClient.getEditorAttribute)替代
>
> 从 API version 8开始支持。
**系统能力**
: SystemCapability.MiscServices.InputMethodFramework
**返回值:**
...
...
@@ -1006,25 +1356,476 @@ getEditorAttribute(): Promise<EditorAttribute>
}
```
##
# moveCursor
<sup>9+</sup>
##
InputClient <a name="InputClient "></a>
<sup>9+</sup>
moveCursor(direction: number, callback: AsyncCallback
<
void
>
): void
下列API示例中都需使用
[
inputStart
](
#inputStart
)
回调获取到InputClient实例,再通过此实例调用对应方法。
移动光标。使用callback形式返回结果。参数个数为1,否则抛出异常。
### sendKeyFunction<sup>9+</sup>
sendKeyFunction(action:number, callback: AsyncCallback
<
boolean
>
): void
发送功能键。使用callback形式返回结果。参数个数为2,否则抛出异常。
**系统能力**
: SystemCapability.MiscServices.InputMethodFramework
**参数:**
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| --------- | ------------------------- | ---- | -------------- |
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| action | number | 是 | 编辑框属性。 |
| callback | AsyncCallback
<
boolean
>
| 是 | 操作成功与否。 |
**示例:**
```
js
TextInputClient
.
sendKeyFunction
(
keyFunction
,
(
err
,
result
)
=>
{
if
(
err
===
undefined
)
{
console
.
error
(
'
sendKeyFunction callback result---err:
'
+
err
.
msg
);
return
;
}
if
(
result
)
{
console
.
info
(
'
Success to sendKeyFunction.(callback)
'
);
}
else
{
console
.
error
(
'
Failed to sendKeyFunction.(callback)
'
);
}
});
```
### sendKeyFunction<sup>9+</sup>
sendKeyFunction(action:number): Promise
<
boolean
>
发送功能键。使用promise形式返回结果。参数个数为1,否则抛出异常。
**系统能力**
: SystemCapability.MiscServices.InputMethodFramework
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| action | number | 是 | 编辑框属性。 |
**返回值:**
| 类型 | 说明 |
| ------------------------------- | ------------------------------------------------------------ |
| Promise
<
boolean
>
| 操作成功与否。 |
**示例:**
```
js
async
function
InputMethodEngine
()
{
await
client
.
sendKeyFunction
(
keyFunction
).
then
((
result
)
=>
{
if
(
result
)
{
console
.
info
(
'
Success to sendKeyFunction.(promise)
'
);
}
else
{
console
.
error
(
'
Failed to sendKeyFunction.(promise)
'
);
}
}).
catch
((
err
)
=>
{
console
.
error
(
'
sendKeyFunction promise err:
'
+
err
.
msg
);
});
}
```
### getForward<sup>9+</sup>
getForward(length:number, callback: AsyncCallback
<
string
>
): void
获取光标前固定长度的文本。使用callback形式返回结果。参数个数为2,否则抛出异常。
**系统能力**
: SystemCapability.MiscServices.InputMethodFramework
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| length | number | 是 | 文本长度。 |
| callback | AsyncCallback
<
string
>
| 是 | 返回文本。 |
**示例:**
```
js
var
length
=
1
;
TextInputClient
.
getForward
(
length
,
(
err
,
text
)
=>
{
if
(
err
===
undefined
)
{
console
.
error
(
'
getForward callback result---err:
'
+
err
.
msg
);
return
;
}
console
.
log
(
'
getForward callback result---text:
'
+
text
);
});
```
### getForward<sup>9+</sup>
getForward(length:number): Promise
<
string
>
获取光标前固定长度的文本。使用promise形式返回结果。参数个数为1,否则抛出异常。
**系统能力**
: SystemCapability.MiscServices.InputMethodFramework
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| length | number | 是 | 文本长度。 |
**返回值:**
| 类型 | 说明 |
| ------------------------------- | ------------------------------------------------------------ |
| Promise
<
string
>
| 返回文本。 |
**示例:**
```
js
async
function
InputMethodEngine
()
{
var
length
=
1
;
await
TextInputClient
.
getForward
(
length
).
then
((
text
)
=>
{
console
.
info
(
'
getForward promise result---res:
'
+
text
);
}).
catch
((
err
)
=>
{
console
.
error
(
'
getForward promise err:
'
+
err
.
msg
);
});
}
```
### getBackward<sup>9+</sup>
getBackward(length:number, callback: AsyncCallback
<
string
>
): void
获取光标后固定长度的文本。使用callback形式返回结果。参数个数为2,否则抛出异常。
**系统能力**
: SystemCapability.MiscServices.InputMethodFramework
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| length | number | 是 | 文本长度。 |
| callback | AsyncCallback
<
string
>
| 是 | 返回文本。 |
**示例:**
```
js
var
length
=
1
;
TextInputClient
.
getBackward
(
length
,
(
err
,
text
)
=>
{
if
(
err
===
undefined
)
{
console
.
error
(
'
getBackward callback result---err:
'
+
err
.
msg
);
return
;
}
console
.
log
(
'
getBackward callback result---text:
'
+
text
);
});
```
### getBackward<sup>9+</sup>
getBackward(length:number): Promise
<
string
>
获取光标后固定长度的文本。使用promise形式返回结果。参数个数为1,否则抛出异常。
**系统能力**
: SystemCapability.MiscServices.InputMethodFramework
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| length | number | 是 | 文本长度。 |
**返回值:**
| 类型 | 说明 |
| ------------------------------- | ------------------------------------------------------------ |
| Promise
<
string
>
| 返回文本。 |
**示例:**
```
js
async
function
InputMethodEngine
()
{
var
length
=
1
;
await
TextInputClient
.
getBackward
(
length
).
then
((
text
)
=>
{
console
.
info
(
'
getBackward promise result---res:
'
+
text
);
}).
catch
((
err
)
=>
{
console
.
error
(
'
getBackward promise err:
'
+
err
.
msg
);
});
}
```
### deleteForward<sup>9+</sup>
deleteForward(length:number, callback: AsyncCallback
<
boolean
>
): void
删除光标前固定长度的文本。使用callback形式返回结果。参数个数为2,否则抛出异常。
**系统能力**
: SystemCapability.MiscServices.InputMethodFramework
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| length | number | 是 | 文本长度。 |
| callback | AsyncCallback
<
boolean
>
| 是 | 操作成功与否。 |
**示例:**
```
js
var
length
=
1
;
TextInputClient
.
deleteForward
(
length
,
(
err
,
result
)
=>
{
if
(
err
===
undefined
)
{
console
.
error
(
'
deleteForward callback result---err:
'
+
err
.
msg
);
return
;
}
if
(
result
)
{
console
.
info
(
'
Success to deleteForward.(callback)
'
);
}
else
{
console
.
error
(
'
Failed to deleteForward.(callback)
'
);
}
});
```
### deleteForward<sup>9+</sup>
deleteForward(length:number): Promise
<
boolean
>
删除光标前固定长度的文本。使用promise形式返回结果。参数个数为1,否则抛出异常。
**系统能力**
: SystemCapability.MiscServices.InputMethodFramework
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| ------ | ------ | ---- | ---------- |
| length | number | 是 | 文本长度。 |
**返回值:**
| 类型 | 说明 |
| ---------------------- | -------------- |
| Promise
<
boolean
>
| 操作成功与否。 |
**示例:**
```
js
async
function
InputMethodEngine
()
{
var
length
=
1
;
await
TextInputClient
.
deleteForward
(
length
).
then
((
result
)
=>
{
if
(
result
)
{
console
.
info
(
'
Success to deleteForward.(promise)
'
);
}
else
{
console
.
error
(
'
Failed to deleteForward.(promise)
'
);
}
}).
catch
((
err
)
=>
{
console
.
error
(
'
deleteForward promise err:
'
+
err
.
msg
);
});
}
```
### deleteBackward<sup>9+</sup>
deleteBackward(length:number, callback: AsyncCallback
<
boolean
>
): void
删除光标后固定长度的文本。使用callback形式返回结果。参数个数为2,否则抛出异常。
**系统能力**
: SystemCapability.MiscServices.InputMethodFramework
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | ---------------------------- | ---- | -------------- |
| length | number | 是 | 文本长度。 |
| callback | AsyncCallback
<
boolean
>
| 是 | 操作成功与否。 |
**示例:**
```
js
var
length
=
1
;
TextInputClient
.
deleteBackward
(
length
,
(
err
,
result
)
=>
{
if
(
err
===
undefined
)
{
console
.
error
(
'
deleteBackward callback result---err:
'
+
err
.
msg
);
return
;
}
if
(
result
)
{
console
.
info
(
'
Success to deleteBackward.(callback)
'
);
}
else
{
console
.
error
(
'
Failed to deleteBackward.(callback)
'
);
}
});
```
### deleteBackward<sup>9+</sup>
deleteBackward(length:number): Promise
<
boolean
>
删除光标后固定长度的文本。使用callback形式返回结果。参数个数为2,否则抛出异常。
**系统能力**
: SystemCapability.MiscServices.InputMethodFramework
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| length | number | 是 | 文本长度。 |
**返回值:**
| 类型 | 说明 |
| ------------------------------- | ------------------------------------------------------------ |
| Promise
<
boolean
>
| 操作成功与否。 |
**示例:**
```
js
async
function
InputMethodAbility
()
{
var
length
=
1
;
await
InputClient
.
deleteBackward
(
length
).
then
((
result
)
=>
{
if
(
result
)
{
console
.
info
(
'
Success to deleteBackward.(promise)
'
);
}
else
{
console
.
error
(
'
Failed to deleteBackward.(promise)
'
);
}
}).
catch
((
err
)
=>
{
console
.
error
(
'
deleteBackward promise err:
'
+
err
.
msg
);
});
}
```
### insertText<sup>9+</sup>
insertText(text:string, callback: AsyncCallback
<
boolean
>
): void
插入文本。使用callback形式返回结果。参数个数为2,否则抛出异常。
**系统能力**
: SystemCapability.MiscServices.InputMethodFramework
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| text | string | 是 | 文本。 |
| callback | AsyncCallback
<
boolean
>
| 是 | 操作成功与否。 |
**示例:**
```
js
TextInputClient
.
insertText
(
'
test
'
,
(
err
,
result
)
=>
{
if
(
err
===
undefined
)
{
console
.
error
(
'
insertText callback result---err:
'
+
err
.
msg
);
return
;
}
if
(
result
)
{
console
.
info
(
'
Success to insertText.(callback)
'
);
}
else
{
console
.
error
(
'
Failed to insertText.(callback)
'
);
}
});
```
### insertText<sup>9+</sup>
insertText(text:string): Promise
<
boolean
>
插入文本。使用promise形式返回结果。参数个数为1,否则抛出异常。
**系统能力**
: SystemCapability.MiscServices.InputMethodFramework
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| text | string | 是 | 文本。 |
**返回值:**
| 类型 | 说明 |
| ------------------------------- | ------------------------------------------------------------ |
| Promise
<
boolean
>
| 操作成功与否。 |
**示例:**
```
js
async
function
InputMethodEngine
()
{
await
TextInputClient
.
insertText
(
'
test
'
).
then
((
result
)
=>
{
if
(
result
)
{
console
.
info
(
'
Success to insertText.(promise)
'
);
}
else
{
console
.
error
(
'
Failed to insertText.(promise)
'
);
}
}).
catch
((
err
)
=>
{
console
.
error
(
'
insertText promise err:
'
+
err
.
msg
);
});
}
```
### getEditorAttribute<sup>9+</sup>
getEditorAttribute(callback: AsyncCallback
<
EditorAttribute
>
): void
获取编辑框属性值。使用callback形式返回结果。参数个数为1,否则抛出异常。
**系统能力**
: SystemCapability.MiscServices.InputMethodFramework
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| ------------------------------- | ------------------------------------------------------------ | ------------------------------------------------------------ | ------------------------------------------------------------ |
| callback | AsyncCallback
<
[EditorAttribute](#EditorAttribute)
>
| 是 | 编辑框属性值。 |
**示例:**
```
js
TextInputClient
.
getEditorAttribute
((
err
,
editorAttribute
)
=>
{
if
(
err
===
undefined
)
{
console
.
error
(
'
getEditorAttribute callback result---err:
'
+
err
.
msg
);
return
;
}
console
.
log
(
'
editorAttribute.inputPattern(callback):
'
+
JSON
.
stringify
(
editorAttribute
.
inputPattern
));
console
.
log
(
'
editorAttribute.enterKeyType(callback):
'
+
JSON
.
stringify
(
editorAttribute
.
enterKeyType
));
});
```
### getEditorAttribute<sup>9+</sup>
getEditorAttribute(): Promise
<
EditorAttribute
>
获取编辑框属性值。使用promise形式返回结果。参数个数为0,否则抛出异常。
**系统能力**
: SystemCapability.MiscServices.InputMethodFramework
**返回值:**
| 类型 | 说明 |
| ------------------------------- | ------------------------------------------------------------ |
| Promise
<
[EditorAttribute](#EditorAttribute)
>
| 返回编辑框属性值。 |
**示例:**
```
js
async
function
InputMethodEngine
()
{
await
TextInputClient
.
getEditorAttribute
().
then
((
editorAttribute
)
=>
{
console
.
info
(
'
editorAttribute.inputPattern(promise):
'
+
JSON
.
stringify
(
editorAttribute
.
inputPattern
));
console
.
info
(
'
editorAttribute.enterKeyType(promise):
'
+
JSON
.
stringify
(
editorAttribute
.
enterKeyType
));
}).
catch
((
err
)
=>
{
console
.
error
(
'
getEditorAttribute promise err:
'
+
err
.
msg
);
});
}
```
### moveCursor<sup>9+</sup>
moveCursor(direction: number, callback: AsyncCallback
<
void
>
): void
移动光标。使用callback形式返回结果。参数个数为1,否则抛出异常。
**系统能力**
: SystemCapability.MiscServices.InputMethodFramework
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| --------- | ------------------------- | ---- | -------------- |
| direction | number | 是 | 光标移动方向。 |
| callback | AsyncCallback
<
void
>
| 是 | 回调函数。 |
**示例:**
```
js
TextInputClient
.
moveCursor
(
inputMethodEngine
.
CURSOR_xxx
,
(
err
)
=>
{
InputClient
.
moveCursor
(
inputMethodAbility
.
CURSOR_xxx
,
(
err
)
=>
{
if
(
err
===
undefined
)
{
console
.
error
(
'
moveCursor callback result---err:
'
+
err
.
msg
);
return
;
...
...
@@ -1055,8 +1856,8 @@ moveCursor(direction: number): Promise<void>
**示例:**
```
js
async
function
InputMethod
Engine
()
{
await
TextInputClient
.
moveCursor
(
inputMethodEngine
.
CURSOR_xxx
).
then
(
async
(
err
)
=>
{
async
function
InputMethod
Ability
()
{
await
InputClient
.
moveCursor
(
inputMethodAbility
.
CURSOR_xxx
).
then
(
async
(
err
)
=>
{
console
.
log
(
'
moveCursor success
'
);
}).
catch
((
err
)
=>
{
console
.
error
(
'
moveCursor success err:
'
+
err
.
msg
);
...
...
zh-cn/application-dev/reference/apis/js-apis-inputmethodsubtype.md
0 → 100644
浏览文件 @
534e97ce
# 输入法子类型
本模块提供对输入法子类型的属性管理
>  **说明:**
>
> 本模块首批接口从API version 9开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
## InputMethodSubtype
属性值。
**系统能力**
:以下各项对应的系统能力均为SystemCapability.MiscServices.InputMethodFramework
| 名称 | 参数类型 | 可读 | 可写 | 必选 | 说明 |
| -------- | -------- | -------- | -------- | -------- | -------- |
| label | string | 是 | 否 | 否 | 输入法子类型的标签。 |
| id | string | 是 | 否 | 是 | 输入法子类型的id。 |
| mode | string | 是 | 否 | 否 | 输入法子类型的模式,包括upper和lower。 |
| locale | string | 是 | 否 | 是 | 输入法子类型的locale。 |
| language | string | 是 | 否 | 是 | 输入法子类型的语言。 |
| icon | string | 是 | 否 | 否 | 输入法子类型的图标。 |
| iconId | number | 是 | 否 | 否 | 输入法子类型的图标id。 |
| extra | object | 是 | 是 | 是 | 输入法子类型的其他信息。 |
\ No newline at end of file
zh-cn/application-dev/reference/errorcodes/errcode-InputMethodFramework.md
0 → 100644
浏览文件 @
534e97ce
# 输入法框架错误码
## 12800201 权限校验异常
### 错误信息
the permissions check fails.
### 可能原因
该错误码表示未通过权限校验。
### 处理步骤
给应用配置相应的权限
## 12800401 参数校验异常
### 错误信息
the parameters check fails.
### 可能原因
该错误码表示调用接口时传入的参数个数不对或者参数类型不对。
### 处理步骤
修改接口调用时传入的参数个数或者类型
## 12800801 功能支持异常
### 错误信息
call unsupported api.
### 可能原因
该错误码表示调用了不被支持的接口
### 处理步骤
调用其他接口去实现想要的功能
## 12800001 包管理异常
### 错误信息
package manager error.
### 可能原因
该错误码表示
### 处理步骤
## 12800002 输入法引擎异常
### 错误信息
input method engine error
### 可能原因
该错误码表示未能正确获得输入法引擎
### 处理步骤
重新获取输入法引擎
## 12800003 输入法客户端异常
### 错误信息
input method client error
### 可能原因
该错误码表示在输入法客户端发生异常
### 处理步骤
检查修改在输入法客户端的操作
## 12800004 鼠标事件进程异常
### 错误信息
key event processing error
### 可能原因
该错误码表示在鼠标执行过程中发生异常
### 处理步骤
重新执行鼠标事件
## 12800005 配置持久化异常
### 错误信息
configuration persisting error
### 可能原因
该错误码表示获取先前的配置失败
### 处理步骤
重新获取先前配置
## 12800006 输入法控制器异常
### 错误信息
input method controller error
### 可能原因
该错误码表示使用输入法控制器时发生异常
### 处理步骤
重新获取输入法控制器
## 12800007 输入法配置拓展异常
### 错误信息
input method settings extension error
### 可能原因
该错误码表示使用输入法配置执行一些操作时候发生异常
### 处理步骤
重新获取输入法配置
## 12800008 输入法管理服务异常
### 错误信息
input method manager service error
### 可能原因
该错误码表示输入法服务侧发生异常
### 处理步骤
重新获取输入法服务
## 12899999 其他异常
### 错误信息
others error
### 可能原因
该错误码表示除了上述异常之外的未定义异常
### 处理步骤
无
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录