1# @ohos.inputMethod (输入法框架)
2
3本模块主要面向普通前台应用(备忘录、信息、设置等系统应用与三方应用),提供对输入法(输入法应用)的控制、管理能力,包括显示/隐藏输入法软键盘、切换输入法、获取所有输入法列表等等。
4
5> **说明:**
6>
7> 本模块首批接口从API version 6开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
8
9
10## 导入模块
11
12```ts
13import { inputMethod } from '@kit.IMEKit';
14```
15
16## 常量
17
18常量值。
19
20**系统能力:** SystemCapability.MiscServices.InputMethodFramework
21
22| 参数名 | 类型 | 常量值 | 说明 |
23| -------- | -------- | -------- | -------- |
24| MAX_TYPE_NUM<sup>8+</sup> | number | 128 | 可支持的最大输入法个数。 |
25
26## InputMethodProperty<sup>8+</sup>
27
28输入法应用属性。
29
30**系统能力:** SystemCapability.MiscServices.InputMethodFramework
31
32| 名称 | 类型 | 只读 | 可选 | 说明 |
33| -------- | -------- | -------- | -------- | -------- |
34| name<sup>9+</sup>  | string | 是 | 否 | 必填。输入法包名。|
35| id<sup>9+</sup>    | string | 是 | 否 | 必填。输入法扩展在应用内唯一标识,与name一起组成输入法扩展的全局唯一标识。|
36| label<sup>9+</sup>    | string | 是 | 是 | 非必填。输入法扩展对外显示名称。优先使用InputmethodExtensionAbility中配置的label,若未配置,自动使用应用入口ability的label,当应用入口ability未配置label时,自动使用应用AppScope中配置的label。|
37| labelId<sup>10+</sup>    | number | 是 | 是 | 非必填。输入法对外显示名称资源号。|
38| icon<sup>9+</sup>    | string | 是 | 是 | 非必填。输入法图标数据,可以通过iconId查询获取。预留字段,暂不支持使用。|
39| iconId<sup>9+</sup>    | number | 是 | 是 | 非必填。输入法图标资源号。 |
40| extra<sup>9+</sup>    | object | 否 | 是 | 输入法扩展信息。预留字段,当前无具体含义,暂不支持使用。<br/>- API version 10起:非必填;<br/>- API version 9:必填。|
41| packageName<sup>(deprecated)</sup> | string | 是 | 否 | 输入法包名。必填。<br/>说明:从API version 8开始支持,从API version 9开始废弃,建议使用name替代。 |
42| methodId<sup>(deprecated)</sup> | string | 是 | 否 | 输入法唯一标识。必填。<br/>说明:从API version 8开始支持,从API version 9开始废弃,建议使用id替代。 |
43
44## inputMethod.getController<sup>9+</sup>
45
46getController(): InputMethodController
47
48获取客户端实例[InputMethodController](#inputmethodcontroller)。
49
50**系统能力:** SystemCapability.MiscServices.InputMethodFramework
51
52**返回值:**
53
54| 类型                                            | 说明                   |
55| ----------------------------------------------- | ---------------------- |
56| [InputMethodController](#inputmethodcontroller) | 返回当前客户端实例。 |
57
58**错误码:**
59
60以下错误码的详细介绍请参见[输入法框架错误码](errorcode-inputmethod-framework.md)。
61
62| 错误码ID | 错误信息                     |
63| -------- | ------------------------------ |
64| 12800006 | input method controller error. |
65
66**示例:**
67
68```ts
69let inputMethodController = inputMethod.getController();
70```
71
72## inputMethod.getDefaultInputMethod<sup>11+</sup>
73
74getDefaultInputMethod(): InputMethodProperty
75
76获取默认输入法。
77
78**系统能力:** SystemCapability.MiscServices.InputMethodFramework
79
80**返回值:**
81
82| 类型                                         | 说明                     |
83| -------------------------------------------- | ------------------------ |
84| [InputMethodProperty](#inputmethodproperty8) | 返回默认输入法属性对象。 |
85
86**错误码:**
87
88以下错误码的详细介绍请参见[输入法框架错误码](errorcode-inputmethod-framework.md)。
89
90| 错误码ID | 错误信息                             |
91| -------- | -------------------------------------- |
92| 12800008 | input method manager service error. |
93
94**示例:**
95
96```ts
97try {
98  let defaultIme = inputMethod.getDefaultInputMethod();
99} catch(err) {
100  console.error(`Failed to getDefaultInputMethod: ${JSON.stringify(err)}`);
101}
102```
103
104## inputMethod.getSystemInputMethodConfigAbility<sup>11+</sup>
105
106getSystemInputMethodConfigAbility(): ElementName
107
108获取系统输入法设置界面Ability信息。
109
110**系统能力:** SystemCapability.MiscServices.InputMethodFramework
111
112**返回值:**
113
114| 类型                                         | 说明                     |
115| -------------------------------------------- | ------------------------ |
116| [ElementName](../apis-ability-kit/js-apis-bundleManager-elementName.md) | 系统输入法设置界面Ability的ElementName。 |
117
118**错误码:**
119
120以下错误码的详细介绍请参见[输入法框架错误码](errorcode-inputmethod-framework.md)。
121
122| 错误码ID | 错误信息                             |
123| -------- | -------------------------------------- |
124| 12800008 | input method manager service error. |
125
126**示例:**
127
128```ts
129try {
130  let inputMethodConfig = inputMethod.getSystemInputMethodConfigAbility();
131} catch(err) {
132  console.error(`Failed to get getSystemInputMethodConfigAbility: ${JSON.stringify(err)}`);
133}
134```
135
136## inputMethod.getSetting<sup>9+</sup>
137
138getSetting(): InputMethodSetting
139
140获取客户端设置实例[InputMethodSetting](#inputmethodsetting8)。
141
142**系统能力:** SystemCapability.MiscServices.InputMethodFramework
143
144**返回值:**
145
146| 类型                                      | 说明                       |
147| ----------------------------------------- | -------------------------- |
148| [InputMethodSetting](#inputmethodsetting8) | 返回当前客户端设置实例。 |
149
150**错误码:**
151
152以下错误码的详细介绍请参见[输入法框架错误码](errorcode-inputmethod-framework.md)。
153
154| 错误码ID | 错误信息                             |
155| -------- | -------------------------------------- |
156| 12800007 |  setter error. |
157
158**示例:**
159
160```ts
161let inputMethodSetting = inputMethod.getSetting();
162```
163
164## inputMethod.switchInputMethod<sup>9+</sup>
165
166switchInputMethod(target: InputMethodProperty, callback: AsyncCallback&lt;boolean&gt;): void
167
168切换输入法,使用callback异步回调。
169> **说明:**
170>
171>  - 在API version 9-10版本,仅支持系统应用调用且需要权限ohos.permission.CONNECT_IME_ABILITY172>  - 在API version 11版本起,仅支持当前输入法应用调用。
173
174**系统能力:** SystemCapability.MiscServices.InputMethodFramework
175
176**参数:**
177
178| 参数名 | 类型 | 必填 | 说明 |
179| -------- | -------- | -------- | -------- |
180| target | [InputMethodProperty](#inputmethodproperty8) | 是 | 目标输入法。 |
181| callback | AsyncCallback&lt;boolean&gt; | 是 | 回调函数。当输入法切换成功,err为undefined,data为true;否则为错误对象。 |
182
183**错误码:**
184
185以下错误码的详细介绍请参见[输入法框架错误码](errorcode-inputmethod-framework.md),[通用错误码说明文档](../errorcode-universal.md)。
186
187| 错误码ID | 错误信息                             |
188| -------- | -------------------------------------- |
189| 401      | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.           |
190| 12800005 | configuration persistence error.        |
191| 12800008 | input method manager service error. |
192
193**示例:**
194
195```ts
196import { BusinessError } from '@kit.BasicServicesKit';
197
198let currentIme = inputMethod.getCurrentInputMethod();
199try{
200  inputMethod.switchInputMethod(currentIme, (err: BusinessError, result: boolean) => {
201    if (err) {
202      console.error(`Failed to switchInputMethod: ${JSON.stringify(err)}`);
203      return;
204    }
205    if (result) {
206      console.log('Succeeded in switching inputmethod.');
207    } else {
208      console.error('Failed to switchInputMethod.');
209    }
210  });
211} catch(err) {
212  console.error(`Failed to switchInputMethod: ${JSON.stringify(err)}`);
213}
214```
215
216> **说明:**
217>
218> 在 api11 中 ` 201 permissions check fails.` 这个错误码被移除。
219
220## inputMethod.switchInputMethod<sup>9+</sup>
221switchInputMethod(target: InputMethodProperty): Promise&lt;boolean&gt;
222
223切换输入法,使用promise异步回调。
224> **说明:**
225>
226>  - 在API version 9-10版本,仅支持系统应用调用且需要权限ohos.permission.CONNECT_IME_ABILITY227>  - 在API version 11版本起,仅支持当前输入法应用调用。
228
229**系统能力:** SystemCapability.MiscServices.InputMethodFramework
230
231**参数:**
232
233  | 参数名 | 类型 | 必填 | 说明 |
234  | -------- | -------- | -------- | -------- |
235  |target |  [InputMethodProperty](#inputmethodproperty8)| 是 | 目标输入法。 |
236
237**返回值:**
238
239  | 类型                                      | 说明                         |
240  | ----------------------------------------- | ---------------------------- |
241  | Promise\<boolean> | Promise对象。返回true表示切换输入法成功,返回false表示切换输入法失败。 |
242
243**错误码:**
244
245以下错误码的详细介绍请参见[输入法框架错误码](errorcode-inputmethod-framework.md),[通用错误码说明文档](../errorcode-universal.md)。
246
247| 错误码ID | 错误信息                             |
248| -------- | -------------------------------------- |
249| 401      | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.           |
250| 12800005 | configuration persistence error.        |
251| 12800008 | input method manager service error. |
252
253**示例:**
254
255```ts
256import { BusinessError } from '@kit.BasicServicesKit';
257
258let currentIme = inputMethod.getCurrentInputMethod();
259try {
260  inputMethod.switchInputMethod(currentIme).then((result: boolean) => {
261    if (result) {
262      console.log('Succeeded in switching inputmethod.');
263    } else {
264      console.error('Failed to switchInputMethod.');
265    }
266  }).catch((err: BusinessError) => {
267    console.error(`Failed to switchInputMethod: ${JSON.stringify(err)}`);
268  })
269} catch (err) {
270  console.error(`Failed to switchInputMethod: ${JSON.stringify(err)}`);
271}
272```
273
274> **说明:**
275>
276> 在 api11 中 ` 201 permissions check fails.` 这个错误码被移除。
277
278## inputMethod.getCurrentInputMethod<sup>9+</sup>
279
280getCurrentInputMethod(): InputMethodProperty
281
282使用同步方法获取当前输入法。
283
284**系统能力:** SystemCapability.MiscServices.InputMethodFramework
285
286**返回值:**
287
288| 类型                                         | 说明                     |
289| -------------------------------------------- | ------------------------ |
290| [InputMethodProperty](#inputmethodproperty8) | 返回当前输入法属性对象。 |
291
292**示例:**
293
294```ts
295let currentIme = inputMethod.getCurrentInputMethod();
296```
297
298## inputMethod.switchCurrentInputMethodSubtype<sup>9+</sup>
299
300switchCurrentInputMethodSubtype(target: InputMethodSubtype, callback: AsyncCallback\<boolean>): void
301
302切换当前输入法的子类型。使用callback异步回调。
303
304> **说明:**
305>
306>  - 在API version 9版本,仅支持系统应用调用且需要权限ohos.permission.CONNECT_IME_ABILITY307>  - 在API version 10版本,支持系统应用和当前输入法应用调用;需要权限ohos.permission.CONNECT_IME_ABILITY308>  - 在API version 11版本起,仅支持当前输入法调用。
309
310**系统能力:** SystemCapability.MiscServices.InputMethodFramework
311
312**参数:**
313
314| 参数名 | 类型 | 必填 | 说明 |
315| -------- | -------- | -------- | -------- |
316| target |  [InputMethodSubtype](./js-apis-inputmethod-subtype.md#inputmethodsubtype)| 是 | 目标输入法子类型。 |
317| callback | AsyncCallback&lt;boolean&gt; | 是 | 回调函数。当输入法子类型切换成功,err为undefined,data为true;否则为错误对象。|
318
319**错误码:**
320
321以下错误码的详细介绍请参见[输入法框架错误码](errorcode-inputmethod-framework.md),[通用错误码说明文档](../errorcode-universal.md)。
322
323| 错误码ID | 错误信息                             |
324| -------- | -------------------------------------- |
325| 401      | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.           |
326| 12800005 | configuration persistence error.        |
327| 12800008 | input method manager service error. |
328
329**示例:**
330
331```ts
332import { BusinessError } from '@kit.BasicServicesKit';
333
334try {
335  let extra: Record<string, string> = {}
336  inputMethod.switchCurrentInputMethodSubtype({
337    id: "ServiceExtAbility",
338    label: "",
339    name: "com.example.kikakeyboard",
340    mode: "upper",
341    locale: "",
342    language: "",
343    icon: "",
344    iconId: 0,
345    extra: extra
346  }, (err: BusinessError, result: boolean) => {
347    if (err) {
348      console.error(`Failed to switchCurrentInputMethodSubtype: ${JSON.stringify(err)}`);
349      return;
350    }
351    if (result) {
352      console.log('Succeeded in switching currentInputMethodSubtype.');
353    } else {
354      console.error('Failed to switchCurrentInputMethodSubtype');
355    }
356  });
357} catch(err) {
358  console.error(`Failed to switchCurrentInputMethodSubtype: ${JSON.stringify(err)}`);
359}
360```
361
362> **说明:**
363>
364> 在 api11 中 ` 201 permissions check fails.` 这个错误码被移除。
365
366## inputMethod.switchCurrentInputMethodSubtype<sup>9+</sup>
367
368switchCurrentInputMethodSubtype(target: InputMethodSubtype): Promise&lt;boolean&gt;
369
370切换当前输入法的子类型。使用promise异步回调。
371
372> **说明:**
373>
374>  - 在API version 9版本,仅支持系统应用调用且需要权限ohos.permission.CONNECT_IME_ABILITY375>  - 在API version 10版本,支持系统应用和当前输入法应用调用;需要权限ohos.permission.CONNECT_IME_ABILITY376>  - 在API version 11版本起,仅支持当前输入法调用。
377
378**系统能力:** SystemCapability.MiscServices.InputMethodFramework
379
380**参数:**
381
382| 参数名 | 类型 | 必填 | 说明 |
383| -------- | -------- | -------- | -------- |
384|target |  [InputMethodSubtype](./js-apis-inputmethod-subtype.md#inputmethodsubtype)| 是 | 目标输入法子类型。 |
385
386**返回值:**
387
388| 类型                                      | 说明                         |
389| ----------------------------------------- | ---------------------------- |
390| Promise\<boolean> | Promise对象。返回true表示当前输入法切换子类型成功,返回false表示当前输入法切换子类型成功失败。 |
391
392**错误码:**
393
394以下错误码的详细介绍请参见[输入法框架错误码](errorcode-inputmethod-framework.md),[通用错误码说明文档](../errorcode-universal.md)。
395
396| 错误码ID | 错误信息                             |
397| -------- | -------------------------------------- |
398| 401      | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.           |
399| 12800005 | configuration persistence error.        |
400| 12800008 | input method manager service error. |
401
402**示例:**
403
404```ts
405import { BusinessError } from '@kit.BasicServicesKit';
406
407try {
408  let extra: Record<string, string> = {}
409  inputMethod.switchCurrentInputMethodSubtype({
410    id: "ServiceExtAbility",
411    label: "",
412    name: "com.example.kikakeyboard",
413    mode: "upper",
414    locale: "",
415    language: "",
416    icon: "",
417    iconId: 0,
418    extra: extra
419  }).then((result: boolean) => {
420    if (result) {
421      console.log('Succeeded in switching currentInputMethodSubtype.');
422    } else {
423      console.error('Failed to switchCurrentInputMethodSubtype.');
424    }
425  }).catch((err: BusinessError) => {
426    console.error(`Failed to switchCurrentInputMethodSubtype: ${JSON.stringify(err)}`);
427  })
428} catch(err) {
429  console.error(`Failed to switchCurrentInputMethodSubtype: ${JSON.stringify(err)}`);
430}
431```
432
433> **说明:**
434>
435> 在 api11 中 ` 201 permissions check fails.` 这个错误码被移除。
436
437## inputMethod.getCurrentInputMethodSubtype<sup>9+</sup>
438
439getCurrentInputMethodSubtype(): InputMethodSubtype
440
441获取当前输入法的子类型。
442
443**系统能力:** SystemCapability.MiscServices.InputMethodFramework
444
445**返回值:**
446
447| 类型                                         | 说明                     |
448| -------------------------------------------- | ------------------------ |
449| [InputMethodSubtype](./js-apis-inputmethod-subtype.md#inputmethodsubtype) | 返回当前输入法子类型对象。 |
450
451**示例:**
452
453```ts
454let currentImeSubType = inputMethod.getCurrentInputMethodSubtype();
455```
456
457## inputMethod.switchCurrentInputMethodAndSubtype<sup>9+</sup>
458
459switchCurrentInputMethodAndSubtype(inputMethodProperty: InputMethodProperty, inputMethodSubtype: InputMethodSubtype, callback: AsyncCallback\<boolean>): void
460
461切换至指定输入法的指定子类型,适用于跨输入法切换子类型。使用callback异步回调。
462
463> **说明:**
464>
465>  - 在API version 9-10版本,仅支持系统应用调用且需要权限ohos.permission.CONNECT_IME_ABILITY466>  - 在API version 11版本起,仅支持当前输入法调用。
467
468**系统能力:** SystemCapability.MiscServices.InputMethodFramework
469
470**参数:**
471
472| 参数名 | 类型 | 必填 | 说明 |
473| -------- | -------- | -------- | -------- |
474|inputMethodProperty |  [InputMethodProperty](#inputmethodproperty8)| 是 | 目标输入法。 |
475|inputMethodSubtype |  [InputMethodSubtype](./js-apis-inputmethod-subtype.md#inputmethodsubtype)| 是 | 目标输入法子类型。 |
476| callback | AsyncCallback&lt;boolean&gt; | 是 | 回调函数。当输入法和子类型切换成功,err为undefined,data为获取到的切换子类型结果true;否则为错误对象。 |
477
478**错误码:**
479
480以下错误码的详细介绍请参见[输入法框架错误码](errorcode-inputmethod-framework.md),[通用错误码说明文档](../errorcode-universal.md)。
481
482| 错误码ID | 错误信息                             |
483| -------- | -------------------------------------- |
484| 401      | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.           |
485| 12800005 | configuration persistence error.        |
486| 12800008 | input method manager service error. |
487
488**示例:**
489
490```ts
491import { BusinessError } from '@kit.BasicServicesKit';
492
493let currentIme = inputMethod.getCurrentInputMethod();
494let imSubType = inputMethod.getCurrentInputMethodSubtype();
495try {
496  inputMethod.switchCurrentInputMethodAndSubtype(currentIme, imSubType, (err: BusinessError, result: boolean) => {
497    if (err) {
498      console.error(`Failed to switchCurrentInputMethodAndSubtype: ${JSON.stringify(err)}`);
499      return;
500    }
501    if (result) {
502      console.log('Succeeded in switching currentInputMethodAndSubtype.');
503    } else {
504      console.error('Failed to switchCurrentInputMethodAndSubtype.');
505    }
506  });
507} catch (err) {
508  console.error(`Failed to switchCurrentInputMethodAndSubtype: ${JSON.stringify(err)}`);
509}
510```
511
512> **说明:**
513>
514> 在 api11 中 ` 201 permissions check fails.` 这个错误码被移除。
515
516## inputMethod.switchCurrentInputMethodAndSubtype<sup>9+</sup>
517
518switchCurrentInputMethodAndSubtype(inputMethodProperty: InputMethodProperty, inputMethodSubtype: InputMethodSubtype): Promise&lt;boolean&gt;
519
520切换至指定输入法的指定子类型,适用于跨输入法切换子类型。使用promise异步回调。
521
522> **说明:**
523>
524>  - 在API version 9-10版本,仅支持系统应用调用且需要权限ohos.permission.CONNECT_IME_ABILITY525>  - 在API version 11版本起,仅支持当前输入法调用。
526
527**系统能力:** SystemCapability.MiscServices.InputMethodFramework
528
529**参数:**
530
531| 参数名 | 类型 | 必填 | 说明 |
532| -------- | -------- | -------- | -------- |
533|inputMethodProperty |  [InputMethodProperty](#inputmethodproperty8)| 是 | 目标输入法。 |
534|inputMethodSubtype |  [InputMethodSubtype](./js-apis-inputmethod-subtype.md#inputmethodsubtype)| 是 | 目标输入法子类型。 |
535
536**返回值:**
537
538| 类型                                      | 说明                         |
539| ----------------------------------------- | ---------------------------- |
540| Promise\<boolean> | Promise对象。返回true表示切换至指定输入法的指定子类型成功,返回false表示切换至指定输入法的指定子类型失败。 |
541
542**错误码:**
543
544以下错误码的详细介绍请参见[输入法框架错误码](errorcode-inputmethod-framework.md),[通用错误码说明文档](../errorcode-universal.md)。
545
546| 错误码ID | 错误信息                             |
547| -------- | -------------------------------------- |
548| 401      | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.           |
549| 12800005 | configuration persistence error.        |
550| 12800008 | input method manager service error. |
551
552**示例:**
553
554```ts
555import { BusinessError } from '@kit.BasicServicesKit';
556
557let currentIme = inputMethod.getCurrentInputMethod();
558let imSubType = inputMethod.getCurrentInputMethodSubtype();
559try {
560  inputMethod.switchCurrentInputMethodAndSubtype(currentIme, imSubType).then((result: boolean) => {
561    if (result) {
562      console.log('Succeeded in switching currentInputMethodAndSubtype.');
563    } else {
564      console.error('Failed to switchCurrentInputMethodAndSubtype.');
565    }
566  }).catch((err: BusinessError) => {
567    console.error(`Failed to switchCurrentInputMethodAndSubtype: ${JSON.stringify(err)}`);
568  })
569} catch(err) {
570  console.error(`Failed to switchCurrentInputMethodAndSubtype: ${JSON.stringify(err)}`);
571}
572```
573
574> **说明:**
575>
576> 在 api11 中 ` 201 permissions check fails.` 这个错误码被移除。
577
578## inputMethod.getInputMethodController<sup>(deprecated)</sup>
579
580getInputMethodController(): InputMethodController
581
582获取客户端实例[InputMethodController](#inputmethodcontroller)。
583
584> **说明:**
585>
586> 从API version 6开始支持,从API version 9开始废弃,建议使用[getController()](#inputmethodgetcontroller9)替代。
587
588**系统能力:** SystemCapability.MiscServices.InputMethodFramework
589
590**返回值:**
591
592| 类型                                            | 说明                     |
593| ----------------------------------------------- | ------------------------ |
594| [InputMethodController](#inputmethodcontroller) | 回调返回当前客户端实例。 |
595
596**示例:**
597
598```ts
599let inputMethodController = inputMethod.getInputMethodController();
600```
601
602## inputMethod.getInputMethodSetting<sup>(deprecated)</sup>
603
604getInputMethodSetting(): InputMethodSetting
605
606获取客户端设置实例[InputMethodSetting](#inputmethodsetting8)。
607
608> **说明:**
609>
610> 从API version 6开始支持,从API version 9开始废弃,建议使用[getSetting()](#inputmethodgetsetting9)替代。
611
612**系统能力:** SystemCapability.MiscServices.InputMethodFramework
613
614**返回值:**
615
616| 类型                                      | 说明                       |
617| ----------------------------------------- | -------------------------- |
618| [InputMethodSetting](#inputmethodsetting8) | 返回当前客户端设置实例。 |
619
620**示例:**
621
622```ts
623let inputMethodSetting = inputMethod.getInputMethodSetting();
624```
625
626## TextInputType<sup>10+</sup>
627
628文本输入类型。
629
630**系统能力:** SystemCapability.MiscServices.InputMethodFramework
631
632| 名称 | 值 |说明 |
633| -------- | -------- |-------- |
634| NONE  | -1 |NONE。 |
635| TEXT  | 0 |文本类型。 |
636| MULTILINE  | 1 |多行类型。 |
637| NUMBER  | 2 |数字类型。 |
638| PHONE  | 3 |电话号码类型。 |
639| DATETIME  | 4 |日期类型。 |
640| EMAIL_ADDRESS  | 5 |邮箱地址类型。 |
641| URL  | 6 |链接类型。 |
642| VISIBLE_PASSWORD  | 7 |密码类型。 |
643| NUMBER_PASSWORD<sup>11+</sup> | 8 |数字密码类型。 |
644
645## EnterKeyType<sup>10+</sup>
646
647Enter键的功能类型。
648
649**系统能力:** SystemCapability.MiscServices.InputMethodFramework
650
651| 名称 | 值 |说明 |
652| -------- | -------- |-------- |
653| UNSPECIFIED  | 0 |未指定。 |
654| NONE  | 1 |NONE。 |
655| GO  | 2 |前往。 |
656| SEARCH  | 3 |查找。 |
657| SEND  | 4 |发送。 |
658| NEXT  | 5 |下一步。 |
659| DONE  | 6 |完成。 |
660| PREVIOUS  | 7 |上一步。 |
661| NEWLINE<sup>12+</sup>  | 8 | 换行。|
662
663## KeyboardStatus<sup>10+</sup>
664
665输入法软键盘状态。
666
667**系统能力:** SystemCapability.MiscServices.InputMethodFramework
668
669| 名称 | 值 |说明 |
670| -------- | -------- |-------- |
671| NONE  | 0 |NONE。 |
672| HIDE  | 1 |隐藏状态。 |
673| SHOW  | 2 |显示状态。 |
674
675## Direction<sup>10+</sup>
676
677光标移动方向。
678
679**系统能力:** SystemCapability.MiscServices.InputMethodFramework
680
681| 名称 | 值 |说明 |
682| -------- | -------- |-------- |
683| CURSOR_UP  | 1 |向上。 |
684| CURSOR_DOWN  | 2 |向下。 |
685| CURSOR_LEFT  | 3 |向左。 |
686| CURSOR_RIGHT  | 4 |向右。 |
687
688## ExtendAction<sup>10+</sup>
689
690编辑框中文本的扩展编辑操作类型,如剪切、复制等。
691
692**系统能力:** SystemCapability.MiscServices.InputMethodFramework
693
694| 名称 | 值 |说明 |
695| -------- | -------- |-------- |
696| SELECT_ALL  | 0 |全选。 |
697| CUT  | 3 |剪切。 |
698| COPY  | 4 |复制。 |
699| PASTE  | 5 |粘贴。 |
700
701## FunctionKey<sup>10+</sup>
702
703输入法功能键类型。
704
705**系统能力:** SystemCapability.MiscServices.InputMethodFramework
706
707| 名称 | 类型 | 只读 | 可选 | 说明 |
708| -------- | -------- | -------- | -------- | -------- |
709| enterKeyType<sup>10+</sup>  | [EnterKeyType](#enterkeytype10) | 否 | 否 | 输入法enter键类型。|
710
711## InputAttribute<sup>10+</sup>
712
713编辑框属性,包含文本输入类型和Enter键功能类型。
714
715**系统能力:** SystemCapability.MiscServices.InputMethodFramework
716
717| 名称 | 类型 | 只读 | 可选 | 说明 |
718| -------- | -------- | -------- | -------- | -------- |
719| textInputType<sup>10+</sup>  | [TextInputType](#textinputtype10) | 否 | 否 | 文本输入类型。|
720| enterKeyType<sup>10+</sup>  | [EnterKeyType](#enterkeytype10) | 否 | 否 | Enter键功能类型。|
721
722## TextConfig<sup>10+</sup>
723
724编辑框的配置信息。
725
726**系统能力:** SystemCapability.MiscServices.InputMethodFramework
727
728| 名称 | 类型 | 只读 | 可选 | 说明 |
729| -------- | -------- | -------- | -------- | -------- |
730| inputAttribute<sup>10+</sup>  | [InputAttribute](#inputattribute10) | 否 | 否 | 编辑框属性。|
731| cursorInfo<sup>10+</sup>  | [CursorInfo](#cursorinfo10) | 否 | 是 | 光标信息。|
732| selection<sup>10+</sup>  | [Range](#range10) | 否 | 是 | 文本选中的范围。|
733| windowId<sup>10+</sup>  | number | 否 | 是 | 编辑框所在的窗口Id。|
734
735## CursorInfo<sup>10+</sup>
736
737光标信息。
738
739**系统能力:** SystemCapability.MiscServices.InputMethodFramework
740
741| 名称 | 类型 | 只读 | 可选 | 说明 |
742| -------- | -------- | -------- | -------- | -------- |
743| left  | number | 否 | 否 | 光标的left坐标。|
744| top  | number | 否 | 否 | 光标的top坐标。|
745| width  | number | 否 | 否 | 光标的宽度。|
746| height  | number | 否 | 否 | 光标的高度。|
747
748## Range<sup>10+</sup>
749
750文本的选中范围。
751
752**系统能力:** SystemCapability.MiscServices.InputMethodFramework
753
754| 名称 | 类型 | 只读 | 可选 | 说明 |
755| -------- | -------- | -------- | -------- | -------- |
756| start  | number | 否 | 否 | 选中文本的首字符在编辑框的索引值。|
757| end  | number | 否 | 否 | 选中文本的末字符在编辑框的索引值。|
758
759## Movement<sup>10+</sup>
760
761选中文本时,光标移动的方向。
762
763**系统能力:** SystemCapability.MiscServices.InputMethodFramework
764
765| 名称 | 类型 | 只读 | 可选 | 说明 |
766| -------- | -------- | -------- | -------- | -------- |
767| direction  | [Direction](#direction10) | 否 | 否 | 选中文本时,光标的移动方向。|
768
769## InputWindowInfo<sup>10+</sup>
770
771输入法软键盘的窗口信息。
772
773**系统能力:** SystemCapability.MiscServices.InputMethodFramework
774
775| 名称 | 类型 | 只读 | 可选 | 说明 |
776| -------- | -------- | -------- | -------- | -------- |
777| name  | string | 否 | 否 | 输入法窗口的名称。|
778| left  | number | 否 | 否 | 输入法窗口左上顶点的横坐标,单位为px。|
779| top  | number | 否 | 否 | 输入法窗口左上顶点的纵坐标,单位为px。|
780| width  | number | 否 | 否 | 输入法窗口的宽度,单位为px。|
781| height  | number | 否 | 否 | 输入法窗口的高度,单位为px。|
782
783## InputMethodController
784
785下列API示例中都需使用[getController](#inputmethodgetcontroller9)获取到InputMethodController实例,再通过实例调用对应方法。
786
787### attach<sup>10+</sup>
788
789attach(showKeyboard: boolean, textConfig: TextConfig, callback: AsyncCallback&lt;void&gt;): void
790
791自绘控件绑定输入法。使用callback异步回调。
792
793> **说明**
794>
795> 需要先调用此接口,完成自绘控件与输入法的绑定,才能使用以下功能:显示/隐藏键盘、更新光标信息、更改编辑框选中范围、保存配置信息、监听处理由输入法应用发送的信息或命令等。
796
797**系统能力:** SystemCapability.MiscServices.InputMethodFramework
798
799**参数:**
800
801| 参数名 | 类型 | 必填 | 说明 |
802| -------- | -------- | -------- | -------- |
803| showKeyboard | boolean | 是 | 绑定输入法成功后,是否拉起输入法键盘。<br>- true表示拉起,false表示不拉起。 |
804| textConfig | [TextConfig](#textconfig10) | 是 | 编辑框的配置信息。 |
805| callback | AsyncCallback&lt;void&gt; | 是 | 回调函数。当绑定输入法成功后,err为undefined;否则为错误对象。 |
806
807**错误码:**
808
809以下错误码的详细介绍请参见[输入法框架错误码](errorcode-inputmethod-framework.md),[通用错误码说明文档](../errorcode-universal.md)。
810
811| 错误码ID | 错误信息                             |
812| -------- | -------------------------------------- |
813| 401      | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
814| 12800003 | input method client error.             |
815| 12800008 | input method manager service error. |
816
817**示例:**
818
819```ts
820import { BusinessError } from '@kit.BasicServicesKit';
821
822try {
823  let textConfig: inputMethod.TextConfig = {
824    inputAttribute: {
825      textInputType: 0,
826      enterKeyType: 1
827    }
828  };
829  inputMethodController.attach(true, textConfig, (err: BusinessError) => {
830    if (err) {
831      console.error(`Failed to attach: ${JSON.stringify(err)}`);
832      return;
833    }
834    console.log('Succeeded in attaching the inputMethod.');
835  });
836} catch(err) {
837  console.error(`Failed to attach: ${JSON.stringify(err)}`);
838}
839```
840
841### attach<sup>10+</sup>
842
843attach(showKeyboard: boolean, textConfig: TextConfig): Promise&lt;void&gt;
844
845自绘控件绑定输入法。使用promise异步回调。
846
847> **说明**
848>
849> 需要先调用此接口,完成自绘控件与输入法的绑定,才能使用以下功能:显示/隐藏键盘、更新光标信息、更改编辑框选中范围、保存配置信息、监听处理由输入法应用发送的信息或命令等。
850
851**系统能力:** SystemCapability.MiscServices.InputMethodFramework
852
853**参数:**
854
855| 参数名 | 类型 | 必填 | 说明 |
856| -------- | -------- | -------- | -------- |
857| showKeyboard | boolean | 是 | 绑定输入法成功后,是否拉起输入法键盘。<br>- true表示拉起,false表示不拉起。|
858| textConfig | [TextConfig](#textconfig10) | 是 | 编辑框的配置信息。 |
859
860**返回值:**
861
862| 类型 | 说明 |
863| -------- | -------- |
864| Promise&lt;void&gt; | 无返回结果的Promise对象。 |
865
866**错误码:**
867
868以下错误码的详细介绍请参见[输入法框架错误码](errorcode-inputmethod-framework.md),[通用错误码说明文档](../errorcode-universal.md)。
869
870| 错误码ID | 错误信息                             |
871| -------- | -------------------------------------- |
872| 401      | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
873| 12800003 | input method client error.             |
874| 12800008 | input method manager service error. |
875
876**示例:**
877
878```ts
879import { BusinessError } from '@kit.BasicServicesKit';
880
881try {
882  let textConfig: inputMethod.TextConfig = {
883    inputAttribute: {
884      textInputType: 0,
885      enterKeyType: 1
886    }
887  };
888  inputMethodController.attach(true, textConfig).then(() => {
889    console.log('Succeeded in attaching inputMethod.');
890  }).catch((err: BusinessError) => {
891    console.error(`Failed to attach: ${JSON.stringify(err)}`);
892  })
893} catch(err) {
894  console.error(`Failed to attach: ${JSON.stringify(err)}`);
895}
896```
897
898### showTextInput<sup>10+</sup>
899
900showTextInput(callback: AsyncCallback&lt;void&gt;): void
901
902进入文本编辑状态。使用callback异步回调。
903
904> **说明**
905>
906> 编辑框与输入法绑定成功后,可调用该接口拉起软键盘,进入文本编辑状态。
907
908**系统能力:** SystemCapability.MiscServices.InputMethodFramework
909
910**参数:**
911
912| 参数名 | 类型 | 必填 | 说明 |
913| -------- | -------- | -------- | -------- |
914| callback | AsyncCallback&lt;void&gt; | 是 | 回调函数。若成功进入编辑状态,err为undefined;否则为错误对象。 |
915
916**错误码:**
917
918以下错误码的详细介绍请参见[输入法框架错误码](errorcode-inputmethod-framework.md)。
919
920| 错误码ID | 错误信息                             |
921| -------- | -------------------------------------- |
922| 12800003 | input method client error.             |
923| 12800008 | input method manager service error. |
924| 12800009 | input method client detached. |
925
926**示例:**
927
928```ts
929import { BusinessError } from '@kit.BasicServicesKit';
930
931inputMethodController.showTextInput((err: BusinessError) => {
932  if (err) {
933    console.error(`Failed to showTextInput: ${JSON.stringify(err)}`);
934    return;
935  }
936  console.log('Succeeded in showing the inputMethod.');
937});
938```
939
940### showTextInput<sup>10+</sup>
941
942showTextInput(): Promise&lt;void&gt;
943
944进入文本编辑状态。使用promise异步回调。
945
946> **说明**
947>
948> 编辑框与输入法绑定成功后,可调用该接口拉起软键盘,进入文本编辑状态。
949
950**系统能力:** SystemCapability.MiscServices.InputMethodFramework
951
952**返回值:**
953
954| 类型 | 说明 |
955| -------- | -------- |
956| Promise&lt;void&gt; | 无返回结果的Promise对象。 |
957
958**错误码:**
959
960以下错误码的详细介绍请参见[输入法框架错误码](errorcode-inputmethod-framework.md)。
961
962| 错误码ID | 错误信息                             |
963| -------- | -------------------------------------- |
964| 12800003 | input method client error.             |
965| 12800008 | input method manager service error. |
966| 12800009 | input method client detached. |
967
968**示例:**
969
970```ts
971import { BusinessError } from '@kit.BasicServicesKit';
972
973inputMethodController.showTextInput().then(() => {
974  console.log('Succeeded in showing text input.');
975}).catch((err: BusinessError) => {
976  console.error(`Failed to showTextInput: ${JSON.stringify(err)}`);
977});
978```
979
980### hideTextInput<sup>10+</sup>
981
982hideTextInput(callback: AsyncCallback&lt;void&gt;): void
983
984退出文本编辑状态。使用callback异步回调。
985
986> **说明**
987>
988> 调用接口时,若软键盘处于显示状态,调用接口后软键盘会被隐藏。
989>
990> 调用该接口不会解除与输入法的绑定,再次调用[showTextInput](#showtextinput10)时,可重新进入文本编辑状态。
991
992**系统能力:** SystemCapability.MiscServices.InputMethodFramework
993
994**参数:**
995
996| 参数名 | 类型 | 必填 | 说明 |
997| -------- | -------- | -------- | -------- |
998| callback | AsyncCallback&lt;void&gt; | 是 | 回调函数。当成功退出编辑状态时,err为undefined;否则为错误对象。 |
999
1000**错误码:**
1001
1002以下错误码的详细介绍请参见[输入法框架错误码](errorcode-inputmethod-framework.md)。
1003
1004| 错误码ID | 错误信息                             |
1005| -------- | -------------------------------------- |
1006| 12800003 | input method client error.             |
1007| 12800008 | input method manager service error. |
1008| 12800009 | input method client detached.             |
1009
1010**示例:**
1011
1012```ts
1013import { BusinessError } from '@kit.BasicServicesKit';
1014
1015inputMethodController.hideTextInput((err: BusinessError) => {
1016  if (err) {
1017    console.error(`Failed to hideTextInput: ${JSON.stringify(err)}`);
1018    return;
1019  }
1020  console.log('Succeeded in hiding text input.');
1021});
1022```
1023
1024### hideTextInput<sup>10+</sup>
1025
1026hideTextInput(): Promise&lt;void&gt;
1027
1028退出文本编辑状态。使用promise异步回调。
1029
1030> **说明**
1031>
1032> 调用接口时,若软键盘处于显示状态,调用接口后软键盘会被隐藏。
1033>
1034> 调用该接口不会解除与输入法的绑定,再次调用[showTextInput](#showtextinput10)时,可重新进入文本编辑状态。
1035
1036**系统能力:** SystemCapability.MiscServices.InputMethodFramework
1037
1038**返回值:**
1039
1040| 类型 | 说明 |
1041| -------- | -------- |
1042| Promise&lt;void&gt; | 无返回结果的Promise对象。 |
1043
1044**错误码:**
1045
1046以下错误码的详细介绍请参见[输入法框架错误码](errorcode-inputmethod-framework.md)。
1047
1048| 错误码ID | 错误信息                             |
1049| -------- | -------------------------------------- |
1050| 12800003 | input method client error.             |
1051| 12800008 | input method manager service error. |
1052| 12800009 | input method client detached. |
1053
1054**示例:**
1055
1056```ts
1057import { BusinessError } from '@kit.BasicServicesKit';
1058
1059inputMethodController.hideTextInput().then(() => {
1060  console.log('Succeeded in hiding inputMethod.');
1061}).catch((err: BusinessError) => {
1062  console.error(`Failed to hideTextInput: ${JSON.stringify(err)}`);
1063})
1064```
1065
1066### detach<sup>10+</sup>
1067
1068detach(callback: AsyncCallback&lt;void&gt;): void
1069
1070自绘控件解除与输入法的绑定。使用callback异步回调。
1071
1072**系统能力:** SystemCapability.MiscServices.InputMethodFramework
1073
1074**参数:**
1075
1076| 参数名 | 类型 | 必填 | 说明 |
1077| -------- | -------- | -------- | -------- |
1078| callback | AsyncCallback&lt;void&gt; | 是 | 回调函数。当解绑定输入法成功时,err为undefined;否则为错误对象。 |
1079
1080**错误码:**
1081
1082以下错误码的详细介绍请参见[输入法框架错误码](errorcode-inputmethod-framework.md)。
1083
1084| 错误码ID | 错误信息                             |
1085| -------- | -------------------------------------- |
1086| 12800003 | input method client error.             |
1087| 12800008 | input method manager service error. |
1088
1089**示例:**
1090
1091```ts
1092import { BusinessError } from '@kit.BasicServicesKit';
1093
1094inputMethodController.detach((err: BusinessError) => {
1095  if (err) {
1096    console.error(`Failed to detach: ${JSON.stringify(err)}`);
1097    return;
1098  }
1099  console.log('Succeeded in detaching inputMethod.');
1100});
1101```
1102
1103### detach<sup>10+</sup>
1104
1105detach(): Promise&lt;void&gt;
1106
1107自绘控件解除与输入法的绑定。使用promise异步回调。
1108
1109**系统能力:** SystemCapability.MiscServices.InputMethodFramework
1110
1111**返回值:**
1112
1113| 类型 | 说明 |
1114| -------- | -------- |
1115| Promise&lt;void&gt; | 无返回结果的Promise对象。 |
1116
1117**错误码:**
1118
1119以下错误码的详细介绍请参见[输入法框架错误码](errorcode-inputmethod-framework.md)。
1120
1121| 错误码ID | 错误信息                             |
1122| -------- | -------------------------------------- |
1123| 12800003 | input method client error.             |
1124| 12800008 | input method manager service error. |
1125
1126**示例:**
1127
1128```ts
1129import { BusinessError } from '@kit.BasicServicesKit';
1130
1131inputMethodController.detach().then(() => {
1132  console.log('Succeeded in detaching inputMethod.');
1133}).catch((err: BusinessError) => {
1134  console.error(`Failed to detach: ${JSON.stringify(err)}`);
1135});
1136```
1137
1138### setCallingWindow<sup>10+</sup>
1139
1140setCallingWindow(windowId: number, callback: AsyncCallback&lt;void&gt;): void
1141
1142设置要避让软键盘的窗口。使用callback异步回调。
1143
1144> **说明**
1145>
1146> 将绑定到输入法的应用程序所在的窗口Id传入,此窗口可以避让输入法窗口。
1147
1148**系统能力:** SystemCapability.MiscServices.InputMethodFramework
1149
1150**参数:**
1151
1152| 参数名 | 类型 | 必填 | 说明 |
1153| -------- | -------- | -------- | -------- |
1154| windowId | number | 是 | 绑定输入法应用的应用程序所在的窗口Id。 |
1155| callback | AsyncCallback&lt;void&gt; | 是 | 回调函数。当设置成功时,err为undefined;否则为错误对象。 |
1156
1157**错误码:**
1158
1159以下错误码的详细介绍请参见[输入法框架错误码](errorcode-inputmethod-framework.md),[通用错误码说明文档](../errorcode-universal.md)。
1160
1161| 错误码ID | 错误信息                             |
1162| -------- | -------------------------------------- |
1163| 401      | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
1164| 12800003 | input method client error.             |
1165| 12800008 | input method manager service error. |
1166| 12800009 | input method client detached.             |
1167
1168**示例:**
1169
1170```ts
1171import { BusinessError } from '@kit.BasicServicesKit';
1172
1173try {
1174  let windowId: number = 2000;
1175  inputMethodController.setCallingWindow(windowId, (err: BusinessError) => {
1176    if (err) {
1177      console.error(`Failed to setCallingWindow: ${JSON.stringify(err)}`);
1178      return;
1179    }
1180    console.log('Succeeded in setting callingWindow.');
1181  });
1182} catch(err) {
1183  console.error(`Failed to setCallingWindow: ${JSON.stringify(err)}`);
1184}
1185```
1186
1187### setCallingWindow<sup>10+</sup>
1188
1189setCallingWindow(windowId: number): Promise&lt;void&gt;
1190
1191设置要避让软键盘的窗口。使用promise异步回调。
1192
1193> **说明**
1194>
1195> 将绑定到输入法的应用程序所在的窗口Id传入,此窗口可以避让输入法窗口。
1196
1197**系统能力:** SystemCapability.MiscServices.InputMethodFramework
1198
1199**参数:**
1200
1201| 参数名 | 类型 | 必填 | 说明 |
1202| -------- | -------- | -------- | -------- |
1203| windowId | number | 是 | 绑定输入法应用的应用程序所在的窗口Id。 |
1204
1205**返回值:**
1206
1207| 类型 | 说明 |
1208| -------- | -------- |
1209| Promise&lt;void&gt; | 无返回结果的Promise对象。 |
1210
1211**错误码:**
1212
1213以下错误码的详细介绍请参见[输入法框架错误码](errorcode-inputmethod-framework.md),[通用错误码说明文档](../errorcode-universal.md)。
1214
1215| 错误码ID | 错误信息                             |
1216| -------- | -------------------------------------- |
1217| 401      | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
1218| 12800003 | input method client error.             |
1219| 12800008 | input method manager service error. |
1220| 12800009 | input method client detached. |
1221
1222**示例:**
1223
1224```ts
1225import { BusinessError } from '@kit.BasicServicesKit';
1226
1227try {
1228  let windowId: number = 2000;
1229  inputMethodController.setCallingWindow(windowId).then(() => {
1230    console.log('Succeeded in setting callingWindow.');
1231  }).catch((err: BusinessError) => {
1232    console.error(`Failed to setCallingWindow: ${JSON.stringify(err)}`);
1233  })
1234} catch(err) {
1235  console.error(`Failed to setCallingWindow: ${JSON.stringify(err)}`);
1236}
1237```
1238
1239### updateCursor<sup>10+</sup>
1240
1241updateCursor(cursorInfo: CursorInfo, callback: AsyncCallback&lt;void&gt;): void
1242
1243当编辑框内的光标信息发生变化时,调用该接口使输入法感知到光标变化。使用callback异步回调。
1244
1245**系统能力:** SystemCapability.MiscServices.InputMethodFramework
1246
1247**参数:**
1248
1249| 参数名 | 类型 | 必填 | 说明 |
1250| -------- | -------- | -------- | -------- |
1251| cursorInfo | [CursorInfo](#cursorinfo10) | 是 | 光标信息。 |
1252| callback | AsyncCallback&lt;void&gt; | 是 | 回调函数。当光标信息更新成功时,err为undefined;否则为错误对象。 |
1253
1254**错误码:**
1255
1256以下错误码的详细介绍请参见[输入法框架错误码](errorcode-inputmethod-framework.md),[通用错误码说明文档](../errorcode-universal.md)。
1257
1258| 错误码ID | 错误信息                             |
1259| -------- | -------------------------------------- |
1260| 401      | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.           |
1261| 12800003 | input method client error.             |
1262| 12800008 | input method manager service error. |
1263| 12800009 | input method client detached.             |
1264
1265**示例:**
1266
1267```ts
1268import { BusinessError } from '@kit.BasicServicesKit';
1269
1270try {
1271  let cursorInfo: inputMethod.CursorInfo = { left: 0, top: 0, width: 600, height: 800 };
1272  inputMethodController.updateCursor(cursorInfo, (err: BusinessError) => {
1273    if (err) {
1274      console.error(`Failed to updateCursor: ${JSON.stringify(err)}`);
1275      return;
1276    }
1277    console.log('Succeeded in updating cursorInfo.');
1278  });
1279} catch(err) {
1280  console.error(`Failed to updateCursor: ${JSON.stringify(err)}`);
1281}
1282```
1283
1284### updateCursor<sup>10+</sup>
1285
1286updateCursor(cursorInfo: CursorInfo): Promise&lt;void&gt;
1287
1288当编辑框内的光标信息发生变化时,调用该接口使输入法感知到光标变化。使用promise异步回调。
1289
1290**系统能力:** SystemCapability.MiscServices.InputMethodFramework
1291
1292**参数:**
1293
1294| 参数名 | 类型 | 必填 | 说明 |
1295| -------- | -------- | -------- | -------- |
1296| cursorInfo | [CursorInfo](#cursorinfo10) | 是 | 光标信息。 |
1297
1298**返回值:**
1299
1300| 类型 | 说明 |
1301| -------- | -------- |
1302| Promise&lt;void&gt; | 无返回结果的Promise对象。 |
1303
1304**错误码:**
1305
1306以下错误码的详细介绍请参见[输入法框架错误码](errorcode-inputmethod-framework.md),[通用错误码说明文档](../errorcode-universal.md)。
1307
1308| 错误码ID | 错误信息                             |
1309| -------- | -------------------------------------- |
1310| 401      | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.           |
1311| 12800003 | input method client error.             |
1312| 12800008 | input method manager service error. |
1313| 12800009 | input method client detached. |
1314
1315**示例:**
1316
1317```ts
1318import { BusinessError } from '@kit.BasicServicesKit';
1319
1320try {
1321  let cursorInfo: inputMethod.CursorInfo = { left: 0, top: 0, width: 600, height: 800 };
1322  inputMethodController.updateCursor(cursorInfo).then(() => {
1323    console.log('Succeeded in updating cursorInfo.');
1324  }).catch((err: BusinessError) => {
1325    console.error(`Failed to updateCursor: ${JSON.stringify(err)}`);
1326  })
1327} catch(err) {
1328  console.error(`Failed to updateCursor: ${JSON.stringify(err)}`);
1329}
1330```
1331
1332### changeSelection<sup>10+</sup>
1333
1334changeSelection(text: string, start: number, end: number, callback: AsyncCallback&lt;void&gt;): void
1335
1336当编辑框内被选中的文本信息内容或文本范围发生变化时,可调用该接口更新文本信息,使输入法应用感知到变化。使用callback异步回调。
1337
1338**系统能力:** SystemCapability.MiscServices.InputMethodFramework
1339
1340**参数:**
1341
1342| 参数名 | 类型 | 必填 | 说明 |
1343| -------- | -------- | -------- | -------- |
1344| text | string | 是 | 整个输入文本。 |
1345| start | number | 是 | 所选文本的起始位置。 |
1346| end | number | 是 | 所选文本的结束位置。 |
1347| callback | AsyncCallback&lt;void&gt; | 是 | 回调函数。当文本信息更新成功时,err为undefined;否则为错误对象。 |
1348
1349**错误码:**
1350
1351以下错误码的详细介绍请参见[输入法框架错误码](errorcode-inputmethod-framework.md),[通用错误码说明文档](../errorcode-universal.md)。
1352
1353| 错误码ID | 错误信息                             |
1354| -------- | -------------------------------------- |
1355| 401      | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
1356| 12800003 | input method client error.             |
1357| 12800008 | input method manager service error. |
1358| 12800009 | input method client detached.             |
1359
1360**示例:**
1361
1362```ts
1363import { BusinessError } from '@kit.BasicServicesKit';
1364
1365try {
1366  inputMethodController.changeSelection('text', 0, 5, (err: BusinessError) => {
1367    if (err) {
1368      console.error(`Failed to changeSelection: ${JSON.stringify(err)}`);
1369      return;
1370    }
1371    console.log('Succeeded in changing selection.');
1372  });
1373} catch(err) {
1374  console.error(`Failed to changeSelection: ${JSON.stringify(err)}`);
1375}
1376```
1377
1378### changeSelection<sup>10+</sup>
1379
1380changeSelection(text: string, start: number, end: number): Promise&lt;void&gt;
1381
1382当编辑框内被选中的文本信息内容或文本范围发生变化时,可调用该接口更新文本信息,使输入法应用感知到变化。使用promise异步回调。
1383
1384**系统能力:** SystemCapability.MiscServices.InputMethodFramework
1385
1386**参数:**
1387
1388| 参数名 | 类型 | 必填 | 说明 |
1389| -------- | -------- | -------- | -------- |
1390| text | string | 是 | 整个输入文本。 |
1391| start | number | 是 | 所选文本的起始位置。 |
1392| end | number | 是 | 所选文本的结束位置。 |
1393
1394**返回值:**
1395
1396| 类型 | 说明 |
1397| -------- | -------- |
1398| Promise&lt;void&gt; | 无返回结果的Promise对象。 |
1399
1400**错误码:**
1401
1402以下错误码的详细介绍请参见[输入法框架错误码](errorcode-inputmethod-framework.md),[通用错误码说明文档](../errorcode-universal.md)。
1403
1404| 错误码ID | 错误信息                             |
1405| -------- | -------------------------------------- |
1406| 401      | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
1407| 12800003 | input method client error.             |
1408| 12800008 | input method manager service error. |
1409| 12800009 | input method client detached. |
1410
1411**示例:**
1412
1413```ts
1414import { BusinessError } from '@kit.BasicServicesKit';
1415
1416try {
1417  inputMethodController.changeSelection('test', 0, 5).then(() => {
1418    console.log('Succeeded in changing selection.');
1419  }).catch((err: BusinessError) => {
1420    console.error(`Failed to changeSelection: ${JSON.stringify(err)}`);
1421  })
1422} catch(err) {
1423  console.error(`Failed to changeSelection: ${JSON.stringify(err)}`);
1424}
1425```
1426
1427### updateAttribute<sup>10+</sup>
1428
1429updateAttribute(attribute: InputAttribute, callback: AsyncCallback&lt;void&gt;): void
1430
1431更新编辑框属性信息。使用callback异步回调。
1432
1433**系统能力:** SystemCapability.MiscServices.InputMethodFramework
1434
1435**参数:**
1436
1437| 参数名 | 类型 | 必填 | 说明 |
1438| -------- | -------- | -------- | -------- |
1439| attribute | [InputAttribute](#inputattribute10) | 是 | 编辑框属性对象。 |
1440| callback | AsyncCallback&lt;void&gt; | 是 | 回调函数。当编辑框属性信息更新成功时,err为undefined;否则为错误对象。 |
1441
1442**错误码:**
1443
1444以下错误码的详细介绍请参见[输入法框架错误码](errorcode-inputmethod-framework.md),[通用错误码说明文档](../errorcode-universal.md)。
1445
1446| 错误码ID | 错误信息                             |
1447| -------- | -------------------------------------- |
1448| 401      | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
1449| 12800003 | input method client error.             |
1450| 12800008 | input method manager service error. |
1451| 12800009 | input method client detached.             |
1452
1453**示例:**
1454
1455```ts
1456import { BusinessError } from '@kit.BasicServicesKit';
1457
1458try {
1459  let inputAttribute: inputMethod.InputAttribute = { textInputType: 0, enterKeyType: 1 };
1460  inputMethodController.updateAttribute(inputAttribute, (err: BusinessError) => {
1461    if (err) {
1462      console.error(`Failed to updateAttribute: ${JSON.stringify(err)}`);
1463      return;
1464    }
1465    console.log('Succeeded in updating attribute.');
1466  });
1467} catch(err) {
1468  console.error(`Failed to updateAttribute: ${JSON.stringify(err)}`);
1469}
1470```
1471
1472### updateAttribute<sup>10+</sup>
1473
1474updateAttribute(attribute: InputAttribute): Promise&lt;void&gt;
1475
1476更新编辑框属性信息。使用promise异步回调。
1477
1478**系统能力:** SystemCapability.MiscServices.InputMethodFramework
1479
1480**参数:**
1481
1482| 参数名 | 类型 | 必填 | 说明 |
1483| -------- | -------- | -------- | -------- |
1484| attribute | [InputAttribute](#inputattribute10) | 是 |  编辑框属性对象。 |
1485
1486**返回值:**
1487
1488| 类型 | 说明 |
1489| -------- | -------- |
1490| Promise&lt;void&gt; | 无返回结果的Promise对象。 |
1491
1492**错误码:**
1493
1494以下错误码的详细介绍请参见[输入法框架错误码](errorcode-inputmethod-framework.md),[通用错误码说明文档](../errorcode-universal.md)。
1495
1496| 错误码ID | 错误信息                             |
1497| -------- | -------------------------------------- |
1498| 401      | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
1499| 12800003 | input method client error.             |
1500| 12800008 | input method manager service error. |
1501| 12800009 | input method client detached. |
1502
1503**示例:**
1504
1505```ts
1506import { BusinessError } from '@kit.BasicServicesKit';
1507
1508try {
1509  let inputAttribute: inputMethod.InputAttribute = { textInputType: 0, enterKeyType: 1 };
1510  inputMethodController.updateAttribute(inputAttribute).then(() => {
1511    console.log('Succeeded in updating attribute.');
1512  }).catch((err: BusinessError) => {
1513    console.error(`Failed to updateAttribute: ${JSON.stringify(err)}`);
1514  })
1515} catch(err) {
1516  console.error(`Failed to updateAttribute: ${JSON.stringify(err)}`);
1517}
1518```
1519
1520### stopInputSession<sup>9+</sup>
1521
1522stopInputSession(callback: AsyncCallback&lt;boolean&gt;): void
1523
1524结束输入会话。使用callback异步回调。
1525
1526> **说明:**
1527>
1528> 该接口需要编辑框与输入法绑定时才能调用,即点击编辑控件后,才可调用该接口结束输入会话。
1529
1530**系统能力:** SystemCapability.MiscServices.InputMethodFramework
1531
1532**参数:**
1533
1534| 参数名 | 类型 | 必填 | 说明 |
1535| -------- | -------- | -------- | -------- |
1536| callback | AsyncCallback&lt;boolean&gt; | 是 | 回调函数。当结束输入会话成功时,err为undefined,data为true;否则为错误对象。 |
1537
1538**错误码:**
1539
1540以下错误码的详细介绍请参见[输入法框架错误码](errorcode-inputmethod-framework.md)。
1541
1542| 错误码ID | 错误信息                             |
1543| -------- | -------------------------------------- |
1544| 12800003 | input method client error.             |
1545| 12800008 | input method manager service error. |
1546
1547**示例:**
1548
1549```ts
1550import { BusinessError } from '@kit.BasicServicesKit';
1551
1552try {
1553  inputMethodController.stopInputSession((err: BusinessError, result: boolean) => {
1554    if (err) {
1555      console.error(`Failed to stopInputSession: ${JSON.stringify(err)}`);
1556      return;
1557    }
1558    if (result) {
1559      console.log('Succeeded in stopping inputSession.');
1560    } else {
1561      console.error('Failed to stopInputSession.');
1562    }
1563  });
1564} catch(err) {
1565  console.error(`Failed to stopInputSession: ${JSON.stringify(err)}`);
1566}
1567```
1568
1569### stopInputSession<sup>9+</sup>
1570
1571stopInputSession(): Promise&lt;boolean&gt;
1572
1573结束输入会话。使用promise异步回调。
1574
1575> **说明:**
1576>
1577> 该接口需要编辑框与输入法绑定时才能调用,即点击编辑控件后,才可调用该接口结束输入会话。
1578
1579**系统能力:** SystemCapability.MiscServices.InputMethodFramework
1580
1581**返回值:**
1582
1583| 类型 | 说明 |
1584| -------- | -------- |
1585| Promise&lt;boolean&gt; | Promise对象。返回true表示结束输入会话成功,返回false表示结束输入会话失败。 |
1586
1587**错误码:**
1588
1589以下错误码的详细介绍请参见[输入法框架错误码](errorcode-inputmethod-framework.md)。
1590
1591| 错误码ID | 错误信息                             |
1592| -------- | -------------------------------------- |
1593| 12800003 | input method client error.             |
1594| 12800008 | input method manager service error. |
1595
1596**示例:**
1597
1598```ts
1599import { BusinessError } from '@kit.BasicServicesKit';
1600
1601try {
1602  inputMethodController.stopInputSession().then((result: boolean) => {
1603    if (result) {
1604      console.log('Succeeded in stopping inputSession.');
1605    } else {
1606      console.error('Failed to stopInputSession.');
1607    }
1608  }).catch((err: BusinessError) => {
1609    console.error(`Failed to stopInputSession: ${JSON.stringify(err)}`);
1610  })
1611} catch(err) {
1612  console.error(`Failed to stopInputSession: ${JSON.stringify(err)}`);
1613}
1614```
1615
1616### showSoftKeyboard<sup>9+</sup>
1617
1618showSoftKeyboard(callback: AsyncCallback&lt;void&gt;): void
1619
1620显示输入法软键盘。使用callback异步回调。
1621
1622> **说明:**
1623>
1624> 该接口需要编辑框与输入法绑定时才能调用,即点击编辑控件后,才可调用显示当前输入法的软键盘。
1625
1626**需要权限:** ohos.permission.CONNECT_IME_ABILITY,仅系统应用可用。
1627
1628**系统能力:**  SystemCapability.MiscServices.InputMethodFramework
1629
1630**参数:**
1631
1632| 参数名   | 类型                  | 必填 | 说明       |
1633| -------- | ------------------------- | ---- | ---------- |
1634| callback | AsyncCallback&lt;void&gt; | 是   | 回调函数。当软键盘显示成功。err为undefined,否则为错误对象。 |
1635
1636**错误码:**
1637
1638以下错误码的详细介绍请参见[输入法框架错误码](errorcode-inputmethod-framework.md),[通用错误码说明文档](../errorcode-universal.md)。
1639
1640| 错误码ID | 错误信息                             |
1641| -------- | -------------------------------------- |
1642| 201      | permissions check fails.  |
1643| 12800003 | input method client error.             |
1644| 12800008 | input method manager service error. |
1645
1646**示例:**
1647
1648```ts
1649import { BusinessError } from '@kit.BasicServicesKit';
1650
1651inputMethodController.showSoftKeyboard((err: BusinessError) => {
1652  if (!err) {
1653    console.log('Succeeded in showing softKeyboard.');
1654  } else {
1655    console.error(`Failed to show softKeyboard: ${JSON.stringify(err)}`);
1656  }
1657})
1658```
1659
1660### showSoftKeyboard<sup>9+</sup>
1661
1662showSoftKeyboard(): Promise&lt;void&gt;
1663
1664显示输入法软键盘。使用Promise异步回调。
1665
1666> **说明:**
1667>
1668> 该接口需要编辑框与输入法绑定时才能调用,即点击编辑控件后,才可调用显示当前输入法的软键盘。
1669
1670**需要权限:** ohos.permission.CONNECT_IME_ABILITY,仅系统应用可用。
1671
1672**系统能力:**  SystemCapability.MiscServices.InputMethodFramework
1673
1674**返回值:**
1675
1676| 类型                | 说明                      |
1677| ------------------- | ------------------------- |
1678| Promise&lt;void&gt; | 无返回结果的Promise对象。 |
1679
1680**错误码:**
1681
1682以下错误码的详细介绍请参见[输入法框架错误码](errorcode-inputmethod-framework.md),[通用错误码说明文档](../errorcode-universal.md)。
1683
1684| 错误码ID | 错误信息                             |
1685| -------- | -------------------------------------- |
1686| 201      | permissions check fails.  |
1687| 12800003 | input method client error.             |
1688| 12800008 | input method manager service error. |
1689
1690**示例:**
1691
1692```ts
1693import { BusinessError } from '@kit.BasicServicesKit';
1694
1695inputMethodController.showSoftKeyboard().then(() => {
1696  console.log('Succeeded in showing softKeyboard.');
1697}).catch((err: BusinessError) => {
1698  console.error(`Failed to show softKeyboard: ${JSON.stringify(err)}`);
1699});
1700```
1701
1702### hideSoftKeyboard<sup>9+</sup>
1703
1704hideSoftKeyboard(callback: AsyncCallback&lt;void&gt;): void
1705
1706隐藏输入法软键盘。使用callback异步回调。
1707
1708> **说明:**
1709>
1710> 该接口需要编辑框与输入法绑定时才能调用,即点击编辑控件后,才可调用隐藏当前输入法的软键盘。
1711
1712**需要权限:** ohos.permission.CONNECT_IME_ABILITY,仅系统应用可用。
1713
1714**系统能力:**  SystemCapability.MiscServices.InputMethodFramework
1715
1716**参数:**
1717
1718| 参数名   | 类型                  | 必填 | 说明       |
1719| -------- | ------------------------- | ---- | ---------- |
1720| callback | AsyncCallback&lt;void&gt; | 是   | 回调函数。当软键盘隐藏成功。err为undefined,否则为错误对象。 |
1721
1722**错误码:**
1723
1724以下错误码的详细介绍请参见[输入法框架错误码](errorcode-inputmethod-framework.md),[通用错误码说明文档](../errorcode-universal.md)。
1725
1726| 错误码ID | 错误信息                             |
1727| -------- | -------------------------------------- |
1728| 201      | permissions check fails.  |
1729| 12800003 | input method client error.             |
1730| 12800008 | input method manager service error. |
1731
1732**示例:**
1733
1734```ts
1735import { BusinessError } from '@kit.BasicServicesKit';
1736
1737inputMethodController.hideSoftKeyboard((err: BusinessError) => {
1738  if (!err) {
1739    console.log('Succeeded in hiding softKeyboard.');
1740  } else {
1741    console.error(`Failed to hide softKeyboard: ${JSON.stringify(err)}`);
1742  }
1743})
1744```
1745
1746### hideSoftKeyboard<sup>9+</sup>
1747
1748hideSoftKeyboard(): Promise&lt;void&gt;
1749
1750隐藏输入法软键盘。使用Promise异步回调。
1751
1752> **说明:**
1753>
1754> 该接口需要编辑框与输入法绑定时才能调用,即点击编辑控件后,才可调用隐藏当前输入法的软键盘。
1755
1756**需要权限:** ohos.permission.CONNECT_IME_ABILITY,仅系统应用可用。
1757
1758**系统能力:**  SystemCapability.MiscServices.InputMethodFramework
1759
1760**返回值:**
1761
1762| 类型                | 说明                      |
1763| ------------------- | ------------------------- |
1764| Promise&lt;void&gt; | 无返回结果的Promise对象。 |
1765
1766**错误码:**
1767
1768以下错误码的详细介绍请参见[输入法框架错误码](errorcode-inputmethod-framework.md),[通用错误码说明文档](../errorcode-universal.md)。
1769
1770| 错误码ID | 错误信息                             |
1771| -------- | -------------------------------------- |
1772| 201      | permissions check fails.  |
1773| 12800003 | input method client error.             |
1774| 12800008 | input method manager service error. |
1775
1776**示例:**
1777
1778```ts
1779import { BusinessError } from '@kit.BasicServicesKit';
1780
1781inputMethodController.hideSoftKeyboard().then(() => {
1782  console.log('Succeeded in hiding softKeyboard.');
1783}).catch((err: BusinessError) => {
1784  console.error(`Failed to hide softKeyboard: ${JSON.stringify(err)}`);
1785});
1786```
1787
1788### stopInput<sup>(deprecated)</sup>
1789
1790stopInput(callback: AsyncCallback&lt;boolean&gt;): void
1791
1792结束输入会话。使用callback异步回调。
1793
1794> **说明:**
1795>
1796> 该接口需要编辑框与输入法绑定时才能调用,即点击编辑控件后,才可调用该接口结束输入会话。
1797>
1798> 从API version 6开始支持,从API version 9开始废弃,建议使用[stopInputSession()](#stopinputsession9)替代。
1799
1800**系统能力:** SystemCapability.MiscServices.InputMethodFramework
1801
1802**参数:**
1803
1804| 参数名 | 类型 | 必填 | 说明 |
1805| -------- | -------- | -------- | -------- |
1806| callback | AsyncCallback&lt;boolean&gt; | 是 | 回调函数。当会话结束成功,err为undefined,data为true;否则为错误对象。 |
1807
1808**示例:**
1809
1810```ts
1811import { BusinessError } from '@kit.BasicServicesKit';
1812
1813inputMethodController.stopInput((err: BusinessError, result: boolean) => {
1814  if (err) {
1815    console.error(`Failed to stopInput: ${JSON.stringify(err)}`);
1816    return;
1817  }
1818  if (result) {
1819    console.log('Succeeded in stopping input.');
1820  } else {
1821    console.error('Failed to stopInput.');
1822  }
1823});
1824```
1825
1826### stopInput<sup>(deprecated)</sup>
1827
1828stopInput(): Promise&lt;boolean&gt;
1829
1830结束输入会话。使用promise异步回调。
1831
1832> **说明:**
1833>
1834> 该接口需要编辑框与输入法绑定时才能调用,即点击编辑控件后,才可调用该接口结束输入会话。
1835>
1836> 从API version 6开始支持,从API version 9开始废弃,建议使用[stopInputSession()](#stopinputsession9)替代。
1837
1838**系统能力:** SystemCapability.MiscServices.InputMethodFramework
1839
1840**返回值:**
1841
1842| 类型 | 说明 |
1843| -------- | -------- |
1844| Promise&lt;boolean&gt; | Promise对象。返回true表示会话结束成功;返回false表示会话结束失败。 |
1845
1846**示例:**
1847
1848```ts
1849import { BusinessError } from '@kit.BasicServicesKit';
1850
1851inputMethodController.stopInput().then((result: boolean) => {
1852  if (result) {
1853    console.log('Succeeded in stopping input.');
1854  } else {
1855    console.error('Failed to stopInput.');
1856  }
1857}).catch((err: BusinessError) => {
1858  console.error(`Failed to stopInput: ${JSON.stringify(err)}`);
1859})
1860```
1861
1862### on('insertText')<sup>10+</sup>
1863
1864on(type: 'insertText', callback: (text: string) => void): void
1865
1866订阅输入法应用插入文本事件。使用callback异步回调。
1867
1868**系统能力:** SystemCapability.MiscServices.InputMethodFramework
1869
1870**参数:**
1871
1872| 参数名   | 类型                                                         | 必填 | 说明                                                         |
1873| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
1874| type     | string                                                       | 是   | 设置监听类型,固定取值为'insertText'。 |
1875| callback | (text: string) => void | 是   | 回调函数,返回需要插入的文本内容。<br/>根据传入的文本,在回调函数中操作编辑框中的内容。 |
1876
1877**错误码:**
1878
1879以下错误码的详细介绍请参见[输入法框架错误码](errorcode-inputmethod-framework.md),[通用错误码说明文档](../errorcode-universal.md)。
1880
1881| 错误码ID | 错误信息                             |
1882| -------- | -------------------------------------- |
1883| 401      | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.           |
1884| 12800009 | input method client detached. |
1885
1886**示例:**
1887
1888```ts
1889function callback1(text: string) {
1890  console.info('Succeeded in getting callback1 data: ' + JSON.stringify(text));
1891}
1892
1893function callback2(text: string) {
1894  console.info('Succeeded in getting callback2 data: ' + JSON.stringify(text));
1895}
1896
1897try {
1898  inputMethodController.on('insertText', callback1);
1899  inputMethodController.on('insertText', callback2);
1900  //仅取消insertText的callback1的回调
1901  inputMethodController.off('insertText', callback1);
1902  //取消insertText的所有回调
1903  inputMethodController.off('insertText');
1904} catch(err) {
1905  console.error(`Failed to subscribe insertText: ${JSON.stringify(err)}`);
1906}
1907```
1908
1909### off('insertText')<sup>10+</sup>
1910
1911off(type: 'insertText', callback?: (text: string) => void): void
1912
1913取消订阅输入法应用插入文本事件。
1914
1915**系统能力:** SystemCapability.MiscServices.InputMethodFramework
1916
1917**参数:**
1918
1919| 参数名   | 类型                   | 必填 | 说明                                                         |
1920| -------- | ---------------------- | ---- | ------------------------------------------------------------ |
1921| type     | string                 | 是   | 设置监听类型,固定取值为'insertText'。 |
1922| callback | (text: string) => void | 否   | 取消订阅的回调函数,需要与on接口传入的保持一致。<br/>参数不填写时,取消订阅type对应的所有回调事件。 |
1923
1924**示例:**
1925
1926```ts
1927let onInsertTextCallback = (text: string) => {
1928    console.log(`Succeeded in subscribing insertText: ${text}`);
1929};
1930inputMethodController.off('insertText', onInsertTextCallback);
1931inputMethodController.off('insertText');
1932```
1933
1934### on('deleteLeft')<sup>10+</sup>
1935
1936on(type: 'deleteLeft', callback: (length: number) => void): void
1937
1938订阅输入法应用向左删除事件。使用callback异步回调。
1939
1940**系统能力:** SystemCapability.MiscServices.InputMethodFramework
1941
1942**参数:**
1943
1944| 参数名   | 类型 | 必填 | 说明 |
1945| -------- | ----- | ---- | ----- |
1946| type     | string  | 是   | 设置监听类型,固定取值为'deleteLeft'。|
1947| callback | (length: number) => void | 是   | 回调函数,返回需要向左删除的文本长度。<br/>根据传入的删除长度,在回调函数中操作编辑框中的文本。 |
1948
1949**错误码:**
1950
1951以下错误码的详细介绍请参见[输入法框架错误码](errorcode-inputmethod-framework.md),[通用错误码说明文档](../errorcode-universal.md)。
1952
1953| 错误码ID | 错误信息                             |
1954| -------- | -------------------------------------- |
1955| 401      | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.           |
1956| 12800009 | input method client detached. |
1957
1958**示例:**
1959
1960```ts
1961try {
1962  inputMethodController.on('deleteLeft', (length: number) => {
1963    console.log(`Succeeded in subscribing deleteLeft, length: ${length}`);
1964  });
1965} catch(err) {
1966  console.error(`Failed to subscribe deleteLeft: ${JSON.stringify(err)}`);
1967}
1968```
1969
1970### off('deleteLeft')<sup>10+</sup>
1971
1972off(type: 'deleteLeft', callback?: (length: number) => void): void
1973
1974取消订阅输入法应用向左删除文本事件。
1975
1976**系统能力:** SystemCapability.MiscServices.InputMethodFramework
1977
1978**参数:**
1979
1980| 参数名   | 类型                     | 必填 | 说明                                                         |
1981| -------- | ------------------------ | ---- | ------------------------------------------------------------ |
1982| type     | string                   | 是   | 设置监听,固定取值为'deleteLeft'。 |
1983| callback | (length: number) => void | 否   | 取消订阅的回调函数,需要与on接口传入的保持一致。<br>参数不填写时,取消订阅type对应的所有回调事件。 |
1984
1985**示例:**
1986
1987```ts
1988let onDeleteLeftCallback = (length: number) => {
1989    console.log(`Succeeded in subscribing deleteLeft, length: ${length}`);
1990};
1991inputMethodController.off('deleteLeft', onDeleteLeftCallback);
1992inputMethodController.off('deleteLeft');
1993```
1994
1995### on('deleteRight')<sup>10+</sup>
1996
1997on(type: 'deleteRight', callback: (length: number) => void): void
1998
1999订阅输入法应用向右删除事件。使用callback异步回调。
2000
2001**系统能力:** SystemCapability.MiscServices.InputMethodFramework
2002
2003**参数:**
2004
2005| 参数名   | 类型 | 必填 | 说明 |
2006| -------- | ----- | ---- | ----- |
2007| type     | string  | 是   | 设置监听类型,固定取值为'deleteRight'。|
2008| callback | (length: number) => void | 是   | 回调函数,返回需要向右删除的文本长度。<br/>根据传入的删除长度,在回调函数中操作编辑框中的文本。 |
2009
2010**错误码:**
2011
2012以下错误码的详细介绍请参见[输入法框架错误码](errorcode-inputmethod-framework.md),[通用错误码说明文档](../errorcode-universal.md)。
2013
2014| 错误码ID | 错误信息                             |
2015| -------- | -------------------------------------- |
2016| 401      | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.           |
2017| 12800009 | input method client detached. |
2018
2019**示例:**
2020
2021```ts
2022try {
2023  inputMethodController.on('deleteRight', (length: number) => {
2024    console.log(`Succeeded in subscribing deleteRight, length: ${length}`);
2025  });
2026} catch(err) {
2027  console.error(`Failed to subscribe deleteRight: ${JSON.stringify(err)}`);
2028}
2029```
2030
2031### off('deleteRight')<sup>10+</sup>
2032
2033off(type: 'deleteRight', callback?: (length: number) => void): void
2034
2035取消订阅输入法应用向右删除文本事件。
2036
2037**系统能力:** SystemCapability.MiscServices.InputMethodFramework
2038
2039**参数:**
2040
2041| 参数名   | 类型                     | 必填 | 说明                                                         |
2042| -------- | ------------------------ | ---- | ------------------------------------------------------------ |
2043| type     | string                   | 是   | 设置监听类型,固定取值为`deleteRight`。 |
2044| callback | (length: number) => void | 否   | 取消订阅的回调函数,需要与on接口传入的保持一致。<br>参数不填写时,取消订阅type对应的所有回调事件。 |
2045
2046**示例:**
2047
2048```ts
2049let onDeleteRightCallback = (length: number) => {
2050    console.log(`Succeeded in subscribing deleteRight, length: ${length}`);
2051};
2052inputMethodController.off('deleteRight', onDeleteRightCallback);
2053inputMethodController.off('deleteRight');
2054```
2055
2056### on('sendKeyboardStatus')<sup>10+</sup>
2057
2058on(type: 'sendKeyboardStatus', callback: (keyboardStatus: KeyboardStatus) => void): void
2059
2060订阅输入法应用发送输入法软键盘状态事件。使用callback异步回调。
2061
2062**系统能力:** SystemCapability.MiscServices.InputMethodFramework
2063
2064**参数:**
2065
2066| 参数名   | 类型  | 必填 | 说明    |
2067| -------- | ------ | ---- | ---- |
2068| type     | string  | 是   | 设置监听类型,固定取值为'sendKeyboardStatus'。 |
2069| callback | (keyboardStatus: [KeyboardStatus](#keyboardstatus10)) => void | 是   | 回调函数,返回软键盘状态。<br/>根据传入的软键盘状态,在回调函数中做相应操作。 |
2070
2071**错误码:**
2072
2073以下错误码的详细介绍请参见[输入法框架错误码](errorcode-inputmethod-framework.md),[通用错误码说明文档](../errorcode-universal.md)。
2074
2075| 错误码ID | 错误信息                             |
2076| -------- | -------------------------------------- |
2077| 401      | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.           |
2078| 12800009 | input method client detached. |
2079
2080**示例:**
2081
2082```ts
2083try {
2084  inputMethodController.on('sendKeyboardStatus', (keyboardStatus: inputMethod.KeyboardStatus) => {
2085    console.log(`Succeeded in subscribing sendKeyboardStatus, keyboardStatus: ${keyboardStatus}`);
2086  });
2087} catch(err) {
2088  console.error(`Failed to subscribe sendKeyboardStatus: ${JSON.stringify(err)}`);
2089}
2090```
2091
2092### off('sendKeyboardStatus')<sup>10+</sup>
2093
2094off(type: 'sendKeyboardStatus', callback?: (keyboardStatus: KeyboardStatus) => void): void
2095
2096取消订阅输入法应用发送软键盘状态事件。
2097
2098**系统能力:** SystemCapability.MiscServices.InputMethodFramework
2099
2100**参数:**
2101
2102| 参数名   | 类型                                                         | 必填 | 说明                                                         |
2103| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
2104| type     | string                                                       | 是   | 设置监听类型,固定取值为'sendKeyboardStatus'。 |
2105| callback | (keyboardStatus: [KeyboardStatus](#keyboardstatus10)) => void | 否   | 取消订阅的回调函数。参数不填写时,取消订阅type对应的所有回调事件。 |
2106
2107**示例:**
2108
2109```ts
2110let onSendKeyboardStatus = (keyboardStatus: inputMethod.KeyboardStatus) => {
2111    console.log(`Succeeded in subscribing sendKeyboardStatus, keyboardStatus: ${keyboardStatus}`);
2112};
2113inputMethodController.off('sendKeyboardStatus', onSendKeyboardStatus);
2114inputMethodController.off('sendKeyboardStatus');
2115```
2116
2117### on('sendFunctionKey')<sup>10+</sup>
2118
2119on(type: 'sendFunctionKey', callback: (functionKey: FunctionKey) => void): void
2120
2121订阅输入法应用发送功能键事件。使用callback异步回调。
2122
2123**系统能力:** SystemCapability.MiscServices.InputMethodFramework
2124
2125**参数:**
2126
2127| 参数名   | 类型  | 必填 | 说明     |
2128| -------- | -------- | ---- | ----- |
2129| type     | string  | 是   | 设置监听类型,固定取值为'sendFunctionKey'。|
2130| callback | (functionKey: [FunctionKey](#functionkey10)) => void | 是   | 回调函数,返回输入法应用发送的功能键信息。<br/>根据返回的功能键信息,做相应操作。 |
2131
2132**错误码:**
2133
2134以下错误码的详细介绍请参见[输入法框架错误码](errorcode-inputmethod-framework.md),[通用错误码说明文档](../errorcode-universal.md)。
2135
2136| 错误码ID | 错误信息                             |
2137| -------- | -------------------------------------- |
2138| 401      | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.           |
2139| 12800009 | input method client detached. |
2140
2141**示例:**
2142
2143```ts
2144try {
2145  inputMethodController.on('sendFunctionKey', (functionKey: inputMethod.FunctionKey) => {
2146    console.log(`Succeeded in subscribing sendFunctionKey, functionKey.enterKeyType: ${functionKey.enterKeyType}`);
2147  });
2148} catch(err) {
2149  console.error(`Failed to subscribe sendFunctionKey: ${JSON.stringify(err)}`);
2150}
2151```
2152
2153### off('sendFunctionKey')<sup>10+</sup>
2154
2155off(type: 'sendFunctionKey', callback?: (functionKey: FunctionKey) => void): void
2156
2157取消订阅输入法应用发送功能键事件。
2158
2159**系统能力:** SystemCapability.MiscServices.InputMethodFramework
2160
2161**参数:**
2162
2163| 参数名   | 类型                                                 | 必填 | 说明                                                         |
2164| -------- | ---------------------------------------------------- | ---- | ------------------------------------------------------------ |
2165| type     | string                                               | 是   | 设置监听类型,固定取值为'sendFunctionKey'。 |
2166| callback | (functionKey: [FunctionKey](#functionkey10)) => void | 否   | 取消订阅的回调函数,需要与on接口传入的保持一致。<br>参数不填写时,取消订阅type对应的所有回调事件。 |
2167
2168**示例:**
2169
2170```ts
2171let onSendFunctionKey = (functionKey: inputMethod.FunctionKey) => {
2172    console.log(`Succeeded in subscribing sendFunctionKey, functionKey: ${functionKey.enterKeyType}`);
2173};
2174inputMethodController.off('sendFunctionKey', onSendFunctionKey);
2175inputMethodController.off('sendFunctionKey');
2176```
2177
2178### on('moveCursor')<sup>10+</sup>
2179
2180on(type: 'moveCursor', callback: (direction: Direction) => void): void
2181
2182订阅输入法应用移动光标事件。使用callback异步回调。
2183
2184**系统能力:** SystemCapability.MiscServices.InputMethodFramework
2185
2186**参数:**
2187
2188| 参数名   | 类型 | 必填 | 说明   |
2189| -------- | ------ | ---- | ------ |
2190| type     | string | 是   | 设置监听类型,固定取值为'moveCursor'。 |
2191| callback | callback: (direction: [Direction<sup>10+</sup>](#direction10)) => void | 是   | 回调函数,返回光标信息。<br/>根据返回的光标移动方向,改变光标位置,如光标向上或向下。  |
2192
2193**错误码:**
2194
2195以下错误码的详细介绍请参见[输入法框架错误码](errorcode-inputmethod-framework.md),[通用错误码说明文档](../errorcode-universal.md)。
2196
2197| 错误码ID | 错误信息                           |
2198| -------- | -------------------------------- |
2199| 401      | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.           |
2200| 12800009 | input method client detached. |
2201
2202**示例:**
2203
2204```ts
2205try {
2206  inputMethodController.on('moveCursor', (direction: inputMethod.Direction) => {
2207    console.log(`Succeeded in subscribing moveCursor, direction: ${direction}`);
2208  });
2209} catch(err) {
2210  console.error(`Failed to subscribe moveCursor: ${JSON.stringify(err)}`);
2211}
2212```
2213
2214### off('moveCursor')<sup>10+</sup>
2215
2216off(type: 'moveCursor', callback?: (direction: Direction) => void): void
2217
2218取消订阅输入法应用移动光标事件。
2219
2220**系统能力:** SystemCapability.MiscServices.InputMethodFramework
2221
2222**参数:**
2223
2224| 参数名  | 类型    | 必填 | 说明  |
2225| ------ | ------ | ---- | ---- |
2226| type   | string | 是   | 设置监听类型,固定取值为'moveCursor'。 |
2227| callback | (direction: [Direction<sup>10+</sup>](#direction10)) => void | 否 | 取消订阅的回调函数,需要与on接口传入的保持一致。<br>参数不填写时,取消订阅type对应的所有回调事件。 |
2228
2229**示例:**
2230
2231```ts
2232let onMoveCursorCallback = (direction: inputMethod.Direction) => {
2233    console.log(`Succeeded in subscribing moveCursor, direction: ${direction}`);
2234};
2235inputMethodController.off('moveCursor', onMoveCursorCallback);
2236inputMethodController.off('moveCursor');
2237```
2238
2239### on('handleExtendAction')<sup>10+</sup>
2240
2241on(type: 'handleExtendAction', callback: (action: ExtendAction) => void): void
2242
2243订阅输入法应用发送扩展编辑操作事件。使用callback异步回调。
2244
2245**系统能力:** SystemCapability.MiscServices.InputMethodFramework
2246
2247**参数:**
2248
2249| 参数名   | 类型  | 必填 | 说明   |
2250| -------- | ------ | ---- | -------- |
2251| type     | string    | 是   | 设置监听类型,固定取值为'handleExtendAction'。 |
2252| callback | callback: (action: [ExtendAction](#extendaction10)) => void | 是   | 回调函数,返回扩展编辑操作类型。<br/>根据传入的扩展编辑操作类型,做相应的操作,如剪切、复制等。|
2253
2254**错误码:**
2255
2256以下错误码的详细介绍请参见[输入法框架错误码](errorcode-inputmethod-framework.md),[通用错误码说明文档](../errorcode-universal.md)。
2257
2258| 错误码ID | 错误信息                             |
2259| -------- | -------------------------------------- |
2260| 401      | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.           |
2261| 12800009 | input method client detached. |
2262
2263**示例:**
2264
2265```ts
2266try {
2267  inputMethodController.on('handleExtendAction', (action: inputMethod.ExtendAction) => {
2268    console.log(`Succeeded in subscribing handleExtendAction, action: ${action}`);
2269  });
2270} catch(err) {
2271  console.error(`Failed to subscribe handleExtendAction: ${JSON.stringify(err)}`);
2272}
2273```
2274
2275### off('handleExtendAction')<sup>10+</sup>
2276
2277off(type: 'handleExtendAction', callback?: (action: ExtendAction) => void): void
2278
2279取消订阅输入法应用发送扩展编辑操作事件。使用callback异步回调。
2280
2281**系统能力:** SystemCapability.MiscServices.InputMethodFramework
2282
2283**参数:**
2284
2285| 参数名 | 类型   | 必填 | 说明  |
2286| ------ | ------ | ---- | ------- |
2287| type   | string | 是   | 设置监听类型,固定取值为'handleExtendAction'。 |
2288| callback | (action: [ExtendAction](#extendaction10)) => void | 否 | 取消订阅的回调函数,需要与on接口传入的保持一致。<br>参数不填写时,取消订阅type对应的所有回调事件。 |
2289
2290**示例:**
2291
2292```ts
2293try {
2294  let onHandleExtendActionCallback = (action: inputMethod.ExtendAction) => {
2295    console.log(`Succeeded in subscribing handleExtendAction, action: ${action}`);
2296  };
2297  inputMethodController.off('handleExtendAction', onHandleExtendActionCallback);
2298  inputMethodController.off('handleExtendAction');
2299} catch(err) {
2300  console.error(`Failed to subscribe handleExtendAction: ${JSON.stringify(err)}`);
2301}
2302```
2303
2304### on('selectByRange')<sup>10+</sup>
2305
2306on(type: 'selectByRange', callback: Callback&lt;Range&gt;): void
2307
2308订阅输入法应用按范围选中文本事件。使用callback异步回调。
2309
2310**系统能力:** SystemCapability.MiscServices.InputMethodFramework
2311
2312**参数:**
2313
2314| 参数名   | 类型     | 必填 | 说明     |
2315| -------- | ---- | ---- | ------- |
2316| type     | string  | 是   | 设置监听类型,固定取值为'selectByRange'。 |
2317| callback | Callback&lt;[Range](#range10)&gt; | 是   | 回调函数,返回需要选中的文本范围。<br/>根据传入的文本范围,开发者在回调函数中编辑框中相应文本。|
2318
2319**错误码:**
2320
2321以下错误码的详细介绍请参见[通用错误码说明文档](../errorcode-universal.md)。
2322
2323| 错误码ID | 错误信息                                                |
2324| -------- | ------------------------------------------------------- |
2325| 401      | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.           |
2326
2327**示例:**
2328
2329```ts
2330try {
2331  inputMethodController.on('selectByRange', (range: inputMethod.Range) => {
2332    console.log(`Succeeded in subscribing selectByRange: start: ${range.start} , end: ${range.end}`);
2333  });
2334} catch(err) {
2335  console.error(`Failed to subscribe selectByRange: ${JSON.stringify(err)}`);
2336}
2337```
2338
2339### off('selectByRange')<sup>10+</sup>
2340
2341off(type: 'selectByRange', callback?:  Callback&lt;Range&gt;): void
2342
2343取消订阅输入法应用按范围选中文本事件。使用callback异步回调。
2344
2345**系统能力:** SystemCapability.MiscServices.InputMethodFramework
2346
2347**参数:**
2348
2349| 参数名   | 类型                              | 必填 | 说明                                                         |
2350| -------- | --------------------------------- | ---- | ------------------------------------------------------------ |
2351| type     | string                            | 是   | 设置监听类型,固定取值为'selectByRange'。 |
2352| callback | Callback&lt;[Range](#range10)&gt; | 否   | 取消订阅的回调函数,需要与on接口传入的保持一致。<br>参数不填写时,取消订阅type对应的所有回调事件。 |
2353
2354**示例:**
2355
2356```ts
2357try {
2358  let onSelectByRangeCallback = (range: inputMethod.Range) => {
2359    console.log(`Succeeded in subscribing selectByRange, start: ${range.start} , end: ${range.end}`);
2360  };
2361  inputMethodController.off('selectByRange', onSelectByRangeCallback);
2362  inputMethodController.off('selectByRange');
2363} catch(err) {
2364  console.error(`Failed to subscribe selectByRange: ${JSON.stringify(err)}`);
2365}
2366```
2367
2368### on('selectByMovement')<sup>10+</sup>
2369
2370on(type: 'selectByMovement', callback: Callback&lt;Movement&gt;): void
2371
2372订阅输入法应用按光标移动方向,选中文本事件。使用callback异步回调。
2373
2374**系统能力:** SystemCapability.MiscServices.InputMethodFramework
2375
2376**参数:**
2377
2378| 参数名   | 类型   | 必填 | 说明     |
2379| -------- | ----- | ---- | ------ |
2380| type     | string  | 是   | 设置监听类型,固定取值为'selectByMovement'。 |
2381| callback | Callback&lt;[Movement](#movement10)&gt; | 是   | 回调函数,返回光标移动的方向。<br/>根据传入的光标移动方向,选中编辑框中相应文本。 |
2382
2383**错误码:**
2384
2385以下错误码的详细介绍请参见[通用错误码说明文档](../errorcode-universal.md)。
2386
2387| 错误码ID | 错误信息                                                |
2388| -------- | ------------------------------------------------------- |
2389| 401      | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.           |
2390
2391**示例:**
2392
2393```ts
2394try {
2395  inputMethodController.on('selectByMovement', (movement: inputMethod.Movement) => {
2396    console.log('Succeeded in subscribing selectByMovement: direction: ' + movement.direction);
2397  });
2398} catch(err) {
2399  console.error(`Failed to subscribe selectByMovement: ${JSON.stringify(err)}`);
2400}
2401```
2402
2403### off('selectByMovement')<sup>10+</sup>
2404
2405off(type: 'selectByMovement', callback?: Callback&lt;Movement&gt;): void
2406
2407取消订阅输入法应用按光标移动方向,选中文本事件。使用callback异步回调。
2408
2409**系统能力:** SystemCapability.MiscServices.InputMethodFramework
2410
2411**参数:**
2412
2413| 参数名   | 类型                                 | 必填 | 说明                                                         |
2414| -------- | ------------------------------------ | ---- | ------------------------------------------------------------ |
2415| type     | string                               | 是   | 设置监听类型,固定取值为'selectByMovement'。 |
2416| callback | Callback&lt;[Movement](#movement10)> | 否   | 取消订阅的回调函数,需要与on接口传入的保持一致。<br>参数不填写时,取消订阅type对应的所有回调事件。 |
2417
2418**示例:**
2419
2420```ts
2421try {
2422  let onSelectByMovementCallback = (movement: inputMethod.Movement) => {
2423    console.log(`Succeeded in subscribing selectByMovement, movement.direction: ${movement.direction}`);
2424  };
2425  inputMethodController.off('selectByMovement', onSelectByMovementCallback);
2426  inputMethodController.off('selectByMovement');
2427} catch(err) {
2428  console.error(`Failed to unsubscribing selectByMovement: ${JSON.stringify(err)}`);
2429}
2430```
2431
2432### on('getLeftTextOfCursor')<sup>10+</sup>
2433
2434on(type: 'getLeftTextOfCursor', callback: (length: number) => string): void
2435
2436订阅输入法应用获取光标左侧指定长度文本事件。使用callback异步回调。
2437
2438**系统能力:** SystemCapability.MiscServices.InputMethodFramework
2439
2440**参数:**
2441
2442| 参数名   | 类型   | 必填 | 说明     |
2443| -------- | ----- | ---- | ------ |
2444| type     | string  | 是   | 设置监听类型,固定取值为'getLeftTextOfCursor'。 |
2445| callback | (length: number) => string | 是   | 回调函数,获取编辑框最新状态下光标左侧指定长度的文本内容并返回。 |
2446
2447**错误码:**
2448
2449以下错误码的详细介绍请参见[输入法框架错误码](errorcode-inputmethod-framework.md),[通用错误码说明文档](../errorcode-universal.md)。
2450
2451| 错误码ID | 错误信息                             |
2452| -------- | -------------------------------------- |
2453| 401      | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.           |
2454| 12800009 | input method client detached. |
2455
2456**示例:**
2457
2458```ts
2459try {
2460  inputMethodController.on('getLeftTextOfCursor', (length: number) => {
2461    console.info(`Succeeded in subscribing getLeftTextOfCursor, length: ${length}`);
2462    let text:string = "";
2463    return text;
2464  });
2465} catch(err) {
2466  console.error(`Failed to unsubscribing getLeftTextOfCursor. err: ${JSON.stringify(err)}`);
2467}
2468```
2469
2470### off('getLeftTextOfCursor')<sup>10+</sup>
2471
2472off(type: 'getLeftTextOfCursor', callback?: (length: number) => string): void
2473
2474取消订阅输入法应用获取光标左侧指定长度文本事件。使用callback异步回调。
2475
2476**系统能力:** SystemCapability.MiscServices.InputMethodFramework
2477
2478**参数:**
2479
2480| 参数名 | 类型   | 必填 | 说明                                                         |
2481| ------ | ------ | ---- | ------------------------------------------------------------ |
2482| type   | string | 是   | 设置监听类型,固定取值为'getLeftTextOfCursor'。 |
2483| callback | (length: number) => string | 否  | 取消订阅的回调函数,需要与on接口传入的保持一致。<br>参数不填写时,取消订阅type对应的所有回调事件。|
2484
2485**示例:**
2486
2487```ts
2488try {
2489  let getLeftTextOfCursorCallback = (length: number) => {
2490    console.info(`Succeeded in unsubscribing getLeftTextOfCursor, length: ${length}`);
2491    let text:string = "";
2492    return text;
2493  };
2494  inputMethodController.off('getLeftTextOfCursor', getLeftTextOfCursorCallback);
2495  inputMethodController.off('getLeftTextOfCursor');
2496} catch(err) {
2497  console.error(`Failed to unsubscribing getLeftTextOfCursor. err: ${JSON.stringify(err)}`);
2498}
2499```
2500
2501### on('getRightTextOfCursor')<sup>10+</sup>
2502
2503on(type: 'getRightTextOfCursor', callback: (length: number) => string): void
2504
2505订阅输入法应用获取光标右侧指定长度文本事件。使用callback异步回调。
2506
2507**系统能力:** SystemCapability.MiscServices.InputMethodFramework
2508
2509**参数:**
2510
2511| 参数名   | 类型   | 必填 | 说明     |
2512| -------- | ----- | ---- | ------ |
2513| type     | string  | 是   | 设置监听类型,固定取值为'getRightTextOfCursor'。 |
2514| callback | (length: number) => string | 是   | 回调函数,获取编辑框最新状态下光标右侧指定长度的文本内容并返回。 |
2515
2516**错误码:**
2517
2518以下错误码的详细介绍请参见[输入法框架错误码](errorcode-inputmethod-framework.md),[通用错误码说明文档](../errorcode-universal.md)。
2519
2520| 错误码ID | 错误信息                             |
2521| -------- | -------------------------------------- |
2522| 401      | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.           |
2523| 12800009 | input method client detached. |
2524
2525**示例:**
2526
2527```ts
2528try {
2529  inputMethodController.on('getRightTextOfCursor', (length: number) => {
2530    console.info(`Succeeded in subscribing getRightTextOfCursor, length: ${length}`);
2531    let text:string = "";
2532    return text;
2533  });
2534} catch(err) {
2535  console.error(`Failed to subscribe getRightTextOfCursor. err: ${JSON.stringify(err)}`);
2536}
2537```
2538
2539### off('getRightTextOfCursor')<sup>10+</sup>
2540
2541off(type: 'getRightTextOfCursor', callback?: (length: number) => string): void
2542
2543取消订阅输入法应用获取光标右侧指定长度文本事件。使用callback异步回调。
2544
2545**系统能力:** SystemCapability.MiscServices.InputMethodFramework
2546
2547**参数:**
2548
2549| 参数名 | 类型   | 必填 | 说明                                                         |
2550| ------ | ------ | ---- | ------------------------------------------------------------ |
2551| type   | string | 是   | 设置监听类型,固定取值为'getRightTextOfCursor'。 |
2552| callback | (length: number) => string | 否  |取消订阅的回调函数,需要与on接口传入的保持一致。<br>参数不填写时,取消订阅type对应的所有回调事件。|
2553
2554**示例:**
2555
2556```ts
2557try {
2558  let getRightTextOfCursorCallback = (length: number) => {
2559    console.info(`Succeeded in unsubscribing getRightTextOfCursor, length: ${length}`);
2560    let text:string = "";
2561    return text;
2562  };
2563  inputMethodController.off('getRightTextOfCursor', getRightTextOfCursorCallback);
2564  inputMethodController.off('getRightTextOfCursor');
2565} catch(err) {
2566  console.error(`Failed to unsubscribing getRightTextOfCursor. err: ${JSON.stringify(err)}`);
2567}
2568```
2569
2570### on('getTextIndexAtCursor')<sup>10+</sup>
2571
2572on(type: 'getTextIndexAtCursor', callback: () => number): void
2573
2574订阅输入法应用获取光标处文本索引事件。使用callback异步回调。
2575
2576**系统能力:** SystemCapability.MiscServices.InputMethodFramework
2577
2578**参数:**
2579
2580| 参数名   | 类型   | 必填 | 说明     |
2581| -------- | ----- | ---- | ------ |
2582| type     | string  | 是   | 设置监听类型,固定取值为'getTextIndexAtCursor'。 |
2583| callback | () => number | 是   | 回调函数,获取编辑框最新状态下光标处文本索引并返回。 |
2584
2585**错误码:**
2586
2587以下错误码的详细介绍请参见[输入法框架错误码](errorcode-inputmethod-framework.md),[通用错误码说明文档](../errorcode-universal.md)。
2588
2589| 错误码ID | 错误信息                             |
2590| -------- | -------------------------------------- |
2591| 401      | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.           |
2592| 12800009 | input method client detached. |
2593
2594**示例:**
2595
2596```ts
2597try {
2598  inputMethodController.on('getTextIndexAtCursor', () => {
2599    console.info(`Succeeded in subscribing getTextIndexAtCursor.`);
2600    let index:number = 0;
2601    return index;
2602  });
2603} catch(err) {
2604  console.error(`Failed to subscribe getTextIndexAtCursor. err: ${JSON.stringify(err)}`);
2605}
2606```
2607
2608### off('getTextIndexAtCursor')<sup>10+</sup>
2609
2610off(type: 'getTextIndexAtCursor', callback?: () => number): void
2611
2612取消订阅输入法应用获取光标处文本索引事件。使用callback异步回调。
2613
2614**系统能力:** SystemCapability.MiscServices.InputMethodFramework
2615
2616**参数:**
2617
2618| 参数名 | 类型   | 必填 | 说明                                                         |
2619| ------ | ------ | ---- | ------------------------------------------------------------ |
2620| type   | string | 是   | 设置监听类型,固定取值为'getTextIndexAtCursor'。 |
2621| callback | () => number | 否  | 取消订阅的回调函数,需要与on接口传入的保持一致。<br>参数不填写时,取消订阅type对应的所有回调事件。|
2622
2623**示例:**
2624
2625```ts
2626try {
2627  let getTextIndexAtCursorCallback = () => {
2628    console.info(`Succeeded in unsubscribing getTextIndexAtCursor.`);
2629    let index:number = 0;
2630    return index;
2631  };
2632  inputMethodController.off('getTextIndexAtCursor', getTextIndexAtCursorCallback);
2633  inputMethodController.off('getTextIndexAtCursor');
2634} catch(err) {
2635  console.error(`Failed to unsubscribing getTextIndexAtCursor. err: ${JSON.stringify(err)}`);
2636}
2637```
2638
2639## InputMethodSetting<sup>8+</sup>
2640
2641下列API均需使用[getSetting](#inputmethodgetsetting9)获取到InputMethodSetting实例后,通过实例调用。
2642
2643### on('imeChange')<sup>9+</sup>
2644
2645on(type: 'imeChange', callback: (inputMethodProperty: InputMethodProperty, inputMethodSubtype: InputMethodSubtype) => void): void
2646
2647订阅输入法及子类型变化监听事件。使用callback异步回调。
2648
2649**系统能力:** SystemCapability.MiscServices.InputMethodFramework
2650
2651**参数:**
2652
2653| 参数名   | 类型                            | 必填 | 说明                                                         |
2654| -------- | ------------------------------- | ---- | ------------------------------------------------------------ |
2655| type     | string                        | 是   | 设置监听类型,固定取值为'imeChange'。 |
2656| callback | (inputMethodProperty: [InputMethodProperty](#inputmethodproperty8), inputMethodSubtype: [InputMethodSubtype](./js-apis-inputmethod-subtype.md#inputmethodsubtype)) => void  | 是 | 回调函数,返回输入法属性对象及子类型对象。 |
2657
2658**示例:**
2659
2660```ts
2661import { InputMethodSubtype } from '@kit.IMEKit';
2662try {
2663  inputMethodSetting.on('imeChange', (inputMethodProperty: inputMethod.InputMethodProperty, inputMethodSubtype: InputMethodSubtype) => {
2664    console.log('Succeeded in subscribing imeChange: inputMethodProperty: ' + JSON.stringify(inputMethodProperty) + " , inputMethodSubtype: " + JSON.stringify(inputMethodSubtype));
2665  });
2666} catch(err) {
2667  console.error(`Failed to unsubscribing inputMethodProperty. err: ${JSON.stringify(err)}`);
2668}
2669```
2670
2671### off('imeChange')<sup>9+</sup>
2672
2673off(type: 'imeChange', callback?: (inputMethodProperty: InputMethodProperty, inputMethodSubtype: InputMethodSubtype) => void): void
2674
2675取消订阅输入法及子类型变化监听事件。使用callback异步回调。
2676
2677**系统能力:** SystemCapability.MiscServices.InputMethodFramework
2678
2679**参数:**
2680
2681| 参数名   | 类型    | 必填 | 说明          |
2682| -------- | --------- | ---- | --------------- |
2683| type     | string    | 是   | 设置监听类型,固定取值为'imeChange'。 |
2684| callback | (inputMethodProperty: [InputMethodProperty](#inputmethodproperty8), inputMethodSubtype: [InputMethodSubtype](./js-apis-inputmethod-subtype.md#inputmethodsubtype)) => void  | 否 | 回调函数,返回取消订阅的输入法属性对象及子类型对象。 |
2685
2686**示例:**
2687
2688```ts
2689inputMethodSetting.off('imeChange');
2690```
2691
2692### listInputMethodSubtype<sup>9+</sup>
2693
2694listInputMethodSubtype(inputMethodProperty: InputMethodProperty, callback: AsyncCallback&lt;Array&lt;InputMethodSubtype&gt;&gt;): void
2695
2696获取指定输入法应用的所有子类型。使用callback异步回调。
2697
2698**系统能力:** SystemCapability.MiscServices.InputMethodFramework
2699
2700**参数:**
2701
2702| 参数名   | 类型                                               | 必填 | 说明                   |
2703| -------- | -------------------------------------------------- | ---- | ---------------------- |
2704| inputMethodProperty | [InputMethodProperty](#inputmethodproperty8)| 是 | 输入法应用。 |
2705| callback | AsyncCallback&lt;Array<[InputMethodSubtype](./js-apis-inputmethod-subtype.md#inputmethodsubtype)>&gt; | 是 | 回调函数,返回指定输入法应用的所有子类型。 |
2706
2707**错误码:**
2708
2709以下错误码的详细介绍请参见[输入法框架错误码](errorcode-inputmethod-framework.md),[通用错误码说明文档](../errorcode-universal.md)。
2710
2711| 错误码ID | 错误信息                             |
2712| -------- | -------------------------------------- |
2713| 401      | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.           |
2714| 12800001 | bundle manager error.                 |
2715| 12800008 | input method manager service error. |
2716
2717**示例:**
2718
2719```ts
2720import { InputMethodSubtype } from '@kit.IMEKit';
2721import { BusinessError } from '@kit.BasicServicesKit';
2722
2723let inputMethodProperty: inputMethod.InputMethodProperty = {
2724  name: 'com.example.kikakeyboard',
2725  id: 'propertyId',
2726  packageName: 'com.example.kikakeyboard',
2727  methodId: 'propertyId',
2728}
2729let inputMethodSetting = inputMethod.getSetting();
2730try {
2731  inputMethodSetting.listInputMethodSubtype(inputMethodProperty, (err: BusinessError, data: Array<InputMethodSubtype>) => {
2732    if (err) {
2733      console.error(`Failed to listInputMethodSubtype: ${JSON.stringify(err)}`);
2734      return;
2735    }
2736    console.log('Succeeded in listing inputMethodSubtype.');
2737  });
2738} catch (err) {
2739  console.error(`Failed to listInputMethodSubtype: ${JSON.stringify(err)}`);
2740}
2741```
2742
2743### listInputMethodSubtype<sup>9+</sup>
2744
2745listInputMethodSubtype(inputMethodProperty: InputMethodProperty): Promise&lt;Array&lt;InputMethodSubtype&gt;&gt;
2746
2747获取指定输入法应用的所有子类型。使用promise异步回调。
2748
2749**系统能力:** SystemCapability.MiscServices.InputMethodFramework
2750
2751**参数:**
2752
2753| 参数名   | 类型                                               | 必填 | 说明                   |
2754| -------- | -------------------------------------------------- | ---- | ---------------------- |
2755| inputMethodProperty | [InputMethodProperty](#inputmethodproperty8)| 是 | 输入法应用。 |
2756
2757**返回值:**
2758
2759| 类型                                                        | 说明                   |
2760| ----------------------------------------------------------- | ---------------------- |
2761| Promise<Array<[InputMethodSubtype](./js-apis-inputmethod-subtype.md#inputmethodsubtype)>> | Promise对象,返回指定输入法应用的所有子类型。 |
2762
2763**错误码:**
2764
2765以下错误码的详细介绍请参见[输入法框架错误码](errorcode-inputmethod-framework.md),[通用错误码说明文档](../errorcode-universal.md)。
2766
2767| 错误码ID | 错误信息                             |
2768| -------- | -------------------------------------- |
2769| 401      | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.           |
2770| 12800001 | bundle manager error.                 |
2771| 12800008 | input method manager service error. |
2772
2773**示例:**
2774
2775```ts
2776import { InputMethodSubtype } from '@kit.IMEKit';
2777import { BusinessError } from '@kit.BasicServicesKit';
2778
2779let inputMethodProperty: inputMethod.InputMethodProperty = {
2780  name: 'com.example.kikakeyboard',
2781  id: 'propertyId',
2782  packageName: 'com.example.kikakeyboard',
2783  methodId: 'propertyId',
2784}
2785let inputMethodSetting = inputMethod.getSetting();
2786try {
2787  inputMethodSetting.listInputMethodSubtype(inputMethodProperty).then((data: Array<InputMethodSubtype>) => {
2788    console.log('Succeeded in listing inputMethodSubtype.');
2789  }).catch((err: BusinessError) => {
2790    console.error(`Failed to listInputMethodSubtype: ${JSON.stringify(err)}`);
2791  })
2792} catch(err) {
2793  console.error(`Failed to listInputMethodSubtype: ${JSON.stringify(err)}`);
2794}
2795```
2796
2797### listCurrentInputMethodSubtype<sup>9+</sup>
2798
2799listCurrentInputMethodSubtype(callback: AsyncCallback&lt;Array&lt;InputMethodSubtype&gt;&gt;): void
2800
2801查询当前输入法应用的所有子类型。使用callback异步回调。
2802
2803**系统能力:** SystemCapability.MiscServices.InputMethodFramework
2804
2805**参数:**
2806
2807| 参数名   | 类型                                               | 必填 | 说明                   |
2808| -------- | -------------------------------------------------- | ---- | ---------------------- |
2809| callback | AsyncCallback&lt;Array<[InputMethodSubtype](./js-apis-inputmethod-subtype.md#inputmethodsubtype)>&gt; | 是   | 回调函数,返回当前输入法应用的所有子类型。 |
2810
2811**错误码:**
2812
2813以下错误码的详细介绍请参见[输入法框架错误码](errorcode-inputmethod-framework.md),[通用错误码说明文档](../errorcode-universal.md)。
2814
2815| 错误码ID | 错误信息                             |
2816| -------- | -------------------------------------- |
2817| 12800001 | bundle manager error.                 |
2818| 12800008 | input method manager service error. |
2819
2820**示例:**
2821
2822```ts
2823import { InputMethodSubtype } from '@kit.IMEKit';
2824import { BusinessError } from '@kit.BasicServicesKit';
2825
2826let inputMethodSetting = inputMethod.getSetting();
2827try {
2828  inputMethodSetting.listCurrentInputMethodSubtype((err: BusinessError, data: Array<InputMethodSubtype>) => {
2829    if (err) {
2830      console.error(`Failed to listCurrentInputMethodSubtype: ${JSON.stringify(err)}`);
2831      return;
2832    }
2833    console.log('Succeeded in listing currentInputMethodSubtype.');
2834  });
2835} catch(err) {
2836  console.error(`Failed to listCurrentInputMethodSubtype: ${JSON.stringify(err)}`);
2837}
2838```
2839
2840### listCurrentInputMethodSubtype<sup>9+</sup>
2841
2842listCurrentInputMethodSubtype(): Promise&lt;Array&lt;InputMethodSubtype&gt;&gt;
2843
2844查询当前输入法应用的所有子类型。使用promise异步回调。
2845
2846**系统能力:** SystemCapability.MiscServices.InputMethodFramework
2847
2848**返回值:**
2849
2850| 类型                                                        | 说明                   |
2851| ----------------------------------------------------------- | ---------------------- |
2852| Promise<Array<[InputMethodSubtype](./js-apis-inputmethod-subtype.md#inputmethodsubtype)>> | Promise对象,返回当前输入法应用的所有子类型。 |
2853
2854**错误码:**
2855
2856以下错误码的详细介绍请参见[输入法框架错误码](errorcode-inputmethod-framework.md),[通用错误码说明文档](../errorcode-universal.md)。
2857
2858| 错误码ID | 错误信息                             |
2859| -------- | -------------------------------------- |
2860| 12800001 | bundle manager error.                 |
2861| 12800008 | input method manager service error. |
2862
2863**示例:**
2864
2865```ts
2866import { InputMethodSubtype } from '@kit.IMEKit';
2867import { BusinessError } from '@kit.BasicServicesKit';
2868
2869let inputMethodSetting = inputMethod.getSetting();
2870try {
2871  inputMethodSetting.listCurrentInputMethodSubtype().then((data: Array<InputMethodSubtype>) => {
2872    console.log('Succeeded in listing currentInputMethodSubtype.');
2873  }).catch((err: BusinessError) => {
2874    console.error(`Failed to listCurrentInputMethodSubtype: ${JSON.stringify(err)}`);
2875  })
2876} catch(err) {
2877  console.error(`Failed to listCurrentInputMethodSubtype: ${JSON.stringify(err)}`);
2878}
2879```
2880
2881### getInputMethods<sup>9+</sup>
2882
2883getInputMethods(enable: boolean, callback: AsyncCallback&lt;Array&lt;InputMethodProperty&gt;&gt;): void
2884
2885获取已激活/未激活的输入法应用列表。使用callback异步回调。
2886
2887> **说明:**
2888>
2889> 已激活输入法为使能的输入法应用。默认输入法默认使能,其他输入法可被设置为使能或非使能。
2890>
2891> 已激活输入法列表包括默认输入法和已被设置为使能的输入法应用,未激活输入法列表包括除使能输入法以外的其他已安装的输入法。
2892
2893**系统能力:** SystemCapability.MiscServices.InputMethodFramework
2894
2895**参数:**
2896
2897| 参数名   | 类型                                                | 必填 | 说明                          |
2898| -------- | --------------------------------------------------- | ---- | ----------------------------- |
2899| enable   | boolean                                             | 是   |true表示返回已激活输入法列表,false表示返回未激活输入法列表。 |
2900| callback | AsyncCallback&lt;Array<[InputMethodProperty](#inputmethodproperty8)>&gt; |  是  | 回调函数,返回已激活/未激活输入法列表。 |
2901
2902**错误码:**
2903
2904以下错误码的详细介绍请参见[输入法框架错误码](errorcode-inputmethod-framework.md),[通用错误码说明文档](../errorcode-universal.md)。
2905
2906| 错误码ID | 错误信息                            |
2907| -------- | ----------------------------------- |
2908| 401      | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
2909| 12800001 | bundle manager error.               |
2910| 12800008 | input method manager service error. |
2911
2912**示例:**
2913
2914```ts
2915import { BusinessError } from '@kit.BasicServicesKit';
2916
2917try {
2918  inputMethodSetting.getInputMethods(true, (err: BusinessError, data: Array<inputMethod.InputMethodProperty>) => {
2919    if (err) {
2920      console.error(`Failed to getInputMethods: ${JSON.stringify(err)}`);
2921      return;
2922    }
2923    console.log('Succeeded in getting inputMethods.');
2924  });
2925} catch (err) {
2926  console.error(`Failed to getInputMethods: ${JSON.stringify(err)}`);
2927}
2928```
2929
2930### getInputMethods<sup>9+</sup>
2931
2932getInputMethods(enable: boolean): Promise&lt;Array&lt;InputMethodProperty&gt;&gt;
2933
2934获取已激活/未激活的输入法应用列表。使用promise异步回调。
2935
2936> **说明:**
2937>
2938> 已激活输入法为使能的输入法应用。默认输入法默认使能,其他输入法可被设置为使能或非使能。
2939>
2940> 已激活输入法列表包括默认输入法和已被设置为使能的输入法应用,未激活输入法列表包括除使能输入法以外的其他已安装的输入法。
2941
2942**系统能力:** SystemCapability.MiscServices.InputMethodFramework
2943
2944**参数:**
2945
2946| 参数名 | 类型    | 必填 | 说明                    |
2947| ------ | ------- | ---- | ----------------------- |
2948| enable | boolean | 是   |- true表示返回已激活输入法列表,false表示返回未激活输入法列表。 |
2949
2950**返回值:**
2951
2952| 类型                                                         | 说明                                       |
2953| ------------------------------------------------------------ | ------------------------------------------ |
2954| Promise\<Array\<[InputMethodProperty](#inputmethodproperty8)>> | Promise对象,返回已激活/未激活输入法列表。 |
2955
2956**错误码:**
2957
2958以下错误码的详细介绍请参见[输入法框架错误码](errorcode-inputmethod-framework.md),[通用错误码说明文档](../errorcode-universal.md)。
2959
2960| 错误码ID | 错误信息                            |
2961| -------- | ----------------------------------- |
2962| 401      | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
2963| 12800001 | bundle manager error.               |
2964| 12800008 | input method manager service error. |
2965
2966**示例:**
2967
2968```ts
2969import { BusinessError } from '@kit.BasicServicesKit';
2970
2971try {
2972  inputMethodSetting.getInputMethods(true).then((data: Array<inputMethod.InputMethodProperty>) => {
2973    console.log('Succeeded in getting inputMethods.');
2974  }).catch((err: BusinessError) => {
2975    console.error(`Failed to getInputMethods: ${JSON.stringify(err)}`);
2976  })
2977} catch(err) {
2978  console.error(`Failed to getInputMethods: ${JSON.stringify(err)}`);
2979}
2980```
2981
2982### getInputMethodsSync<sup>11+</sup>
2983
2984getInputMethodsSync(enable: boolean): Array&lt;InputMethodProperty&gt;
2985
2986获取已激活/未激活的输入法应用列表。同步接口。
2987
2988> **说明:**
2989>
2990> 已激活输入法为使能的输入法应用。默认输入法默认使能,其他输入法可被设置为使能或非使能。
2991>
2992> 已激活输入法列表包括默认输入法和已被设置为使能的输入法应用,未激活输入法列表包括除使能输入法以外的其他已安装的输入法。
2993
2994**系统能力:** SystemCapability.MiscServices.InputMethodFramework
2995
2996**参数:**
2997
2998| 参数名 | 类型    | 必填 | 说明                    |
2999| ------ | ------- | ---- | ----------------------- |
3000| enable | boolean | 是   |- true表示返回已激活输入法列表,false表示返回未激活输入法列表。 |
3001
3002**返回值:**
3003
3004| 类型                                                 | 说明                          |
3005| ---------------------------------------------------- | ----------------------------- |
3006| Array\<[InputMethodProperty](#inputmethodproperty8)> | 返回已激活/未激活输入法列表。 |
3007
3008**错误码:**
3009
3010以下错误码的详细介绍请参见[输入法框架错误码](errorcode-inputmethod-framework.md),[通用错误码说明文档](../errorcode-universal.md)。
3011
3012| 错误码ID | 错误信息                             |
3013| -------- | -------------------------------------- |
3014| 401      | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
3015| 12800001 | bundle manager error.                 |
3016| 12800008 |input method manager service error. |
3017
3018**示例:**
3019
3020```ts
3021try {
3022  let imeProp = inputMethodSetting.getInputMethodsSync(true);
3023} catch(err) {
3024  console.error(`Failed to getInputMethods: ${JSON.stringify(err)}`);
3025}
3026```
3027
3028### getAllInputMethods<sup>11+</sup>
3029
3030getAllInputMethods(callback: AsyncCallback&lt;Array&lt;InputMethodProperty&gt;&gt;): void
3031
3032获取所有输入法应用列表。使用callback异步回调。
3033
3034**系统能力:** SystemCapability.MiscServices.InputMethodFramework
3035
3036**参数:**
3037
3038| 参数名   | 类型                                                         | 必填 | 说明                           |
3039| -------- | ------------------------------------------------------------ | ---- | ------------------------------ |
3040| callback | AsyncCallback&lt;Array<[InputMethodProperty](#inputmethodproperty8)>&gt; | 是   | 回调函数,返回所有输入法列表。 |
3041
3042**错误码:**
3043
3044以下错误码的详细介绍请参见[输入法框架错误码](errorcode-inputmethod-framework.md),[通用错误码说明文档](../errorcode-universal.md)。
3045
3046| 错误码ID | 错误信息                            |
3047| -------- | ----------------------------------- |
3048| 12800001 | bundle manager error.               |
3049| 12800008 | input method manager service error. |
3050
3051**示例:**
3052
3053```ts
3054import { BusinessError } from '@kit.BasicServicesKit';
3055
3056try {
3057  inputMethodSetting.getAllInputMethods((err: BusinessError, data: Array<inputMethod.InputMethodProperty>) => {
3058    if (err) {
3059      console.error(`Failed to getAllInputMethods: ${JSON.stringify(err)}`);
3060      return;
3061    }
3062    console.log('Succeeded in getting all inputMethods.');
3063  });
3064} catch (err) {
3065  console.error(`Failed to getAllInputMethods: ${JSON.stringify(err)}`);
3066}
3067```
3068
3069### getAllInputMethods<sup>11+</sup>
3070
3071getAllInputMethods(): Promise&lt;Array&lt;InputMethodProperty&gt;&gt;
3072
3073获取所有输入法应用列表。使用promise异步回调。
3074
3075**系统能力:** SystemCapability.MiscServices.InputMethodFramework
3076
3077**返回值:**
3078
3079| 类型                                                         | 说明                              |
3080| ------------------------------------------------------------ | --------------------------------- |
3081| Promise\<Array\<[InputMethodProperty](#inputmethodproperty8)>> | Promise对象,返回所有输入法列表。 |
3082
3083**错误码:**
3084
3085以下错误码的详细介绍请参见[输入法框架错误码](errorcode-inputmethod-framework.md),[通用错误码说明文档](../errorcode-universal.md)。
3086
3087| 错误码ID | 错误信息                            |
3088| -------- | ----------------------------------- |
3089| 12800001 | bundle manager error.              |
3090| 12800008 | input method manager service error. |
3091
3092**示例:**
3093
3094```ts
3095import { BusinessError } from '@kit.BasicServicesKit';
3096
3097inputMethodSetting.getAllInputMethods().then((data: Array<inputMethod.InputMethodProperty>) => {
3098  console.log('Succeeded in getting all inputMethods.');
3099}).catch((err: BusinessError) => {
3100  console.error(`Failed to getAllInputMethods: ${JSON.stringify(err)}`);
3101})
3102```
3103
3104### getAllInputMethodsSync<sup>11+</sup>
3105
3106getAllInputMethodsSync(): Array&lt;InputMethodProperty&gt;
3107
3108获取所有输入法应用列表。同步接口。
3109
3110**系统能力:** SystemCapability.MiscServices.InputMethodFramework
3111
3112**返回值:**
3113
3114| 类型                                                 | 说明               |
3115| ---------------------------------------------------- | ------------------ |
3116| Array\<[InputMethodProperty](#inputmethodproperty8)> | 返回所有输入法列表 |
3117
3118**错误码:**
3119
3120以下错误码的详细介绍请参见[输入法框架错误码](errorcode-inputmethod-framework.md)。
3121
3122| 错误码ID | 错误信息                            |
3123| -------- | ----------------------------------- |
3124| 12800001 | bundle manager error.              |
3125| 12800008 | input method manager service error. |
3126
3127**示例:**
3128
3129```ts
3130try {
3131  let imeProp = inputMethodSetting.getAllInputMethodsSync();
3132} catch(err) {
3133  console.error(`Failed to getAllInputMethodsSync: ${JSON.stringify(err)}`);
3134}
3135```
3136
3137### showOptionalInputMethods<sup>9+</sup>
3138
3139showOptionalInputMethods(callback: AsyncCallback&lt;boolean&gt;): void
3140
3141显示输入法选择对话框。使用callback异步回调。
3142
3143**系统能力:** SystemCapability.MiscServices.InputMethodFramework
3144
3145**参数:**
3146
3147| 参数名 | 类型 | 必填 | 说明 |
3148| -------- | -------- | -------- | -------- |
3149| callback | AsyncCallback&lt;boolean&gt; | 是 | 回调函数。当输入法选择对话框显示成功,err为undefined,data为true;否则为错误对象。 |
3150
3151**错误码:**
3152
3153以下错误码的详细介绍请参见[输入法框架错误码](errorcode-inputmethod-framework.md)。
3154
3155| 错误码ID | 错误信息                             |
3156| -------- | -------------------------------------- |
3157| 12800008 | input method manager service error. |
3158
3159**示例:**
3160
3161```ts
3162import { BusinessError } from '@kit.BasicServicesKit';
3163
3164try {
3165  inputMethodSetting.showOptionalInputMethods((err: BusinessError, data: boolean) => {
3166    if (err) {
3167      console.error(`Failed to showOptionalInputMethods: ${JSON.stringify(err)}`);
3168      return;
3169    }
3170    console.log('Succeeded in showing optionalInputMethods.');
3171  });
3172} catch (err) {
3173  console.error(`Failed to showOptionalInputMethods: ${JSON.stringify(err)}`);
3174}
3175```
3176
3177### showOptionalInputMethods<sup>9+</sup>
3178
3179showOptionalInputMethods(): Promise&lt;boolean&gt;
3180
3181显示输入法选择对话框。使用promise异步回调。
3182
3183**系统能力:** SystemCapability.MiscServices.InputMethodFramework
3184
3185**返回值:**
3186
3187| 类型 | 说明 |
3188| -------- | -------- |
3189| Promise&lt;boolean&gt; | Promise对象。当输入法选择对话框显示成功,err为undefined,data为true;否则为错误对象。 |
3190
3191**错误码:**
3192
3193以下错误码的详细介绍请参见[输入法框架错误码](errorcode-inputmethod-framework.md)。
3194
3195| 错误码ID | 错误信息                             |
3196| -------- | -------------------------------------- |
3197| 12800008 | input method manager service error. |
3198
3199**示例:**
3200
3201```ts
3202import { BusinessError } from '@kit.BasicServicesKit';
3203
3204inputMethodSetting.showOptionalInputMethods().then((data: boolean) => {
3205  console.log('Succeeded in showing optionalInputMethods.');
3206}).catch((err: BusinessError) => {
3207  console.error(`Failed to showOptionalInputMethods: ${JSON.stringify(err)}`);
3208})
3209```
3210
3211### listInputMethod<sup>(deprecated)</sup>
3212
3213listInputMethod(callback: AsyncCallback&lt;Array&lt;InputMethodProperty&gt;&gt;): void
3214
3215查询已安装的输入法列表。使用callback异步回调。
3216
3217> **说明:**
3218>
3219> 从API version 8开始支持,从API version 9开始废弃,建议使用[getInputMethods](#getinputmethods9)替代。
3220
3221**系统能力:** SystemCapability.MiscServices.InputMethodFramework
3222
3223**参数:**
3224
3225| 参数名   | 类型                                               | 必填 | 说明                   |
3226| -------- | -------------------------------------------------- | ---- | ---------------------- |
3227| callback | AsyncCallback&lt;Array<[InputMethodProperty](#inputmethodproperty8)>&gt; | 是   | 回调函数,返回已安装的输入法列表。 |
3228
3229**示例:**
3230
3231```ts
3232import { BusinessError } from '@kit.BasicServicesKit';
3233
3234inputMethodSetting.listInputMethod((err: BusinessError, data: Array<inputMethod.InputMethodProperty>) => {
3235  if (err) {
3236    console.error(`Failed to listInputMethod: ${JSON.stringify(err)}`);
3237    return;
3238  }
3239  console.log('Succeeded in listing inputMethod.');
3240 });
3241```
3242
3243### listInputMethod<sup>(deprecated)</sup>
3244
3245listInputMethod(): Promise&lt;Array&lt;InputMethodProperty&gt;&gt;
3246
3247查询已安装的输入法列表。使用promise异步回调。
3248
3249> **说明:**
3250>
3251> 从API version 8开始支持,从API version 9开始废弃,建议使用[getInputMethods](#getinputmethods9-1)替代。
3252
3253**系统能力:** SystemCapability.MiscServices.InputMethodFramework
3254
3255**返回值:**
3256
3257| 类型                                                        | 说明                   |
3258| ----------------------------------------------------------- | ---------------------- |
3259| Promise<Array<[InputMethodProperty](#inputmethodproperty8)>> | Promise对象,返回已安装输入法列表。 |
3260
3261**示例:**
3262
3263```ts
3264import { BusinessError } from '@kit.BasicServicesKit';
3265
3266inputMethodSetting.listInputMethod().then((data: Array<inputMethod.InputMethodProperty>) => {
3267  console.log('Succeeded in listing inputMethod.');
3268}).catch((err: BusinessError) => {
3269  console.error(`Failed to listInputMethod: ${JSON.stringify(err)}`);
3270})
3271```
3272
3273### displayOptionalInputMethod<sup>(deprecated)</sup>
3274
3275displayOptionalInputMethod(callback: AsyncCallback&lt;void&gt;): void
3276
3277显示输入法选择对话框。使用callback异步回调。
3278
3279> **说明:**
3280>
3281> 从API version 8开始支持,从API version 9开始废弃,建议使用[showOptionalInputMethods()](#showoptionalinputmethods9)替代。
3282
3283**系统能力:** SystemCapability.MiscServices.InputMethodFramework
3284
3285**参数:**
3286
3287| 参数名 | 类型 | 必填 | 说明 |
3288| -------- | -------- | -------- | -------- |
3289| callback | AsyncCallback&lt;void&gt; | 是 | 回调函数。当输入法选择对话框显示成功。err为undefined,否则为错误对象。 |
3290
3291**示例:**
3292
3293```ts
3294import { BusinessError } from '@kit.BasicServicesKit';
3295
3296inputMethodSetting.displayOptionalInputMethod((err: BusinessError) => {
3297  if (err) {
3298    console.error(`Failed to displayOptionalInputMethod: ${JSON.stringify(err)}`);
3299    return;
3300  }
3301  console.log('Succeeded in displaying optionalInputMethod.');
3302});
3303```
3304
3305### displayOptionalInputMethod<sup>(deprecated)</sup>
3306
3307displayOptionalInputMethod(): Promise&lt;void&gt;
3308
3309显示输入法选择对话框。使用promise异步回调。
3310
3311> **说明:**
3312>
3313> 从API version 8开始支持,从API version 9开始废弃,建议使用[showOptionalInputMethods()](#showoptionalinputmethods9-1)替代。
3314
3315**系统能力:** SystemCapability.MiscServices.InputMethodFramework
3316
3317**返回值:**
3318
3319| 类型 | 说明 |
3320| -------- | -------- |
3321| Promise&lt;void&gt; | 无返回结果的Promise对象。 |
3322
3323**示例:**
3324
3325```ts
3326import { BusinessError } from '@kit.BasicServicesKit';
3327
3328inputMethodSetting.displayOptionalInputMethod().then(() => {
3329  console.log('Succeeded in displaying optionalInputMethod.');
3330}).catch((err: BusinessError) => {
3331  console.error(`Failed to displayOptionalInputMethod: ${JSON.stringify(err)}`);
3332})
3333```