js-apis-inputmethod.md 85.9 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 37 38 39 40
| name<sup>9+</sup>  | string | 是 | 否 | 必填。输入法内部名称。|
| id<sup>9+</sup>    | string | 是 | 否 | 必填。输入法唯一标识。|
| label<sup>9+</sup>    | string | 是 | 否 | 非必填。输入法对外显示名称。|
| labelId<sup>10+</sup>    | string | 是 | 否 | 非必填。输入法对外显示名称资源号。|
| icon<sup>9+</sup>    | string | 是 | 否 | 非必填。输入法图标数据。|
| iconId<sup>9+</sup>    | number | 是 | 否 | 非必填。输入法图标资源号。 |
| extra<sup>10+</sup>    | object | 是 | 是 | 非必填。输入法扩展信息。|
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
let currentIme = inputMethod.getCurrentInputMethod();
H
Hollokin 已提交
130
try{
H
Hollokin 已提交
131
  inputMethod.switchInputMethod(currentIme, (err, result) => {
132
    if (err) {
H
Hollokin 已提交
133
      console.error(`Failed to switchInputMethod: ${JSON.stringify(err)}`);
134 135 136
      return;
    }
    if (result) {
H
Hollokin 已提交
137
      console.log('Succeeded in switching inputmethod.');
138 139 140 141
    } else {
      console.error('Failed to switchInputMethod.');
    }
  });
H
Hollokin 已提交
142
} catch(err) {
H
Hollokin 已提交
143
  console.error(`Failed to switchInputMethod: ${JSON.stringify(err)}`);
H
Hollokin 已提交
144
}
G
gaoxiang 已提交
145
```
G
gaoxiang 已提交
146
## inputMethod.switchInputMethod<sup>9+</sup>
Z
zhaolinglan 已提交
147
switchInputMethod(target: InputMethodProperty): Promise&lt;boolean&gt;
G
gaoxiang 已提交
148

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

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

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

G
gaoxiang 已提交
155
**参数:**
G
gaoxiang 已提交
156 157 158

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

G
gaoxiang 已提交
161
**返回值:**
B
bmeangel 已提交
162

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

H
Hollokin 已提交
167 168
**错误码:**

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

171
| 错误码ID | 错误信息                             |
H
Hollokin 已提交
172 173
| -------- | -------------------------------------- |
| 12800005 | Configuration persisting error.        |
H
Hollokin 已提交
174
| 12800008 | Input method manager service error. |
H
Hollokin 已提交
175

G
gaoxiang 已提交
176 177
**示例:**

H
Hollokin 已提交
178
```js
H
Hollokin 已提交
179
let currentIme = inputMethod.getCurrentInputMethod();
H
Hollokin 已提交
180
try {
H
Hollokin 已提交
181
  inputMethod.switchInputMethod(currentIme).then((result) => {
182
    if (result) {
H
Hollokin 已提交
183
      console.log('Succeeded in switching inputmethod.');
184 185 186 187
    } else {
      console.error('Failed to switchInputMethod.');
    }
  }).catch((err) => {
H
Hollokin 已提交
188
    console.error(`Failed to switchInputMethod: ${JSON.stringify(err)}`);
189 190
  })
} catch(err) {
H
Hollokin 已提交
191
  console.error(`Failed to switchInputMethod: ${JSON.stringify(err)}`);
H
Hollokin 已提交
192
}
G
gaoxiang 已提交
193
```
194

Z
zhaolinglan 已提交
195 196 197 198
## inputMethod.getCurrentInputMethod<sup>9+</sup>

getCurrentInputMethod(): InputMethodProperty

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

H
update  
Hollokin 已提交
201
**系统能力:** SystemCapability.MiscServices.InputMethodFramework
Z
zhaolinglan 已提交
202 203 204

**返回值:**

Z
zhaolinglan 已提交
205 206
| 类型                                         | 说明                     |
| -------------------------------------------- | ------------------------ |
207
| [InputMethodProperty](#inputmethodproperty8) | 返回当前输入法属性对象。 |
Z
zhaolinglan 已提交
208 209 210

**示例:**

H
Hollokin 已提交
211
```js
H
Hollokin 已提交
212
let currentIme = inputMethod.getCurrentInputMethod();
Z
zhaolinglan 已提交
213 214
```

215
## inputMethod.switchCurrentInputMethodSubtype<sup>10+</sup>
216

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

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

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

H
update  
Hollokin 已提交
223
**系统能力:** SystemCapability.MiscServices.InputMethodFramework
224 225 226 227 228

**参数:**

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

H
Hollokin 已提交
232 233
**错误码:**

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

236
| 错误码ID | 错误信息                             |
H
Hollokin 已提交
237 238
| -------- | -------------------------------------- |
| 12800005 | Configuration persisting error.        |
H
Hollokin 已提交
239
| 12800008 | Input method manager service error. |
H
Hollokin 已提交
240

241 242
**示例:**

H
Hollokin 已提交
243
```js
H
Hollokin 已提交
244
try {
245 246 247 248 249 250 251 252 253 254 255 256
  inputMethod.switchCurrentInputMethodSubtype({
    id: "ServiceExtAbility",
    label: "",
    name: "com.example.kikakeyboard",
    mode: "upper",
    locale: "",
    language: "",
    icon: "",
    iconId: 0,
    extra: {}
  }, (err, result) => {
    if (err) {
H
Hollokin 已提交
257
      console.error(`Failed to switchCurrentInputMethodSubtype: ${JSON.stringify(err)}`);
258 259 260
      return;
    }
    if (result) {
H
Hollokin 已提交
261
      console.log('Succeeded in switching currentInputMethodSubtype.');
262 263 264 265
    } else {
      console.error('Failed to switchCurrentInputMethodSubtype');
    }
  });
H
Hollokin 已提交
266
} catch(err) {
H
Hollokin 已提交
267
  console.error(`Failed to switchCurrentInputMethodSubtype: ${JSON.stringify(err)}`);
H
Hollokin 已提交
268
}
269 270
```

271
## inputMethod.switchCurrentInputMethodSubtype<sup>10+</sup>
272 273 274

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

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

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

H
update  
Hollokin 已提交
279
**系统能力:** SystemCapability.MiscServices.InputMethodFramework
280 281 282 283 284

**参数:**

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

H
Hollokin 已提交
287 288 289 290 291 292
**返回值:**

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

H
Hollokin 已提交
293 294
**错误码:**

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

297
| 错误码ID | 错误信息                             |
H
Hollokin 已提交
298 299
| -------- | -------------------------------------- |
| 12800005 | Configuration persisting error.        |
H
Hollokin 已提交
300
| 12800008 | Input method manager service error. |
H
Hollokin 已提交
301

302 303
**示例:**

H
Hollokin 已提交
304
```js
H
Hollokin 已提交
305
try {
306 307 308 309 310 311 312 313 314 315 316 317
  inputMethod.switchCurrentInputMethodSubtype({
    id: "ServiceExtAbility",
    label: "",
    name: "com.example.kikakeyboard",
    mode: "upper",
    locale: "",
    language: "",
    icon: "",
    iconId: 0,
    extra: {}
  }).then((result) => {
    if (result) {
H
Hollokin 已提交
318
      console.log('Succeeded in switching currentInputMethodSubtype.');
319 320 321 322
    } else {
      console.error('Failed to switchCurrentInputMethodSubtype.');
    }
  }).catch((err) => {
H
Hollokin 已提交
323
    console.error(`Failed to switchCurrentInputMethodSubtype: ${JSON.stringify(err)}`);
324 325
  })
} catch(err) {
H
Hollokin 已提交
326
  console.error(`Failed to switchCurrentInputMethodSubtype: ${JSON.stringify(err)}`);
H
Hollokin 已提交
327
}
328 329 330 331 332 333 334 335
```

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

getCurrentInputMethodSubtype(): InputMethodSubtype

获取当前输入法子类型。

H
update  
Hollokin 已提交
336
**系统能力:** SystemCapability.MiscServices.InputMethodFramework
337 338 339 340 341

**返回值:**

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

**示例:**

H
Hollokin 已提交
346
```js
H
Hollokin 已提交
347
let currentImeSubType = inputMethod.getCurrentInputMethodSubtype();
348 349 350 351
```

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

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

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

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

H
update  
Hollokin 已提交
358
**系统能力:** SystemCapability.MiscServices.InputMethodFramework
359 360 361 362 363

**参数:**

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

H
Hollokin 已提交
368 369
**错误码:**

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

372
| 错误码ID | 错误信息                             |
H
Hollokin 已提交
373 374
| -------- | -------------------------------------- |
| 12800005 | Configuration persisting error.        |
H
Hollokin 已提交
375
| 12800008 | Input method manager service error. |
H
Hollokin 已提交
376

377 378
**示例:**

H
Hollokin 已提交
379
```js
H
Hollokin 已提交
380
let currentIme = inputMethod.getCurrentInputMethod();
381
let imSubType = inputMethod.getCurrentInputMethodSubtype();
H
Hollokin 已提交
382
try {
H
Hollokin 已提交
383
  inputMethod.switchCurrentInputMethodAndSubtype(currentIme, imSubType, (err,result) => {
384
    if (err) {
H
Hollokin 已提交
385
      console.error(`Failed to switchCurrentInputMethodAndSubtype: ${JSON.stringify(err)}`);
386 387 388
      return;
    }
    if (result) {
H
Hollokin 已提交
389
      console.log('Succeeded in switching currentInputMethodAndSubtype.');
390 391 392 393
    } else {
      console.error('Failed to switchCurrentInputMethodAndSubtype.');
    }
  });
H
Hollokin 已提交
394
} catch (err) {
H
Hollokin 已提交
395
  console.error(`Failed to switchCurrentInputMethodAndSubtype: ${JSON.stringify(err)}`);
H
Hollokin 已提交
396
}
397 398 399 400
```

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

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

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

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

H
update  
Hollokin 已提交
407
**系统能力:** SystemCapability.MiscServices.InputMethodFramework
408 409 410 411 412

**参数:**

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

H
Hollokin 已提交
416 417 418 419 420 421
**返回值:**

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

H
Hollokin 已提交
422 423
**错误码:**

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

426
| 错误码ID | 错误信息                             |
H
Hollokin 已提交
427 428
| -------- | -------------------------------------- |
| 12800005 | Configuration persisting error.        |
H
Hollokin 已提交
429
| 12800008 | Input method manager service error. |
H
Hollokin 已提交
430

431 432
**示例:**

H
Hollokin 已提交
433
```js
H
Hollokin 已提交
434
let currentIme = inputMethod.getCurrentInputMethod();
435
let imSubType = inputMethod.getCurrentInputMethodSubtype();
H
Hollokin 已提交
436
try {
H
Hollokin 已提交
437
  inputMethod.switchCurrentInputMethodAndSubtype(currentIme, imSubType).then((result) => {
438
    if (result) {
H
Hollokin 已提交
439
      console.log('Succeeded in switching currentInputMethodAndSubtype.');
440 441 442 443
    } else {
      console.error('Failed to switchCurrentInputMethodAndSubtype.');
    }
  }).catch((err) => {
H
Hollokin 已提交
444
    console.error(`Failed to switchCurrentInputMethodAndSubtype: ${JSON.stringify(err)}`);
445 446
  })
} catch(err) {
H
Hollokin 已提交
447
  console.error(`Failed to switchCurrentInputMethodAndSubtype: ${JSON.stringify(err)}`);
H
Hollokin 已提交
448
}
449 450
```

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

H
Hollokin 已提交
453
getInputMethodController(): InputMethodController
Z
zhouyongfei 已提交
454

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

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

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

H
Hollokin 已提交
463
**返回值:**
Z
zhouyongfei 已提交
464

H
Hollokin 已提交
465 466 467
| 类型                                            | 说明                     |
| ----------------------------------------------- | ------------------------ |
| [InputMethodController](#inputmethodcontroller) | 回调返回当前客户端实例。 |
Z
zhouyongfei 已提交
468

469
**示例:**
Z
zhouyongfei 已提交
470

471
```js
472
let inputMethodController = inputMethod.getInputMethodController();
Z
zhouyongfei 已提交
473 474
```

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

H
Hollokin 已提交
477
getInputMethodSetting(): InputMethodSetting
Z
zhouyongfei 已提交
478

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

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

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

487
**返回值:**
Z
zhouyongfei 已提交
488

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

493
**示例:**
Z
zhouyongfei 已提交
494

495
```js
H
Hollokin 已提交
496
let inputMethodSetting = inputMethod.getInputMethodSetting();
Z
zhouyongfei 已提交
497 498
```

499 500
## TextInputType<sup>10+</sup>

H
update  
Hollokin 已提交
501
文本输入类型。
502

H
Hollokin 已提交
503
**系统能力:** SystemCapability.MiscServices.InputMethodFramework
504 505 506 507 508

| 名称 | 值 |说明 |
| -------- | -------- |-------- |
| NONE  | -1 |NONE。 |
| TEXT  | 0 |文本类型。 |
509 510 511 512 513 514 515
| MULTILINE  | 1 |多行类型。 |
| NUMBER  | 2 |数字类型。 |
| PHONE  | 3 |电话号码类型。 |
| DATETIME  | 4 |日期类型。 |
| EMAIL_ADDRESS  | 5 |邮箱地址类型。 |
| URL  | 6 |链接类型。 |
| VISIBLE_PASSWORD  | 7 |密码类型。 |
516 517 518 519 520

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

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

H
Hollokin 已提交
521
**系统能力:** SystemCapability.MiscServices.InputMethodFramework
522 523 524 525

| 名称 | 值 |说明 |
| -------- | -------- |-------- |
| UNSPECIFIED  | 0 |未指定。 |
526 527 528 529 530 531 532
| NONE  | 1 |NONE。 |
| GO  | 2 |前往。 |
| SEARCH  | 3 |查找。 |
| SEND  | 4 |发送。 |
| NEXT  | 5 |下一步。 |
| DONE  | 6 |完成。 |
| PREVIOUS  | 7 |上一步。 |
533 534 535 536 537

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

输入法软键盘状态。

H
Hollokin 已提交
538
**系统能力:** SystemCapability.MiscServices.InputMethodFramework
539 540 541 542 543 544 545 546 547 548 549

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

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

光标移动方向。

H
Hollokin 已提交
550
**系统能力:** SystemCapability.MiscServices.InputMethodFramework
551 552 553 554

| 名称 | 值 |说明 |
| -------- | -------- |-------- |
| CURSOR_UP  | 1 |向上。 |
555 556 557
| CURSOR_DOWN  | 2 |向下。 |
| CURSOR_LEFT  | 3 |向左。 |
| CURSOR_RIGHT  | 4 |向右。 |
558 559 560 561 562

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

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

H
Hollokin 已提交
563
**系统能力:** SystemCapability.MiscServices.InputMethodFramework
564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590

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

## 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 已提交
591
| enterKeyType<sup>10+</sup>  | [EnterKeyType](#enterkeytype10) | 是 | 是 | Enter键功能类型。|
592 593 594

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

H
update  
Hollokin 已提交
595
编辑控件配置信息。编辑控件请求绑定输入法应用时传入,将编辑控件相关属性配置信息保存到输入法框架内。
596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636

**系统能力:** 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 已提交
637 638
## InputMethodController

639 640 641 642 643 644
下列API示例中都需使用[getController](#inputmethodgetcontroller9)获取到InputMethodController实例,再通过此实例调用对应方法。

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

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

645
用于自绘控件绑定输入法应用。使用callback异步回调。
H
换行  
Hollokin 已提交
646

H
update  
Hollokin 已提交
647
必须先调用此接口完成自绘控件与输入法应用的绑定,才可以使用输入法框架的以下功能:显示、隐藏键盘;更新光标信息;更改编辑框选中范围;保存配置信息;监听处理由输入法应用发送的信息或命令等。
648 649 650 651 652 653 654 655

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

**参数:**

| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| showKeyboard | boolean | 是 | 绑定输入法成功后是否拉起输入法键盘。 |
656
| textConfig | [TextConfig](#textconfig10) | 是 | 编辑控件配置信息。 |
657 658 659 660 661 662 663 664 665 666 667 668 669 670 671
| 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 {
672 673 674 675 676 677 678 679 680 681 682
  let textConfig: inputMethod.TextConfig = {
    inputAttribute: {
      textInputType: 0,
      enterKeyType: 1
    }
  };
  inputMethodController.attach(true, textConfig, (err) => {
    if (err) {
      console.error(`Failed to attach: ${JSON.stringify(err)}`);
      return;
    }
H
Hollokin 已提交
683
    console.log('Succeeded in attaching the inputMethod.');
684
  });
H
Hollokin 已提交
685 686
} catch(err) {
  console.error(`Failed to attach: ${JSON.stringify(err)}`);
687 688 689 690 691 692 693
}
```

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

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

H
update  
Hollokin 已提交
694
用于自绘控件绑定输入法应用。使用callback异步回调。
H
换行  
Hollokin 已提交
695

H
update  
Hollokin 已提交
696
必须先调用此接口完成自绘控件与输入法应用的绑定,才可以使用输入法框架的以下功能:显示、隐藏键盘;更新光标信息;更改编辑框选中范围;保存配置信息;监听处理由输入法应用发送的信息或命令等。
697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725

**系统能力:** 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 {
726 727 728 729 730 731 732
  let textConfig: inputMethod.TextConfig = {
    inputAttribute: {
      textInputType: 0,
      enterKeyType: 1
    }
  };
  inputMethodController.attach(true, textConfig).then(() => {
H
Hollokin 已提交
733
    console.log('Succeeded in attaching inputMethod.');
734 735 736
  }).catch((err) => {
    console.error(`Failed to attach: ${JSON.stringify(err)}`);
  })
H
Hollokin 已提交
737 738
} catch(err) {
  console.error(`Failed to attach: ${JSON.stringify(err)}`);
739 740 741 742 743 744 745
}
```

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

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

H
update  
Hollokin 已提交
746
进入文本编辑状态。使用callback异步回调。
H
换行  
Hollokin 已提交
747

H
update  
Hollokin 已提交
748
编辑控件与输入法应用绑定成功后,可调用该接口去拉起软键盘。
749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771

**系统能力:** 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) => {
772 773 774 775
  if (err) {
    console.error(`Failed to showTextInput: ${JSON.stringify(err)}`);
    return;
  }
H
Hollokin 已提交
776
  console.log('Succeeded in showing the inputMethod.');
777 778 779 780 781 782 783
});
```

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

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

H
update  
Hollokin 已提交
784
进入文本编辑状态。使用promise异步回调。
H
换行  
Hollokin 已提交
785

H
update  
Hollokin 已提交
786
编辑控件与输入法应用绑定成功后,可调用该接口去拉起软键盘。
787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809

**系统能力:** 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(() => {
H
Hollokin 已提交
810
  console.log('Succeeded in showing text input.');
811
}).catch((err) => {
812
  console.error(`Failed to showTextInput: ${JSON.stringify(err)}`);
813 814 815 816 817 818 819
});
```

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

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

H
update  
Hollokin 已提交
820
退出文本编辑状态。使用callback异步回调。
H
换行  
Hollokin 已提交
821

H
update  
Hollokin 已提交
822
编辑控件可调用该接口退出编辑状态。若调用该接口时当前软键盘处于显示状态,则调用该接口后软键盘会被隐藏。
H
换行  
Hollokin 已提交
823

H
update  
Hollokin 已提交
824
调用该接口不解除与输入法应用的绑定,再次调用[showTextInput](#showtextinput10)时,可重新进入编辑状态。
825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847

**系统能力:** 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) => {
848 849 850 851
  if (err) {
    console.error(`Failed to hideTextInput: ${JSON.stringify(err)}`);
    return;
  }
H
Hollokin 已提交
852
  console.log('Succeeded in hiding text input.');
853 854 855 856 857 858 859
});
```

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

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

H
update  
Hollokin 已提交
860
退出文本编辑状态。使用promise异步回调。
H
换行  
Hollokin 已提交
861

H
update  
Hollokin 已提交
862
编辑控件可调用该接口退出编辑状态。若调用该接口时当前软键盘处于显示状态,则调用该接口后软键盘会被隐藏。
H
换行  
Hollokin 已提交
863

H
update  
Hollokin 已提交
864
调用该接口不解除与输入法应用的绑定,再次调用[showTextInput](#showtextinput10)时,可重新进入编辑状态。
865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886

**系统能力:** 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
H
Hollokin 已提交
887
inputMethodController.hideTextInput().then(() => {
H
Hollokin 已提交
888
  console.log('Succeeded in hiding inputMethod.');
H
Hollokin 已提交
889 890 891
}).catch((err) => {
  console.error(`Failed to hideTextInput: ${JSON.stringify(err)}`);
})
892 893 894 895 896 897
```

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

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

H
--amend  
Hollokin 已提交
898
解除与输入法应用的绑定。使用callback异步回调。
899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920

**系统能力:** 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) => {
921 922 923 924
  if (err) {
    console.error(`Failed to detach: ${JSON.stringify(err)}`);
    return;
  }
H
Hollokin 已提交
925
  console.log('Succeeded in detaching inputMethod.');
926 927 928 929 930 931 932
});
```

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

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

H
--amend  
Hollokin 已提交
933
解除与输入法应用的绑定。使用promise异步回调。
934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955

**系统能力:** 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(() => {
H
Hollokin 已提交
956
  console.log('Succeeded in detaching inputMethod.');
H
Hollokin 已提交
957 958
}).catch((err) => {
  console.error(`Failed to detach: ${JSON.stringify(err)}`);
959 960 961 962 963 964 965
});
```

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

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

H
Hollokin 已提交
966
设置要避让的窗口。使用callback异步回调。
H
换行  
Hollokin 已提交
967

H
Hollokin 已提交
968
比如:将当前绑定到输入法的应用程序的窗口ID通知系统,正确设置后,客户端所在的窗口可以避开输入法窗口。
969 970 971 972 973 974 975

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

**参数:**

| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
H
Hollokin 已提交
976
| windowId | number | 是 | 要避让的窗口id。 |
977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992
| 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 {
993 994 995 996 997 998
  let windowId: number = 2000;
  inputMethodController.setCallingWindow(windowId, (err) => {
    if (err) {
      console.error(`Failed to setCallingWindow: ${JSON.stringify(err)}`);
      return;
    }
H
Hollokin 已提交
999
    console.log('Succeeded in setting callingWindow.');
1000
  });
H
Hollokin 已提交
1001 1002
} catch(err) {
  console.error(`Failed to setCallingWindow: ${JSON.stringify(err)}`);
1003 1004 1005 1006 1007 1008 1009
}
```

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

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

H
Hollokin 已提交
1010
设置要避让的窗口。使用promise异步回调。
H
换行  
Hollokin 已提交
1011

H
Hollokin 已提交
1012
比如:将当前绑定到输入法的应用程序的窗口ID通知系统,正确设置后,客户端所在的窗口可以避开输入法窗口。
1013 1014 1015 1016 1017 1018 1019

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

**参数:**

| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
H
Hollokin 已提交
1020
| windowId | number | 是 | 要避让的窗口id。 |
1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041

**返回值:**

| 类型 | 说明 |
| -------- | -------- |
| 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 {
1042 1043
  let windowId: number = 2000;
  inputMethodController.setCallingWindow(windowId).then(() => {
H
Hollokin 已提交
1044
    console.log('Succeeded in setting callingWindow.');
1045 1046 1047
  }).catch((err) => {
    console.error(`Failed to setCallingWindow: ${JSON.stringify(err)}`);
  })
H
Hollokin 已提交
1048 1049
} catch(err) {
  console.error(`Failed to setCallingWindow: ${JSON.stringify(err)}`);
1050 1051 1052 1053 1054 1055 1056
}
```

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

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

H
Hollokin 已提交
1057
更新当前编辑框内光标信息。使用callback异步回调。
H
换行  
Hollokin 已提交
1058

H
Hollokin 已提交
1059
当光标信息发生变化时,可调用该接口更新光标信息,从而被输入法应用感知到光标变化。
1060 1061 1062 1063 1064 1065 1066 1067

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

**参数:**

| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| cursorInfo | [CursorInfo](#cursorinfo10) | 是 | 光标信息。 |
H
update  
Hollokin 已提交
1068
| callback | AsyncCallback&lt;void&gt; | 是 | 回调函数。当光标信息更新成功时,err为undefined;否则为错误对象。 |
1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083

**错误码:**

以下错误码的详细介绍请参见[输入法框架错误码](../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 {
1084 1085 1086 1087 1088
  inputMethodController.updateCursor({left: 0, top: 0, width: 600, height: 800}, (err) => {
    if (err) {
      console.error(`Failed to updateCursor: ${JSON.stringify(err)}`);
      return;
    }
H
Hollokin 已提交
1089
    console.log('Succeeded in updating cursorInfo.');
1090
  });
H
Hollokin 已提交
1091 1092
} catch(err) {
  console.error(`Failed to updateCursor: ${JSON.stringify(err)}`);
1093 1094 1095 1096 1097 1098 1099
}
```

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

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

H
Hollokin 已提交
1100
更新当前编辑控件内的光标信息。使用promise异步回调。
H
换行  
Hollokin 已提交
1101

H
Hollokin 已提交
1102
当光标信息发生变化时,编辑控件可调用该接口更新光标信息,从而被输入法应用感知到光标变化。
1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131

**系统能力:** 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 {
1132
  inputMethodController.updateCursor({left: 0, top: 0, width: 600, height: 800}).then(() => {
H
Hollokin 已提交
1133
    console.log('Succeeded in updating cursorInfo.');
1134 1135 1136
  }).catch((err) => {
    console.error(`Failed to updateCursor: ${JSON.stringify(err)}`);
  })
H
Hollokin 已提交
1137 1138
} catch(err) {
  console.error(`Failed to updateCursor: ${JSON.stringify(err)}`);
1139 1140 1141 1142 1143 1144 1145
}
```

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

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

H
update  
Hollokin 已提交
1146
向输入法应用更新当前编辑框内被选中的文本信息,当选中的文本内容或文本范围发生变化时,可调用该接口更新文本信息。使用callback异步回调。
1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172

**系统能力:** 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 {
1173 1174 1175 1176 1177
  inputMethodController.changeSelection('text', 0, 5, (err) => {
    if (err) {
      console.error(`Failed to changeSelection: ${JSON.stringify(err)}`);
      return;
    }
H
Hollokin 已提交
1178
    console.log('Succeeded in changing selection.');
1179
  });
H
Hollokin 已提交
1180 1181
} catch(err) {
  console.error(`Failed to changeSelection: ${JSON.stringify(err)}`);
1182 1183 1184 1185 1186 1187 1188
}
```

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

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

H
update  
Hollokin 已提交
1189
向输入法应用更新当前编辑框内被选中的文本信息,当选中的文本内容或文本范围发生变化时,可调用该接口更新文本信息。使用promise异步回调。
1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220

**系统能力:** 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 {
1221
  inputMethodController.changeSelection('test', 0, 5).then(() => {
H
Hollokin 已提交
1222
    console.log('Succeeded in changing selection.');
1223 1224 1225
  }).catch((err) => {
    console.error(`Failed to changeSelection: ${JSON.stringify(err)}`);
  })
H
Hollokin 已提交
1226 1227
} catch(err) {
  console.error(`Failed to changeSelection: ${JSON.stringify(err)}`);
1228 1229 1230 1231 1232 1233 1234
}
```

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

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

H
update  
Hollokin 已提交
1235
更新编辑框属性配置信息。使用callback异步回调。
1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259

**系统能力:** 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 {
1260 1261 1262 1263 1264
  inputMethodController.updateAttribute({textInputType: 0, enterKeyType: 1}, (err) => {
    if (err) {
      console.error(`Failed to updateAttribute: ${JSON.stringify(err)}`);
      return;
    }
H
Hollokin 已提交
1265
    console.log('Succeeded in updating attribute.');
1266
  });
H
Hollokin 已提交
1267 1268
} catch(err) {
  console.error(`Failed to updateAttribute: ${JSON.stringify(err)}`);
1269 1270 1271 1272 1273 1274 1275
}
```

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

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

H
update  
Hollokin 已提交
1276
更新编辑框属性配置信息。使用promise异步回调。
1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305

**系统能力:** 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 {
1306
  inputMethodController.updateAttribute({textInputType: 0, enterKeyType: 1}).then(() => {
H
Hollokin 已提交
1307
    console.log('Succeeded in updating attribute.');
1308 1309 1310
  }).catch((err) => {
    console.error(`Failed to updateAttribute: ${JSON.stringify(err)}`);
  })
H
Hollokin 已提交
1311 1312
} catch(err) {
  console.error(`Failed to updateAttribute: ${JSON.stringify(err)}`);
1313 1314 1315 1316 1317 1318 1319
}
```

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

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

H
Hollokin 已提交
1320
结束输入会话。使用callback异步回调。
H
换行  
Hollokin 已提交
1321

H
Hollokin 已提交
1322
需要与编辑控件(如:输入框)绑定使用。当点击编辑控件后,才可通过调用该接口结束输入会话。
1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344

**系统能力:** 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 {
H
Hollokin 已提交
1345 1346 1347
  inputMethodController.stopInputSession((err, result) => {
    if (err) {
      console.error(`Failed to stopInputSession: ${JSON.stringify(err)}`);
1348 1349 1350
      return;
    }
    if (result) {
H
Hollokin 已提交
1351
      console.log('Succeeded in stopping inputSession.');
1352 1353 1354 1355
    } else {
      console.error('Failed to stopInputSession.');
    }
  });
H
Hollokin 已提交
1356 1357
} catch(err) {
  console.error(`Failed to stopInputSession: ${JSON.stringify(err)}`);
1358 1359 1360 1361 1362 1363 1364
}
```

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

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

H
Hollokin 已提交
1365
结束输入会话。使用promise异步回调。
H
换行  
Hollokin 已提交
1366

H
Hollokin 已提交
1367
需要与编辑控件(如:输入框)绑定使用。当点击编辑控件后,才可通过调用该接口结束输入会话。
1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389

**系统能力:** 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 {
1390 1391
  inputMethodController.stopInputSession().then((result) => {
    if (result) {
H
Hollokin 已提交
1392
      console.log('Succeeded in stopping inputSession.');
1393 1394 1395 1396
    } else {
      console.error('Failed to stopInputSession.');
    }
  }).catch((err) => {
H
Hollokin 已提交
1397
    console.error(`Failed to stopInputSession: ${JSON.stringify(err)}`);
1398 1399
  })
} catch(err) {
H
Hollokin 已提交
1400
  console.error(`Failed to stopInputSession: ${JSON.stringify(err)}`);
1401 1402 1403 1404 1405 1406 1407
}
```

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

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

H
Hollokin 已提交
1408
显示软键盘。使用callback异步回调。
H
换行  
Hollokin 已提交
1409

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

**需要权限:** 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) => {
1435
  if (!err) {
H
Hollokin 已提交
1436
    console.log('Succeeded in showing softKeyboard.');
1437
  } else {
H
Hollokin 已提交
1438
    console.error(`Failed to show softKeyboard: ${JSON.stringify(err)}`);
1439
  }
1440 1441 1442 1443 1444 1445 1446
})
```

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

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

H
Hollokin 已提交
1447
显示软键盘。使用Promise异步回调。
H
换行  
Hollokin 已提交
1448

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

**需要权限:** 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(() => {
1474
  console.log('Succeeded in showing softKeyboard.');
1475
}).catch((err) => {
H
Hollokin 已提交
1476
  console.error(`Failed to show softKeyboard: ${JSON.stringify(err)}`);
1477 1478 1479 1480 1481 1482 1483
});
```

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

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

H
Hollokin 已提交
1484
隐藏软键盘。使用callback异步回调。
H
换行  
Hollokin 已提交
1485

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

**需要权限:** 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) => {
1511
  if (!err) {
H
Hollokin 已提交
1512
    console.log('Succeeded in hiding softKeyboard.');
1513
  } else {
H
Hollokin 已提交
1514
    console.error(`Failed to hide softKeyboard: ${JSON.stringify(err)}`);
1515
  }
1516 1517 1518 1519 1520 1521 1522
})
```

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

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

H
Hollokin 已提交
1523
隐藏软键盘。使用Promise异步回调。
H
换行  
Hollokin 已提交
1524

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

**需要权限:** 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(() => {
1550
  console.log('Succeeded in hiding softKeyboard.');
1551
}).catch((err) => {
H
Hollokin 已提交
1552
  console.error(`Failed to hide softKeyboard: ${JSON.stringify(err)}`);
1553 1554 1555 1556 1557 1558 1559
});
```

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

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

H
Hollokin 已提交
1560
结束输入会话。使用callback异步回调。
H
换行  
Hollokin 已提交
1561

H
Hollokin 已提交
1562
需要与编辑控件(如:输入框)绑定使用。当点击编辑控件后,才可通过调用该接口结束输入会话。
1563 1564 1565

> **说明:** 
>
1566
> 从API version 6开始支持,从API version 9开始废弃,建议使用[stopInputSession()](#stopinputsession9)替代。
1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578

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

**参数:**

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

**示例:**

```js
H
Hollokin 已提交
1579 1580 1581
inputMethodController.stopInput((err, result) => {
  if (err) {
    console.error(`Failed to stopInput: ${JSON.stringify(err)}`);
1582 1583 1584
    return;
  }
  if (result) {
H
Hollokin 已提交
1585
    console.log('Succeeded in stopping input.');
1586 1587 1588
  } else {
    console.error('Failed to stopInput.');
  }
1589 1590 1591 1592 1593 1594 1595
});
```

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

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

H
Hollokin 已提交
1596
结束输入会话。使用promise异步回调。
H
换行  
Hollokin 已提交
1597

H
Hollokin 已提交
1598
需要与编辑控件(如:输入框)绑定使用。当点击编辑控件后,才可通过调用该接口结束输入会话。
1599 1600 1601

> **说明:** 
>
1602
> 从API version 6开始支持,从API version 9开始废弃,建议使用[stopInputSession()](#stopinputsession9)替代。
1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615

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

**返回值:**

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

**示例:**

```js
inputMethodController.stopInput().then((result) => {
1616
  if (result) {
H
Hollokin 已提交
1617
    console.log('Succeeded in stopping input.');
1618 1619 1620
  } else {
    console.error('Failed to stopInput.');
  }
1621
}).catch((err) => {
H
Hollokin 已提交
1622
  console.error(`Failed to stopInput: ${JSON.stringify(err)}`);
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
})
```

### 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 {
1653
  inputMethodController.on('insertText', (text) => {
H
Hollokin 已提交
1654
    console.log(`Succeeded in subscribing insertText: ${text}`);
1655
  });
H
Hollokin 已提交
1656 1657
} catch(err) {
  console.error(`Failed to subscribe insertText: ${JSON.stringify(err)}`);
1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677
}
```

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

off(type: 'insertText'): void

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

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

**参数:**

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

**示例:**

```js
H
Hollokin 已提交
1678
inputMethodController.off('insertText');
1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690
```

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

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

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

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

**参数:**

H
update  
Hollokin 已提交
1691 1692 1693
| 参数名   | 类型 | 必填 | 说明 |
| -------- | ----- | ---- | ----- |
| type     | string  | 是   | 设置监听类型。<br/>-type为‘deleteLeft’时表示订阅输入法应用向左删除事件监听。 <br/>-type为‘deleteRight’时表示订阅输入法应用向右删除事件监听。|
1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707
| callback | (length: number) => void | 是   | 回调函数,返回需要向左或向右删除的文本的长度。<br/>开发者需要在回调函数中根据传入的删除长度操作编辑框中相应文本。 |

**错误码:**

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

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

**示例:**

```js
try {
1708
  inputMethodController.on('deleteLeft', (length) => {
H
Hollokin 已提交
1709
    console.log(`Succeeded in subscribing deleteLeft, length: ${length}`);
1710
  });
H
Hollokin 已提交
1711 1712
} catch(err) {
  console.error(`Failed to subscribe deleteLeft: ${JSON.stringify(err)}`);
1713 1714 1715
}

try {
1716
  inputMethodController.on('deleteRight', (length) => {
H
Hollokin 已提交
1717
    console.log(`Succeeded in subscribing deleteRight, length: ${length}`);
1718
  });
H
Hollokin 已提交
1719 1720
} catch(err) {
  console.error(`Failed to subscribe deleteRight: ${JSON.stringify(err)}`);
1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738
}
```

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

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

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

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

**参数:**

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

**示例:**
1739

1740
```js
H
Hollokin 已提交
1741 1742
inputMethodController.off('deleteLeft');
inputMethodController.off('deleteRight');
1743 1744 1745 1746 1747 1748 1749
```

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

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

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

H
update  
Hollokin 已提交
1751
**系统能力:** SystemCapability.MiscServices.InputMethodFramework
1752 1753 1754

**参数:**

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

H
Hollokin 已提交
1760 1761
**错误码:**

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

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

1768 1769 1770
**示例:**

```js
H
Hollokin 已提交
1771
try {
1772
  inputMethodController.on('sendKeyboardStatus', (keyBoardStatus) => {
H
Hollokin 已提交
1773
    console.log(`Succeeded in subscribing sendKeyboardStatus, keyBoardStatus: ${keyBoardStatus}`);
1774
  });
H
Hollokin 已提交
1775 1776
} catch(err) {
  console.error(`Failed to subscribe sendKeyboardStatus: ${JSON.stringify(err)}`);
H
Hollokin 已提交
1777
}
1778 1779
```

1780
### off('sendKeyboardStatus')<sup>10+</sup>
1781

1782
off(type: 'sendKeyboardStatus'): void
1783

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

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

1788
**参数:**
1789

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

**示例:**

```js
H
Hollokin 已提交
1797
inputMethodController.off('sendKeyboardStatus');
1798 1799
```

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

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

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

1806
**系统能力:** SystemCapability.MiscServices.InputMethodFramework
Z
zhaolinglan 已提交
1807 1808 1809

**参数:**

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

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

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

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

Z
zhaolinglan 已提交
1823 1824 1825
**示例:**

```js
1826
try {
1827
  inputMethodController.on('sendFunctionKey', (functionKey) => {
H
Hollokin 已提交
1828
    console.log(`Succeeded in subscribing sendFunctionKey, functionKey.enterKeyType: ${functionKey.enterKeyType}`);
1829
  });
H
Hollokin 已提交
1830 1831
} catch(err) {
  console.error(`Failed to subscribe sendFunctionKey: ${JSON.stringify(err)}`);
1832
}
Z
zhaolinglan 已提交
1833 1834
```

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

1837
off(type: 'sendFunctionKey'): void
Z
zhaolinglan 已提交
1838

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

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

1843
**参数:**
Z
zhaolinglan 已提交
1844

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

**示例:**

```js
H
Hollokin 已提交
1852
inputMethodController.off('sendFunctionKey');
Z
zhaolinglan 已提交
1853 1854
```

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

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

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

1861
**系统能力:** SystemCapability.MiscServices.InputMethodFramework
Z
zhaolinglan 已提交
1862 1863 1864

**参数:**

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

H
Hollokin 已提交
1870 1871
**错误码:**

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

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

Z
zhaolinglan 已提交
1878 1879 1880
**示例:**

```js
1881
try {
1882
  inputMethodController.on('moveCursor', (direction) => {
H
Hollokin 已提交
1883
    console.log(`Succeeded in subscribing moveCursor, direction: ${direction}`);
1884
  });
H
Hollokin 已提交
1885 1886
} catch(err) {
  console.error(`Failed to subscribe moveCursor: ${JSON.stringify(err)}`);
1887
}
Z
zhaolinglan 已提交
1888 1889
```

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

1892
off(type: 'moveCursor'): void
Z
zhaolinglan 已提交
1893

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

1896
**系统能力:** SystemCapability.MiscServices.InputMethodFramework
Z
zhaolinglan 已提交
1897

1898
**参数:**
Z
zhaolinglan 已提交
1899

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

**示例:**

```js
H
Hollokin 已提交
1907
inputMethodController.off('moveCursor');
Z
zhaolinglan 已提交
1908 1909
```

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

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

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

H
update  
Hollokin 已提交
1916
**系统能力:** SystemCapability.MiscServices.InputMethodFramework
H
Hollokin 已提交
1917 1918 1919

**参数:**

H
update  
Hollokin 已提交
1920 1921 1922 1923
| 参数名   | 类型  | 必填 | 说明   |
| -------- | ------ | ---- | -------- |
| type     | string    | 是   | 设置监听类型。<br/>-type为‘handleExtendAction’时表示订阅输入法应用发送扩展操作代码事件监听。 |
| callback | callback: (action: [ExtendAction](#extendaction10)) => void | 是   | 回调函数,返回扩展操作类型。<br/>开发者需要在回调函数中根据传入的扩展操作类型做相应的操作。 |
1924 1925 1926 1927 1928 1929 1930 1931

**错误码:**

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

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

**示例:**

```js
1936
try {
1937
  inputMethodController.on('handleExtendAction', (action) => {
H
Hollokin 已提交
1938
    console.log(`Succeeded in subscribing handleExtendAction, action: ${action}`);
1939
  });
H
Hollokin 已提交
1940 1941
} catch(err) {
  console.error(`Failed to subscribe handleExtendAction: ${JSON.stringify(err)}`);
1942
}
H
Hollokin 已提交
1943 1944
```

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

1947
off(type: 'handleExtendAction'): void
H
Hollokin 已提交
1948

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

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

1953
**参数:**
H
Hollokin 已提交
1954

H
update  
Hollokin 已提交
1955 1956
| 参数名 | 类型   | 必填 | 说明  |
| ------ | ------ | ---- | ------- |
1957 1958
| type   | string | 是   | 设置监听类型。<br/>-type为‘handleExtendAction’时表示取消订阅输入法应用发送扩展代码事件监听。 |

H
Hollokin 已提交
1959 1960 1961
**示例:**

```js
H
Hollokin 已提交
1962
inputMethodController.off('handleExtendAction');
H
Hollokin 已提交
1963 1964
```

Z
add doc  
zhaolinglan 已提交
1965 1966 1967 1968 1969 1970 1971 1972 1973 1974
### on('selectByRange')<sup>10+</sup>

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

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

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

**参数:**

H
update  
Hollokin 已提交
1975 1976 1977
| 参数名   | 类型     | 必填 | 说明     |
| -------- | ---- | ---- | ------- |
| type     | string  | 是   | 设置监听类型。<br/>-type为‘selectByRange’时表示订阅输入法应用按范围选中文本事件监听。 |
1978
| callback | Callback&lt;[Range](#range10)&gt; | 是   | 回调函数,返回需要选中的文本的范围。<br/>开发者需要在回调函数中根据传入的范围选中编辑框中相应文本。 |
Z
add doc  
zhaolinglan 已提交
1979 1980 1981 1982 1983

**示例:**

```js
inputMethodController.on('selectByRange', (range) => {
H
Hollokin 已提交
1984
  console.log(`Succeeded in subscribing selectByRange: start: ${range.start} , end: ${range.end}`);
Z
add doc  
zhaolinglan 已提交
1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009
});
```

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

2010
on(type: 'selectByMovement', callback: Callback&lt;Movement&gt;): void
Z
add doc  
zhaolinglan 已提交
2011 2012 2013 2014 2015 2016 2017

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

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

**参数:**

H
update  
Hollokin 已提交
2018 2019 2020
| 参数名   | 类型   | 必填 | 说明     |
| -------- | ----- | ---- | ------ |
| type     | string  | 是   | 设置监听类型。<br/>-type为‘selectByMovement’时表示订阅输入法应用按光标移动动作选中文本事件监听。 |
2021
| callback | Callback&lt;[Movement](#movement10)&gt; | 是   | 回调函数,返回需要选中的文本的范围。<br/>开发者需要在回调函数中根据传入的光标动作选中编辑框中相应文本。 |
Z
add doc  
zhaolinglan 已提交
2022 2023 2024 2025 2026

**示例:**

```js
inputMethodController.on('selectByMovement', (movement) => {
H
Hollokin 已提交
2027
  console.log('Succeeded in subscribing selectByMovement: direction: ' + movement.direction);
Z
add doc  
zhaolinglan 已提交
2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050
});
```

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

off(type: 'selectByMovement'): void

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

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

**参数:**

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

**示例:**

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

2051
## InputMethodSetting<sup>8+</sup>
Z
zhouyongfei 已提交
2052

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

H
Hollokin 已提交
2055
### on('imeChange')<sup>9+</sup>
2056 2057 2058

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

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

H
update  
Hollokin 已提交
2061
**系统能力:** SystemCapability.MiscServices.InputMethodFramework
2062 2063 2064 2065 2066 2067

**参数:**

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

**示例:**

H
Hollokin 已提交
2072
```js
H
Hollokin 已提交
2073
inputMethodSetting.on('imeChange', (inputMethodProperty, inputMethodSubtype) => {
H
Hollokin 已提交
2074
  console.log('Succeeded in subscribing imeChange: inputMethodProperty: ' + JSON.stringify(inputMethodProperty) + " , inputMethodSubtype: " + JSON.stringify(inputMethodSubtype));
H
Hollokin 已提交
2075 2076
});
```
2077

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

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

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

H
update  
Hollokin 已提交
2084
**系统能力:** SystemCapability.MiscServices.InputMethodFramework
2085 2086 2087

**参数:**

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

**示例:**

H
Hollokin 已提交
2095
```js
H
Hollokin 已提交
2096
inputMethodSetting.off('imeChange');
H
Hollokin 已提交
2097
```
2098 2099 2100 2101 2102

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

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

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

H
update  
Hollokin 已提交
2105
**系统能力:** SystemCapability.MiscServices.InputMethodFramework
2106 2107 2108 2109 2110

**参数:**

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

H
Hollokin 已提交
2114 2115
**错误码:**

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

2118
| 错误码ID | 错误信息                             |
H
Hollokin 已提交
2119 2120
| -------- | -------------------------------------- |
| 12800001 | Package manager error.                 |
H
Hollokin 已提交
2121
| 12800008 | Input method manager service error. |
H
Hollokin 已提交
2122

2123 2124
**示例:**

H
Hollokin 已提交
2125
```js
H
update  
Hollokin 已提交
2126
let inputMethodProperty = {
2127
  name: 'com.example.kikakeyboard',
2128
  id: 'propertyId',
H
Hollokin 已提交
2129 2130
}
try {
2131
  inputMethodSetting.listInputMethodSubtype(inputMethodProperty, (err, data) => {
2132
    if (err) {
H
Hollokin 已提交
2133
      console.error(`Failed to listInputMethodSubtype: ${JSON.stringify(err)}`);
2134 2135 2136 2137
      return;
    }
    console.log('Succeeded in listing inputMethodSubtype.');
  });
H
Hollokin 已提交
2138
} catch (err) {
H
Hollokin 已提交
2139
  console.error(`Failed to listInputMethodSubtype: ${JSON.stringify(err)}`);
H
Hollokin 已提交
2140
}
2141 2142 2143 2144 2145 2146
```

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

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

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

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

H
Hollokin 已提交
2151 2152 2153 2154
**参数:**

| 参数名   | 类型                                               | 必填 | 说明                   |
| -------- | -------------------------------------------------- | ---- | ---------------------- |
H
Hollokin 已提交
2155
| inputMethodProperty | [InputMethodProperty](#inputmethodproperty8)| 是 | 子类型所属的输入法应用。 |
H
Hollokin 已提交
2156

2157 2158 2159 2160
**返回值:**

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

H
Hollokin 已提交
2163 2164
**错误码:**

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

2167
| 错误码ID | 错误信息                             |
H
Hollokin 已提交
2168 2169
| -------- | -------------------------------------- |
| 12800001 | Package manager error.                 |
H
Hollokin 已提交
2170
| 12800008 | Input method manager service error. |
H
Hollokin 已提交
2171

2172 2173
**示例:**

H
Hollokin 已提交
2174
```js
H
Hollokin 已提交
2175
let inputMethodProperty = {
2176
  name: 'com.example.kikakeyboard',
2177
  id: 'propertyId',
H
Hollokin 已提交
2178 2179
}
try {
2180
  inputMethodSetting.listInputMethodSubtype(inputMethodProperty).then((data) => {
H
Hollokin 已提交
2181
    console.log('Succeeded in listing inputMethodSubtype.');
2182
  }).catch((err) => {
H
Hollokin 已提交
2183
    console.error(`Failed to listInputMethodSubtype: ${JSON.stringify(err)}`);
2184 2185
  })
} catch(err) {
H
Hollokin 已提交
2186
  console.error(`Failed to listInputMethodSubtype: ${JSON.stringify(err)}`);
H
Hollokin 已提交
2187
}
2188 2189 2190 2191 2192
```

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

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

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

H
update  
Hollokin 已提交
2196
**系统能力:** SystemCapability.MiscServices.InputMethodFramework
2197 2198 2199 2200 2201

**参数:**

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

H
Hollokin 已提交
2204 2205
**错误码:**

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

2208
| 错误码ID | 错误信息                             |
H
Hollokin 已提交
2209 2210
| -------- | -------------------------------------- |
| 12800001 | Package manager error.                 |
H
Hollokin 已提交
2211
| 12800008 | Input method manager service error. |
H
Hollokin 已提交
2212

2213 2214
**示例:**

H
Hollokin 已提交
2215
```js
H
Hollokin 已提交
2216
try {
2217 2218
  inputMethodSetting.listCurrentInputMethodSubtype((err, data) => {
    if (err) {
H
Hollokin 已提交
2219
      console.error(`Failed to listCurrentInputMethodSubtype: ${JSON.stringify(err)}`);
2220 2221 2222 2223
      return;
    }
    console.log('Succeeded in listing currentInputMethodSubtype.');
  });
H
Hollokin 已提交
2224
} catch(err) {
H
Hollokin 已提交
2225
  console.error(`Failed to listCurrentInputMethodSubtype: ${JSON.stringify(err)}`);
H
Hollokin 已提交
2226
}
2227 2228 2229 2230 2231 2232
```

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

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

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

H
update  
Hollokin 已提交
2235
**系统能力:** SystemCapability.MiscServices.InputMethodFramework
2236 2237 2238 2239 2240

**返回值:**

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

H
Hollokin 已提交
2243 2244
**错误码:**

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

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

2252 2253
**示例:**

H
Hollokin 已提交
2254
```js
H
Hollokin 已提交
2255
try {
2256
  inputMethodSetting.listCurrentInputMethodSubtype().then((data) => {
H
Hollokin 已提交
2257
    console.log('Succeeded in listing currentInputMethodSubtype.');
2258
  }).catch((err) => {
H
Hollokin 已提交
2259
    console.error(`Failed to listCurrentInputMethodSubtype: ${JSON.stringify(err)}`);
2260 2261
  })
} catch(err) {
H
Hollokin 已提交
2262
  console.error(`Failed to listCurrentInputMethodSubtype: ${JSON.stringify(err)}`);
H
Hollokin 已提交
2263
}
2264 2265 2266 2267 2268
```

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

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

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

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

**参数:**

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

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

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

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

Z
zhaolinglan 已提交
2290 2291
**示例:**

H
Hollokin 已提交
2292
```js
H
Hollokin 已提交
2293
try {
2294
  inputMethodSetting.getInputMethods(true, (err, data) => {
2295
    if (err) {
H
Hollokin 已提交
2296
      console.error(`Failed to getInputMethods: ${JSON.stringify(err)}`);
2297 2298 2299 2300
      return;
    }
    console.log('Succeeded in getting inputMethods.');
  });
H
Hollokin 已提交
2301
} catch (err) {
H
Hollokin 已提交
2302
  console.error(`Failed to getInputMethods: ${JSON.stringify(err)}`);
H
Hollokin 已提交
2303
}
Z
zhaolinglan 已提交
2304 2305
```

2306
### getInputMethods<sup>9+</sup>
Z
zhaolinglan 已提交
2307

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

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

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

**参数:**

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

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

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

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

Z
zhaolinglan 已提交
2329 2330 2331 2332
**返回值:**

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

**示例:**

H
Hollokin 已提交
2337
```js
H
Hollokin 已提交
2338
try {
2339
  inputMethodSetting.getInputMethods(true).then((data) => {
H
Hollokin 已提交
2340
    console.log('Succeeded in getting inputMethods.');
2341
  }).catch((err) => {
H
Hollokin 已提交
2342
    console.error(`Failed to getInputMethods: ${JSON.stringify(err)}`);
2343 2344
  })
} catch(err) {
H
Hollokin 已提交
2345
  console.error(`Failed to getInputMethods: ${JSON.stringify(err)}`);
H
Hollokin 已提交
2346
}
Z
zhaolinglan 已提交
2347 2348
```

H
Hollokin 已提交
2349 2350
### showOptionalInputMethods<sup>9+</sup>

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

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

H
update  
Hollokin 已提交
2355
**系统能力:** SystemCapability.MiscServices.InputMethodFramework
H
Hollokin 已提交
2356 2357 2358 2359 2360

**参数:**

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

H
Hollokin 已提交
2363 2364
**错误码:**

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

2367
| 错误码ID | 错误信息                             |
H
Hollokin 已提交
2368
| -------- | -------------------------------------- |
H
Hollokin 已提交
2369
| 12800008 | Input method manager service error. |
H
Hollokin 已提交
2370

H
Hollokin 已提交
2371 2372
**示例:**

H
Hollokin 已提交
2373
```js
H
Hollokin 已提交
2374
try {
2375 2376
  inputMethodSetting.showOptionalInputMethods((err, data) => {
    if (err) {
H
Hollokin 已提交
2377
      console.error(`Failed to showOptionalInputMethods: ${JSON.stringify(err)}`);
2378 2379
      return;
    }
H
Hollokin 已提交
2380
    console.log('Succeeded in showing optionalInputMethods.');
2381
  });
H
Hollokin 已提交
2382
} catch (err) {
H
Hollokin 已提交
2383
  console.error(`Failed to showOptionalInputMethods: ${JSON.stringify(err)}`);
H
Hollokin 已提交
2384 2385 2386 2387 2388
}
```

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

H
Hollokin 已提交
2389
showOptionalInputMethods(): Promise&lt;boolean&gt;
H
Hollokin 已提交
2390

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

H
update  
Hollokin 已提交
2393
**系统能力:** SystemCapability.MiscServices.InputMethodFramework
H
Hollokin 已提交
2394 2395 2396 2397 2398

**返回值:**

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

H
Hollokin 已提交
2401 2402
**错误码:**

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

2405
| 错误码ID | 错误信息                             |
H
Hollokin 已提交
2406
| -------- | -------------------------------------- |
H
Hollokin 已提交
2407
| 12800008 | Input method manager service error. |
H
Hollokin 已提交
2408

H
Hollokin 已提交
2409 2410
**示例:**

H
Hollokin 已提交
2411
```js
H
Hollokin 已提交
2412
inputMethodSetting.showOptionalInputMethods().then((data) => {
H
Hollokin 已提交
2413
  console.log('Succeeded in showing optionalInputMethods.');
H
Hollokin 已提交
2414
}).catch((err) => {
H
Hollokin 已提交
2415
  console.error(`Failed to showOptionalInputMethods: ${JSON.stringify(err)}`);
H
Hollokin 已提交
2416 2417 2418
})
```

H
Hollokin 已提交
2419
### listInputMethod<sup>(deprecated)</sup>
Z
zhouyongfei 已提交
2420 2421 2422

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

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

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

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

2431
**参数:**
B
bmeangel 已提交
2432

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

2437
**示例:**
T
explain  
tianyu 已提交
2438

2439
```js
2440
inputMethodSetting.listInputMethod((err, data) => {
2441
  if (err) {
H
Hollokin 已提交
2442
    console.error(`Failed to listInputMethod: ${JSON.stringify(err)}`);
2443 2444 2445
    return;
  }
  console.log('Succeeded in listing inputMethod.');
2446
 });
2447
```
Z
zhouyongfei 已提交
2448

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

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

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

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

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

2461
**返回值:**
B
bmeangel 已提交
2462

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

2467
**示例:**
2468 2469

```js
H
Hollokin 已提交
2470
inputMethodSetting.listInputMethod().then((data) => {
H
Hollokin 已提交
2471
  console.log('Succeeded in listing inputMethod.');
Z
zhaolinglan 已提交
2472
}).catch((err) => {
H
Hollokin 已提交
2473
  console.error(`Failed to listInputMethod: ${JSON.stringify(err)}`);
Z
zhaolinglan 已提交
2474
})
2475
```
Z
zhouyongfei 已提交
2476

H
Hollokin 已提交
2477
### displayOptionalInputMethod<sup>(deprecated)</sup>
Z
zhouyongfei 已提交
2478 2479 2480

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

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

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

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

2489
**参数:**
Z
zhouyongfei 已提交
2490 2491 2492

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

2495
**示例:**
2496 2497

```js
H
Hollokin 已提交
2498
inputMethodSetting.displayOptionalInputMethod((err) => {
2499
  if (err) {
H
Hollokin 已提交
2500
    console.error(`Failed to displayOptionalInputMethod: ${JSON.stringify(err)}`);
2501 2502
    return;
  }
H
Hollokin 已提交
2503
  console.log('Succeeded in displaying optionalInputMethod.');
2504
});
2505
```
Z
zhouyongfei 已提交
2506

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

2509 2510
displayOptionalInputMethod(): Promise&lt;void&gt;

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

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

H
update  
Hollokin 已提交
2517
**系统能力:** SystemCapability.MiscServices.InputMethodFramework
2518 2519 2520 2521 2522

**返回值:**

| 类型 | 说明 |
| -------- | -------- |
H
Hollokin 已提交
2523
| Promise&lt;void&gt; | 无返回结果的Promise对象。 |
2524 2525 2526 2527

**示例:**

```js
H
Hollokin 已提交
2528
inputMethodSetting.displayOptionalInputMethod().then(() => {
H
Hollokin 已提交
2529
  console.log('Succeeded in displaying optionalInputMethod.');
2530
}).catch((err) => {
H
Hollokin 已提交
2531
  console.error(`Failed to displayOptionalInputMethod: ${JSON.stringify(err)}`);
2532 2533
})
```