js-apis-inputmethod.md 91.5 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
## TextInputType<sup>10+</sup>

H
update  
Hollokin 已提交
515
文本输入类型。
516 517 518 519 520 521 522

**系统能力**: 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

## 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) | 是 | 是 | 文本输入类型。|
H
update  
Hollokin 已提交
619
| enterKeyType<sup>10+</sup>  | [EnterKeyType](#enterkeytype10) | 是 | 是 | Enter键功能类型。|
620 621 622

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

H
update  
Hollokin 已提交
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

**系统能力:** 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
用于自绘控件绑定输入法应用。使用callback异步回调。
H
update  
Hollokin 已提交
674
必须先调用此接口完成自绘控件与输入法应用的绑定,才可以使用输入法框架的以下功能:显示、隐藏键盘;更新光标信息;更改编辑框选中范围;保存配置信息;监听处理由输入法应用发送的信息或命令等。
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
| 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;

H
update  
Hollokin 已提交
717 718
用于自绘控件绑定输入法应用。使用callback异步回调。
必须先调用此接口完成自绘控件与输入法应用的绑定,才可以使用输入法框架的以下功能:显示、隐藏键盘;更新光标信息;更改编辑框选中范围;保存配置信息;监听处理由输入法应用发送的信息或命令等。
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

**系统能力:** 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

H
update  
Hollokin 已提交
764 765
进入文本编辑状态。使用callback异步回调。
编辑控件与输入法应用绑定成功后,可调用该接口去拉起软键盘。
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

**系统能力:** 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;

H
update  
Hollokin 已提交
801 802
进入文本编辑状态。使用promise异步回调。
编辑控件与输入法应用绑定成功后,可调用该接口去拉起软键盘。
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

**系统能力:** 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

H
update  
Hollokin 已提交
836 837 838
退出文本编辑状态。使用callback异步回调。
编辑控件可调用该接口退出编辑状态。若调用该接口时当前软键盘处于显示状态,则调用该接口后软键盘会被隐藏。
调用该接口不解除与输入法应用的绑定,再次调用[showTextInput](#showtextinput10)时,可重新进入编辑状态。
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

**系统能力:** 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;

H
update  
Hollokin 已提交
874 875 876
退出文本编辑状态。使用promise异步回调。
编辑控件可调用该接口退出编辑状态。若调用该接口时当前软键盘处于显示状态,则调用该接口后软键盘会被隐藏。
调用该接口不解除与输入法应用的绑定,再次调用[showTextInput](#showtextinput10)时,可重新进入编辑状态。
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 907 908 909 910 911 912 913

**系统能力:** 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 已提交
914
解除与输入法应用的绑定。使用callback异步回调。
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 942 943 944 945 946 947 948

**系统能力:** 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 已提交
949
解除与输入法应用的绑定。使用promise异步回调。
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

**系统能力:** 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

H
update  
Hollokin 已提交
1069
更新当前编辑框内光标信息。当光标信息发生变化时,可调用该接口更新光标信息,从而被输入法应用感知到光标变化。使用callback异步回调。
1070 1071 1072 1073 1074 1075 1076 1077

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

**参数:**

| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| cursorInfo | [CursorInfo](#cursorinfo10) | 是 | 光标信息。 |
H
update  
Hollokin 已提交
1078
| callback | AsyncCallback&lt;void&gt; | 是 | 回调函数。当光标信息更新成功时,err为undefined;否则为错误对象。 |
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

**错误码:**

以下错误码的详细介绍请参见[输入法框架错误码](../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;

H
update  
Hollokin 已提交
1110
更新当前编辑控件内的光标信息。当光标信息发生变化时,编辑控件可调用该接口更新光标信息,从而被输入法应用感知到光标变化。使用promise异步回调。
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

**系统能力:** 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

H
update  
Hollokin 已提交
1154
向输入法应用更新当前编辑框内被选中的文本信息,当选中的文本内容或文本范围发生变化时,可调用该接口更新文本信息。使用callback异步回调。
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

**系统能力:** 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;

H
update  
Hollokin 已提交
1197
向输入法应用更新当前编辑框内被选中的文本信息,当选中的文本内容或文本范围发生变化时,可调用该接口更新文本信息。使用promise异步回调。
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

**系统能力:** 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

H
update  
Hollokin 已提交
1243
更新编辑框属性配置信息。使用callback异步回调。
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

**系统能力:** 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;

H
update  
Hollokin 已提交
1285
更新编辑框属性配置信息。使用promise异步回调。
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

**系统能力:** 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

**参数:**

H
update  
Hollokin 已提交
1699 1700 1701
| 参数名   | 类型 | 必填 | 说明 |
| -------- | ----- | ---- | ----- |
| type     | string  | 是   | 设置监听类型。<br/>-type为‘deleteLeft’时表示订阅输入法应用向左删除事件监听。 <br/>-type为‘deleteRight’时表示订阅输入法应用向右删除事件监听。|
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 1746 1747 1748 1749 1750 1751 1752
| 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 已提交
1753

1754
**示例:**
1755

1756 1757 1758 1759 1760 1761 1762
```js
try {
    inputMethodController.off('deleteLeft');
    console.info('Succeeded in unsubscribing deleteLeft.');
} catch(error) {
    console.error(`Failed to unsubscribe deleteLeft: ${JSON.stringify(error)}`);
}
1763

1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776
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异步回调。
1777

H
update  
Hollokin 已提交
1778
**系统能力:** SystemCapability.MiscServices.InputMethodFramework
1779 1780 1781

**参数:**

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

H
Hollokin 已提交
1787 1788
**错误码:**

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

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

1795 1796 1797
**示例:**

```js
H
Hollokin 已提交
1798
try {
1799 1800
    inputMethodController.on('sendKeyboardStatus', (keyBoardStatus) => {
        console.info(`Succeeded in subscribing sendKeyboardStatus, keyBoardStatus: ${keyBoardStatus}`);
H
Hollokin 已提交
1801
    });
H
Hollokin 已提交
1802
} catch(error) {
1803
    console.error(`Failed to subscribe sendKeyboardStatus: ${JSON.stringify(error)}`);
H
Hollokin 已提交
1804
}
1805 1806
```

1807
### off('sendKeyboardStatus')<sup>10+</sup>
1808

1809
off(type: 'sendKeyboardStatus'): void
1810

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

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

1815
**参数:**
1816

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

H
Hollokin 已提交
1821 1822
**错误码:**

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

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

1829 1830 1831
**示例:**

```js
H
Hollokin 已提交
1832
try {
1833 1834 1835 1836
    inputMethodController.off('sendKeyboardStatus');
    console.info('Succeeded in unsubscribing sendKeyboardStatus.');
} catch(error) {
    console.error(`Failed to unsubscribe sendKeyboardStatus: ${JSON.stringify(error)}`);
H
Hollokin 已提交
1837
}
1838 1839
```

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

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

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

1846
**系统能力:** SystemCapability.MiscServices.InputMethodFramework
Z
zhaolinglan 已提交
1847 1848 1849

**参数:**

H
update  
Hollokin 已提交
1850 1851 1852
| 参数名   | 类型  | 必填 | 说明     |
| -------- | -------- | ---- | ----- |
| type     | string  | 是   | 设置监听类型。<br/>-type为‘sendFunctionKey’时表示订阅输入法应用发送功能键事件监听。 |
H
update  
Hollokin 已提交
1853
| callback | (functionKey: [FunctionKey](#functionkey10)) => void | 是   | 回调函数,返回输入法应用发送的功能键信息。<br/>开发者需要根据返回的功能键做相应的操作。 |
Z
zhaolinglan 已提交
1854

H
Hollokin 已提交
1855 1856
**错误码:**

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

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

Z
zhaolinglan 已提交
1863 1864 1865
**示例:**

```js
1866 1867 1868 1869 1870 1871 1872
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 已提交
1873 1874
```

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

1877
off(type: 'sendFunctionKey'): void
Z
zhaolinglan 已提交
1878

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

1881
**系统能力:** SystemCapability.MiscServices.InputMethodFramework
Z
zhaolinglan 已提交
1882

1883
**参数:**
Z
zhaolinglan 已提交
1884

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

H
Hollokin 已提交
1889 1890
**错误码:**

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

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

Z
zhaolinglan 已提交
1897 1898 1899
**示例:**

```js
1900 1901 1902 1903 1904 1905
try {
    inputMethodController.off('sendFunctionKey');
    console.info('Succeeded in unsubscribing sendFunctionKey.');
} catch(error) {
    console.error(`Failed to unsubscribe sendFunctionKey: ${JSON.stringify(error)}`);
}
Z
zhaolinglan 已提交
1906 1907
```

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

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

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

1914
**系统能力:** SystemCapability.MiscServices.InputMethodFramework
Z
zhaolinglan 已提交
1915 1916 1917

**参数:**

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

H
Hollokin 已提交
1923 1924
**错误码:**

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

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

Z
zhaolinglan 已提交
1931 1932 1933
**示例:**

```js
1934 1935 1936 1937 1938 1939 1940
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 已提交
1941 1942
```

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

1945
off(type: 'moveCursor'): void
Z
zhaolinglan 已提交
1946

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

1949
**系统能力:** SystemCapability.MiscServices.InputMethodFramework
Z
zhaolinglan 已提交
1950

1951
**参数:**
Z
zhaolinglan 已提交
1952

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

H
Hollokin 已提交
1957 1958
**错误码:**

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

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

Z
zhaolinglan 已提交
1965 1966 1967
**示例:**

```js
1968 1969 1970 1971 1972 1973
try {
    inputMethodController.off('moveCursor');
    console.info('Succeeded in unsubscribing moveCursor.');
} catch(error) {
    console.error(`Failed to unsubscribe moveCursor: ${JSON.stringify(error)}`);
}
Z
zhaolinglan 已提交
1974 1975
```

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

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

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

H
update  
Hollokin 已提交
1982
**系统能力:** SystemCapability.MiscServices.InputMethodFramework
H
Hollokin 已提交
1983 1984 1985

**参数:**

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

**错误码:**

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

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

**示例:**

```js
2002 2003 2004 2005 2006 2007 2008
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 已提交
2009 2010
```

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

2013
off(type: 'handleExtendAction'): void
H
Hollokin 已提交
2014

H
update  
Hollokin 已提交
2015
取消订阅输入法应用发送扩展操作事件。
H
Hollokin 已提交
2016

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

2019
**参数:**
H
Hollokin 已提交
2020

H
update  
Hollokin 已提交
2021 2022
| 参数名 | 类型   | 必填 | 说明  |
| ------ | ------ | ---- | ------- |
2023 2024 2025 2026 2027 2028 2029 2030 2031
| type   | string | 是   | 设置监听类型。<br/>-type为‘handleExtendAction’时表示取消订阅输入法应用发送扩展代码事件监听。 |

**错误码:**

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

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

**示例:**

```js
2036 2037 2038 2039 2040 2041
try {
    inputMethodController.off('handleExtendAction');
    console.info('Succeeded in unsubscribing handleExtendAction.');
} catch(error) {
    console.error(`Failed to unsubscribe handleExtendAction: ${JSON.stringify(error)}`);
}
H
Hollokin 已提交
2042 2043
```

Z
add doc  
zhaolinglan 已提交
2044 2045 2046 2047 2048 2049 2050 2051 2052 2053
### on('selectByRange')<sup>10+</sup>

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

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

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

**参数:**

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

**示例:**

```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>

2089
on(type: 'selectByMovement', callback: Callback&lt;Movement&gt;): void
Z
add doc  
zhaolinglan 已提交
2090 2091 2092 2093 2094 2095 2096

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

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

**参数:**

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

**示例:**

```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');
```

2130
## InputMethodSetting<sup>8+</sup>
Z
zhouyongfei 已提交
2131

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

H
Hollokin 已提交
2134
### on('imeChange')<sup>9+</sup>
2135 2136 2137

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

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

H
update  
Hollokin 已提交
2140
**系统能力:** SystemCapability.MiscServices.InputMethodFramework
2141 2142 2143 2144 2145 2146

**参数:**

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

**示例:**

H
Hollokin 已提交
2151
```js
H
Hollokin 已提交
2152 2153
inputMethodSetting.on('imeChange', (inputMethodProperty, inputMethodSubtype) => {
    console.info('Succeeded in subscribing imeChange: inputMethodProperty: ' + JSON.stringify(inputMethodProperty) + " , inputMethodSubtype: " + JSON.stringify(inputMethodSubtype));
H
Hollokin 已提交
2154 2155
});
```
2156

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

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

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

H
update  
Hollokin 已提交
2163
**系统能力:** SystemCapability.MiscServices.InputMethodFramework
2164 2165 2166

**参数:**

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

**示例:**

H
Hollokin 已提交
2174
```js
H
Hollokin 已提交
2175
inputMethodSetting.off('imeChange');
H
Hollokin 已提交
2176
```
2177 2178 2179 2180 2181

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

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

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

H
update  
Hollokin 已提交
2184
**系统能力:** SystemCapability.MiscServices.InputMethodFramework
2185 2186 2187 2188 2189

**参数:**

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

H
Hollokin 已提交
2193 2194
**错误码:**

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

2197
| 错误码ID | 错误信息                             |
H
Hollokin 已提交
2198 2199
| -------- | -------------------------------------- |
| 12800001 | Package manager error.                 |
H
Hollokin 已提交
2200
| 12800008 | Input method manager service error. |
H
Hollokin 已提交
2201

2202 2203
**示例:**

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

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

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

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

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

H
Hollokin 已提交
2233 2234 2235 2236
**参数:**

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

2239 2240 2241 2242
**返回值:**

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

H
Hollokin 已提交
2245 2246
**错误码:**

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

2249
| 错误码ID | 错误信息                             |
H
Hollokin 已提交
2250 2251
| -------- | -------------------------------------- |
| 12800001 | Package manager error.                 |
H
Hollokin 已提交
2252
| 12800008 | Input method manager service error. |
H
Hollokin 已提交
2253

2254 2255
**示例:**

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

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

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

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

H
update  
Hollokin 已提交
2281
**系统能力:** SystemCapability.MiscServices.InputMethodFramework
2282 2283 2284 2285 2286

**参数:**

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

H
Hollokin 已提交
2289 2290
**错误码:**

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

2293
| 错误码ID | 错误信息                             |
H
Hollokin 已提交
2294 2295
| -------- | -------------------------------------- |
| 12800001 | Package manager error.                 |
H
Hollokin 已提交
2296
| 12800008 | Input method manager service error. |
H
Hollokin 已提交
2297

2298 2299
**示例:**

H
Hollokin 已提交
2300
```js
H
Hollokin 已提交
2301
try {
H
Hollokin 已提交
2302
    inputMethodSetting.listCurrentInputMethodSubtype((err, data) => {
H
Hollokin 已提交
2303 2304
        if (err !== undefined) {
            console.error('Failed to listCurrentInputMethodSubtype: ' + JSON.stringify(err));
H
Hollokin 已提交
2305 2306
            return;
        }
H
Hollokin 已提交
2307
        console.log('Succeeded in listing currentInputMethodSubtype.');
H
Hollokin 已提交
2308 2309
    });
} catch(err) {
H
Hollokin 已提交
2310
    console.error('Failed to listCurrentInputMethodSubtype: ' + JSON.stringify(err));
H
Hollokin 已提交
2311
}
2312 2313 2314 2315 2316 2317
```

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

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

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

H
update  
Hollokin 已提交
2320
**系统能力:** SystemCapability.MiscServices.InputMethodFramework
2321 2322 2323 2324 2325

**返回值:**

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

H
Hollokin 已提交
2328 2329
**错误码:**

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

2332
| 错误码ID | 错误信息                             |
H
Hollokin 已提交
2333 2334
| -------- | -------------------------------------- |
| 12800001 | Package manager error.                 |
H
Hollokin 已提交
2335
| 12800008 | Input method manager service error. |
H
Hollokin 已提交
2336

2337 2338
**示例:**

H
Hollokin 已提交
2339
```js
H
Hollokin 已提交
2340
try {
H
Hollokin 已提交
2341
    inputMethodSetting.listCurrentInputMethodSubtype().then((data) => {
H
Hollokin 已提交
2342
        console.info('Succeeded in listing currentInputMethodSubtype.');
H
Hollokin 已提交
2343
    }).catch((err) => {
H
Hollokin 已提交
2344
        console.error('Failed to listCurrentInputMethodSubtype: ' + JSON.stringify(err));
H
Hollokin 已提交
2345 2346
    })
} catch(err) {
H
Hollokin 已提交
2347
    console.error('Failed to listCurrentInputMethodSubtype: ' + JSON.stringify(err));
H
Hollokin 已提交
2348
}
2349 2350 2351 2352 2353
```

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

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

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

H
update  
Hollokin 已提交
2357
**系统能力:** SystemCapability.MiscServices.InputMethodFramework
Z
zhaolinglan 已提交
2358 2359 2360 2361 2362 2363

**参数:**

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

H
Hollokin 已提交
2366 2367
**错误码:**

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

2370
| 错误码ID | 错误信息                             |
H
Hollokin 已提交
2371 2372
| -------- | -------------------------------------- |
| 12800001 | Package manager error.                 |
H
Hollokin 已提交
2373
| 12800008 | Input method manager service error. |
H
Hollokin 已提交
2374

Z
zhaolinglan 已提交
2375 2376
**示例:**

H
Hollokin 已提交
2377
```js
H
Hollokin 已提交
2378
try {
H
Hollokin 已提交
2379
    inputMethodSetting.getInputMethods(true, (err,data) => {
H
Hollokin 已提交
2380 2381
        if (err !== undefined) {
            console.error('Failed to getInputMethods: ' + JSON.stringify(err));
H
Hollokin 已提交
2382 2383
            return;
        }
H
Hollokin 已提交
2384
        console.log('Succeeded in getting inputMethods.');
H
Hollokin 已提交
2385 2386
    });
} catch (err) {
H
Hollokin 已提交
2387
    console.error('Failed to getInputMethods: ' + JSON.stringify(err));
H
Hollokin 已提交
2388
}
Z
zhaolinglan 已提交
2389 2390
```

2391
### getInputMethods<sup>9+</sup>
Z
zhaolinglan 已提交
2392

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

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

H
update  
Hollokin 已提交
2397
**系统能力:** SystemCapability.MiscServices.InputMethodFramework
Z
zhaolinglan 已提交
2398 2399 2400 2401 2402 2403 2404

**参数:**

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

H
Hollokin 已提交
2405 2406
**错误码:**

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

2409
| 错误码ID | 错误信息                             |
H
Hollokin 已提交
2410 2411
| -------- | -------------------------------------- |
| 12800001 | Package manager error.                 |
H
Hollokin 已提交
2412
| 12800008 | Input method manager service error. |
H
Hollokin 已提交
2413

Z
zhaolinglan 已提交
2414 2415 2416 2417
**返回值:**

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

**示例:**

H
Hollokin 已提交
2422
```js
H
Hollokin 已提交
2423
try {
H
Hollokin 已提交
2424
    inputMethodSetting.getInputMethods(true).then((data) => {
H
Hollokin 已提交
2425
        console.info('Succeeded in getting inputMethods.');
H
Hollokin 已提交
2426
    }).catch((err) => {
H
Hollokin 已提交
2427
        console.error('Failed to getInputMethods: ' + JSON.stringify(err));
H
Hollokin 已提交
2428 2429
    })
} catch(err) {
H
Hollokin 已提交
2430
    console.error('Failed to getInputMethods: ' + JSON.stringify(err));
H
Hollokin 已提交
2431
}
Z
zhaolinglan 已提交
2432 2433
```

H
Hollokin 已提交
2434 2435
### showOptionalInputMethods<sup>9+</sup>

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

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

H
update  
Hollokin 已提交
2440
**系统能力:** SystemCapability.MiscServices.InputMethodFramework
H
Hollokin 已提交
2441 2442 2443 2444 2445

**参数:**

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

H
Hollokin 已提交
2448 2449
**错误码:**

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

2452
| 错误码ID | 错误信息                             |
H
Hollokin 已提交
2453
| -------- | -------------------------------------- |
H
Hollokin 已提交
2454
| 12800008 | Input method manager service error. |
H
Hollokin 已提交
2455

H
Hollokin 已提交
2456 2457
**示例:**

H
Hollokin 已提交
2458
```js
H
Hollokin 已提交
2459
try {
H
Hollokin 已提交
2460
    inputMethodSetting.showOptionalInputMethods((err, data) => {
H
Hollokin 已提交
2461 2462
        if (err !== undefined) {
            console.error('Failed to showOptionalInputMethods: ' + JSON.stringify(err));
H
Hollokin 已提交
2463 2464
            return;
        }
H
Hollokin 已提交
2465
        console.info('Succeeded in showing optionalInputMethods.');
H
Hollokin 已提交
2466 2467
    });
} catch (err) {
H
Hollokin 已提交
2468
    console.error('Failed to showOptionalInputMethods: ' + JSON.stringify(err));
H
Hollokin 已提交
2469 2470 2471 2472 2473
}
```

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

H
Hollokin 已提交
2474
showOptionalInputMethods(): Promise&lt;boolean&gt;
H
Hollokin 已提交
2475

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

H
update  
Hollokin 已提交
2478
**系统能力:** SystemCapability.MiscServices.InputMethodFramework
H
Hollokin 已提交
2479 2480 2481 2482 2483

**返回值:**

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

H
Hollokin 已提交
2486 2487
**错误码:**

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

2490
| 错误码ID | 错误信息                             |
H
Hollokin 已提交
2491
| -------- | -------------------------------------- |
H
Hollokin 已提交
2492
| 12800008 | Input method manager service error. |
H
Hollokin 已提交
2493

H
Hollokin 已提交
2494 2495
**示例:**

H
Hollokin 已提交
2496
```js
H
Hollokin 已提交
2497
inputMethodSetting.showOptionalInputMethods().then((data) => {
H
Hollokin 已提交
2498
    console.info('Succeeded in showing optionalInputMethods.');
H
Hollokin 已提交
2499
}).catch((err) => {
H
Hollokin 已提交
2500
    console.error('Failed to showOptionalInputMethods: ' + JSON.stringify(err));
H
Hollokin 已提交
2501 2502 2503
})
```

H
Hollokin 已提交
2504
### listInputMethod<sup>(deprecated)</sup>
Z
zhouyongfei 已提交
2505 2506 2507

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

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

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

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

2516
**参数:**
B
bmeangel 已提交
2517

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

2522
**示例:**
T
explain  
tianyu 已提交
2523

2524
```js
H
Hollokin 已提交
2525
inputMethodSetting.listInputMethod((err,data) => {
H
Hollokin 已提交
2526 2527
    if (err !== undefined) {
        console.error('Failed to listInputMethod: ' + JSON.stringify(err));
2528
        return;
2529
    }
H
Hollokin 已提交
2530
    console.log('Succeeded in listing inputMethod.');
2531
 });
2532
```
Z
zhouyongfei 已提交
2533

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

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

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

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

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

2546
**返回值:**
B
bmeangel 已提交
2547

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

2552
**示例:**
2553 2554

```js
H
Hollokin 已提交
2555
inputMethodSetting.listInputMethod().then((data) => {
H
Hollokin 已提交
2556
    console.info('Succeeded in listing inputMethod.');
Z
zhaolinglan 已提交
2557
}).catch((err) => {
H
Hollokin 已提交
2558
    console.error('Failed to listInputMethod: ' + JSON.stringify(err));
Z
zhaolinglan 已提交
2559
})
2560
```
Z
zhouyongfei 已提交
2561

H
Hollokin 已提交
2562
### displayOptionalInputMethod<sup>(deprecated)</sup>
Z
zhouyongfei 已提交
2563 2564 2565

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

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

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

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

2574
**参数:**
Z
zhouyongfei 已提交
2575 2576 2577

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

2580
**示例:**
2581 2582

```js
H
Hollokin 已提交
2583
inputMethodSetting.displayOptionalInputMethod((err) => {
H
Hollokin 已提交
2584 2585
    if (err !== undefined) {
        console.error('Failed to displayOptionalInputMethod: ' + JSON.stringify(err));
2586 2587
        return;
    }
H
Hollokin 已提交
2588
    console.info('Succeeded in displaying optionalInputMethod.');
2589
});
2590
```
Z
zhouyongfei 已提交
2591

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

2594 2595
displayOptionalInputMethod(): Promise&lt;void&gt;

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

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

H
update  
Hollokin 已提交
2602
**系统能力:** SystemCapability.MiscServices.InputMethodFramework
2603 2604 2605 2606 2607

**返回值:**

| 类型 | 说明 |
| -------- | -------- |
H
Hollokin 已提交
2608
| Promise&lt;void&gt; | 无返回结果的Promise对象。 |
2609 2610 2611 2612

**示例:**

```js
H
Hollokin 已提交
2613
inputMethodSetting.displayOptionalInputMethod().then(() => {
H
Hollokin 已提交
2614
    console.info('Succeeded in displaying optionalInputMethod.');
2615
}).catch((err) => {
H
Hollokin 已提交
2616
    console.error('Failed to displayOptionalInputMethod: ' + JSON.stringify(err));
2617 2618
})
```