js-apis-inputmethod.md 93.1 KB
Newer Older
1
# @ohos.inputMethod (输入法框架)
Z
zhouyongfei 已提交
2

Z
zhaolinglan 已提交
3
本模块主要面向普通前台应用(备忘录、信息、设置等系统应用与三方应用),提供对输入法的控制、管理能力,包括显示/隐藏输入法软键盘、切换输入法、获取所有输入法列表等。
T
explain  
tianyu 已提交
4

5
> **说明:**
H
update  
Hollokin 已提交
6
>
7
> 本模块首批接口从API version 6开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
Z
zhouyongfei 已提交
8 9 10 11


## 导入模块

12
```js
13
import inputMethod from '@ohos.inputMethod';
Z
zhouyongfei 已提交
14 15
```

H
Hollokin 已提交
16
## 常量<sup>8+</sup>
Z
zhouyongfei 已提交
17 18 19

常量值。

H
update  
Hollokin 已提交
20
**系统能力:** SystemCapability.MiscServices.InputMethodFramework
Z
刷新  
zhouyongfei 已提交
21

22
| 参数名 | 类型 | 常量值 | 说明 |
H
Hollokin 已提交
23 24
| -------- | -------- | -------- | -------- |
| MAX_TYPE_NUM | number | 128 | 可支持的最大输入法个数。 |
Z
zhouyongfei 已提交
25

26
## InputMethodProperty<sup>8+</sup>
Z
zhouyongfei 已提交
27 28 29

输入法应用属性。

H
update  
Hollokin 已提交
30
**系统能力:** SystemCapability.MiscServices.InputMethodFramework
Z
刷新  
zhouyongfei 已提交
31

32
| 名称 | 类型 | 可读 | 可写 | 说明 |
Z
zhouyongfei 已提交
33
| -------- | -------- | -------- | -------- | -------- |
H
Hollokin 已提交
34 35 36
| name<sup>9+</sup>  | string | 是 | 否 | 输入法内部名称。必填。|
| id<sup>9+</sup>    | string | 是 | 否 | 输入法唯一标识。必填。|
| label<sup>9+</sup>    | string | 是 | 否 | 输入法对外显示名称。 非必填。|
C
cy7717 已提交
37
| labelId<sup>10+</sup>    | string | 是 | 否 | 输入法对外显示名称资源号。 非必填。|
H
Hollokin 已提交
38 39
| icon<sup>9+</sup>    | string | 是 | 否 | 输入法图标数据。非必填。 |
| iconId<sup>9+</sup>    | number | 是 | 否 | 输入法图标资源号。非必填。 |
C
cy7717 已提交
40
| extra<sup>9+</sup>    | object | 是 | 是 | 输入法扩展信息。 非必填。<br/>**说明:** 从API version 10开始改为非必选参数。|
H
Hollokin 已提交
41 42
| packageName<sup>(deprecated)</sup> | string | 是 | 否 | 输入法包名。必填。<br/>**说明:** 从API version 8开始支持,从API version 9开始废弃,建议使用name替代。 |
| methodId<sup>(deprecated)</sup> | string | 是 | 否 | 输入法唯一标识。必填。<br/>**说明:** 从API version 8开始支持,从API version 9开始废弃,建议使用id替代。 |
Z
zhouyongfei 已提交
43

44 45 46 47 48 49
## inputMethod.getController<sup>9+</sup>

getController(): InputMethodController

获取客户端实例[InputMethodController](#inputmethodcontroller)

H
update  
Hollokin 已提交
50
**系统能力:** SystemCapability.MiscServices.InputMethodFramework
51 52 53 54 55 56 57

**返回值:**

| 类型                                            | 说明                     |
| ----------------------------------------------- | ------------------------ |
| [InputMethodController](#inputmethodcontroller) | 回调返回当前客户端实例。 |

H
Hollokin 已提交
58 59
**错误码:**

60
以下错误码的详细介绍请参见[输入法框架错误码](../errorcodes/errorcode-inputmethod-framework.md)
H
Hollokin 已提交
61

62
| 错误码ID | 错误信息                     |
H
Hollokin 已提交
63 64 65
| -------- | ------------------------------ |
| 12800006 | Input method controller error. |

66 67
**示例:**

H
Hollokin 已提交
68
```js
69
let inputMethodController = inputMethod.getController();
70
```
71 72 73 74 75 76 77

## inputMethod.getSetting<sup>9+</sup>

getSetting(): InputMethodSetting

获取客户端设置实例[InputMethodSetting](#inputmethodsetting8)

H
update  
Hollokin 已提交
78
**系统能力:** SystemCapability.MiscServices.InputMethodFramework
79 80 81 82 83 84 85

**返回值:**

| 类型                                      | 说明                         |
| ----------------------------------------- | ---------------------------- |
| [InputMethodSetting](#inputmethodsetting8) | 回调返回当前客户端设置实例。 |

H
Hollokin 已提交
86 87
**错误码:**

88
以下错误码的详细介绍请参见[输入法框架错误码](../errorcodes/errorcode-inputmethod-framework.md)
H
Hollokin 已提交
89

90
| 错误码ID | 错误信息                             |
H
Hollokin 已提交
91 92 93
| -------- | -------------------------------------- |
| 12800007 | Input method settings extension error. |

94 95
**示例:**

H
Hollokin 已提交
96
```js
H
Hollokin 已提交
97
let inputMethodSetting = inputMethod.getSetting();
98 99
```

G
gaoxiang 已提交
100
## inputMethod.switchInputMethod<sup>9+</sup>
Z
zhouyongfei 已提交
101

Z
zhaolinglan 已提交
102
switchInputMethod(target: InputMethodProperty, callback: AsyncCallback&lt;boolean&gt;): void
G
gaoxiang 已提交
103

H
Hollokin 已提交
104
切换输入法。使用callback异步回调。
105

H
Hollokin 已提交
106
**需要权限:** ohos.permission.CONNECT_IME_ABILITY,仅系统应用可用。
107

H
update  
Hollokin 已提交
108
**系统能力:** SystemCapability.MiscServices.InputMethodFramework
G
gaoxiang 已提交
109 110 111

**参数:**

H
Hollokin 已提交
112 113 114 115
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| target | [InputMethodProperty](#inputmethodproperty8) | 是 | 传入要切换的目标输入法。 |
| callback | AsyncCallback&lt;boolean&gt; | 是 | 回调函数。当输入法切换成功,err为undefined,data为true;否则为错误对象。 |
G
gaoxiang 已提交
116

H
Hollokin 已提交
117 118
**错误码:**

119
以下错误码的详细介绍请参见[输入法框架错误码](../errorcodes/errorcode-inputmethod-framework.md)
H
Hollokin 已提交
120

121
| 错误码ID | 错误信息                             |
H
Hollokin 已提交
122 123
| -------- | -------------------------------------- |
| 12800005 | Configuration persisting error.        |
H
Hollokin 已提交
124
| 12800008 | Input method manager service error. |
H
Hollokin 已提交
125

G
gaoxiang 已提交
126 127
**示例:**

H
Hollokin 已提交
128
```js
H
Hollokin 已提交
129 130 131 132 133 134 135 136
let im = inputMethod.getCurrentInputMethod();
let prop = {
    packageName: im.packageName,
    methodId: im.methodId,
    name: im.packageName,
    id: im.methodId,
    extra: {}
}
H
Hollokin 已提交
137
try{
H
Hollokin 已提交
138 139 140
    inputMethod.switchInputMethod(prop, (err, result) => {
        if (err !== undefined) {
            console.error('Failed to switchInputMethod: ' + JSON.stringify(err));
H
Hollokin 已提交
141 142 143
            return;
        }
        if (result) {
H
Hollokin 已提交
144
            console.info('Succeeded in switching inputmethod.');
H
Hollokin 已提交
145
        } else {
H
Hollokin 已提交
146
            console.error('Failed to switchInputMethod.');
H
Hollokin 已提交
147 148 149
        }
    });
} catch(err) {
H
Hollokin 已提交
150
    console.error('Failed to switchInputMethod: ' + JSON.stringify(err));
H
Hollokin 已提交
151
}
G
gaoxiang 已提交
152
```
G
gaoxiang 已提交
153
## inputMethod.switchInputMethod<sup>9+</sup>
Z
zhaolinglan 已提交
154
switchInputMethod(target: InputMethodProperty): Promise&lt;boolean&gt;
G
gaoxiang 已提交
155

H
Hollokin 已提交
156
切换输入法。使用promise异步回调。
G
gaoxiang 已提交
157

H
Hollokin 已提交
158
**需要权限:** ohos.permission.CONNECT_IME_ABILITY,仅系统应用可用。
159

H
update  
Hollokin 已提交
160
**系统能力:** SystemCapability.MiscServices.InputMethodFramework
G
gaoxiang 已提交
161

G
gaoxiang 已提交
162
**参数:**
G
gaoxiang 已提交
163 164 165

  | 参数名 | 类型 | 必填 | 说明 |
  | -------- | -------- | -------- | -------- |
166
  |target |  [InputMethodProperty](#inputmethodproperty8)| 是 | 传入要切换的目标输入法。 |
G
gaoxiang 已提交
167

G
gaoxiang 已提交
168
**返回值:**
B
bmeangel 已提交
169

G
gaoxiang 已提交
170 171
  | 类型                                      | 说明                         |
  | ----------------------------------------- | ---------------------------- |
H
Hollokin 已提交
172
  | Promise\<boolean> | Promise对象。返回true表示切换输入法成功;返回false表示切换输入法失败。 |
G
gaoxiang 已提交
173

H
Hollokin 已提交
174 175
**错误码:**

176
以下错误码的详细介绍请参见[输入法框架错误码](../errorcodes/errorcode-inputmethod-framework.md)
H
Hollokin 已提交
177

178
| 错误码ID | 错误信息                             |
H
Hollokin 已提交
179 180
| -------- | -------------------------------------- |
| 12800005 | Configuration persisting error.        |
H
Hollokin 已提交
181
| 12800008 | Input method manager service error. |
H
Hollokin 已提交
182

G
gaoxiang 已提交
183 184
**示例:**

H
Hollokin 已提交
185
```js
H
Hollokin 已提交
186 187 188 189 190 191 192 193
let im = inputMethod.getCurrentInputMethod();
let prop = {
    packageName: im.packageName,
    methodId: im.methodId,
    name: im.packageName,
    id: im.methodId,
    extra: {}
}
H
Hollokin 已提交
194
try {
H
Hollokin 已提交
195
    inputMethod.switchInputMethod(prop).then((result) => {
H
Hollokin 已提交
196
        if (result) {
H
Hollokin 已提交
197
            console.info('Succeeded in switching inputmethod.');
H
Hollokin 已提交
198
        } else {
H
Hollokin 已提交
199
            console.error('Failed to switchInputMethod.');
H
Hollokin 已提交
200 201
        }
    }).catch((err) => {
H
Hollokin 已提交
202
        console.error('Failed to switchInputMethod: ' + JSON.stringify(err));
H
Hollokin 已提交
203 204
    })
} catch(err) {
H
Hollokin 已提交
205
    console.error('Failed to switchInputMethod: ' + JSON.stringify(err));
H
Hollokin 已提交
206
}
G
gaoxiang 已提交
207
```
208

Z
zhaolinglan 已提交
209 210 211 212
## inputMethod.getCurrentInputMethod<sup>9+</sup>

getCurrentInputMethod(): InputMethodProperty

H
Hollokin 已提交
213
获取当前输入法扩展应用,提供同步接口,返回当前输入法属性。
Z
zhaolinglan 已提交
214

H
update  
Hollokin 已提交
215
**系统能力:** SystemCapability.MiscServices.InputMethodFramework
Z
zhaolinglan 已提交
216 217 218

**返回值:**

Z
zhaolinglan 已提交
219 220
| 类型                                         | 说明                     |
| -------------------------------------------- | ------------------------ |
221
| [InputMethodProperty](#inputmethodproperty8) | 返回当前输入法属性对象。 |
Z
zhaolinglan 已提交
222 223 224

**示例:**

H
Hollokin 已提交
225
```js
H
Hollokin 已提交
226
let currentIme = inputMethod.getCurrentInputMethod();
Z
zhaolinglan 已提交
227 228
```

229 230
## inputMethod.switchCurrentInputMethodSubtype<sup>9+</sup>

H
Hollokin 已提交
231
switchCurrentInputMethodSubtype(target: InputMethodSubtype, callback: AsyncCallback\<boolean>): void
232

H
Hollokin 已提交
233
在当前输入法应用内切换子类型。使用callback异步回调。
234

C
cy7717 已提交
235
**需要权限:** ohos.permission.CONNECT_IME_ABILITY,仅系统应用可用。<br/>**说明:** 从API version 10开始,如果调用者为当前输入法应用,则不需要此权限。
236

H
update  
Hollokin 已提交
237
**系统能力:** SystemCapability.MiscServices.InputMethodFramework
238 239 240 241 242

**参数:**

| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
H
update  
Hollokin 已提交
243
| target |  [InputMethodSubtype](./js-apis-inputmethod-subtype.md#inputmethodsubtype)| 是 | 传入要切换的目标输入法子类型。 |
H
Hollokin 已提交
244
| callback | AsyncCallback&lt;boolean&gt; | 是 | 回调函数。当输入法子类型切换成功,err为undefined,data为true;否则为错误对象。|
245

H
Hollokin 已提交
246 247
**错误码:**

248
以下错误码的详细介绍请参见[输入法框架错误码](../errorcodes/errorcode-inputmethod-framework.md)
H
Hollokin 已提交
249

250
| 错误码ID | 错误信息                             |
H
Hollokin 已提交
251 252
| -------- | -------------------------------------- |
| 12800005 | Configuration persisting error.        |
H
Hollokin 已提交
253
| 12800008 | Input method manager service error. |
H
Hollokin 已提交
254

255 256
**示例:**

H
Hollokin 已提交
257
```js
H
Hollokin 已提交
258
try {
H
Hollokin 已提交
259
    inputMethod.switchCurrentInputMethodSubtype({
260 261 262
      id: "ServiceExtAbility",
      label: "",
      name: "com.example.kikakeyboard",
H
Hollokin 已提交
263 264 265 266 267 268 269 270 271
      mode: "upper",
      locale: "",
      language: "",
      icon: "",
      iconId: 0,
      extra: {}
    }, (err, result) => {
        if (err !== undefined) {
            console.error('Failed to switchCurrentInputMethodSubtype: ' + JSON.stringify(err));
H
Hollokin 已提交
272 273 274
            return;
        }
        if (result) {
H
Hollokin 已提交
275
            console.info('Succeeded in switching currentInputMethodSubtype.');
H
Hollokin 已提交
276
        } else {
H
Hollokin 已提交
277
            console.error('Failed to switchCurrentInputMethodSubtype');
H
Hollokin 已提交
278 279 280
        }
    });
} catch(err) {
H
Hollokin 已提交
281
    console.error('Failed to switchCurrentInputMethodSubtype: ' + JSON.stringify(err));
H
Hollokin 已提交
282
}
283 284 285 286 287 288
```

## inputMethod.switchCurrentInputMethodSubtype<sup>9+</sup>

switchCurrentInputMethodSubtype(target: InputMethodSubtype): Promise&lt;boolean&gt;

H
Hollokin 已提交
289
在当前输入法应用内切换子类型。使用promise异步回调。
290

C
cy7717 已提交
291
**需要权限:** ohos.permission.CONNECT_IME_ABILITY,仅系统应用可用。<br/>**说明:** 从API version 10开始,如果调用者为当前输入法应用,则不需要此权限。
292

H
update  
Hollokin 已提交
293
**系统能力:** SystemCapability.MiscServices.InputMethodFramework
294 295 296 297 298

**参数:**

| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
H
update  
Hollokin 已提交
299
|target |  [InputMethodSubtype](./js-apis-inputmethod-subtype.md#inputmethodsubtype)| 是 | 传入要切换的目标输入法子类型。 |
300

H
Hollokin 已提交
301 302 303 304 305 306
**返回值:**

| 类型                                      | 说明                         |
| ----------------------------------------- | ---------------------------- |
| Promise\<boolean> | Promise对象。返回true表示在当前输入法应用内切换子类型成功;返回false表示在当前输入法应用内切换子类型失败。 |

H
Hollokin 已提交
307 308
**错误码:**

309
以下错误码的详细介绍请参见[输入法框架错误码](../errorcodes/errorcode-inputmethod-framework.md)
H
Hollokin 已提交
310

311
| 错误码ID | 错误信息                             |
H
Hollokin 已提交
312 313
| -------- | -------------------------------------- |
| 12800005 | Configuration persisting error.        |
H
Hollokin 已提交
314
| 12800008 | Input method manager service error. |
H
Hollokin 已提交
315

316 317
**示例:**

H
Hollokin 已提交
318
```js
H
Hollokin 已提交
319
try {
H
Hollokin 已提交
320
    inputMethod.switchCurrentInputMethodSubtype({
321 322 323
      id: "ServiceExtAbility",
      label: "",
      name: "com.example.kikakeyboard",
H
Hollokin 已提交
324 325 326 327 328 329 330
      mode: "upper",
      locale: "",
      language: "",
      icon: "",
      iconId: 0,
      extra: {}
    }).then((result) => {
H
Hollokin 已提交
331
        if (result) {
H
Hollokin 已提交
332
            console.info('Succeeded in switching currentInputMethodSubtype.');
H
Hollokin 已提交
333
        } else {
H
Hollokin 已提交
334
            console.error('Failed to switchCurrentInputMethodSubtype.');
H
Hollokin 已提交
335 336
        }
    }).catch((err) => {
H
Hollokin 已提交
337
        console.error('Failed to switchCurrentInputMethodSubtype: ' + JSON.stringify(err));
H
Hollokin 已提交
338 339
    })
} catch(err) {
H
Hollokin 已提交
340
    console.error('Failed to switchCurrentInputMethodSubtype: ' + JSON.stringify(err));
H
Hollokin 已提交
341
}
342 343 344 345 346 347 348 349
```

## inputMethod.getCurrentInputMethodSubtype<sup>9+</sup>

getCurrentInputMethodSubtype(): InputMethodSubtype

获取当前输入法子类型。

H
update  
Hollokin 已提交
350
**系统能力:** SystemCapability.MiscServices.InputMethodFramework
351 352 353 354 355

**返回值:**

| 类型                                         | 说明                     |
| -------------------------------------------- | ------------------------ |
H
update  
Hollokin 已提交
356
| [InputMethodSubtype](./js-apis-inputmethod-subtype.md#inputmethodsubtype) | 返回当前输入法子类型对象。 |
357 358 359

**示例:**

H
Hollokin 已提交
360
```js
H
Hollokin 已提交
361
let currentImeSubType = inputMethod.getCurrentInputMethodSubtype();
362 363 364 365
```

## inputMethod.switchCurrentInputMethodAndSubtype<sup>9+</sup>

H
Hollokin 已提交
366
switchCurrentInputMethodAndSubtype(inputMethodProperty: InputMethodProperty, inputMethodSubtype: InputMethodSubtype, callback: AsyncCallback\<boolean>): void
367

H
Hollokin 已提交
368
切换至指定输入法应用的指定子类型,用于跨输入法应用切换子类型。使用callback异步回调。
369

H
Hollokin 已提交
370
**需要权限:** ohos.permission.CONNECT_IME_ABILITY,仅系统应用可用。
371

H
update  
Hollokin 已提交
372
**系统能力:** SystemCapability.MiscServices.InputMethodFramework
373 374 375 376 377

**参数:**

| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
378
|inputMethodProperty |  [InputMethodProperty](#inputmethodproperty8)| 是 | 传入要切换的目标输入法。 |
H
update  
Hollokin 已提交
379
|inputMethodSubtype |  [InputMethodSubtype](./js-apis-inputmethod-subtype.md#inputmethodsubtype)| 是 | 传入要切换的目标输入法子类型。 |
H
Hollokin 已提交
380
| callback | AsyncCallback&lt;boolean&gt; | 是 | 回调函数。当输入法和子类型切换成功,err为undefined,data为获取到的切换子类型结果true;否则为错误对象。 |
381

H
Hollokin 已提交
382 383
**错误码:**

384
以下错误码的详细介绍请参见[输入法框架错误码](../errorcodes/errorcode-inputmethod-framework.md)
H
Hollokin 已提交
385

386
| 错误码ID | 错误信息                             |
H
Hollokin 已提交
387 388
| -------- | -------------------------------------- |
| 12800005 | Configuration persisting error.        |
H
Hollokin 已提交
389
| 12800008 | Input method manager service error. |
H
Hollokin 已提交
390

391 392
**示例:**

H
Hollokin 已提交
393
```js
H
Hollokin 已提交
394
let im = inputMethod.getCurrentInputMethod();
395
let imSubType = inputMethod.getCurrentInputMethodSubtype();
H
Hollokin 已提交
396
try {
397
    inputMethod.switchCurrentInputMethodAndSubtype(im, imSubType, (err,result) => {
H
Hollokin 已提交
398 399
        if (err !== undefined) {
            console.error('Failed to switchCurrentInputMethodAndSubtype: ' + JSON.stringify(err));
H
Hollokin 已提交
400 401 402
            return;
        }
        if (result) {
H
Hollokin 已提交
403
            console.info('Succeeded in switching currentInputMethodAndSubtype.');
H
Hollokin 已提交
404
        } else {
H
Hollokin 已提交
405
            console.error('Failed to switchCurrentInputMethodAndSubtype.');
H
Hollokin 已提交
406 407 408
        }
    });
} catch (err) {
H
Hollokin 已提交
409
    console.error('Failed to switchCurrentInputMethodAndSubtype: ' + JSON.stringify(err));
H
Hollokin 已提交
410
}
411 412 413 414
```

## inputMethod.switchCurrentInputMethodAndSubtype<sup>9+</sup>

H
Hollokin 已提交
415
switchCurrentInputMethodAndSubtype(inputMethodProperty: InputMethodProperty, inputMethodSubtype: InputMethodSubtype): Promise&lt;boolean&gt;
416

H
Hollokin 已提交
417
切换至指定输入法应用的指定子类型,用于跨输入法应用切换子类型。使用promise异步回调。
418

H
Hollokin 已提交
419
**需要权限:** ohos.permission.CONNECT_IME_ABILITY,仅系统应用可用。
420

H
update  
Hollokin 已提交
421
**系统能力:** SystemCapability.MiscServices.InputMethodFramework
422 423 424 425 426

**参数:**

| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
427
|inputMethodProperty |  [InputMethodProperty](#inputmethodproperty8)| 是 | 传入要切换的目标输入法。 |
H
update  
Hollokin 已提交
428
|inputMethodSubtype |  [InputMethodSubtype](./js-apis-inputmethod-subtype.md#inputmethodsubtype)| 是 | 传入要切换的目标输入法子类型。 |
429

H
Hollokin 已提交
430 431 432 433 434 435
**返回值:**

| 类型                                      | 说明                         |
| ----------------------------------------- | ---------------------------- |
| Promise\<boolean> | Promise对象。返回true表示切换至指定输入法应用的指定子类型成功;返回false表示切换至指定输入法应用的指定子类型失败。 |

H
Hollokin 已提交
436 437
**错误码:**

438
以下错误码的详细介绍请参见[输入法框架错误码](../errorcodes/errorcode-inputmethod-framework.md)
H
Hollokin 已提交
439

440
| 错误码ID | 错误信息                             |
H
Hollokin 已提交
441 442
| -------- | -------------------------------------- |
| 12800005 | Configuration persisting error.        |
H
Hollokin 已提交
443
| 12800008 | Input method manager service error. |
H
Hollokin 已提交
444

445 446
**示例:**

H
Hollokin 已提交
447
```js
H
Hollokin 已提交
448
let im = inputMethod.getCurrentInputMethod();
449
let imSubType = inputMethod.getCurrentInputMethodSubtype();
H
Hollokin 已提交
450
try {
451
    inputMethod.switchCurrentInputMethodAndSubtype(im, imSubType).then((result) => {
H
Hollokin 已提交
452
        if (result) {
H
Hollokin 已提交
453
            console.info('Succeeded in switching currentInputMethodAndSubtype.');
H
Hollokin 已提交
454
        } else {
H
Hollokin 已提交
455
            console.error('Failed to switchCurrentInputMethodAndSubtype.');
H
Hollokin 已提交
456 457
        }
    }).catch((err) => {
H
Hollokin 已提交
458
        console.error('Failed to switchCurrentInputMethodAndSubtype: ' + JSON.stringify(err));
H
Hollokin 已提交
459 460
    })
} catch(err) {
H
Hollokin 已提交
461
    console.error('Failed to switchCurrentInputMethodAndSubtype: ' + JSON.stringify(err));
H
Hollokin 已提交
462
}
463 464
```

H
Hollokin 已提交
465
## inputMethod.getInputMethodController<sup>(deprecated)</sup>
Z
zhouyongfei 已提交
466

H
Hollokin 已提交
467
getInputMethodController(): InputMethodController
Z
zhouyongfei 已提交
468

H
Hollokin 已提交
469
获取客户端实例[InputMethodController](#inputmethodcontroller)
Z
zhouyongfei 已提交
470

H
update  
Hollokin 已提交
471 472 473
> **说明:** 
>
> 从API version 6开始支持,从API version 9开始废弃, 建议使用[getController()](#inputmethodgetcontroller9)替代。
H
Hollokin 已提交
474

H
update  
Hollokin 已提交
475
**系统能力:** SystemCapability.MiscServices.InputMethodFramework
Z
zhouyongfei 已提交
476

H
Hollokin 已提交
477
**返回值:**
Z
zhouyongfei 已提交
478

H
Hollokin 已提交
479 480 481
| 类型                                            | 说明                     |
| ----------------------------------------------- | ------------------------ |
| [InputMethodController](#inputmethodcontroller) | 回调返回当前客户端实例。 |
Z
zhouyongfei 已提交
482

483
**示例:**
Z
zhouyongfei 已提交
484

485
```js
486
let inputMethodController = inputMethod.getInputMethodController();
Z
zhouyongfei 已提交
487 488
```

H
Hollokin 已提交
489
## inputMethod.getInputMethodSetting<sup>(deprecated)</sup>
Z
zhouyongfei 已提交
490

H
Hollokin 已提交
491
getInputMethodSetting(): InputMethodSetting
Z
zhouyongfei 已提交
492

H
Hollokin 已提交
493
获取客户端设置实例[InputMethodSetting](#inputmethodsetting8)
Z
zhouyongfei 已提交
494

495 496 497
> **说明:**
>
> 从API version 6开始支持,从API version 9开始废弃, 建议使用[getSetting()](#inputmethodgetsetting9)替代。
H
Hollokin 已提交
498

H
update  
Hollokin 已提交
499
**系统能力:** SystemCapability.MiscServices.InputMethodFramework
Z
zhouyongfei 已提交
500

501
**返回值:**
Z
zhouyongfei 已提交
502

H
Hollokin 已提交
503 504 505
| 类型                                      | 说明                         |
| ----------------------------------------- | ---------------------------- |
| [InputMethodSetting](#inputmethodsetting8) | 回调返回当前客户端设置实例。 |
Z
zhouyongfei 已提交
506

507
**示例:**
Z
zhouyongfei 已提交
508

509
```js
H
Hollokin 已提交
510
let inputMethodSetting = inputMethod.getInputMethodSetting();
Z
zhouyongfei 已提交
511 512
```

513 514 515 516 517 518 519 520 521 522
## TextInputType<sup>10+</sup>

输入法文本输入类型。

**系统能力**: SystemCapability.MiscServices.InputMethodFramework

| 名称 | 值 |说明 |
| -------- | -------- |-------- |
| NONE  | -1 |NONE。 |
| TEXT  | 0 |文本类型。 |
523 524 525 526 527 528 529
| MULTILINE  | 1 |多行类型。 |
| NUMBER  | 2 |数字类型。 |
| PHONE  | 3 |电话号码类型。 |
| DATETIME  | 4 |日期类型。 |
| EMAIL_ADDRESS  | 5 |邮箱地址类型。 |
| URL  | 6 |链接类型。 |
| VISIBLE_PASSWORD  | 7 |密码类型。 |
530 531 532 533 534 535 536 537 538 539

## EnterKeyType<sup>10+</sup>

输入法Enter键所代表的功能类型。

**系统能力**: SystemCapability.MiscServices.InputMethodFramework

| 名称 | 值 |说明 |
| -------- | -------- |-------- |
| UNSPECIFIED  | 0 |未指定。 |
540 541 542 543 544 545 546
| NONE  | 1 |NONE。 |
| GO  | 2 |前往。 |
| SEARCH  | 3 |查找。 |
| SEND  | 4 |发送。 |
| NEXT  | 5 |下一步。 |
| DONE  | 6 |完成。 |
| PREVIOUS  | 7 |上一步。 |
547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568

## KeyboardStatus<sup>10+</sup>

输入法软键盘状态。

**系统能力**: SystemCapability.MiscServices.InputMethodFramework

| 名称 | 值 |说明 |
| -------- | -------- |-------- |
| NONE  | 0 |NONE。 |
| HIDE  | 1 |隐藏状态。 |
| SHOW  | 2 |显示状态。 |

## Direction<sup>10+</sup>

光标移动方向。

**系统能力**: SystemCapability.MiscServices.InputMethodFramework

| 名称 | 值 |说明 |
| -------- | -------- |-------- |
| CURSOR_UP  | 1 |向上。 |
569 570 571
| CURSOR_DOWN  | 2 |向下。 |
| CURSOR_LEFT  | 3 |向左。 |
| CURSOR_RIGHT  | 4 |向右。 |
572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664

## ExtendAction<sup>10+</sup>

对编辑框中文本的扩展编辑操作类型。

**系统能力**: SystemCapability.MiscServices.InputMethodFramework

| 名称 | 值 |说明 |
| -------- | -------- |-------- |
| SELECT_ALL  | 0 |全选。 |
| CUT  | 3 |剪切。 |
| COPY  | 4 |复制。 |
| PASTE  | 5 |粘贴。 |

## InputWindowInfo<sup>10+</sup>

输入法软键盘的窗口信息。

**系统能力:** SystemCapability.MiscServices.InputMethodFramework

| 名称 | 类型 | 可读 | 可写 | 说明 |
| -------- | -------- | -------- | -------- | -------- |
| name<sup>10+</sup>  | string | 是 | 是 | 输入法窗口的名称。|
| left<sup>10+</sup>  | string | 是 | 是 | 输入法窗口左上顶点的x坐标。|
| top<sup>10+</sup>  | string | 是 | 是 | 输入法窗口左上顶点的y坐标。|
| width<sup>10+</sup>  | string | 是 | 是 | 输入法窗口的宽度。|
| height<sup>10+</sup>  | string | 是 | 是 | 输入法窗口的高度。|

## FunctionKey<sup>10+</sup>

输入法功能键类型。

**系统能力:** SystemCapability.MiscServices.InputMethodFramework

| 名称 | 类型 | 可读 | 可写 | 说明 |
| -------- | -------- | -------- | -------- | -------- |
| enterKeyType<sup>10+</sup>  | [EnterKeyType](#enterkeytype10) | 是 | 是 | 输入法enter键类型。|

## InputAttribute<sup>10+</sup>

编辑框属性,包含文本输入类型,Enter键功能类型。

**系统能力:** SystemCapability.MiscServices.InputMethodFramework

| 名称 | 类型 | 可读 | 可写 | 说明 |
| -------- | -------- | -------- | -------- | -------- |
| textInputType<sup>10+</sup>  | [TextInputType](#textinputtype10) | 是 | 是 | 文本输入类型。|
| enterKeyType<sup>10+</sup>  | [EnterKeyType](#enterkeytype10) | 是 | 是 | Enter键类型。|

## TextConfig<sup>10+</sup>

编辑控件配置。编辑控件请求绑定输入法框架时传入,将编辑控件相关属性配置到输入法框架内。

**系统能力:** SystemCapability.MiscServices.InputMethodFramework

| 名称 | 类型 | 可读 | 可写 | 说明 |
| -------- | -------- | -------- | -------- | -------- |
| inputAttribute<sup>10+</sup>  | [InputAttribute](#inputattribute10) | 是 | 是 | 编辑框属性。|

## CursorInfo<sup>10+</sup>

光标信息。

**系统能力:** SystemCapability.MiscServices.InputMethodFramework

| 名称 | 类型 | 可读 | 可写 | 说明 |
| -------- | -------- | -------- | -------- | -------- |
| left  | number | 是 | 是 | 光标的left坐标。|
| top  | number | 是 | 是 | 光标的top坐标。|
| width  | number | 是 | 是 | 光标的宽度。|
| height  | number | 是 | 是 | 光标的高度。|

## Range<sup>10+</sup>

描述选中文本的范围。

**系统能力:** SystemCapability.MiscServices.InputMethodFramework

| 名称 | 类型 | 可读 | 可写 | 说明 |
| -------- | -------- | -------- | -------- | -------- |
| start  | number | 是 | 是 | 选中文本的首字符在编辑框的索引值。|
| end  | number | 是 | 是 | 选中文本的末字符在编辑框的索引值。|

## Movement<sup>10+</sup>

描述进行选中文本动作时光标移动的方向。

**系统能力:** SystemCapability.MiscServices.InputMethodFramework

| 名称 | 类型 | 可读 | 可写 | 说明 |
| -------- | -------- | -------- | -------- | -------- |
| direction  | [Direction](#direction10) | 是 | 是 | 进行选中文本动作时光标移动的方向。|

H
Hollokin 已提交
665 666
## InputMethodController

667 668 669 670 671 672
下列API示例中都需使用[getController](#inputmethodgetcontroller9)获取到InputMethodController实例,再通过此实例调用对应方法。

### attach<sup>10+</sup>

attach(showKeyboard: boolean, textConfig: TextConfig, callback: AsyncCallback&lt;void&gt;): void

673 674
用于自绘控件绑定输入法应用。使用callback异步回调。
开发者必须先调用此接口完成绑定,才可以使用框架提供的功能:显示、隐藏键盘;更新光标信息;更改编辑框选中范围;保存配置信息;监听处理由输入法应用发送的信息或命令等。
675 676 677 678 679 680 681 682

**系统能力:** SystemCapability.MiscServices.InputMethodFramework

**参数:**

| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| showKeyboard | boolean | 是 | 绑定输入法成功后是否拉起输入法键盘。 |
683
| textConfig | [TextConfig](#textconfig10) | 是 | 编辑控件配置信息。 |
684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906
| callback | AsyncCallback&lt;void&gt; | 是 | 回调函数。当绑定输入法成功后,err为undefined;否则为错误对象。 |

**错误码:**

以下错误码的详细介绍请参见[输入法框架错误码](../errorcodes/errorcode-inputmethod-framework.md)

| 错误码ID | 错误信息                             |
| -------- | -------------------------------------- |
| 12800003 | Input method client error.             |
| 12800008 | Input method manager service error. |

**示例:**

```js
try {
    let textConfig: inputMethod.TextConfig = {inputAttribute: {textInputType: inputMethodController.TextInputType.TEXT, 
        enterKeyType: inputMethodController.EnterKeyType.GO}};
    inputMethodController.attach(true, textConfig, (err) => {
        if (err !== undefined) {
            console.error(`Failed to attach: ${JSON.stringify(err)}`);
            return;
        }
        console.info('Succeeded in attaching the inputMethod.');
    });
} catch(error) {
    console.error(`Failed to attach: ${JSON.stringify(error)}`);
}
```

### attach<sup>10+</sup>

attach(showKeyboard: boolean, textConfig: TextConfig): Promise&lt;void&gt;

用于自绘控件解绑定输入法框架。自绘控件开发者必须先调用此接口完成绑定,才可以使用框架提供的以下功能,使用callback异步回调。

**系统能力:** SystemCapability.MiscServices.InputMethodFramework

**参数:**

| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| showKeyboard | boolean | 是 | 绑定输入法成功后是否拉起输入法键盘。 |
| textConfig | [TextConfig](#textconfig10) | 是 | 编辑框属性。 |

**返回值:**

| 类型 | 说明 |
| -------- | -------- |
| Promise&lt;void&gt; | 无返回结果的Promise对象。 |

**错误码:**

以下错误码的详细介绍请参见[输入法框架错误码](../errorcodes/errorcode-inputmethod-framework.md)

| 错误码ID | 错误信息                             |
| -------- | -------------------------------------- |
| 12800003 | Input method client error.             |
| 12800008 | Input method manager service error. |

**示例:**

```js
try {
    let textConfig: inputMethod.TextConfig = {inputAttribute: {textInputType: inputMethodController.TextInputType.TEXT, 
        enterKeyType: inputMethodController.EnterKeyType.GO}};
    inputMethodController.attach(true, textConfig).then(() => {
        console.info('Succeeded in attaching inputMethod.');
    }).catch((err) => {
        console.error(`Failed to attach: ${JSON.stringify(err)}`);
    })
} catch(error) {
    console.error(`Failed to attach: ${JSON.stringify(error)}`);
}
```

### showTextInput<sup>10+</sup>

showTextInput(callback: AsyncCallback&lt;void&gt;): void

进入文本编辑状态。编辑控件绑定输入法应用成功后可以使用该接口显示输入法应用软键盘。使用callback异步回调。

**系统能力:** SystemCapability.MiscServices.InputMethodFramework

**参数:**

| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| callback | AsyncCallback&lt;void&gt; | 是 | 回调函数。若成功进入编辑状态,err为undefined;否则为错误对象。 |

**错误码:**

以下错误码的详细介绍请参见[输入法框架错误码](../errorcodes/errorcode-inputmethod-framework.md)

| 错误码ID | 错误信息                             |
| -------- | -------------------------------------- |
| 12800003 | Input method client error.             |
| 12800008 | Input method manager service error. |
| 12800009 | Input method client is detached. |

**示例:**

```js
inputMethodController.showTextInput((err) => {
    if (err !== undefined) {
        console.error(`Failed to showTextInput: ${JSON.stringify(err)}`);
        return;
    }
    console.info('Succeeded in showing the inputMethod.');
});
```

### showTextInput<sup>10+</sup>

showTextInput(): Promise&lt;void&gt;

进入文本编辑状态。编辑控件绑定输入法应用成功后可以使用该接口显示输入法应用软键盘。使用promise异步回调。

**系统能力:** SystemCapability.MiscServices.InputMethodFramework

**返回值:**

| 类型 | 说明 |
| -------- | -------- |
| Promise&lt;void&gt; | 无返回结果的Promise对象。 |

**错误码:**

以下错误码的详细介绍请参见[输入法框架错误码](../errorcodes/errorcode-inputmethod-framework.md)

| 错误码ID | 错误信息                             |
| -------- | -------------------------------------- |
| 12800003 | Input method client error.             |
| 12800008 | Input method manager service error. |
| 12800009 | Input method client is detached. |

**示例:**

```js
inputMethodController.showTextInput().then(() => {
    console.info('Succeeded in showing inputMethod.');
}).catch((err) => {
    console.error(`Failed to showTextInput: ${JSON.stringify(err)}`);
});
```

### hideTextInput<sup>10+</sup>

hideTextInput(callback: AsyncCallback&lt;void&gt;): void

退出文本编辑状态。编辑控件可调用该接口退出编辑状态,若当前软键盘正在显示,则软键盘会被隐藏。调用该接口不解除与输入法框架的绑定,再次直接调用[showTextInput](#showtextinput10)可重新进入编辑状态。使用callback异步回调。

**系统能力:** SystemCapability.MiscServices.InputMethodFramework

**参数:**

| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| callback | AsyncCallback&lt;void&gt; | 是 | 回调函数。当成功退出编辑状态时,err为undefined;否则为错误对象。 |

**错误码:**

以下错误码的详细介绍请参见[输入法框架错误码](../errorcodes/errorcode-inputmethod-framework.md)

| 错误码ID | 错误信息                             |
| -------- | -------------------------------------- |
| 12800003 | Input method client error.             |
| 12800008 | Input method manager service error. |
| 12800009 | Input method client is detached.             |

**示例:**

```js
inputMethodController.hideTextInput((err) => {
    if (err !== undefined) {
        console.error(`Failed to hideTextInput: ${JSON.stringify(err)}`);
        return;
    }
    console.info('Succeeded in hiding inputMethod.');
});
```

### hideTextInput<sup>10+</sup>

hideTextInput(): Promise&lt;void&gt;

退出文本编辑状态。编辑控件可调用该接口退出编辑状态,若当前软键盘正在显示,则软键盘会被隐藏。调用该接口不解除与输入法框架的绑定,再次直接调用[showTextInput](#showtextinput10)可重新进入编辑状态。使用promise异步回调。

**系统能力:** SystemCapability.MiscServices.InputMethodFramework

**返回值:**

| 类型 | 说明 |
| -------- | -------- |
| Promise&lt;void&gt; | 无返回结果的Promise对象。 |

**错误码:**

以下错误码的详细介绍请参见[输入法框架错误码](../errorcodes/errorcode-inputmethod-framework.md)

| 错误码ID | 错误信息                             |
| -------- | -------------------------------------- |
| 12800003 | Input method client error.             |
| 12800008 | Input method manager service error. |
| 12800009 | Input method client is detached. |

**示例:**

```js
try {
    inputMethodController.hideTextInput().then(() => {
        console.info('Succeeded in hiding inputMethod.');
    }).catch((err) => {
        console.error(`Failed to hideTextInput: ${JSON.stringify(err)}`);
    })
} catch(err) {
    console.error(`Failed to hideTextInput: ${JSON.stringify(err)}`);
}
```

### detach<sup>10+</sup>

detach(callback: AsyncCallback&lt;void&gt;): void

H
--amend  
Hollokin 已提交
907
解除与输入法应用的绑定。使用callback异步回调。
908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941

**系统能力:** SystemCapability.MiscServices.InputMethodFramework

**参数:**

| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| callback | AsyncCallback&lt;void&gt; | 是 | 回调函数。当解绑定输入法成功时,err为undefined;否则为错误对象。 |

**错误码:**

以下错误码的详细介绍请参见[输入法框架错误码](../errorcodes/errorcode-inputmethod-framework.md)

| 错误码ID | 错误信息                             |
| -------- | -------------------------------------- |
| 12800003 | Input method client error.             |
| 12800008 | Input method manager service error. |

**示例:**

```js
inputMethodController.detach((err) => {
    if (err !== undefined) {
        console.error(`Failed to detach: ${JSON.stringify(err)}`);
        return;
    }
    console.info('Succeeded in detaching inputMethod.');
});
```

### detach<sup>10+</sup>

detach(): Promise&lt;void&gt;

H
--amend  
Hollokin 已提交
942
解除与输入法应用的绑定。使用promise异步回调。
943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745

**系统能力:** SystemCapability.MiscServices.InputMethodFramework

**返回值:**

| 类型 | 说明 |
| -------- | -------- |
| Promise&lt;void&gt; | 无返回结果的Promise对象。 |

**错误码:**

以下错误码的详细介绍请参见[输入法框架错误码](../errorcodes/errorcode-inputmethod-framework.md)

| 错误码ID | 错误信息                             |
| -------- | -------------------------------------- |
| 12800003 | Input method client error.             |
| 12800008 | Input method manager service error. |

**示例:**

```js
inputMethodController.detach().then(() => {
    console.info('Succeeded in detaching inputMethod.');
}).catch((error) => {
    console.error(`Failed to detach: ${JSON.stringify(error)}`);
});
```

### setCallingWindow<sup>10+</sup>

setCallingWindow(windowId: number, callback: AsyncCallback&lt;void&gt;): void

避让窗口。将当前绑定到输入法的应用程序的窗口ID通知系统,正确设置后,客户端所在的窗口可以避开输入法窗口。使用callback异步回调。

**系统能力:** SystemCapability.MiscServices.InputMethodFramework

**参数:**

| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| windowId | number | 是 | 当前绑定到输入方法的应用程序的窗口ID。 |
| callback | AsyncCallback&lt;void&gt; | 是 | 回调函数。当设置成功时,err为undefined;否则为错误对象。 |

**错误码:**

以下错误码的详细介绍请参见[输入法框架错误码](../errorcodes/errorcode-inputmethod-framework.md)

| 错误码ID | 错误信息                             |
| -------- | -------------------------------------- |
| 12800003 | Input method client error.             |
| 12800008 | Input method manager service error. |
| 12800009 | Input method client is detached.             |

**示例:**

```js
try {
    let windowId: number = 2000;
    inputMethodController.setCallingWindow(windowId, (err) => {
        if (err !== undefined) {
            console.error(`Failed to setCallingWindow: ${JSON.stringify(err)}`);
            return;
        }
        console.info('Succeeded in setting callingWindow.');
    });
} catch(error) {
    console.error(`Failed to setCallingWindow: ${JSON.stringify(error)}`);
}
```

### setCallingWindow<sup>10+</sup>

setCallingWindow(windowId: number): Promise&lt;void&gt;

避让窗口。将当前绑定到输入法的应用程序的窗口ID通知系统,正确设置后,客户端所在的窗口可以避开输入法窗口。使用promise异步回调。

**系统能力:** SystemCapability.MiscServices.InputMethodFramework

**参数:**

| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| windowId | number | 是 | 当前绑定到输入方法的应用程序的窗口ID。 |

**返回值:**

| 类型 | 说明 |
| -------- | -------- |
| Promise&lt;void&gt; | 无返回结果的Promise对象。 |

**错误码:**

以下错误码的详细介绍请参见[输入法框架错误码](../errorcodes/errorcode-inputmethod-framework.md)

| 错误码ID | 错误信息                             |
| -------- | -------------------------------------- |
| 12800003 | Input method client error.             |
| 12800008 | Input method manager service error. |
| 12800009 | Input method client is detached. |

**示例:**

```js
try {
    let windowId: number = 2000;
    inputMethodController.setCallingWindow(windowId).then(() => {
        console.info('Succeeded in setting callingWindow.');
    }).catch((err) => {
        console.error(`Failed to setCallingWindow: ${JSON.stringify(err)}`);
    })
} catch(error) {
    console.error(`Failed to setCallingWindow: ${JSON.stringify(error)}`);
}
```

### updateCursor<sup>10+</sup>

updateCursor(cursorInfo: CursorInfo, callback: AsyncCallback&lt;void&gt;): void

向输入法应用更新当前编辑框内光标信息,要求开发者在编辑控件内光标信息发生改变时调用该接口更新信息。使用callback异步回调。

**系统能力:** SystemCapability.MiscServices.InputMethodFramework

**参数:**

| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| cursorInfo | [CursorInfo](#cursorinfo10) | 是 | 光标信息。 |
| callback | AsyncCallback&lt;void&gt; | 是 | 回调函数。当设置成功时,err为undefined;否则为错误对象。 |

**错误码:**

以下错误码的详细介绍请参见[输入法框架错误码](../errorcodes/errorcode-inputmethod-framework.md)

| 错误码ID | 错误信息                             |
| -------- | -------------------------------------- |
| 12800003 | Input method client error.             |
| 12800008 | Input method manager service error. |
| 12800009 | Input method client is detached.             |

**示例:**

```js
try {
    inputMethodController.updateCursor({left: 0, top: 0, width: 600, height: 800}, (err) => {
        if (err !== undefined) {
            console.error(`Failed to updateCursor: ${JSON.stringify(err)}`);
            return;
        }
        console.info('Succeeded in updating cursorInfo.');
    });
} catch(error) {
    console.error(`Failed to updateCursor: ${JSON.stringify(error)}`);
}
```

### updateCursor<sup>10+</sup>

updateCursor(cursorInfo: CursorInfo): Promise&lt;void&gt;

通知输入法当前应用程序光标已更改。使用promise异步回调。

**系统能力:** SystemCapability.MiscServices.InputMethodFramework

**参数:**

| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| cursorInfo | [CursorInfo](#cursorinfo10) | 是 | 光标信息。 |

**返回值:**

| 类型 | 说明 |
| -------- | -------- |
| Promise&lt;void&gt; | 无返回结果的Promise对象。 |

**错误码:**

以下错误码的详细介绍请参见[输入法框架错误码](../errorcodes/errorcode-inputmethod-framework.md)

| 错误码ID | 错误信息                             |
| -------- | -------------------------------------- |
| 12800003 | Input method client error.             |
| 12800008 | Input method manager service error. |
| 12800009 | Input method client is detached. |

**示例:**

```js
try {
    inputMethodController.updateCursor({left: 0, top: 0, width: 600, height: 800}).then(() => {
        console.info('Succeeded in updating cursorInfo.');
    }).catch((err) => {
        console.error(`Failed to updateCursor: ${JSON.stringify(err)}`);
    })
} catch(error) {
    console.error(`Failed to updateCursor: ${JSON.stringify(error)}`);
}
```

### changeSelection<sup>10+</sup>

changeSelection(text: string, start: number, end: number, callback: AsyncCallback&lt;void&gt;): void

向输入法应用更新当前编辑框内被选中文本的信息,要求开发者在编辑控件内被选中文本内容或范围发生变化时调用该接口更新信息。使用callback异步回调。

**系统能力:** SystemCapability.MiscServices.InputMethodFramework

**参数:**

| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| text | string | 是 | 整个输入文本。 |
| start | number | 是 | 所选文本的起始位置。 |
| end | number | 是 | 所选文本的结束位置。 |
| callback | AsyncCallback&lt;void&gt; | 是 | 回调函数。当隐藏输入法成功时,err为undefined;否则为错误对象。 |

**错误码:**

以下错误码的详细介绍请参见[输入法框架错误码](../errorcodes/errorcode-inputmethod-framework.md)

| 错误码ID | 错误信息                             |
| -------- | -------------------------------------- |
| 12800003 | Input method client error.             |
| 12800008 | Input method manager service error. |
| 12800009 | Input method client is detached.             |

**示例:**

```js
try {
    inputMethodController.changeSelection('text', 0, 5, (err) => {
        if (err !== undefined) {
            console.error(`Failed to changeSelection: ${JSON.stringify(err)}`);
            return;
        }
        console.info('Succeeded in changing selection.');
    });
} catch(error) {
    console.error(`Failed to changeSelection: ${JSON.stringify(error)}`);
}
```

### changeSelection<sup>10+</sup>

changeSelection(text: string, start: number, end: number): Promise&lt;void&gt;

通知输入法当前应用程序文本的选择范围已更改。使用promise异步回调。

**系统能力:** SystemCapability.MiscServices.InputMethodFramework

**参数:**

| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| text | string | 是 | 整个输入文本。 |
| start | number | 是 | 所选文本的起始位置。 |
| end | number | 是 | 所选文本的结束位置。 |

**返回值:**

| 类型 | 说明 |
| -------- | -------- |
| Promise&lt;void&gt; | 无返回结果的Promise对象。 |

**错误码:**

以下错误码的详细介绍请参见[输入法框架错误码](../errorcodes/errorcode-inputmethod-framework.md)

| 错误码ID | 错误信息                             |
| -------- | -------------------------------------- |
| 12800003 | Input method client error.             |
| 12800008 | Input method manager service error. |
| 12800009 | Input method client is detached. |

**示例:**

```js
try {
    inputMethodController.changeSelection('test', 0, 5).then(() => {
        console.info('Succeeded in changing selection.');
    }).catch((err) => {
        console.error(`Failed to changeSelection: ${JSON.stringify(err)}`);
    })
} catch(error) {
    console.error(`Failed to changeSelection: ${JSON.stringify(error)}`);
}
```

### updateAttribute<sup>10+</sup>

updateAttribute(attribute: InputAttribute, callback: AsyncCallback&lt;void&gt;): void

更新编辑框属性。使用callback异步回调。

**系统能力:** SystemCapability.MiscServices.InputMethodFramework

**参数:**

| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| attribute | [InputAttribute](#inputattribute10) | 是 | InputAttribute对象,包含的额外信息。 |
| callback | AsyncCallback&lt;void&gt; | 是 | 回调函数。当隐藏输入法成功时,err为undefined;否则为错误对象。 |

**错误码:**

以下错误码的详细介绍请参见[输入法框架错误码](../errorcodes/errorcode-inputmethod-framework.md)

| 错误码ID | 错误信息                             |
| -------- | -------------------------------------- |
| 12800003 | Input method client error.             |
| 12800008 | Input method manager service error. |
| 12800009 | Input method client is detached.             |

**示例:**

```js
try {
    inputMethodController.updateAttribute({textInputType: inputMethod.TextInputType.TEXT, 
        enterKeyType: inputMethod.EnterKeyType.GO}, (err) => {
        if (err !== undefined) {
            console.error(`Failed to updateAttribute: ${JSON.stringify(err)}`);
            return;
        }
        console.info('Succeeded in updating attribute.');
    });
} catch(error) {
    console.error(`Failed to updateAttribute: ${JSON.stringify(error)}`);
}
```

### updateAttribute<sup>10+</sup>

updateAttribute(attribute: InputAttribute): Promise&lt;void&gt;

更新输入文本的InputAttribute信息。使用promise异步回调。

**系统能力:** SystemCapability.MiscServices.InputMethodFramework

**参数:**

| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| attribute | [InputAttribute](#inputattribute10) | 是 | InputAttribute对象,包含的额外信息。 |

**返回值:**

| 类型 | 说明 |
| -------- | -------- |
| Promise&lt;void&gt; | 无返回结果的Promise对象。 |

**错误码:**

以下错误码的详细介绍请参见[输入法框架错误码](../errorcodes/errorcode-inputmethod-framework.md)

| 错误码ID | 错误信息                             |
| -------- | -------------------------------------- |
| 12800003 | Input method client error.             |
| 12800008 | Input method manager service error. |
| 12800009 | Input method client is detached. |

**示例:**

```js
try {
    inputMethodController.updateAttribute({textInputType: inputMethod.TextInputType.TEXT, 
        enterKeyType: inputMethod.EnterKeyType.GO}).then(() => {
        console.info('Succeeded in updating attribute.');
    }).catch((err) => {
        console.error(`Failed to updateAttribute: ${JSON.stringify(err)}`);
    })
} catch(error) {
    console.error(`Failed to updateAttribute: ${JSON.stringify(error)}`);
}
```

### stopInputSession<sup>9+</sup>

stopInputSession(callback: AsyncCallback&lt;boolean&gt;): void

结束输入会话。通过点击输入框实现输入会话的开启之后该接口的调用才可生效。使用callback异步回调。

**系统能力:** SystemCapability.MiscServices.InputMethodFramework

**参数:**

| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| callback | AsyncCallback&lt;boolean&gt; | 是 | 回调函数。当结束输入会话成功时,err为undefined,data为true;否则为错误对象。 |

**错误码:**

以下错误码的详细介绍请参见[输入法框架错误码](../errorcodes/errorcode-inputmethod-framework.md)

| 错误码ID | 错误信息                             |
| -------- | -------------------------------------- |
| 12800003 | Input method client error.             |
| 12800008 | Input method manager service error. |

**示例:**

```js
try {
    inputMethodController.stopInputSession((error, result) => {
        if (error !== undefined) {
            console.error('Failed to stopInputSession: ' + JSON.stringify(error));
            return;
        }
        if (result) {
            console.info('Succeeded in stopping inputSession.');
        } else {
            console.error('Failed to stopInputSession.');
        }
    });
} catch(error) {
    console.error('Failed to stopInputSession: ' + JSON.stringify(error));
}
```

### stopInputSession<sup>9+</sup>

stopInputSession(): Promise&lt;boolean&gt;

结束输入会话。通过点击输入框实现输入会话的开启之后此接口才可生效。使用promise异步回调。

**系统能力:** SystemCapability.MiscServices.InputMethodFramework

**返回值:**

| 类型 | 说明 |
| -------- | -------- |
| Promise&lt;boolean&gt; | Promise对象。返回true表示结束输入会话成功;返回false表示结束输入会话失败。 |

**错误码:**

以下错误码的详细介绍请参见[输入法框架错误码](../errorcodes/errorcode-inputmethod-framework.md)

| 错误码ID | 错误信息                             |
| -------- | -------------------------------------- |
| 12800003 | Input method client error.             |
| 12800008 | Input method manager service error. |

**示例:**

```js
try {
    inputMethodController.stopInputSession().then((result) => {
        if (result) {
            console.info('Succeeded in stopping inputSession.');
        } else {
            console.error('Failed to stopInputSession.');
        }
    }).catch((err) => {
        console.error('Failed to stopInputSession: ' + JSON.stringify(err));
    })
} catch(err) {
    console.error('Failed to stopInputSession: ' + JSON.stringify(err));
}
```

### showSoftKeyboard<sup>9+</sup>

showSoftKeyboard(callback: AsyncCallback&lt;void&gt;): void

显示软键盘。需要与输入框绑定使用。当点击输入框后,才可通过该接口的调用显示出当前输入法的软键盘。使用callback异步回调。

**需要权限:** ohos.permission.CONNECT_IME_ABILITY,仅系统应用可用。

**系统能力:**  SystemCapability.MiscServices.InputMethodFramework

**参数:**

| 参数名   | 类型                  | 必填 | 说明       |
| -------- | ------------------------- | ---- | ---------- |
| callback | AsyncCallback&lt;void&gt; | 是   | 回调函数。当软键盘显示成功。err为undefined,否则为错误对象。 |

**错误码:**

以下错误码的详细介绍请参见[输入法框架错误码](../errorcodes/errorcode-inputmethod-framework.md)

| 错误码ID | 错误信息                             |
| -------- | -------------------------------------- |
| 12800003 | Input method client error.             |
| 12800008 | Input method manager service error. |

**示例:**

```js
inputMethodController.showSoftKeyboard((err) => {
    if (err === undefined) {
        console.info('Succeeded in showing softKeyboard.');
    } else {
        console.error('Failed to showSoftKeyboard: ' + JSON.stringify(err));
    }
})
```

### showSoftKeyboard<sup>9+</sup>

showSoftKeyboard(): Promise&lt;void&gt;

显示软键盘。需要与输入框绑定使用。当点击输入框后,才可通过该接口的调用显示出当前输入法的软键盘。使用Promise异步回调。

**需要权限:** ohos.permission.CONNECT_IME_ABILITY,仅系统应用可用。

**系统能力:**  SystemCapability.MiscServices.InputMethodFramework

**返回值:**

| 类型                | 说明                      |
| ------------------- | ------------------------- |
| Promise&lt;void&gt; | 无返回结果的Promise对象。 |

**错误码:**

以下错误码的详细介绍请参见[输入法框架错误码](../errorcodes/errorcode-inputmethod-framework.md)

| 错误码ID | 错误信息                             |
| -------- | -------------------------------------- |
| 12800003 | Input method client error.             |
| 12800008 | Input method manager service error. |

**示例:**

```js
inputMethodController.showSoftKeyboard().then(() => {
    console.log('Succeeded in showing softKeyboard.');
}).catch((err) => {
    console.error('Failed to showSoftKeyboard: ' + JSON.stringify(err));
});
```

### hideSoftKeyboard<sup>9+</sup>

hideSoftKeyboard(callback: AsyncCallback&lt;void&gt;): void

隐藏软键盘。需要与输入框绑定使用。点击输入框后,才可以使用该接口的调用隐藏软键盘。使用callback异步回调。

**需要权限:** ohos.permission.CONNECT_IME_ABILITY,仅系统应用可用。

**系统能力:**  SystemCapability.MiscServices.InputMethodFramework

**参数:**

| 参数名   | 类型                  | 必填 | 说明       |
| -------- | ------------------------- | ---- | ---------- |
| callback | AsyncCallback&lt;void&gt; | 是   | 回调函数。当软键盘隐藏成功。err为undefined,否则为错误对象。 |

**错误码:**

以下错误码的详细介绍请参见[输入法框架错误码](../errorcodes/errorcode-inputmethod-framework.md)

| 错误码ID | 错误信息                             |
| -------- | -------------------------------------- |
| 12800003 | Input method client error.             |
| 12800008 | Input method manager service error. |

**示例:**

```js
inputMethodController.hideSoftKeyboard((err) => {
    if (err === undefined) {
        console.info('Succeeded in hiding softKeyboard.');
    } else {
        console.error('Failed to hideSoftKeyboard: ' + JSON.stringify(err));
    }
})
```

### hideSoftKeyboard<sup>9+</sup>

hideSoftKeyboard(): Promise&lt;void&gt;

隐藏软键盘。需要与输入框绑定使用。点击输入框后,才可以使用该接口的调用隐藏软键盘。使用Promise异步回调。

**需要权限:** ohos.permission.CONNECT_IME_ABILITY,仅系统应用可用。

**系统能力:**  SystemCapability.MiscServices.InputMethodFramework

**返回值:**

| 类型                | 说明                      |
| ------------------- | ------------------------- |
| Promise&lt;void&gt; | 无返回结果的Promise对象。 |

**错误码:**

以下错误码的详细介绍请参见[输入法框架错误码](../errorcodes/errorcode-inputmethod-framework.md)

| 错误码ID | 错误信息                             |
| -------- | -------------------------------------- |
| 12800003 | Input method client error.             |
| 12800008 | Input method manager service error. |

**示例:**

```js
inputMethodController.hideSoftKeyboard().then(() => {
    console.log('Succeeded in hiding softKeyboard.');
}).catch((err) => {
    console.error('Failed to hideSoftKeyboard: ' + JSON.stringify(err));
});
```

### stopInput<sup>(deprecated)</sup>

stopInput(callback: AsyncCallback&lt;boolean&gt;): void

结束输入会话。通过点击输入框实现输入会话的开启之后该接口的调用才可生效。使用callback异步回调。

> **说明:** 
>
> 从API version 6开始支持,从API version 9开始废弃, 建议使用[stopInputSession()](#stopinputsession9)替代。

**系统能力:** SystemCapability.MiscServices.InputMethodFramework

**参数:**

| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| callback | AsyncCallback&lt;boolean&gt; | 是 | 回调函数。当输入法隐藏成功,err为undefined,data为true;否则为错误对象。 |

**示例:**

```js
inputMethodController.stopInput((error, result) => {
    if (error !== undefined) {
        console.error('Failed to stopInput: ' + JSON.stringify(error));
        return;
    }
    if (result) {
        console.info('Succeeded in stopping input.');
    } else {
        console.error('Failed to stopInput.');
    }
});
```

### stopInput<sup>(deprecated)</sup>

stopInput(): Promise&lt;boolean&gt;

结束输入会话。通过点击输入框实现输入会话的开启之后该接口的调用才可生效。使用promise异步回调。

> **说明:** 
>
> 从API version 6开始支持,从API version 9开始废弃, 建议使用[stopInputSession()](#stopinputsession9)替代。

**系统能力:** SystemCapability.MiscServices.InputMethodFramework

**返回值:**

| 类型 | 说明 |
| -------- | -------- |
| Promise&lt;boolean&gt; | Promise对象。返回true表示输入法隐藏成功;返回false表示输入法隐藏失败。 |

**示例:**

```js
inputMethodController.stopInput().then((result) => {
    if (result) {
        console.info('Succeeded in stopping input.');
    } else {
        console.error('Failed to stopInput.');
    }
}).catch((err) => {
    console.error('Failed to stopInput: ' + err);
})
```

### on('insertText')<sup>10+</sup>

on(type: 'insertText', callback: (text: string) => void): void;

订阅输入法应用插入文本事件。使用callback异步回调。

**系统能力:** SystemCapability.MiscServices.InputMethodFramework

**参数:**

| 参数名   | 类型                                                         | 必填 | 说明                                                         |
| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
| type     | string                                                       | 是   | 设置监听类型。<br/>-type为‘insertText’时表示订阅输入法应用插入文本事件监听。 |
| callback | (text: string) => void | 是   | 回调函数,返回需要插入的文本内容。<br/>开发者需要在回调函数中根据传入的文本内容操作编辑框中的内容。 |

**错误码:**

以下错误码的详细介绍请参见[输入法框架错误码](../errorcodes/errorcode-inputmethod-framework.md)

| 错误码ID | 错误信息                             |
| -------- | -------------------------------------- |
| 12800009 | Input method client is detached. |

**示例:**

```js
try {
    inputMethodController.on('insertText', (text) => {
        console.info(`Succeeded in subscribing insertText: ${text}`);
    });
} catch(error) {
    console.error(`Failed to subscribe insertText: ${JSON.stringify(error)}`);
}

```

### off('insertText')<sup>10+</sup>

off(type: 'insertText'): void

取消订阅输入法应用插入文本事件。

**系统能力:** SystemCapability.MiscServices.InputMethodFramework

**参数:**

| 参数名 | 类型   | 必填 | 说明                                                         |
| ------ | ------ | ---- | ------------------------------------------------------------ |
| type   | string | 是   | 设置监听类型。<br/>-type为‘insertText’时表示取消订阅输入法应用插入文本事件监听。 |

**错误码:**

以下错误码的详细介绍请参见[输入法框架错误码](../errorcodes/errorcode-inputmethod-framework.md)

| 错误码ID | 错误信息                             |
| -------- | -------------------------------------- |
| 12800009 | Input method client is detached. |

**示例:**

```js
try {
    inputMethodController.off('insertText');
    console.info('Succeeded in unsubscribing insertText.');
} catch(error) {
    console.error(`Failed to unsubscribe insertText: ${JSON.stringify(error)}`);
}
```

### on('deleteLeft' | 'deleteRight')<sup>10+</sup>

on(type: 'deleteLeft' | 'deleteRight', callback: (length: number) => void): void

订阅输入法应用向左删除或向右删除事件。使用callback异步回调。

**系统能力:** SystemCapability.MiscServices.InputMethodFramework

**参数:**

| 参数名   | 类型                                                         | 必填 | 说明                                                         |
| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
| type     | string                                                       | 是   | 设置监听类型。<br/>-type为‘deleteLeft’时表示订阅输入法应用向左删除事件监听。 <br/>-type为‘deleteRight’时表示订阅输入法应用向右删除事件监听。|
| callback | (length: number) => void | 是   | 回调函数,返回需要向左或向右删除的文本的长度。<br/>开发者需要在回调函数中根据传入的删除长度操作编辑框中相应文本。 |

**错误码:**

以下错误码的详细介绍请参见[输入法框架错误码](../errorcodes/errorcode-inputmethod-framework.md)

| 错误码ID | 错误信息                             |
| -------- | -------------------------------------- |
| 12800009 | Input method client is detached. |

**示例:**

```js
try {
    inputMethodController.on('deleteLeft', (length) => {
        console.info(`Succeeded in subscribing deleteLeft, length: ${length}`);
    });
} catch(error) {
    console.error(`Failed to subscribe deleteLeft: ${JSON.stringify(error)}`);
}

try {
    inputMethodController.on('deleteRight', (length) => {
        console.info(`Succeeded in subscribing deleteRight, length: ${length}`);
    });
} catch(error) {
    console.error(`Failed to subscribe deleteRight: ${JSON.stringify(error)}`);
}
```

### off('deleteLeft' | 'deleteRight')<sup>10+</sup>

off(type: 'deleteLeft' | 'deleteRight'): void

取消订阅输入法应用向左或向右删除文本事件。

**系统能力:** SystemCapability.MiscServices.InputMethodFramework

**参数:**

| 参数名 | 类型   | 必填 | 说明                                                         |
| ------ | ------ | ---- | ------------------------------------------------------------ |
| type   | string | 是   | 设置监听类型。<br/>-type为‘deleteLeft’时表示取消订阅输入法应用向左删除的事件监听。 <br/>-type为‘deleteRight’时表示取消订阅输入法应用向右删除的事件监听。|

**错误码:**

以下错误码的详细介绍请参见[输入法框架错误码](../errorcodes/errorcode-inputmethod-framework.md)

| 错误码ID | 错误信息                             |
| -------- | -------------------------------------- |
| 12800009 | Input method client is detached. |
H
Hollokin 已提交
1746

1747
**示例:**
1748

1749 1750 1751 1752 1753 1754 1755
```js
try {
    inputMethodController.off('deleteLeft');
    console.info('Succeeded in unsubscribing deleteLeft.');
} catch(error) {
    console.error(`Failed to unsubscribe deleteLeft: ${JSON.stringify(error)}`);
}
1756

1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769
try {
    inputMethodController.off('deleteRight');
    console.info('Succeeded in unsubscribing deleteRight.');
} catch(error) {
    console.error(`Failed to unsubscribe deleteRight: ${JSON.stringify(error)}`);
}
```

### on('sendKeyboardStatus')<sup>10+</sup>

on(type: 'sendKeyboardStatus', callback: (keyBoardStatus: KeyboardStatus) => void): void

订阅输入法应用发送键盘状态事件。使用callback异步回调。
1770

H
update  
Hollokin 已提交
1771
**系统能力:** SystemCapability.MiscServices.InputMethodFramework
1772 1773 1774

**参数:**

1775 1776 1777 1778
| 参数名   | 类型                                                         | 必填 | 说明                                                         |
| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
| type     | string                                                       | 是   | 设置监听类型。<br/>-type为‘sendKeyboardStatus’时表示订阅输入法应用发送键盘状态事件监听。 |
| callback | (keyBoardStatus: [KeyboardStatus](#keyboardstatus10)) => void | 是   | 回调函数,返回键盘状态。<br/>开发者需要在回调函数中根据传入的键盘状态做相应动作。 |
1779

H
Hollokin 已提交
1780 1781
**错误码:**

1782
以下错误码的详细介绍请参见[输入法框架错误码](../errorcodes/errorcode-inputmethod-framework.md)
H
Hollokin 已提交
1783

1784
| 错误码ID | 错误信息                             |
H
Hollokin 已提交
1785
| -------- | -------------------------------------- |
1786
| 12800009 | Input method client is detached. |
H
Hollokin 已提交
1787

1788 1789 1790
**示例:**

```js
H
Hollokin 已提交
1791
try {
1792 1793
    inputMethodController.on('sendKeyboardStatus', (keyBoardStatus) => {
        console.info(`Succeeded in subscribing sendKeyboardStatus, keyBoardStatus: ${keyBoardStatus}`);
H
Hollokin 已提交
1794
    });
H
Hollokin 已提交
1795
} catch(error) {
1796
    console.error(`Failed to subscribe sendKeyboardStatus: ${JSON.stringify(error)}`);
H
Hollokin 已提交
1797
}
1798 1799
```

1800
### off('sendKeyboardStatus')<sup>10+</sup>
1801

1802
off(type: 'sendKeyboardStatus'): void
1803

1804
取消订阅输入法应用发送键盘状态事件。
1805

H
update  
Hollokin 已提交
1806
**系统能力:** SystemCapability.MiscServices.InputMethodFramework
1807

1808
**参数:**
1809

1810 1811 1812
| 参数名 | 类型   | 必填 | 说明                                                         |
| ------ | ------ | ---- | ------------------------------------------------------------ |
| type   | string | 是   | 设置监听类型。<br/>-type为‘sendKeyboardStatus’时表示取消订阅输入法应用发送键盘状态事件监听。 |
1813

H
Hollokin 已提交
1814 1815
**错误码:**

1816
以下错误码的详细介绍请参见[输入法框架错误码](../errorcodes/errorcode-inputmethod-framework.md)
H
Hollokin 已提交
1817

1818
| 错误码ID | 错误信息                             |
H
Hollokin 已提交
1819
| -------- | -------------------------------------- |
1820
| 12800009 | Input method client is detached. |
H
Hollokin 已提交
1821

1822 1823 1824
**示例:**

```js
H
Hollokin 已提交
1825
try {
1826 1827 1828 1829
    inputMethodController.off('sendKeyboardStatus');
    console.info('Succeeded in unsubscribing sendKeyboardStatus.');
} catch(error) {
    console.error(`Failed to unsubscribe sendKeyboardStatus: ${JSON.stringify(error)}`);
H
Hollokin 已提交
1830
}
1831 1832
```

1833
### on('sendFunctionKey')<sup>10+</sup>
Z
zhaolinglan 已提交
1834

1835
on(type: 'sendFunctionKey', callback: (functionKey: FunctionKey) => void): void
Z
zhaolinglan 已提交
1836

1837
订阅输入法应用发送功能键事件。使用callback异步回调。
H
Hollokin 已提交
1838

1839
**系统能力:** SystemCapability.MiscServices.InputMethodFramework
Z
zhaolinglan 已提交
1840 1841 1842

**参数:**

1843 1844 1845 1846
| 参数名   | 类型                                                         | 必填 | 说明                                                         |
| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
| type     | string                                                       | 是   | 设置监听类型。<br/>-type为‘sendFunctionKey’时表示订阅输入法应用发送FunctionKey事件监听。 |
| callback | (functionKey: [FunctionKey](#functionkey10)) => void | 是   | 回调函数,返回输入法应用发送的FunctionKey对象。<br/>开发者需要在回调函数中根据传入的FunctionKey对象做相应的操作。 |
Z
zhaolinglan 已提交
1847

H
Hollokin 已提交
1848 1849
**错误码:**

1850
以下错误码的详细介绍请参见[输入法框架错误码](../errorcodes/errorcode-inputmethod-framework.md)
H
Hollokin 已提交
1851

1852
| 错误码ID | 错误信息                             |
H
Hollokin 已提交
1853
| -------- | -------------------------------------- |
1854
| 12800009 | Input method client is detached. |
H
Hollokin 已提交
1855

Z
zhaolinglan 已提交
1856 1857 1858
**示例:**

```js
1859 1860 1861 1862 1863 1864 1865
try {
    inputMethodController.on('sendFunctionKey', (functionKey) => {
        console.info(`Succeeded in subscribing sendFunctionKey, functionKey.enterKeyType: ${functionKey.enterKeyType}`);
    });
} catch(error) {
    console.error(`Failed to subscribe sendFunctionKey: ${JSON.stringify(error)}`);
}
Z
zhaolinglan 已提交
1866 1867
```

1868
### off('sendFunctionKey')<sup>10+</sup>
H
Hollokin 已提交
1869

1870
off(type: 'sendFunctionKey'): void
Z
zhaolinglan 已提交
1871

1872
取消订阅输入法应用发送FunctionKey事件。
H
Hollokin 已提交
1873

1874
**系统能力:** SystemCapability.MiscServices.InputMethodFramework
Z
zhaolinglan 已提交
1875

1876
**参数:**
Z
zhaolinglan 已提交
1877

1878 1879 1880
| 参数名 | 类型   | 必填 | 说明                                                         |
| ------ | ------ | ---- | ------------------------------------------------------------ |
| type   | string | 是   | 设置监听类型。<br/>-type为‘sendFunctionKey’时表示取消订阅输入法应用发送FunctionKey事件监听。 |
Z
zhaolinglan 已提交
1881

H
Hollokin 已提交
1882 1883
**错误码:**

1884
以下错误码的详细介绍请参见[输入法框架错误码](../errorcodes/errorcode-inputmethod-framework.md)
H
Hollokin 已提交
1885

1886
| 错误码ID | 错误信息                             |
H
Hollokin 已提交
1887
| -------- | -------------------------------------- |
1888
| 12800009 | Input method client is detached. |
H
Hollokin 已提交
1889

Z
zhaolinglan 已提交
1890 1891 1892
**示例:**

```js
1893 1894 1895 1896 1897 1898
try {
    inputMethodController.off('sendFunctionKey');
    console.info('Succeeded in unsubscribing sendFunctionKey.');
} catch(error) {
    console.error(`Failed to unsubscribe sendFunctionKey: ${JSON.stringify(error)}`);
}
Z
zhaolinglan 已提交
1899 1900
```

1901
### on('moveCursor')<sup>10+</sup>
Z
zhaolinglan 已提交
1902

1903
on(type: 'moveCursor', callback: (direction: Direction) => void): void
Z
zhaolinglan 已提交
1904

1905
订阅输入法应用移动光标事件。使用callback异步回调。
H
Hollokin 已提交
1906

1907
**系统能力:** SystemCapability.MiscServices.InputMethodFramework
Z
zhaolinglan 已提交
1908 1909 1910

**参数:**

1911 1912 1913 1914
| 参数名   | 类型                                                         | 必填 | 说明                                                         |
| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
| type     | string                                                       | 是   | 设置监听类型。<br/>-type为‘moveCursor’时表示订阅输入法应用移动光标事件监听。 |
| callback | callback: (direction: [Direction<sup>10+</sup>](#direction10)) => void | 是   | 回调函数,返回光标信息。<br/>开发者需要在回调函数中根据传入的光标移动方向改变光标位置。 |
Z
zhaolinglan 已提交
1915

H
Hollokin 已提交
1916 1917
**错误码:**

1918
以下错误码的详细介绍请参见[输入法框架错误码](../errorcodes/errorcode-inputmethod-framework.md)
H
Hollokin 已提交
1919

1920
| 错误码ID | 错误信息                             |
H
Hollokin 已提交
1921
| -------- | -------------------------------------- |
1922
| 12800009 | Input method client is detached. |
H
Hollokin 已提交
1923

Z
zhaolinglan 已提交
1924 1925 1926
**示例:**

```js
1927 1928 1929 1930 1931 1932 1933
try {
    inputMethodController.on('moveCursor', (direction) => {
        console.info(`Succeeded in subscribing moveCursor, direction: ${direction}`);
    });
} catch(error) {
    console.error(`Failed to subscribe moveCursor: ${JSON.stringify(error)}`);
}
Z
zhaolinglan 已提交
1934 1935
```

1936
### off('moveCursor')<sup>10+</sup>
Z
zhaolinglan 已提交
1937

1938
off(type: 'moveCursor'): void
Z
zhaolinglan 已提交
1939

1940
取消订阅输入法应用移动光标事件。
H
Hollokin 已提交
1941

1942
**系统能力:** SystemCapability.MiscServices.InputMethodFramework
Z
zhaolinglan 已提交
1943

1944
**参数:**
Z
zhaolinglan 已提交
1945

1946 1947 1948
| 参数名 | 类型   | 必填 | 说明                                                         |
| ------ | ------ | ---- | ------------------------------------------------------------ |
| type   | string | 是   | 设置监听类型。<br/>-type为‘moveCursor’时表示取消订阅输入法应用发送移动光标事件监听。 |
Z
zhaolinglan 已提交
1949

H
Hollokin 已提交
1950 1951
**错误码:**

1952
以下错误码的详细介绍请参见[输入法框架错误码](../errorcodes/errorcode-inputmethod-framework.md)
H
Hollokin 已提交
1953

1954
| 错误码ID | 错误信息                             |
H
Hollokin 已提交
1955
| -------- | -------------------------------------- |
1956
| 12800009 | Input method client is detached. |
H
Hollokin 已提交
1957

Z
zhaolinglan 已提交
1958 1959 1960
**示例:**

```js
1961 1962 1963 1964 1965 1966
try {
    inputMethodController.off('moveCursor');
    console.info('Succeeded in unsubscribing moveCursor.');
} catch(error) {
    console.error(`Failed to unsubscribe moveCursor: ${JSON.stringify(error)}`);
}
Z
zhaolinglan 已提交
1967 1968
```

1969
### on('handleExtendAction')<sup>10+</sup>
H
Hollokin 已提交
1970

1971
on(type: 'handleExtendAction', callback: (action: ExtendAction) => void): void
H
Hollokin 已提交
1972

1973
订阅输入法应用发送扩展操作事件。使用callback异步回调。
H
Hollokin 已提交
1974

H
update  
Hollokin 已提交
1975
**系统能力:** SystemCapability.MiscServices.InputMethodFramework
H
Hollokin 已提交
1976 1977 1978

**参数:**

1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990
| 参数名   | 类型                                                         | 必填 | 说明                                                         |
| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
| type     | string                                                       | 是   | 设置监听类型。<br/>-type为‘handleExtendAction’时表示订阅输入法应用发送扩展操作代码事件监听。 |
| callback | callback: (action: [ExtendAction](#extendaction10)) => void | 是   | 回调函数,返回扩展代码。<br/>开发者需要在回调函数中根据传入的扩展操作类型做相应的操作。 |

**错误码:**

以下错误码的详细介绍请参见[输入法框架错误码](../errorcodes/errorcode-inputmethod-framework.md)

| 错误码ID | 错误信息                             |
| -------- | -------------------------------------- |
| 12800009 | Input method client is detached. |
H
Hollokin 已提交
1991 1992 1993 1994

**示例:**

```js
1995 1996 1997 1998 1999 2000 2001
try {
    inputMethodController.on('handleExtendAction', (action) => {
        console.info(`Succeeded in subscribing handleExtendAction, action: ${action}`);
    });
} catch(error) {
    console.error(`Failed to subscribe handleExtendAction: ${JSON.stringify(error)}`);
}
H
Hollokin 已提交
2002 2003
```

2004
### off('handleExtendAction')<sup>10+</sup>
H
Hollokin 已提交
2005

2006
off(type: 'handleExtendAction'): void
H
Hollokin 已提交
2007

2008
取消订阅输入法应用发送扩展事件。
H
Hollokin 已提交
2009

H
update  
Hollokin 已提交
2010
**系统能力:** SystemCapability.MiscServices.InputMethodFramework
H
Hollokin 已提交
2011

2012
**参数:**
H
Hollokin 已提交
2013

2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024
| 参数名 | 类型   | 必填 | 说明                                                         |
| ------ | ------ | ---- | ------------------------------------------------------------ |
| type   | string | 是   | 设置监听类型。<br/>-type为‘handleExtendAction’时表示取消订阅输入法应用发送扩展代码事件监听。 |

**错误码:**

以下错误码的详细介绍请参见[输入法框架错误码](../errorcodes/errorcode-inputmethod-framework.md)

| 错误码ID | 错误信息                             |
| -------- | -------------------------------------- |
| 12800009 | Input method client is detached. |
H
Hollokin 已提交
2025 2026 2027 2028

**示例:**

```js
2029 2030 2031 2032 2033 2034
try {
    inputMethodController.off('handleExtendAction');
    console.info('Succeeded in unsubscribing handleExtendAction.');
} catch(error) {
    console.error(`Failed to unsubscribe handleExtendAction: ${JSON.stringify(error)}`);
}
H
Hollokin 已提交
2035 2036
```

Z
add doc  
zhaolinglan 已提交
2037 2038 2039 2040 2041 2042 2043 2044 2045 2046
### on('selectByRange')<sup>10+</sup>

on(type: 'selectByRange', callback: Callback&lt;Range&gt;): void

订阅输入法应用按范围选中文本事件。使用callback异步回调。

**系统能力:** SystemCapability.MiscServices.InputMethodFramework

**参数:**

Z
add doc  
zhaolinglan 已提交
2047 2048 2049
| 参数名   | 类型                                                         | 必填 | 说明                                                         |
| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
| type     | string                                                       | 是   | 设置监听类型。<br/>-type为‘selectByRange’时表示订阅输入法应用按范围选中文本事件监听。 |
2050
| callback | Callback&lt;[Range](#range10)&gt; | 是   | 回调函数,返回需要选中的文本的范围。<br/>开发者需要在回调函数中根据传入的范围选中编辑框中相应文本。 |
Z
add doc  
zhaolinglan 已提交
2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081

**示例:**

```js
inputMethodController.on('selectByRange', (range) => {
    console.info('Succeeded in subscribing selectByRange: start: ' + range.start + " , end: " + range.end);
});
```

### off('selectByRange')<sup>10+</sup>

off(type: 'selectByRange'): void

取消订阅输入法应用按范围选中文本事件。

**系统能力:** SystemCapability.MiscServices.InputMethodFramework

**参数:**

| 参数名 | 类型   | 必填 | 说明                                                         |
| ------ | ------ | ---- | ------------------------------------------------------------ |
| type   | string | 是   | 设置监听类型。<br/>-type为‘selectByRange’时表示取消订阅输入法应用按范围选中文本事件监听。 |

**示例:**

```js
inputMethodController.off('selectByRange');
```

### on('selectByMovement')<sup>10+</sup>

2082
on(type: 'selectByMovement', callback: Callback&lt;Movement&gt;): void
Z
add doc  
zhaolinglan 已提交
2083 2084 2085 2086 2087 2088 2089

订阅输入法应用按光标动作选中文本事件。使用callback异步回调。

**系统能力:** SystemCapability.MiscServices.InputMethodFramework

**参数:**

Z
add doc  
zhaolinglan 已提交
2090 2091 2092
| 参数名   | 类型                                                         | 必填 | 说明                                                         |
| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
| type     | string                                                       | 是   | 设置监听类型。<br/>-type为‘selectByMovement’时表示订阅输入法应用按光标移动动作选中文本事件监听。 |
2093
| callback | Callback&lt;[Movement](#movement10)&gt; | 是   | 回调函数,返回需要选中的文本的范围。<br/>开发者需要在回调函数中根据传入的光标动作选中编辑框中相应文本。 |
Z
add doc  
zhaolinglan 已提交
2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122

**示例:**

```js
inputMethodController.on('selectByMovement', (movement) => {
    console.info('Succeeded in subscribing selectByMovement: direction: ' + movement.direction);
});
```

### off('selectByMovement')<sup>10+</sup>

off(type: 'selectByMovement'): void

取消订阅输入法应用按光标动作选中文本事件。

**系统能力:** SystemCapability.MiscServices.InputMethodFramework

**参数:**

| 参数名 | 类型   | 必填 | 说明                                                         |
| ------ | ------ | ---- | ------------------------------------------------------------ |
| type   | string | 是   | 设置监听类型。<br/>-type为‘selectByMovement’时表示取消订阅输入法应用按范围选中文本事件监听。 |

**示例:**

```js
inputMethodController.off('selectByMovement');
```

2123
## InputMethodSetting<sup>8+</sup>
Z
zhouyongfei 已提交
2124

2125
下列API示例中都需使用[getSetting](#inputmethodgetsetting9)获取到InputMethodSetting实例,再通过此实例调用对应方法。
Z
zhouyongfei 已提交
2126

H
Hollokin 已提交
2127
### on('imeChange')<sup>9+</sup>
2128 2129 2130

on(type: 'imeChange', callback: (inputMethodProperty: InputMethodProperty, inputMethodSubtype: InputMethodSubtype) => void): void

H
Hollokin 已提交
2131
订阅输入法及子类型变化监听事件。使用callback异步回调。
2132

H
update  
Hollokin 已提交
2133
**系统能力:** SystemCapability.MiscServices.InputMethodFramework
2134 2135 2136 2137 2138 2139

**参数:**

| 参数名   | 类型                            | 必填 | 说明                                                         |
| -------- | ------------------------------- | ---- | ------------------------------------------------------------ |
| type     | string                        | 是   | 设置监听类型。<br/>-type为‘imeChange’时表示订阅输入法及子类型变化监听事件。 |
2140
| callback | (inputMethodProperty: [InputMethodProperty](#inputmethodproperty8), inputMethodSubtype: [InputMethodSubtype](./js-apis-inputmethod-subtype.md#inputmethodsubtype)) => void  | 是 | 回调函数,返回输入法属性对象及输入法子类型对象。 |
2141 2142 2143

**示例:**

H
Hollokin 已提交
2144
```js
H
Hollokin 已提交
2145 2146
inputMethodSetting.on('imeChange', (inputMethodProperty, inputMethodSubtype) => {
    console.info('Succeeded in subscribing imeChange: inputMethodProperty: ' + JSON.stringify(inputMethodProperty) + " , inputMethodSubtype: " + JSON.stringify(inputMethodSubtype));
H
Hollokin 已提交
2147 2148
});
```
2149

H
Hollokin 已提交
2150
### off('imeChange')<sup>9+</sup>
2151

H
Hollokin 已提交
2152
off(type: 'imeChange', callback?: (inputMethodProperty: InputMethodProperty, inputMethodSubtype: InputMethodSubtype) => void): void
2153

H
Hollokin 已提交
2154
取消订阅输入法及子类型变化监听事件。使用callback异步回调。
2155

H
update  
Hollokin 已提交
2156
**系统能力:** SystemCapability.MiscServices.InputMethodFramework
2157 2158 2159 2160 2161 2162

**参数:**

| 参数名   | 类型                            | 必填 | 说明                                                         |
| -------- | ------------------------------- | ---- | ------------------------------------------------------------ |
| type     | string                        | 是   | 设置监听类型。<br/>-type为‘imeChange’时表示取消订阅输入法及子类型变化监听事件。 |
2163
| callback | (inputMethodProperty: [InputMethodProperty](#inputmethodproperty8), inputMethodSubtype: [InputMethodSubtype](./js-apis-inputmethod-subtype.md#inputmethodsubtype)) => void  | 否 | 回调函数,返回取消订阅的输入法属性对象及输入法子类型对象。 |
2164 2165 2166

**示例:**

H
Hollokin 已提交
2167
```js
H
Hollokin 已提交
2168
inputMethodSetting.off('imeChange');
H
Hollokin 已提交
2169
```
2170 2171 2172 2173 2174

### listInputMethodSubtype<sup>9+</sup>

listInputMethodSubtype(inputMethodProperty: InputMethodProperty, callback: AsyncCallback&lt;Array&lt;InputMethodSubtype&gt;&gt;): void

H
Hollokin 已提交
2175
获取指定输入法应用的所有子类型。使用callback异步回调。
2176

H
update  
Hollokin 已提交
2177
**系统能力:** SystemCapability.MiscServices.InputMethodFramework
2178 2179 2180 2181 2182

**参数:**

| 参数名   | 类型                                               | 必填 | 说明                   |
| -------- | -------------------------------------------------- | ---- | ---------------------- |
2183
| inputMethodProperty | InputMethodProperty| 是 | 子类型所属的输入法应用。 |
2184
| callback | AsyncCallback&lt;Array<[InputMethodSubtype](./js-apis-inputmethod-subtype.md#inputmethodsubtype)>&gt; | 是 | 回调函数,返回指定输入法应用的所有子类型。 |
2185

H
Hollokin 已提交
2186 2187
**错误码:**

2188
以下错误码的详细介绍请参见[输入法框架错误码](../errorcodes/errorcode-inputmethod-framework.md)
H
Hollokin 已提交
2189

2190
| 错误码ID | 错误信息                             |
H
Hollokin 已提交
2191 2192
| -------- | -------------------------------------- |
| 12800001 | Package manager error.                 |
H
Hollokin 已提交
2193
| 12800008 | Input method manager service error. |
H
Hollokin 已提交
2194

2195 2196
**示例:**

H
Hollokin 已提交
2197
```js
H
update  
Hollokin 已提交
2198
let inputMethodProperty = {
H
Hollokin 已提交
2199 2200 2201 2202
    packageName: 'com.example.kikakeyboard',
    methodId: 'com.example.kikakeyboard',
    name: 'com.example.kikakeyboard',
    id: 'com.example.kikakeyboard',
2203
    extra:{}
H
Hollokin 已提交
2204 2205
}
try {
H
Hollokin 已提交
2206
    inputMethodSetting.listInputMethodSubtype(inputMethodProperty, (err,data) => {
H
Hollokin 已提交
2207 2208
        if (err !== undefined) {
            console.error('Failed to listInputMethodSubtype: ' + JSON.stringify(err));
H
Hollokin 已提交
2209 2210
            return;
        }
H
Hollokin 已提交
2211
        console.log('Succeeded in listing inputMethodSubtype.');
H
Hollokin 已提交
2212 2213
    });
} catch (err) {
H
Hollokin 已提交
2214
    console.error('Failed to listInputMethodSubtype: ' + JSON.stringify(err));
H
Hollokin 已提交
2215
}
2216 2217 2218 2219 2220 2221
```

### listInputMethodSubtype<sup>9+</sup>

listInputMethodSubtype(inputMethodProperty: InputMethodProperty): Promise&lt;Array&lt;InputMethodSubtype&gt;&gt;

H
Hollokin 已提交
2222
获取指定输入法应用的所有子类型。使用promise异步回调。
2223

H
update  
Hollokin 已提交
2224
**系统能力:** SystemCapability.MiscServices.InputMethodFramework
2225

H
Hollokin 已提交
2226 2227 2228 2229
**参数:**

| 参数名   | 类型                                               | 必填 | 说明                   |
| -------- | -------------------------------------------------- | ---- | ---------------------- |
2230
| inputMethodProperty | InputMethodProperty| 是 | 子类型所属的输入法应用。 |
H
Hollokin 已提交
2231

2232 2233 2234 2235
**返回值:**

| 类型                                                        | 说明                   |
| ----------------------------------------------------------- | ---------------------- |
2236
| Promise<Array<[InputMethodSubtype](./js-apis-inputmethod-subtype.md#inputmethodsubtype)>> | Promise对象,返回指定输入法应用的所有子类型。 |
2237

H
Hollokin 已提交
2238 2239
**错误码:**

2240
以下错误码的详细介绍请参见[输入法框架错误码](../errorcodes/errorcode-inputmethod-framework.md)
H
Hollokin 已提交
2241

2242
| 错误码ID | 错误信息                             |
H
Hollokin 已提交
2243 2244
| -------- | -------------------------------------- |
| 12800001 | Package manager error.                 |
H
Hollokin 已提交
2245
| 12800008 | Input method manager service error. |
H
Hollokin 已提交
2246

2247 2248
**示例:**

H
Hollokin 已提交
2249
```js
H
Hollokin 已提交
2250
let inputMethodProperty = {
H
Hollokin 已提交
2251 2252 2253 2254
    packageName: 'com.example.kikakeyboard',
    methodId: 'com.example.kikakeyboard',
    name: 'com.example.kikakeyboard',
    id: 'com.example.kikakeyboard',
2255
    extra:{}
H
Hollokin 已提交
2256 2257
}
try {
H
Hollokin 已提交
2258
    inputMethodSetting.listInputMethodSubtype(inputMethodProperty).then((data) => {
H
Hollokin 已提交
2259
        console.info('Succeeded in listing inputMethodSubtype.');
H
Hollokin 已提交
2260
    }).catch((err) => {
H
Hollokin 已提交
2261
        console.error('Failed to listInputMethodSubtype: ' + JSON.stringify(err));
H
Hollokin 已提交
2262 2263
    })
} catch(err) {
H
Hollokin 已提交
2264
    console.error('Failed to listInputMethodSubtype: ' + JSON.stringify(err));
H
Hollokin 已提交
2265
}
2266 2267 2268 2269 2270
```

### listCurrentInputMethodSubtype<sup>9+</sup>

listCurrentInputMethodSubtype(callback: AsyncCallback&lt;Array&lt;InputMethodSubtype&gt;&gt;): void
Z
zhaolinglan 已提交
2271

H
Hollokin 已提交
2272
查询当前输入法应用的所有子类型。使用callback异步回调。
2273

H
update  
Hollokin 已提交
2274
**系统能力:** SystemCapability.MiscServices.InputMethodFramework
2275 2276 2277 2278 2279

**参数:**

| 参数名   | 类型                                               | 必填 | 说明                   |
| -------- | -------------------------------------------------- | ---- | ---------------------- |
2280
| callback | AsyncCallback&lt;Array<[InputMethodSubtype](./js-apis-inputmethod-subtype.md#inputmethodsubtype)>&gt; | 是   | 回调函数,返回当前输入法应用的所有子类型。 |
2281

H
Hollokin 已提交
2282 2283
**错误码:**

2284
以下错误码的详细介绍请参见[输入法框架错误码](../errorcodes/errorcode-inputmethod-framework.md)
H
Hollokin 已提交
2285

2286
| 错误码ID | 错误信息                             |
H
Hollokin 已提交
2287 2288
| -------- | -------------------------------------- |
| 12800001 | Package manager error.                 |
H
Hollokin 已提交
2289
| 12800008 | Input method manager service error. |
H
Hollokin 已提交
2290

2291 2292
**示例:**

H
Hollokin 已提交
2293
```js
H
Hollokin 已提交
2294
try {
H
Hollokin 已提交
2295
    inputMethodSetting.listCurrentInputMethodSubtype((err, data) => {
H
Hollokin 已提交
2296 2297
        if (err !== undefined) {
            console.error('Failed to listCurrentInputMethodSubtype: ' + JSON.stringify(err));
H
Hollokin 已提交
2298 2299
            return;
        }
H
Hollokin 已提交
2300
        console.log('Succeeded in listing currentInputMethodSubtype.');
H
Hollokin 已提交
2301 2302
    });
} catch(err) {
H
Hollokin 已提交
2303
    console.error('Failed to listCurrentInputMethodSubtype: ' + JSON.stringify(err));
H
Hollokin 已提交
2304
}
2305 2306 2307 2308 2309 2310
```

### listCurrentInputMethodSubtype<sup>9+</sup>

listCurrentInputMethodSubtype(): Promise&lt;Array&lt;InputMethodSubtype&gt;&gt;

H
Hollokin 已提交
2311
查询当前输入法的子类型列表。使用promise异步回调。
2312

H
update  
Hollokin 已提交
2313
**系统能力:** SystemCapability.MiscServices.InputMethodFramework
2314 2315 2316 2317 2318

**返回值:**

| 类型                                                        | 说明                   |
| ----------------------------------------------------------- | ---------------------- |
2319
| Promise<Array<[InputMethodSubtype](./js-apis-inputmethod-subtype.md#inputmethodsubtype)>> | Promise对象,返回当前输入法应用的所有子类型。 |
2320

H
Hollokin 已提交
2321 2322
**错误码:**

2323
以下错误码的详细介绍请参见[输入法框架错误码](../errorcodes/errorcode-inputmethod-framework.md)
H
Hollokin 已提交
2324

2325
| 错误码ID | 错误信息                             |
H
Hollokin 已提交
2326 2327
| -------- | -------------------------------------- |
| 12800001 | Package manager error.                 |
H
Hollokin 已提交
2328
| 12800008 | Input method manager service error. |
H
Hollokin 已提交
2329

2330 2331
**示例:**

H
Hollokin 已提交
2332
```js
H
Hollokin 已提交
2333
try {
H
Hollokin 已提交
2334
    inputMethodSetting.listCurrentInputMethodSubtype().then((data) => {
H
Hollokin 已提交
2335
        console.info('Succeeded in listing currentInputMethodSubtype.');
H
Hollokin 已提交
2336
    }).catch((err) => {
H
Hollokin 已提交
2337
        console.error('Failed to listCurrentInputMethodSubtype: ' + JSON.stringify(err));
H
Hollokin 已提交
2338 2339
    })
} catch(err) {
H
Hollokin 已提交
2340
    console.error('Failed to listCurrentInputMethodSubtype: ' + JSON.stringify(err));
H
Hollokin 已提交
2341
}
2342 2343 2344 2345 2346
```

### getInputMethods<sup>9+</sup>

getInputMethods(enable: boolean, callback: AsyncCallback&lt;Array&lt;InputMethodProperty&gt;&gt;): void
Z
zhaolinglan 已提交
2347

2348
获取已激活/未激活输入法列表。参数enable取true,返回已激活输入法列表,取false返回未激活输入法列表。已激活/未激活输入法的确切功能当前版本未支持。当前版本中,已激活输入法包括当前使用的输入法,未激活输入法包括当前输入法以外的其他已安装的输入法。使用callback异步回调。
Z
zhaolinglan 已提交
2349

H
update  
Hollokin 已提交
2350
**系统能力:** SystemCapability.MiscServices.InputMethodFramework
Z
zhaolinglan 已提交
2351 2352 2353 2354 2355 2356

**参数:**

| 参数名   | 类型                                                | 必填 | 说明                          |
| -------- | --------------------------------------------------- | ---- | ----------------------------- |
| enable   | boolean                                             | 是   | 指定返回已激活/未激活。       |
2357
| callback | AsyncCallback&lt;Array<[InputMethodProperty](#inputmethodproperty8)>&gt; | 是   | 回调函数,返回已激活/未激活输入法列表。 |
Z
zhaolinglan 已提交
2358

H
Hollokin 已提交
2359 2360
**错误码:**

2361
以下错误码的详细介绍请参见[输入法框架错误码](../errorcodes/errorcode-inputmethod-framework.md)
H
Hollokin 已提交
2362

2363
| 错误码ID | 错误信息                             |
H
Hollokin 已提交
2364 2365
| -------- | -------------------------------------- |
| 12800001 | Package manager error.                 |
H
Hollokin 已提交
2366
| 12800008 | Input method manager service error. |
H
Hollokin 已提交
2367

Z
zhaolinglan 已提交
2368 2369
**示例:**

H
Hollokin 已提交
2370
```js
H
Hollokin 已提交
2371
try {
H
Hollokin 已提交
2372
    inputMethodSetting.getInputMethods(true, (err,data) => {
H
Hollokin 已提交
2373 2374
        if (err !== undefined) {
            console.error('Failed to getInputMethods: ' + JSON.stringify(err));
H
Hollokin 已提交
2375 2376
            return;
        }
H
Hollokin 已提交
2377
        console.log('Succeeded in getting inputMethods.');
H
Hollokin 已提交
2378 2379
    });
} catch (err) {
H
Hollokin 已提交
2380
    console.error('Failed to getInputMethods: ' + JSON.stringify(err));
H
Hollokin 已提交
2381
}
Z
zhaolinglan 已提交
2382 2383
```

2384
### getInputMethods<sup>9+</sup>
Z
zhaolinglan 已提交
2385

2386
getInputMethods(enable: boolean): Promise&lt;Array&lt;InputMethodProperty&gt;&gt;
Z
zhaolinglan 已提交
2387

2388
获取已激活/未激活输入法列表。参数enable取true,返回已激活输入法列表,取false返回未激活输入法列表。已激活/未激活输入法的确切功能当前版本未支持。当前版本中,已激活输入法包括当前使用的输入法,未激活输入法包括当前输入法以外的其他已安装的输入法。使用promise异步回调。
Z
zhaolinglan 已提交
2389

H
update  
Hollokin 已提交
2390
**系统能力:** SystemCapability.MiscServices.InputMethodFramework
Z
zhaolinglan 已提交
2391 2392 2393 2394 2395 2396 2397

**参数:**

| 参数名 | 类型    | 必填 | 说明                    |
| ------ | ------- | ---- | ----------------------- |
| enable | boolean | 是   | 指定返回已激活/未激活。 |

H
Hollokin 已提交
2398 2399
**错误码:**

2400
以下错误码的详细介绍请参见[输入法框架错误码](../errorcodes/errorcode-inputmethod-framework.md)
H
Hollokin 已提交
2401

2402
| 错误码ID | 错误信息                             |
H
Hollokin 已提交
2403 2404
| -------- | -------------------------------------- |
| 12800001 | Package manager error.                 |
H
Hollokin 已提交
2405
| 12800008 | Input method manager service error. |
H
Hollokin 已提交
2406

Z
zhaolinglan 已提交
2407 2408 2409 2410
**返回值:**

| 类型                                                         | 说明                          |
| ------------------------------------------------------------ | ----------------------------- |
H
Hollokin 已提交
2411
| Promise<Array<[InputMethodProperty](#inputmethodproperty8)>> | Promise对象,返回已激活/未激活输入法列表。 |
Z
zhaolinglan 已提交
2412 2413 2414

**示例:**

H
Hollokin 已提交
2415
```js
H
Hollokin 已提交
2416
try {
H
Hollokin 已提交
2417
    inputMethodSetting.getInputMethods(true).then((data) => {
H
Hollokin 已提交
2418
        console.info('Succeeded in getting inputMethods.');
H
Hollokin 已提交
2419
    }).catch((err) => {
H
Hollokin 已提交
2420
        console.error('Failed to getInputMethods: ' + JSON.stringify(err));
H
Hollokin 已提交
2421 2422
    })
} catch(err) {
H
Hollokin 已提交
2423
    console.error('Failed to getInputMethods: ' + JSON.stringify(err));
H
Hollokin 已提交
2424
}
Z
zhaolinglan 已提交
2425 2426
```

H
Hollokin 已提交
2427 2428
### showOptionalInputMethods<sup>9+</sup>

H
Hollokin 已提交
2429
showOptionalInputMethods(callback: AsyncCallback&lt;boolean&gt;): void
H
Hollokin 已提交
2430

H
Hollokin 已提交
2431
显示输入法选择对话框。使用callback异步回调。
H
Hollokin 已提交
2432

H
update  
Hollokin 已提交
2433
**系统能力:** SystemCapability.MiscServices.InputMethodFramework
H
Hollokin 已提交
2434 2435 2436 2437 2438

**参数:**

| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
H
Hollokin 已提交
2439
| callback | AsyncCallback&lt;boolean&gt; | 是 | 回调函数。当输入法选择对话框显示成功,err为undefined,data为true;否则为错误对象。 |
H
Hollokin 已提交
2440

H
Hollokin 已提交
2441 2442
**错误码:**

2443
以下错误码的详细介绍请参见[输入法框架错误码](../errorcodes/errorcode-inputmethod-framework.md)
H
Hollokin 已提交
2444

2445
| 错误码ID | 错误信息                             |
H
Hollokin 已提交
2446
| -------- | -------------------------------------- |
H
Hollokin 已提交
2447
| 12800008 | Input method manager service error. |
H
Hollokin 已提交
2448

H
Hollokin 已提交
2449 2450
**示例:**

H
Hollokin 已提交
2451
```js
H
Hollokin 已提交
2452
try {
H
Hollokin 已提交
2453
    inputMethodSetting.showOptionalInputMethods((err, data) => {
H
Hollokin 已提交
2454 2455
        if (err !== undefined) {
            console.error('Failed to showOptionalInputMethods: ' + JSON.stringify(err));
H
Hollokin 已提交
2456 2457
            return;
        }
H
Hollokin 已提交
2458
        console.info('Succeeded in showing optionalInputMethods.');
H
Hollokin 已提交
2459 2460
    });
} catch (err) {
H
Hollokin 已提交
2461
    console.error('Failed to showOptionalInputMethods: ' + JSON.stringify(err));
H
Hollokin 已提交
2462 2463 2464 2465 2466
}
```

### showOptionalInputMethods<sup>9+</sup>

H
Hollokin 已提交
2467
showOptionalInputMethods(): Promise&lt;boolean&gt;
H
Hollokin 已提交
2468

H
Hollokin 已提交
2469
显示输入法选择对话框。使用promise异步回调。
H
Hollokin 已提交
2470

H
update  
Hollokin 已提交
2471
**系统能力:** SystemCapability.MiscServices.InputMethodFramework
H
Hollokin 已提交
2472 2473 2474 2475 2476

**返回值:**

| 类型 | 说明 |
| -------- | -------- |
H
Hollokin 已提交
2477
| Promise&lt;boolean&gt; | Promise对象。返回true表示输入法选择对话框显示成功;返回false表示输入法选择对话框显示失败。 |
H
Hollokin 已提交
2478

H
Hollokin 已提交
2479 2480
**错误码:**

2481
以下错误码的详细介绍请参见[输入法框架错误码](../errorcodes/errorcode-inputmethod-framework.md)
H
Hollokin 已提交
2482

2483
| 错误码ID | 错误信息                             |
H
Hollokin 已提交
2484
| -------- | -------------------------------------- |
H
Hollokin 已提交
2485
| 12800008 | Input method manager service error. |
H
Hollokin 已提交
2486

H
Hollokin 已提交
2487 2488
**示例:**

H
Hollokin 已提交
2489
```js
H
Hollokin 已提交
2490
inputMethodSetting.showOptionalInputMethods().then((data) => {
H
Hollokin 已提交
2491
    console.info('Succeeded in showing optionalInputMethods.');
H
Hollokin 已提交
2492
}).catch((err) => {
H
Hollokin 已提交
2493
    console.error('Failed to showOptionalInputMethods: ' + JSON.stringify(err));
H
Hollokin 已提交
2494 2495 2496
})
```

H
Hollokin 已提交
2497
### listInputMethod<sup>(deprecated)</sup>
Z
zhouyongfei 已提交
2498 2499 2500

listInputMethod(callback: AsyncCallback&lt;Array&lt;InputMethodProperty&gt;&gt;): void

H
Hollokin 已提交
2501
查询已安装的输入法列表。使用callback异步回调。
Z
zhouyongfei 已提交
2502

H
update  
Hollokin 已提交
2503 2504
> **说明:** 
>
H
update  
Hollokin 已提交
2505
> 从API version 8开始支持,从API version 9开始废弃, 建议使用[getInputMethods](#getinputmethods9)替代。
H
Hollokin 已提交
2506

H
update  
Hollokin 已提交
2507
**系统能力:** SystemCapability.MiscServices.InputMethodFramework
Z
zhouyongfei 已提交
2508

2509
**参数:**
B
bmeangel 已提交
2510

T
explain  
tianyu 已提交
2511 2512
| 参数名   | 类型                                               | 必填 | 说明                   |
| -------- | -------------------------------------------------- | ---- | ---------------------- |
2513
| callback | AsyncCallback&lt;Array<[InputMethodProperty](#inputmethodproperty8)>&gt; | 是   | 回调函数,返回已安装的输入法列表。 |
Z
zhouyongfei 已提交
2514

2515
**示例:**
T
explain  
tianyu 已提交
2516

2517
```js
H
Hollokin 已提交
2518
inputMethodSetting.listInputMethod((err,data) => {
H
Hollokin 已提交
2519 2520
    if (err !== undefined) {
        console.error('Failed to listInputMethod: ' + JSON.stringify(err));
2521
        return;
2522
    }
H
Hollokin 已提交
2523
    console.log('Succeeded in listing inputMethod.');
2524
 });
2525
```
Z
zhouyongfei 已提交
2526

H
Hollokin 已提交
2527
### listInputMethod<sup>(deprecated)</sup>
Z
zhouyongfei 已提交
2528

Z
zhaolinglan 已提交
2529
listInputMethod(): Promise&lt;Array&lt;InputMethodProperty&gt;&gt;
Z
zhouyongfei 已提交
2530

H
Hollokin 已提交
2531
查询已安装的输入法列表。使用promise异步回调。
Z
zhouyongfei 已提交
2532

H
update  
Hollokin 已提交
2533 2534
> **说明:**
>
H
update  
Hollokin 已提交
2535
> 从API version 8开始支持,从API version 9开始废弃, 建议使用[getInputMethods](#getinputmethods9-1)替代。
H
Hollokin 已提交
2536

H
update  
Hollokin 已提交
2537
**系统能力:** SystemCapability.MiscServices.InputMethodFramework
Z
zhouyongfei 已提交
2538

2539
**返回值:**
B
bmeangel 已提交
2540

T
explain  
tianyu 已提交
2541 2542
| 类型                                                        | 说明                   |
| ----------------------------------------------------------- | ---------------------- |
H
Hollokin 已提交
2543
| Promise<Array<[InputMethodProperty](#inputmethodproperty8)>> | Promise对象,返回已安装输入法列表。 |
Z
zhouyongfei 已提交
2544

2545
**示例:**
2546 2547

```js
H
Hollokin 已提交
2548
inputMethodSetting.listInputMethod().then((data) => {
H
Hollokin 已提交
2549
    console.info('Succeeded in listing inputMethod.');
Z
zhaolinglan 已提交
2550
}).catch((err) => {
H
Hollokin 已提交
2551
    console.error('Failed to listInputMethod: ' + JSON.stringify(err));
Z
zhaolinglan 已提交
2552
})
2553
```
Z
zhouyongfei 已提交
2554

H
Hollokin 已提交
2555
### displayOptionalInputMethod<sup>(deprecated)</sup>
Z
zhouyongfei 已提交
2556 2557 2558

displayOptionalInputMethod(callback: AsyncCallback&lt;void&gt;): void

H
Hollokin 已提交
2559
显示输入法选择对话框。使用callback异步回调。
Z
zhouyongfei 已提交
2560

H
update  
Hollokin 已提交
2561 2562
> **说明:**
>
H
update  
Hollokin 已提交
2563
> 从API version 8开始支持,从API version 9开始废弃, 建议使用[showOptionalInputMethods()](#showoptionalinputmethods9)替代。
H
Hollokin 已提交
2564

H
update  
Hollokin 已提交
2565
**系统能力:** SystemCapability.MiscServices.InputMethodFramework
Z
zhouyongfei 已提交
2566

2567
**参数:**
Z
zhouyongfei 已提交
2568 2569 2570

| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
H
Hollokin 已提交
2571
| callback | AsyncCallback&lt;void&gt; | 是 | 回调函数。当输入法选择对话框显示成功。err为undefined,否则为错误对象。 |
Z
zhouyongfei 已提交
2572

2573
**示例:**
2574 2575

```js
H
Hollokin 已提交
2576
inputMethodSetting.displayOptionalInputMethod((err) => {
H
Hollokin 已提交
2577 2578
    if (err !== undefined) {
        console.error('Failed to displayOptionalInputMethod: ' + JSON.stringify(err));
2579 2580
        return;
    }
H
Hollokin 已提交
2581
    console.info('Succeeded in displaying optionalInputMethod.');
2582
});
2583
```
Z
zhouyongfei 已提交
2584

H
Hollokin 已提交
2585
### displayOptionalInputMethod<sup>(deprecated)</sup>
Z
zhouyongfei 已提交
2586

2587 2588
displayOptionalInputMethod(): Promise&lt;void&gt;

H
Hollokin 已提交
2589
显示输入法选择对话框。使用promise异步回调。
2590

H
update  
Hollokin 已提交
2591 2592
> **说明:**
>
2593
> 从API version 8开始支持,从API version 9开始废弃, 建议使用[showOptionalInputMethods()](#showoptionalinputmethods9-1)替代。
H
Hollokin 已提交
2594

H
update  
Hollokin 已提交
2595
**系统能力:** SystemCapability.MiscServices.InputMethodFramework
2596 2597 2598 2599 2600

**返回值:**

| 类型 | 说明 |
| -------- | -------- |
H
Hollokin 已提交
2601
| Promise&lt;void&gt; | 无返回结果的Promise对象。 |
2602 2603 2604 2605

**示例:**

```js
H
Hollokin 已提交
2606
inputMethodSetting.displayOptionalInputMethod().then(() => {
H
Hollokin 已提交
2607
    console.info('Succeeded in displaying optionalInputMethod.');
2608
}).catch((err) => {
H
Hollokin 已提交
2609
    console.error('Failed to displayOptionalInputMethod: ' + JSON.stringify(err));
2610 2611
})
```