1# @ohos.inputMethod (Input Method Framework)
2
3The **inputMethod** module is oriented to common foreground applications (third-party applications and system applications such as Notes, Messaging, and Settings). It provides input method control and management capabilities, including displaying or hiding the soft keyboard, switching between input methods, and obtaining the list of all input methods.
4
5> **NOTE**
6>
7> The initial APIs of this module are supported since API version 6. Newly added APIs will be marked with a superscript to indicate their earliest API version.
8
9
10## Modules to Import
11
12```ts
13import { inputMethod } from '@kit.IMEKit';
14```
15
16## Constants
17
18Provides the constants.
19
20**System capability**: SystemCapability.MiscServices.InputMethodFramework
21
22| Name| Type| Value| Description|
23| -------- | -------- | -------- | -------- |
24| MAX_TYPE_NUM<sup>8+</sup> | number | 128 | Maximum number of supported input methods.|
25
26## InputMethodProperty<sup>8+</sup>
27
28Describes the input method application attributes.
29
30**System capability**: SystemCapability.MiscServices.InputMethodFramework
31
32| Name| Type| Read-only| Optional| Description|
33| -------- | -------- | -------- | -------- | -------- |
34| name<sup>9+</sup>  | string | Yes| No| Mandatory. Name of the input method package.|
35| id<sup>9+</sup>    | string | Yes| No| Mandatory. Unique identifier of an input method extension in an app. **id** and **name** form a globally unique identifier of the input method extension.|
36| label<sup>9+</sup>    | string | Yes| Yes| Optional. External label of the input method extension. Use the label configured for the InputmethodExtensionAbility. If no label is configured, the label of the application entry ability is automatically used. If no label is configured for the application entry ability, the label configured in **AppScope** is automatically used.|
37| labelId<sup>10+</sup>    | number | Yes| Yes| Optional. External ID of the input method.|
38| icon<sup>9+</sup>    | string | Yes| Yes| Optional. Icon of the input method. It can be obtained by using **iconId**. This parameter is reserved.|
39| iconId<sup>9+</sup>    | number | Yes| Yes| Optional. Icon ID of the input method.|
40| extra<sup>9+</sup>    | object | No| Yes| Extra information about the input method. This parameter is reserved and currently has no specific meaning.<br>- API version 10 and later: optional<br>- API version 9: mandatory|
41| packageName<sup>(deprecated)</sup> | string | Yes| No| Name of the input method package. Mandatory.<br>**NOTE**<br>This API is supported since API version 8 and deprecated since API version 9. You are advised to use **name** instead.|
42| methodId<sup>(deprecated)</sup> | string | Yes| No| Unique ID of the input method. Mandatory.<br>**NOTE**<br>This API is supported since API version 8 and deprecated since API version 9. You are advised to use **id** instead.|
43
44## inputMethod.getController<sup>9+</sup>
45
46getController(): InputMethodController
47
48Obtains an [InputMethodController](#inputmethodcontroller) instance.
49
50**System capability**: SystemCapability.MiscServices.InputMethodFramework
51
52**Return value**
53
54| Type                                           | Description                  |
55| ----------------------------------------------- | ---------------------- |
56| [InputMethodController](#inputmethodcontroller) | **InputMethodController** instance.|
57
58**Error codes**
59
60For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md).
61
62| ID| Error Message                    |
63| -------- | ------------------------------ |
64| 12800006 | input method controller error. |
65
66**Example**
67
68```ts
69let inputMethodController = inputMethod.getController();
70```
71
72## inputMethod.getDefaultInputMethod<sup>11+</sup>
73
74getDefaultInputMethod(): InputMethodProperty
75
76Obtains the default input method.
77
78**System capability**: SystemCapability.MiscServices.InputMethodFramework
79
80**Return value**
81
82| Type                                        | Description                    |
83| -------------------------------------------- | ------------------------ |
84| [InputMethodProperty](#inputmethodproperty8) | Default input method.|
85
86**Error codes**
87
88For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md).
89
90| ID| Error Message                            |
91| -------- | -------------------------------------- |
92| 12800008 | input method manager service error. |
93
94**Example**
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
108Obtains the information about the input method configuration page ability.
109
110**System capability**: SystemCapability.MiscServices.InputMethodFramework
111
112**Return value**
113
114| Type                                        | Description                    |
115| -------------------------------------------- | ------------------------ |
116| [ElementName](../apis-ability-kit/js-apis-bundleManager-elementName.md) | Element name of the input method configuration page ability.|
117
118**Error codes**
119
120For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md).
121
122| ID| Error Message                            |
123| -------- | -------------------------------------- |
124| 12800008 | input method manager service error. |
125
126**Example**
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
140Obtains an [InputMethodSetting](#inputmethodsetting8) instance.
141
142**System capability**: SystemCapability.MiscServices.InputMethodFramework
143
144**Return value**
145
146| Type                                     | Description                      |
147| ----------------------------------------- | -------------------------- |
148| [InputMethodSetting](#inputmethodsetting8) | **InputMethodSetting** instance.|
149
150**Error codes**
151
152For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md).
153
154| ID| Error Message                            |
155| -------- | -------------------------------------- |
156| 12800007 |  setter error. |
157
158**Example**
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
168Switches to another input method. This API uses an asynchronous callback to return the result.
169> **NOTE**
170>
171>  - In API versions 9 and 10, this API can only be called by system applications granted the **ohos.permission.CONNECT_IME_ABILITY** permission.
172>  - Since API version 11, this API can only be called by the current input method application.
173
174**System capability**: SystemCapability.MiscServices.InputMethodFramework
175
176**Parameters**
177
178| Name| Type| Mandatory| Description|
179| -------- | -------- | -------- | -------- |
180| target | [InputMethodProperty](#inputmethodproperty8) | Yes| Target input method.|
181| callback | AsyncCallback&lt;boolean&gt; | Yes| Callback used to return the result. If the operation is successful, **err** is **undefined** and **data** is **true**. Otherwise, **err** is an error object.|
182
183**Error codes**
184
185For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md) and [Universal Error Codes](../errorcode-universal.md).
186
187| ID| Error Message                            |
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**Example**
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> **NOTE**
217>
218> Since API version 11, the error code `201 permissions check fails` is removed.
219
220## inputMethod.switchInputMethod<sup>9+</sup>
221switchInputMethod(target: InputMethodProperty): Promise&lt;boolean&gt;
222
223Switches to another input method. This API uses a promise to return the result.
224> **NOTE**
225>
226>  - In API versions 9 and 10, this API can only be called by system applications granted the **ohos.permission.CONNECT_IME_ABILITY** permission.
227>  - Since API version 11, this API can only be called by the current input method application.
228
229**System capability**: SystemCapability.MiscServices.InputMethodFramework
230
231**Parameters**
232
233  | Name| Type| Mandatory| Description|
234  | -------- | -------- | -------- | -------- |
235  |target |  [InputMethodProperty](#inputmethodproperty8)| Yes| Target input method.|
236
237**Return value**
238
239  | Type                                     | Description                        |
240  | ----------------------------------------- | ---------------------------- |
241  | Promise\<boolean> | Promise used to return the result. The value **true** means that the switching is successful, and **false** means the opposite.|
242
243**Error codes**
244
245For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md) and [Universal Error Codes](../errorcode-universal.md).
246
247| ID| Error Message                            |
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**Example**
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> **NOTE**
275>
276> Since API version 11, the error code `201 permissions check fails` is removed.
277
278## inputMethod.getCurrentInputMethod<sup>9+</sup>
279
280getCurrentInputMethod(): InputMethodProperty
281
282Obtains the current input method. This API returns the result synchronously.
283
284**System capability**: SystemCapability.MiscServices.InputMethodFramework
285
286**Return value**
287
288| Type                                        | Description                    |
289| -------------------------------------------- | ------------------------ |
290| [InputMethodProperty](#inputmethodproperty8) | **InputmethodProperty** instance of the current input method.|
291
292**Example**
293
294```ts
295let currentIme = inputMethod.getCurrentInputMethod();
296```
297
298## inputMethod.switchCurrentInputMethodSubtype<sup>9+</sup>
299
300switchCurrentInputMethodSubtype(target: InputMethodSubtype, callback: AsyncCallback\<boolean>): void
301
302Switches to another subtype of this input method. This API uses an asynchronous callback to return the result.
303
304> **NOTE**
305>
306>  - In API version 9 , this API can only be called by system applications granted the **ohos.permission.CONNECT_IME_ABILITY** permission.
307>  - In API version 10, this API can only be called by system applications and the current input method application, and the **ohos.permission.CONNECT_IME_ABILITY** permission is required.
308>  - Since API version 11, this API can only be called by the current input method application.
309
310**System capability**: SystemCapability.MiscServices.InputMethodFramework
311
312**Parameters**
313
314| Name| Type| Mandatory| Description|
315| -------- | -------- | -------- | -------- |
316| target |  [InputMethodSubtype](./js-apis-inputmethod-subtype.md#inputmethodsubtype)| Yes| Target input method subtype.|
317| callback | AsyncCallback&lt;boolean&gt; | Yes| Callback used to return the result. If the operation is successful, **err** is **undefined** and **data** is **true**. Otherwise, **err** is an error object.|
318
319**Error codes**
320
321For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md) and [Universal Error Codes](../errorcode-universal.md).
322
323| ID| Error Message                            |
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**Example**
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> **NOTE**
363>
364> Since API version 11, the error code `201 permissions check fails` is removed.
365
366## inputMethod.switchCurrentInputMethodSubtype<sup>9+</sup>
367
368switchCurrentInputMethodSubtype(target: InputMethodSubtype): Promise&lt;boolean&gt;
369
370Switches to another subtype of this input method. This API uses a promise to return the result.
371
372> **NOTE**
373>
374>  - In API version 9 , this API can only be called by system applications granted the **ohos.permission.CONNECT_IME_ABILITY** permission.
375>  - In API version 10, this API can only be called by system applications and the current input method application, and the **ohos.permission.CONNECT_IME_ABILITY** permission is required.
376>  - Since API version 11, this API can only be called by the current input method application.
377
378**System capability**: SystemCapability.MiscServices.InputMethodFramework
379
380**Parameters**
381
382| Name| Type| Mandatory| Description|
383| -------- | -------- | -------- | -------- |
384|target |  [InputMethodSubtype](./js-apis-inputmethod-subtype.md#inputmethodsubtype)| Yes| Target input method subtype.|
385
386**Return value**
387
388| Type                                     | Description                        |
389| ----------------------------------------- | ---------------------------- |
390| Promise\<boolean> | Promise used to return the result. The value **true** means that the switching is successful, and **false** means the opposite.|
391
392**Error codes**
393
394For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md) and [Universal Error Codes](../errorcode-universal.md).
395
396| ID| Error Message                            |
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**Example**
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> **NOTE**
434>
435> Since API version 11, the error code `201 permissions check fails` is removed.
436
437## inputMethod.getCurrentInputMethodSubtype<sup>9+</sup>
438
439getCurrentInputMethodSubtype(): InputMethodSubtype
440
441Obtains the current input method subtype.
442
443**System capability**: SystemCapability.MiscServices.InputMethodFramework
444
445**Return value**
446
447| Type                                        | Description                    |
448| -------------------------------------------- | ------------------------ |
449| [InputMethodSubtype](./js-apis-inputmethod-subtype.md#inputmethodsubtype) | Current input method subtype.|
450
451**Example**
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
461Switches to a specified subtype of a specified input method. This API uses an asynchronous callback to return the result.
462
463> **NOTE**
464>
465>  - In API versions 9 and 10, this API can only be called by system applications granted the **ohos.permission.CONNECT_IME_ABILITY** permission.
466>  - Since API version 11, this API can only be called by the current input method application.
467
468**System capability**: SystemCapability.MiscServices.InputMethodFramework
469
470**Parameters**
471
472| Name| Type| Mandatory| Description|
473| -------- | -------- | -------- | -------- |
474|inputMethodProperty |  [InputMethodProperty](#inputmethodproperty8)| Yes| Target input method.|
475|inputMethodSubtype |  [InputMethodSubtype](./js-apis-inputmethod-subtype.md#inputmethodsubtype)| Yes| Target input method subtype.|
476| callback | AsyncCallback&lt;boolean&gt; | Yes| Callback used to return the result. If the operation is successful, **err** is **undefined** and **data** is **true**. Otherwise, **err** is an error object.|
477
478**Error codes**
479
480For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md) and [Universal Error Codes](../errorcode-universal.md).
481
482| ID| Error Message                            |
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**Example**
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> **NOTE**
513>
514> Since API version 11, the error code `201 permissions check fails` is removed.
515
516## inputMethod.switchCurrentInputMethodAndSubtype<sup>9+</sup>
517
518switchCurrentInputMethodAndSubtype(inputMethodProperty: InputMethodProperty, inputMethodSubtype: InputMethodSubtype): Promise&lt;boolean&gt;
519
520Switches to a specified subtype of a specified input method. This API uses a promise to return the result.
521
522> **NOTE**
523>
524>  - In API versions 9 and 10, this API can only be called by system applications granted the **ohos.permission.CONNECT_IME_ABILITY** permission.
525>  - Since API version 11, this API can only be called by the current input method application.
526
527**System capability**: SystemCapability.MiscServices.InputMethodFramework
528
529**Parameters**
530
531| Name| Type| Mandatory| Description|
532| -------- | -------- | -------- | -------- |
533|inputMethodProperty |  [InputMethodProperty](#inputmethodproperty8)| Yes| Target input method.|
534|inputMethodSubtype |  [InputMethodSubtype](./js-apis-inputmethod-subtype.md#inputmethodsubtype)| Yes| Target input method subtype.|
535
536**Return value**
537
538| Type                                     | Description                        |
539| ----------------------------------------- | ---------------------------- |
540| Promise\<boolean> | Promise used to return the result. The value **true** means that the switching is successful, and **false** means the opposite.|
541
542**Error codes**
543
544For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md) and [Universal Error Codes](../errorcode-universal.md).
545
546| ID| Error Message                            |
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**Example**
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> **NOTE**
575>
576> Since API version 11, the error code `201 permissions check fails` is removed.
577
578## inputMethod.getInputMethodController<sup>(deprecated)</sup>
579
580getInputMethodController(): InputMethodController
581
582Obtains an [InputMethodController](#inputmethodcontroller) instance.
583
584> **NOTE**
585>
586> This API is supported since API version 6 and deprecated since API version 9. You are advised to use [getController()](#inputmethodgetcontroller9) instead.
587
588**System capability**: SystemCapability.MiscServices.InputMethodFramework
589
590**Return value**
591
592| Type                                           | Description                    |
593| ----------------------------------------------- | ------------------------ |
594| [InputMethodController](#inputmethodcontroller) | Current **InputMethodController** instance.|
595
596**Example**
597
598```ts
599let inputMethodController = inputMethod.getInputMethodController();
600```
601
602## inputMethod.getInputMethodSetting<sup>(deprecated)</sup>
603
604getInputMethodSetting(): InputMethodSetting
605
606Obtains an [InputMethodSetting](#inputmethodsetting8) instance.
607
608> **NOTE**
609>
610> This API is supported since API version 6 and deprecated since API version 9. You are advised to use [getSetting()](#inputmethodgetsetting9) instead.
611
612**System capability**: SystemCapability.MiscServices.InputMethodFramework
613
614**Return value**
615
616| Type                                     | Description                      |
617| ----------------------------------------- | -------------------------- |
618| [InputMethodSetting](#inputmethodsetting8) | **InputMethodSetting** instance.|
619
620**Example**
621
622```ts
623let inputMethodSetting = inputMethod.getInputMethodSetting();
624```
625
626## TextInputType<sup>10+</sup>
627
628Enumerates the text input types.
629
630**System capability**: SystemCapability.MiscServices.InputMethodFramework
631
632| Name| Value|Description|
633| -------- | -------- |-------- |
634| NONE  | -1 |None.|
635| TEXT  | 0 |Text.|
636| MULTILINE  | 1 |Multi-line.|
637| NUMBER  | 2 |Number.|
638| PHONE  | 3 |Phone number.|
639| DATETIME  | 4 |Date.|
640| EMAIL_ADDRESS  | 5 |Email address.|
641| URL  | 6 |URL.|
642| VISIBLE_PASSWORD  | 7 |Password.|
643| NUMBER_PASSWORD<sup>11+</sup> | 8 |Numeric password.|
644
645## EnterKeyType<sup>10+</sup>
646
647Enumerates the function types represented by the Enter key of the input method.
648
649**System capability**: SystemCapability.MiscServices.InputMethodFramework
650
651| Name| Value|Description|
652| -------- | -------- |-------- |
653| UNSPECIFIED  | 0 |Not specified.|
654| NONE  | 1 |None.|
655| GO  | 2 |Go.|
656| SEARCH  | 3 |Search.|
657| SEND  | 4 |Send.|
658| NEXT  | 5 |Next.|
659| DONE  | 6 |Done.|
660| PREVIOUS  | 7 |Previous.|
661| NEWLINE<sup>12+</sup>  | 8 | Line break.|
662
663## KeyboardStatus<sup>10+</sup>
664
665Enumerates the soft keyboard states of the input method.
666
667**System capability**: SystemCapability.MiscServices.InputMethodFramework
668
669| Name| Value|Description|
670| -------- | -------- |-------- |
671| NONE  | 0 |None.|
672| HIDE  | 1 |Hidden.|
673| SHOW  | 2 |Shown.|
674
675## Direction<sup>10+</sup>
676
677Enumerates the directions of cursor movement of the input method.
678
679**System capability**: SystemCapability.MiscServices.InputMethodFramework
680
681| Name| Value|Description|
682| -------- | -------- |-------- |
683| CURSOR_UP  | 1 |Upward.|
684| CURSOR_DOWN  | 2 |Downward.|
685| CURSOR_LEFT  | 3 |Leftward.|
686| CURSOR_RIGHT  | 4 |Rightward.|
687
688## ExtendAction<sup>10+</sup>
689
690Describes the type of the extended edit action on the text box.
691
692**System capability**: SystemCapability.MiscServices.InputMethodFramework
693
694| Name| Value|Description|
695| -------- | -------- |-------- |
696| SELECT_ALL  | 0 |Select all.|
697| CUT  | 3 |Cut.|
698| COPY  | 4 |Copy.|
699| PASTE  | 5 |Paste.|
700
701## FunctionKey<sup>10+</sup>
702
703Describes the type of the input method function key.
704
705**System capability**: SystemCapability.MiscServices.InputMethodFramework
706
707| Name| Type| Read-only| Optional| Description|
708| -------- | -------- | -------- | -------- | -------- |
709| enterKeyType<sup>10+</sup>  | [EnterKeyType](#enterkeytype10) | No| No| Function type represented by the Enter key of the input method.|
710
711## InputAttribute<sup>10+</sup>
712
713Describes the attributes of the edit box, including the text input type and Enter key function type.
714
715**System capability**: SystemCapability.MiscServices.InputMethodFramework
716
717| Name| Type| Read-only| Optional| Description|
718| -------- | -------- | -------- | -------- | -------- |
719| textInputType<sup>10+</sup>  | [TextInputType](#textinputtype10) | No| No| Enumerates the text input types.|
720| enterKeyType<sup>10+</sup>  | [EnterKeyType](#enterkeytype10) | No| No| Function type represented by the Enter key.|
721
722## TextConfig<sup>10+</sup>
723
724Describes the configuration of the edit box.
725
726**System capability**: SystemCapability.MiscServices.InputMethodFramework
727
728| Name| Type| Read-only| Optional| Description|
729| -------- | -------- | -------- | -------- | -------- |
730| inputAttribute<sup>10+</sup>  | [InputAttribute](#inputattribute10) | No| No| Edit box attribute.|
731| cursorInfo<sup>10+</sup>  | [CursorInfo](#cursorinfo10) | No| Yes| Cursor information.|
732| selection<sup>10+</sup>  | [Range](#range10) | No| Yes| Text selection range.|
733| windowId<sup>10+</sup>  | number | No| Yes| ID of the window where the edit box is located.|
734
735## CursorInfo<sup>10+</sup>
736
737Represents the cursor information.
738
739**System capability**: SystemCapability.MiscServices.InputMethodFramework
740
741| Name| Type| Read-only| Optional| Description|
742| -------- | -------- | -------- | -------- | -------- |
743| left  | number | No| No| Left coordinate of the cursor.|
744| top  | number | No| No| Top coordinate of the cursor.|
745| width  | number | No| No| Width of the cursor.|
746| height  | number | No| No| Height of the cursor.|
747
748## Range<sup>10+</sup>
749
750Describes the range of the selected text.
751
752**System capability**: SystemCapability.MiscServices.InputMethodFramework
753
754| Name| Type| Read-only| Optional| Description|
755| -------- | -------- | -------- | -------- | -------- |
756| start  | number | No| No| Index of the first selected character in the text box.|
757| end  | number | No| No| Index of the last selected character in the text box.|
758
759## Movement<sup>10+</sup>
760
761Describes the direction in which the cursor moves when the text is selected.
762
763**System capability**: SystemCapability.MiscServices.InputMethodFramework
764
765| Name| Type| Read-only| Optional| Description|
766| -------- | -------- | -------- | -------- | -------- |
767| direction  | [Direction](#direction10) | No| No| Direction in which the cursor moves when the text is selected.|
768
769## InputWindowInfo<sup>10+</sup>
770
771Describes the window information of the input method keyboard.
772
773**System capability**: SystemCapability.MiscServices.InputMethodFramework
774
775| Name| Type| Read-only| Optional| Description|
776| -------- | -------- | -------- | -------- | -------- |
777| name  | string | No| No| Name of the input method keyboard window.|
778| left  | number | No| No| Horizontal coordinate of the upper left corner of the input method keyboard window, in px.|
779| top  | number | No| No| Vertical coordinate of the upper left corner of the input method keyboard window, in px.|
780| width  | number | No| No| Width of the input method keyboard window, in px.|
781| height  | number | No| No| Height of the input method keyboard window, in px.|
782## InputMethodController
783
784In the following API examples, you must first use [getController](#inputmethodgetcontroller9) to obtain an **InputMethodController** instance, and then call the APIs using the obtained instance.
785
786### attach<sup>10+</sup>
787
788attach(showKeyboard: boolean, textConfig: TextConfig, callback: AsyncCallback&lt;void&gt;): void
789
790Attaches a self-drawing component to the input method. This API uses an asynchronous callback to return the result.
791
792> **NOTE**
793>
794> An input method can use the following features only when it has a self-drawing component attached to it: showing or hiding the keyboard, updating the cursor information, changing the selection range of the edit box, saving the configuration information, and listening for and processing the information or commands sent by the input method.
795
796**System capability**: SystemCapability.MiscServices.InputMethodFramework
797
798**Parameters**
799
800| Name| Type| Mandatory| Description|
801| -------- | -------- | -------- | -------- |
802| showKeyboard | boolean | Yes| Whether to start the input method keyboard after the self-drawing component is attached to the input method.<br>- The value **true** means to start the input method keyboard, and **false** means the opposite.|
803| textConfig | [TextConfig](#textconfig10) | Yes| Configuration of the edit box.|
804| callback | AsyncCallback&lt;void&gt; | Yes| Callback used to return the result. If the operation is successful, **err** is **undefined**. Otherwise, **err** is an error object.|
805
806**Error codes**
807
808For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md) and [Universal Error Codes](../errorcode-universal.md).
809
810| ID| Error Message                            |
811| -------- | -------------------------------------- |
812| 401      | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
813| 12800003 | input method client error.             |
814| 12800008 | input method manager service error. |
815
816**Example**
817
818```ts
819import { BusinessError } from '@kit.BasicServicesKit';
820
821try {
822  let textConfig: inputMethod.TextConfig = {
823    inputAttribute: {
824      textInputType: 0,
825      enterKeyType: 1
826    }
827  };
828  inputMethodController.attach(true, textConfig, (err: BusinessError) => {
829    if (err) {
830      console.error(`Failed to attach: ${JSON.stringify(err)}`);
831      return;
832    }
833    console.log('Succeeded in attaching the inputMethod.');
834  });
835} catch(err) {
836  console.error(`Failed to attach: ${JSON.stringify(err)}`);
837}
838```
839
840### attach<sup>10+</sup>
841
842attach(showKeyboard: boolean, textConfig: TextConfig): Promise&lt;void&gt;
843
844Attaches a self-drawing component to the input method. This API uses a promise to return the result.
845
846> **NOTE**
847>
848> An input method can use the following features only when it has a self-drawing component attached to it: showing or hiding the keyboard, updating the cursor information, changing the selection range of the edit box, saving the configuration information, and listening for and processing the information or commands sent by the input method.
849
850**System capability**: SystemCapability.MiscServices.InputMethodFramework
851
852**Parameters**
853
854| Name| Type| Mandatory| Description|
855| -------- | -------- | -------- | -------- |
856| showKeyboard | boolean | Yes| Whether to start the input method keyboard after the self-drawing component is attached to the input method.<br>- The value **true** means to start the input method keyboard, and **false** means the opposite.|
857| textConfig | [TextConfig](#textconfig10) | Yes| Configuration of the edit box.|
858
859**Return value**
860
861| Type| Description|
862| -------- | -------- |
863| Promise&lt;void&gt; | Promise that returns no value.|
864
865**Error codes**
866
867For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md) and [Universal Error Codes](../errorcode-universal.md).
868
869| ID| Error Message                            |
870| -------- | -------------------------------------- |
871| 401      | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
872| 12800003 | input method client error.             |
873| 12800008 | input method manager service error. |
874
875**Example**
876
877```ts
878import { BusinessError } from '@kit.BasicServicesKit';
879
880try {
881  let textConfig: inputMethod.TextConfig = {
882    inputAttribute: {
883      textInputType: 0,
884      enterKeyType: 1
885    }
886  };
887  inputMethodController.attach(true, textConfig).then(() => {
888    console.log('Succeeded in attaching inputMethod.');
889  }).catch((err: BusinessError) => {
890    console.error(`Failed to attach: ${JSON.stringify(err)}`);
891  })
892} catch(err) {
893  console.error(`Failed to attach: ${JSON.stringify(err)}`);
894}
895```
896
897### showTextInput<sup>10+</sup>
898
899showTextInput(callback: AsyncCallback&lt;void&gt;): void
900
901Enters the text editing mode. This API uses an asynchronous callback to return the result.
902
903> **NOTE**
904>
905> After the edit box is attached to an input method, this API can be called to start the soft keyboard and enter the text editing state.
906
907**System capability**: SystemCapability.MiscServices.InputMethodFramework
908
909**Parameters**
910
911| Name| Type| Mandatory| Description|
912| -------- | -------- | -------- | -------- |
913| callback | AsyncCallback&lt;void&gt; | Yes| Callback used to return the result. If the operation is successful, **err** is **undefined**. Otherwise, **err** is an error object.|
914
915**Error codes**
916
917For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md).
918
919| ID| Error Message                            |
920| -------- | -------------------------------------- |
921| 12800003 | input method client error.             |
922| 12800008 | input method manager service error. |
923| 12800009 | input method client detached. |
924
925**Example**
926
927```ts
928import { BusinessError } from '@kit.BasicServicesKit';
929
930inputMethodController.showTextInput((err: BusinessError) => {
931  if (err) {
932    console.error(`Failed to showTextInput: ${JSON.stringify(err)}`);
933    return;
934  }
935  console.log('Succeeded in showing the inputMethod.');
936});
937```
938
939### showTextInput<sup>10+</sup>
940
941showTextInput(): Promise&lt;void&gt;
942
943Enters the text editing mode. This API uses a promise to return the result.
944
945> **NOTE**
946>
947> After the edit box is attached to an input method, this API can be called to start the soft keyboard and enter the text editing state.
948
949**System capability**: SystemCapability.MiscServices.InputMethodFramework
950
951**Return value**
952
953| Type| Description|
954| -------- | -------- |
955| Promise&lt;void&gt; | Promise that returns no value.|
956
957**Error codes**
958
959For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md).
960
961| ID| Error Message                            |
962| -------- | -------------------------------------- |
963| 12800003 | input method client error.             |
964| 12800008 | input method manager service error. |
965| 12800009 | input method client detached. |
966
967**Example**
968
969```ts
970import { BusinessError } from '@kit.BasicServicesKit';
971
972inputMethodController.showTextInput().then(() => {
973  console.log('Succeeded in showing text input.');
974}).catch((err: BusinessError) => {
975  console.error(`Failed to showTextInput: ${JSON.stringify(err)}`);
976});
977```
978
979### hideTextInput<sup>10+</sup>
980
981hideTextInput(callback: AsyncCallback&lt;void&gt;): void
982
983Exits the text editing mode. This API uses an asynchronous callback to return the result.
984
985> **NOTE**
986>
987> If the soft keyboard is displayed when this API is called, it will be hidden.
988>
989> Calling this API does not detach the edit box from the input method. The edit box can call [showTextInput](#showtextinput10) again to reenter the text editing mode.
990
991**System capability**: SystemCapability.MiscServices.InputMethodFramework
992
993**Parameters**
994
995| Name| Type| Mandatory| Description|
996| -------- | -------- | -------- | -------- |
997| callback | AsyncCallback&lt;void&gt; | Yes| Callback used to return the result. If the operation is successful, **err** is **undefined**. Otherwise, **err** is an error object.|
998
999**Error codes**
1000
1001For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md).
1002
1003| ID| Error Message                            |
1004| -------- | -------------------------------------- |
1005| 12800003 | input method client error.             |
1006| 12800008 | input method manager service error. |
1007| 12800009 | input method client detached.             |
1008
1009**Example**
1010
1011```ts
1012import { BusinessError } from '@kit.BasicServicesKit';
1013
1014inputMethodController.hideTextInput((err: BusinessError) => {
1015  if (err) {
1016    console.error(`Failed to hideTextInput: ${JSON.stringify(err)}`);
1017    return;
1018  }
1019  console.log('Succeeded in hiding text input.');
1020});
1021```
1022
1023### hideTextInput<sup>10+</sup>
1024
1025hideTextInput(): Promise&lt;void&gt;
1026
1027Exits the text editing mode. This API uses a promise to return the result.
1028
1029> **NOTE**
1030>
1031> If the soft keyboard is displayed when this API is called, it will be hidden.
1032>
1033> Calling this API does not detach the edit box from the input method. The edit box can call [showTextInput](#showtextinput10) again to reenter the text editing mode.
1034
1035**System capability**: SystemCapability.MiscServices.InputMethodFramework
1036
1037**Return value**
1038
1039| Type| Description|
1040| -------- | -------- |
1041| Promise&lt;void&gt; | Promise that returns no value.|
1042
1043**Error codes**
1044
1045For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md).
1046
1047| ID| Error Message                            |
1048| -------- | -------------------------------------- |
1049| 12800003 | input method client error.             |
1050| 12800008 | input method manager service error. |
1051| 12800009 | input method client detached. |
1052
1053**Example**
1054
1055```ts
1056import { BusinessError } from '@kit.BasicServicesKit';
1057
1058inputMethodController.hideTextInput().then(() => {
1059  console.log('Succeeded in hiding inputMethod.');
1060}).catch((err: BusinessError) => {
1061  console.error(`Failed to hideTextInput: ${JSON.stringify(err)}`);
1062})
1063```
1064
1065### detach<sup>10+</sup>
1066
1067detach(callback: AsyncCallback&lt;void&gt;): void
1068
1069Detaches the self-drawing component from the input method. This API uses an asynchronous callback to return the result.
1070
1071**System capability**: SystemCapability.MiscServices.InputMethodFramework
1072
1073**Parameters**
1074
1075| Name| Type| Mandatory| Description|
1076| -------- | -------- | -------- | -------- |
1077| callback | AsyncCallback&lt;void&gt; | Yes| Callback used to return the result. If the operation is successful, **err** is **undefined**. Otherwise, **err** is an error object.|
1078
1079**Error codes**
1080
1081For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md).
1082
1083| ID| Error Message                            |
1084| -------- | -------------------------------------- |
1085| 12800003 | input method client error.             |
1086| 12800008 | input method manager service error. |
1087
1088**Example**
1089
1090```ts
1091import { BusinessError } from '@kit.BasicServicesKit';
1092
1093inputMethodController.detach((err: BusinessError) => {
1094  if (err) {
1095    console.error(`Failed to detach: ${JSON.stringify(err)}`);
1096    return;
1097  }
1098  console.log('Succeeded in detaching inputMethod.');
1099});
1100```
1101
1102### detach<sup>10+</sup>
1103
1104detach(): Promise&lt;void&gt;
1105
1106Detaches the self-drawing component from the input method. This API uses a promise to return the result.
1107
1108**System capability**: SystemCapability.MiscServices.InputMethodFramework
1109
1110**Return value**
1111
1112| Type| Description|
1113| -------- | -------- |
1114| Promise&lt;void&gt; | Promise that returns no value.|
1115
1116**Error codes**
1117
1118For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md).
1119
1120| ID| Error Message                            |
1121| -------- | -------------------------------------- |
1122| 12800003 | input method client error.             |
1123| 12800008 | input method manager service error. |
1124
1125**Example**
1126
1127```ts
1128import { BusinessError } from '@kit.BasicServicesKit';
1129
1130inputMethodController.detach().then(() => {
1131  console.log('Succeeded in detaching inputMethod.');
1132}).catch((err: BusinessError) => {
1133  console.error(`Failed to detach: ${JSON.stringify(err)}`);
1134});
1135```
1136
1137### setCallingWindow<sup>10+</sup>
1138
1139setCallingWindow(windowId: number, callback: AsyncCallback&lt;void&gt;): void
1140
1141Sets the window to be avoided by the input method. This API uses an asynchronous callback to return the result.
1142
1143> **NOTE**
1144>
1145> After the window ID of the application bound to the input method is passed in the API, the input method window will not cover the window holding the application.
1146
1147**System capability**: SystemCapability.MiscServices.InputMethodFramework
1148
1149**Parameters**
1150
1151| Name| Type| Mandatory| Description|
1152| -------- | -------- | -------- | -------- |
1153| windowId | number | Yes| Window ID of the application bound to the input method.|
1154| callback | AsyncCallback&lt;void&gt; | Yes| Callback used to return the result. If the operation is successful, **err** is **undefined**. Otherwise, **err** is an error object.|
1155
1156**Error codes**
1157
1158For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md) and [Universal Error Codes](../errorcode-universal.md).
1159
1160| ID| Error Message                            |
1161| -------- | -------------------------------------- |
1162| 401      | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
1163| 12800003 | input method client error.             |
1164| 12800008 | input method manager service error. |
1165| 12800009 | input method client detached.             |
1166
1167**Example**
1168
1169```ts
1170import { BusinessError } from '@kit.BasicServicesKit';
1171
1172try {
1173  let windowId: number = 2000;
1174  inputMethodController.setCallingWindow(windowId, (err: BusinessError) => {
1175    if (err) {
1176      console.error(`Failed to setCallingWindow: ${JSON.stringify(err)}`);
1177      return;
1178    }
1179    console.log('Succeeded in setting callingWindow.');
1180  });
1181} catch(err) {
1182  console.error(`Failed to setCallingWindow: ${JSON.stringify(err)}`);
1183}
1184```
1185
1186### setCallingWindow<sup>10+</sup>
1187
1188setCallingWindow(windowId: number): Promise&lt;void&gt;
1189
1190Sets the window to be avoided by the input method. This API uses a promise to return the result.
1191
1192> **NOTE**
1193>
1194> After the window ID of the application bound to the input method is passed in the API, the input method window will not cover the window holding the application.
1195
1196**System capability**: SystemCapability.MiscServices.InputMethodFramework
1197
1198**Parameters**
1199
1200| Name| Type| Mandatory| Description|
1201| -------- | -------- | -------- | -------- |
1202| windowId | number | Yes| Window ID of the application bound to the input method.|
1203
1204**Return value**
1205
1206| Type| Description|
1207| -------- | -------- |
1208| Promise&lt;void&gt; | Promise that returns no value.|
1209
1210**Error codes**
1211
1212For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md) and [Universal Error Codes](../errorcode-universal.md).
1213
1214| ID| Error Message                            |
1215| -------- | -------------------------------------- |
1216| 401      | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
1217| 12800003 | input method client error.             |
1218| 12800008 | input method manager service error. |
1219| 12800009 | input method client detached. |
1220
1221**Example**
1222
1223```ts
1224import { BusinessError } from '@kit.BasicServicesKit';
1225
1226try {
1227  let windowId: number = 2000;
1228  inputMethodController.setCallingWindow(windowId).then(() => {
1229    console.log('Succeeded in setting callingWindow.');
1230  }).catch((err: BusinessError) => {
1231    console.error(`Failed to setCallingWindow: ${JSON.stringify(err)}`);
1232  })
1233} catch(err) {
1234  console.error(`Failed to setCallingWindow: ${JSON.stringify(err)}`);
1235}
1236```
1237
1238### updateCursor<sup>10+</sup>
1239
1240updateCursor(cursorInfo: CursorInfo, callback: AsyncCallback&lt;void&gt;): void
1241
1242Updates the cursor information in this edit box. This API can be called to notify the input method of the cursor changes. This API uses an asynchronous callback to return the result.
1243
1244**System capability**: SystemCapability.MiscServices.InputMethodFramework
1245
1246**Parameters**
1247
1248| Name| Type| Mandatory| Description|
1249| -------- | -------- | -------- | -------- |
1250| cursorInfo | [CursorInfo](#cursorinfo10) | Yes| Cursor information.|
1251| callback | AsyncCallback&lt;void&gt; | Yes| Callback used to return the result. If the operation is successful, **err** is **undefined**. Otherwise, **err** is an error object.|
1252
1253**Error codes**
1254
1255For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md) and [Universal Error Codes](../errorcode-universal.md).
1256
1257| ID| Error Message                            |
1258| -------- | -------------------------------------- |
1259| 401      | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.           |
1260| 12800003 | input method client error.             |
1261| 12800008 | input method manager service error. |
1262| 12800009 | input method client detached.             |
1263
1264**Example**
1265
1266```ts
1267import { BusinessError } from '@kit.BasicServicesKit';
1268
1269try {
1270  let cursorInfo: inputMethod.CursorInfo = { left: 0, top: 0, width: 600, height: 800 };
1271  inputMethodController.updateCursor(cursorInfo, (err: BusinessError) => {
1272    if (err) {
1273      console.error(`Failed to updateCursor: ${JSON.stringify(err)}`);
1274      return;
1275    }
1276    console.log('Succeeded in updating cursorInfo.');
1277  });
1278} catch(err) {
1279  console.error(`Failed to updateCursor: ${JSON.stringify(err)}`);
1280}
1281```
1282
1283### updateCursor<sup>10+</sup>
1284
1285updateCursor(cursorInfo: CursorInfo): Promise&lt;void&gt;
1286
1287Updates the cursor information in this edit box. This API can be called to notify the input method of the cursor changes. This API uses a promise to return the result.
1288
1289**System capability**: SystemCapability.MiscServices.InputMethodFramework
1290
1291**Parameters**
1292
1293| Name| Type| Mandatory| Description|
1294| -------- | -------- | -------- | -------- |
1295| cursorInfo | [CursorInfo](#cursorinfo10) | Yes| Cursor information.|
1296
1297**Return value**
1298
1299| Type| Description|
1300| -------- | -------- |
1301| Promise&lt;void&gt; | Promise that returns no value.|
1302
1303**Error codes**
1304
1305For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md) and [Universal Error Codes](../errorcode-universal.md).
1306
1307| ID| Error Message                            |
1308| -------- | -------------------------------------- |
1309| 401      | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.           |
1310| 12800003 | input method client error.             |
1311| 12800008 | input method manager service error. |
1312| 12800009 | input method client detached. |
1313
1314**Example**
1315
1316```ts
1317import { BusinessError } from '@kit.BasicServicesKit';
1318
1319try {
1320  let cursorInfo: inputMethod.CursorInfo = { left: 0, top: 0, width: 600, height: 800 };
1321  inputMethodController.updateCursor(cursorInfo).then(() => {
1322    console.log('Succeeded in updating cursorInfo.');
1323  }).catch((err: BusinessError) => {
1324    console.error(`Failed to updateCursor: ${JSON.stringify(err)}`);
1325  })
1326} catch(err) {
1327  console.error(`Failed to updateCursor: ${JSON.stringify(err)}`);
1328}
1329```
1330
1331### changeSelection<sup>10+</sup>
1332
1333changeSelection(text: string, start: number, end: number, callback: AsyncCallback&lt;void&gt;): void
1334
1335Updates the information about the selected text in this edit box, to notify the input method when the selected text content or text range changes. This API uses an asynchronous callback to return the result.
1336
1337**System capability**: SystemCapability.MiscServices.InputMethodFramework
1338
1339**Parameters**
1340
1341| Name| Type| Mandatory| Description|
1342| -------- | -------- | -------- | -------- |
1343| text | string | Yes| All input text.|
1344| start | number | Yes| Start position of the selected text.|
1345| end | number | Yes| End position of the selected text.|
1346| callback | AsyncCallback&lt;void&gt; | Yes| Callback used to return the result. If the operation is successful, **err** is **undefined**. Otherwise, **err** is an error object.|
1347
1348**Error codes**
1349
1350For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md) and [Universal Error Codes](../errorcode-universal.md).
1351
1352| ID| Error Message                            |
1353| -------- | -------------------------------------- |
1354| 401      | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
1355| 12800003 | input method client error.             |
1356| 12800008 | input method manager service error. |
1357| 12800009 | input method client detached.             |
1358
1359**Example**
1360
1361```ts
1362import { BusinessError } from '@kit.BasicServicesKit';
1363
1364try {
1365  inputMethodController.changeSelection('text', 0, 5, (err: BusinessError) => {
1366    if (err) {
1367      console.error(`Failed to changeSelection: ${JSON.stringify(err)}`);
1368      return;
1369    }
1370    console.log('Succeeded in changing selection.');
1371  });
1372} catch(err) {
1373  console.error(`Failed to changeSelection: ${JSON.stringify(err)}`);
1374}
1375```
1376
1377### changeSelection<sup>10+</sup>
1378
1379changeSelection(text: string, start: number, end: number): Promise&lt;void&gt;
1380
1381Updates the information about the selected text in this edit box, to notify the input method when the selected text content or text range changes. This API uses a promise to return the result.
1382
1383**System capability**: SystemCapability.MiscServices.InputMethodFramework
1384
1385**Parameters**
1386
1387| Name| Type| Mandatory| Description|
1388| -------- | -------- | -------- | -------- |
1389| text | string | Yes| All input text.|
1390| start | number | Yes| Start position of the selected text.|
1391| end | number | Yes| End position of the selected text.|
1392
1393**Return value**
1394
1395| Type| Description|
1396| -------- | -------- |
1397| Promise&lt;void&gt; | Promise that returns no value.|
1398
1399**Error codes**
1400
1401For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md) and [Universal Error Codes](../errorcode-universal.md).
1402
1403| ID| Error Message                            |
1404| -------- | -------------------------------------- |
1405| 401      | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
1406| 12800003 | input method client error.             |
1407| 12800008 | input method manager service error. |
1408| 12800009 | input method client detached. |
1409
1410**Example**
1411
1412```ts
1413import { BusinessError } from '@kit.BasicServicesKit';
1414
1415try {
1416  inputMethodController.changeSelection('test', 0, 5).then(() => {
1417    console.log('Succeeded in changing selection.');
1418  }).catch((err: BusinessError) => {
1419    console.error(`Failed to changeSelection: ${JSON.stringify(err)}`);
1420  })
1421} catch(err) {
1422  console.error(`Failed to changeSelection: ${JSON.stringify(err)}`);
1423}
1424```
1425
1426### updateAttribute<sup>10+</sup>
1427
1428updateAttribute(attribute: InputAttribute, callback: AsyncCallback&lt;void&gt;): void
1429
1430Updates the attribute information of this edit box. This API uses an asynchronous callback to return the result.
1431
1432**System capability**: SystemCapability.MiscServices.InputMethodFramework
1433
1434**Parameters**
1435
1436| Name| Type| Mandatory| Description|
1437| -------- | -------- | -------- | -------- |
1438| attribute | [InputAttribute](#inputattribute10) | Yes| Attribute information.|
1439| callback | AsyncCallback&lt;void&gt; | Yes| Callback used to return the result. If the operation is successful, **err** is **undefined**. Otherwise, **err** is an error object.|
1440
1441**Error codes**
1442
1443For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md) and [Universal Error Codes](../errorcode-universal.md).
1444
1445| ID| Error Message                            |
1446| -------- | -------------------------------------- |
1447| 401      | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
1448| 12800003 | input method client error.             |
1449| 12800008 | input method manager service error. |
1450| 12800009 | input method client detached.             |
1451
1452**Example**
1453
1454```ts
1455import { BusinessError } from '@kit.BasicServicesKit';
1456
1457try {
1458  let inputAttribute: inputMethod.InputAttribute = { textInputType: 0, enterKeyType: 1 };
1459  inputMethodController.updateAttribute(inputAttribute, (err: BusinessError) => {
1460    if (err) {
1461      console.error(`Failed to updateAttribute: ${JSON.stringify(err)}`);
1462      return;
1463    }
1464    console.log('Succeeded in updating attribute.');
1465  });
1466} catch(err) {
1467  console.error(`Failed to updateAttribute: ${JSON.stringify(err)}`);
1468}
1469```
1470
1471### updateAttribute<sup>10+</sup>
1472
1473updateAttribute(attribute: InputAttribute): Promise&lt;void&gt;
1474
1475Updates the attribute information of this edit box. This API uses a promise to return the result.
1476
1477**System capability**: SystemCapability.MiscServices.InputMethodFramework
1478
1479**Parameters**
1480
1481| Name| Type| Mandatory| Description|
1482| -------- | -------- | -------- | -------- |
1483| attribute | [InputAttribute](#inputattribute10) | Yes|  Attribute information.|
1484
1485**Return value**
1486
1487| Type| Description|
1488| -------- | -------- |
1489| Promise&lt;void&gt; | Promise that returns no value.|
1490
1491**Error codes**
1492
1493For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md) and [Universal Error Codes](../errorcode-universal.md).
1494
1495| ID| Error Message                            |
1496| -------- | -------------------------------------- |
1497| 401      | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
1498| 12800003 | input method client error.             |
1499| 12800008 | input method manager service error. |
1500| 12800009 | input method client detached. |
1501
1502**Example**
1503
1504```ts
1505import { BusinessError } from '@kit.BasicServicesKit';
1506
1507try {
1508  let inputAttribute: inputMethod.InputAttribute = { textInputType: 0, enterKeyType: 1 };
1509  inputMethodController.updateAttribute(inputAttribute).then(() => {
1510    console.log('Succeeded in updating attribute.');
1511  }).catch((err: BusinessError) => {
1512    console.error(`Failed to updateAttribute: ${JSON.stringify(err)}`);
1513  })
1514} catch(err) {
1515  console.error(`Failed to updateAttribute: ${JSON.stringify(err)}`);
1516}
1517```
1518
1519### stopInputSession<sup>9+</sup>
1520
1521stopInputSession(callback: AsyncCallback&lt;boolean&gt;): void
1522
1523Ends this input session. This API uses an asynchronous callback to return the result.
1524
1525> **NOTE**
1526>
1527> This API can be called only when the edit box is attached to the input method. That is, it can be called to end the input session only when the edit box is focused.
1528
1529**System capability**: SystemCapability.MiscServices.InputMethodFramework
1530
1531**Parameters**
1532
1533| Name| Type| Mandatory| Description|
1534| -------- | -------- | -------- | -------- |
1535| callback | AsyncCallback&lt;boolean&gt; | Yes| Callback used to return the result. If the operation is successful, **err** is **undefined** and **data** is **true**. Otherwise, **err** is an error object.|
1536
1537**Error codes**
1538
1539For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md).
1540
1541| ID| Error Message                            |
1542| -------- | -------------------------------------- |
1543| 12800003 | input method client error.             |
1544| 12800008 | input method manager service error. |
1545
1546**Example**
1547
1548```ts
1549import { BusinessError } from '@kit.BasicServicesKit';
1550
1551try {
1552  inputMethodController.stopInputSession((err: BusinessError, result: boolean) => {
1553    if (err) {
1554      console.error(`Failed to stopInputSession: ${JSON.stringify(err)}`);
1555      return;
1556    }
1557    if (result) {
1558      console.log('Succeeded in stopping inputSession.');
1559    } else {
1560      console.error('Failed to stopInputSession.');
1561    }
1562  });
1563} catch(err) {
1564  console.error(`Failed to stopInputSession: ${JSON.stringify(err)}`);
1565}
1566```
1567
1568### stopInputSession<sup>9+</sup>
1569
1570stopInputSession(): Promise&lt;boolean&gt;
1571
1572Ends this input session. This API uses a promise to return the result.
1573
1574> **NOTE**
1575>
1576> This API can be called only when the edit box is attached to the input method. That is, it can be called to end the input session only when the edit box is focused.
1577
1578**System capability**: SystemCapability.MiscServices.InputMethodFramework
1579
1580**Return value**
1581
1582| Type| Description|
1583| -------- | -------- |
1584| Promise&lt;boolean&gt; | Promise used to return the result. The value **true** means that the operation is successful, and **false** means the opposite.|
1585
1586**Error codes**
1587
1588For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md).
1589
1590| ID| Error Message                            |
1591| -------- | -------------------------------------- |
1592| 12800003 | input method client error.             |
1593| 12800008 | input method manager service error. |
1594
1595**Example**
1596
1597```ts
1598import { BusinessError } from '@kit.BasicServicesKit';
1599
1600try {
1601  inputMethodController.stopInputSession().then((result: boolean) => {
1602    if (result) {
1603      console.log('Succeeded in stopping inputSession.');
1604    } else {
1605      console.error('Failed to stopInputSession.');
1606    }
1607  }).catch((err: BusinessError) => {
1608    console.error(`Failed to stopInputSession: ${JSON.stringify(err)}`);
1609  })
1610} catch(err) {
1611  console.error(`Failed to stopInputSession: ${JSON.stringify(err)}`);
1612}
1613```
1614
1615### showSoftKeyboard<sup>9+</sup>
1616
1617showSoftKeyboard(callback: AsyncCallback&lt;void&gt;): void
1618
1619Shows the soft keyboard. This API uses an asynchronous callback to return the result.
1620
1621> **NOTE**
1622>
1623> This API can be called only when the edit box is attached to the input method. That is, it can be called to show the soft keyboard only when the edit box is focused.
1624
1625**Required permissions**: ohos.permission.CONNECT_IME_ABILITY (for system applications only)
1626
1627**System capability**: SystemCapability.MiscServices.InputMethodFramework
1628
1629**Parameters**
1630
1631| Name  | Type                 | Mandatory| Description      |
1632| -------- | ------------------------- | ---- | ---------- |
1633| callback | AsyncCallback&lt;void&gt; | Yes  | Callback used to return the result. If the operation is successful, **err** is **undefined**. Otherwise, **err** is an error object.|
1634
1635**Error codes**
1636
1637For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md) and [Universal Error Codes](../errorcode-universal.md).
1638
1639| ID| Error Message                            |
1640| -------- | -------------------------------------- |
1641| 201      | permissions check fails.  |
1642| 12800003 | input method client error.             |
1643| 12800008 | input method manager service error. |
1644
1645**Example**
1646
1647```ts
1648import { BusinessError } from '@kit.BasicServicesKit';
1649
1650inputMethodController.showSoftKeyboard((err: BusinessError) => {
1651  if (!err) {
1652    console.log('Succeeded in showing softKeyboard.');
1653  } else {
1654    console.error(`Failed to show softKeyboard: ${JSON.stringify(err)}`);
1655  }
1656})
1657```
1658
1659### showSoftKeyboard<sup>9+</sup>
1660
1661showSoftKeyboard(): Promise&lt;void&gt;
1662
1663Shows the soft keyboard. This API uses a promise to return the result.
1664
1665> **NOTE**
1666>
1667> This API can be called only when the edit box is attached to the input method. That is, it can be called to show the soft keyboard only when the edit box is focused.
1668
1669**Required permissions**: ohos.permission.CONNECT_IME_ABILITY (for system applications only)
1670
1671**System capability**: SystemCapability.MiscServices.InputMethodFramework
1672
1673**Return value**
1674
1675| Type               | Description                     |
1676| ------------------- | ------------------------- |
1677| Promise&lt;void&gt; | Promise that returns no value.|
1678
1679**Error codes**
1680
1681For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md) and [Universal Error Codes](../errorcode-universal.md).
1682
1683| ID| Error Message                            |
1684| -------- | -------------------------------------- |
1685| 201      | permissions check fails.  |
1686| 12800003 | input method client error.             |
1687| 12800008 | input method manager service error. |
1688
1689**Example**
1690
1691```ts
1692import { BusinessError } from '@kit.BasicServicesKit';
1693
1694inputMethodController.showSoftKeyboard().then(() => {
1695  console.log('Succeeded in showing softKeyboard.');
1696}).catch((err: BusinessError) => {
1697  console.error(`Failed to show softKeyboard: ${JSON.stringify(err)}`);
1698});
1699```
1700
1701### hideSoftKeyboard<sup>9+</sup>
1702
1703hideSoftKeyboard(callback: AsyncCallback&lt;void&gt;): void
1704
1705Hides the soft keyboard. This API uses an asynchronous callback to return the result.
1706
1707> **NOTE**
1708>
1709> This API can be called only when the edit box is attached to the input method. That is, it can be called to hide the soft keyboard only when the edit box is focused.
1710
1711**Required permissions**: ohos.permission.CONNECT_IME_ABILITY (for system applications only)
1712
1713**System capability**: SystemCapability.MiscServices.InputMethodFramework
1714
1715**Parameters**
1716
1717| Name  | Type                 | Mandatory| Description      |
1718| -------- | ------------------------- | ---- | ---------- |
1719| callback | AsyncCallback&lt;void&gt; | Yes  | Callback used to return the result. If the operation is successful, **err** is **undefined**. Otherwise, **err** is an error object.|
1720
1721**Error codes**
1722
1723For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md) and [Universal Error Codes](../errorcode-universal.md).
1724
1725| ID| Error Message                            |
1726| -------- | -------------------------------------- |
1727| 201      | permissions check fails.  |
1728| 12800003 | input method client error.             |
1729| 12800008 | input method manager service error. |
1730
1731**Example**
1732
1733```ts
1734import { BusinessError } from '@kit.BasicServicesKit';
1735
1736inputMethodController.hideSoftKeyboard((err: BusinessError) => {
1737  if (!err) {
1738    console.log('Succeeded in hiding softKeyboard.');
1739  } else {
1740    console.error(`Failed to hide softKeyboard: ${JSON.stringify(err)}`);
1741  }
1742})
1743```
1744
1745### hideSoftKeyboard<sup>9+</sup>
1746
1747hideSoftKeyboard(): Promise&lt;void&gt;
1748
1749Hides the soft keyboard. This API uses a promise to return the result.
1750
1751> **NOTE**
1752>
1753> This API can be called only when the edit box is attached to the input method. That is, it can be called to hide the soft keyboard only when the edit box is focused.
1754
1755**Required permissions**: ohos.permission.CONNECT_IME_ABILITY (for system applications only)
1756
1757**System capability**: SystemCapability.MiscServices.InputMethodFramework
1758
1759**Return value**
1760
1761| Type               | Description                     |
1762| ------------------- | ------------------------- |
1763| Promise&lt;void&gt; | Promise that returns no value.|
1764
1765**Error codes**
1766
1767For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md) and [Universal Error Codes](../errorcode-universal.md).
1768
1769| ID| Error Message                            |
1770| -------- | -------------------------------------- |
1771| 201      | permissions check fails.  |
1772| 12800003 | input method client error.             |
1773| 12800008 | input method manager service error. |
1774
1775**Example**
1776
1777```ts
1778import { BusinessError } from '@kit.BasicServicesKit';
1779
1780inputMethodController.hideSoftKeyboard().then(() => {
1781  console.log('Succeeded in hiding softKeyboard.');
1782}).catch((err: BusinessError) => {
1783  console.error(`Failed to hide softKeyboard: ${JSON.stringify(err)}`);
1784});
1785```
1786
1787### stopInput<sup>(deprecated)</sup>
1788
1789stopInput(callback: AsyncCallback&lt;boolean&gt;): void
1790
1791Ends this input session. This API uses an asynchronous callback to return the result.
1792
1793> **NOTE**
1794>
1795> This API can be called only when the edit box is attached to the input method. That is, it can be called to end the input session only when the edit box is focused.
1796>
1797> This API is supported since API version 6 and deprecated since API version 9. You are advised to use [stopInputSession()](#stopinputsession9) instead.
1798
1799**System capability**: SystemCapability.MiscServices.InputMethodFramework
1800
1801**Parameters**
1802
1803| Name| Type| Mandatory| Description|
1804| -------- | -------- | -------- | -------- |
1805| callback | AsyncCallback&lt;boolean&gt; | Yes| Callback used to return the result. If the operation is successful, **err** is **undefined** and **data** is **true**. Otherwise, **err** is an error object.|
1806
1807**Example**
1808
1809```ts
1810import { BusinessError } from '@kit.BasicServicesKit';
1811
1812inputMethodController.stopInput((err: BusinessError, result: boolean) => {
1813  if (err) {
1814    console.error(`Failed to stopInput: ${JSON.stringify(err)}`);
1815    return;
1816  }
1817  if (result) {
1818    console.log('Succeeded in stopping input.');
1819  } else {
1820    console.error('Failed to stopInput.');
1821  }
1822});
1823```
1824
1825### stopInput<sup>(deprecated)</sup>
1826
1827stopInput(): Promise&lt;boolean&gt;
1828
1829Ends this input session. This API uses a promise to return the result.
1830
1831> **NOTE**
1832>
1833> This API can be called only when the edit box is attached to the input method. That is, it can be called to end the input session only when the edit box is focused.
1834>
1835> This API is supported since API version 6 and deprecated since API version 9. You are advised to use [stopInputSession()](#stopinputsession9) instead.
1836
1837**System capability**: SystemCapability.MiscServices.InputMethodFramework
1838
1839**Return value**
1840
1841| Type| Description|
1842| -------- | -------- |
1843| Promise&lt;boolean&gt; | Promise used to return the result. The value **true** means that the operation is successful, and **false** means the opposite.|
1844
1845**Example**
1846
1847```ts
1848import { BusinessError } from '@kit.BasicServicesKit';
1849
1850inputMethodController.stopInput().then((result: boolean) => {
1851  if (result) {
1852    console.log('Succeeded in stopping input.');
1853  } else {
1854    console.error('Failed to stopInput.');
1855  }
1856}).catch((err: BusinessError) => {
1857  console.error(`Failed to stopInput: ${JSON.stringify(err)}`);
1858})
1859```
1860
1861### on('insertText')<sup>10+</sup>
1862
1863on(type: 'insertText', callback: (text: string) => void): void
1864
1865Enables listening for the text insertion event of the input method. This API uses an asynchronous callback to return the result.
1866
1867**System capability**: SystemCapability.MiscServices.InputMethodFramework
1868
1869**Parameters**
1870
1871| Name  | Type                                                        | Mandatory| Description                                                        |
1872| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
1873| type     | string                                                       | Yes  | Listening type. The value is fixed at **'insertText'**.|
1874| callback | (text: string) => void | Yes  | Callback used to return the text to be inserted.<br>The application needs to operate the content in the edit box based on the text content returned in the callback.|
1875
1876**Error codes**
1877
1878For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md) and [Universal Error Codes](../errorcode-universal.md).
1879
1880| ID| Error Message                            |
1881| -------- | -------------------------------------- |
1882| 401      | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.           |
1883| 12800009 | input method client detached. |
1884
1885**Example**
1886
1887```ts
1888function callback1(text: string) {
1889  console.info('Succeeded in getting callback1 data: ' + JSON.stringify(text));
1890}
1891
1892function callback2(text: string) {
1893  console.info('Succeeded in getting callback2 data: ' + JSON.stringify(text));
1894}
1895
1896try {
1897  inputMethodController.on('insertText', callback1);
1898  inputMethodController.on('insertText', callback2);
1899  // Cancel only callback1 of insertText.
1900  inputMethodController.off('insertText', callback1);
1901  // Cancel all callbacks of insertText.
1902  inputMethodController.off('insertText');
1903} catch(err) {
1904  console.error(`Failed to subscribe insertText: ${JSON.stringify(err)}`);
1905}
1906```
1907
1908### off('insertText')<sup>10+</sup>
1909
1910off(type: 'insertText', callback?: (text: string) => void): void
1911
1912Disables listening for the text insertion event of the input method.
1913
1914**System capability**: SystemCapability.MiscServices.InputMethodFramework
1915
1916**Parameters**
1917
1918| Name  | Type                  | Mandatory| Description                                                        |
1919| -------- | ---------------------- | ---- | ------------------------------------------------------------ |
1920| type     | string                 | Yes  | Listening type. The value is fixed at **'insertText'**.|
1921| callback | (text: string) => void | No  | Callback used for disable listening, which must be the same as that passed by the **on** API.<br>If this parameter is not specified, listening will be disabled for all callbacks corresponding to the specified type.|
1922
1923**Example**
1924
1925```ts
1926let onInsertTextCallback = (text: string) => {
1927    console.log(`Succeeded in subscribing insertText: ${text}`);
1928};
1929inputMethodController.off('insertText', onInsertTextCallback);
1930inputMethodController.off('insertText');
1931```
1932
1933### on('deleteLeft')<sup>10+</sup>
1934
1935on(type: 'deleteLeft', callback: (length: number) => void): void
1936
1937Enables listening for the leftward delete event. This API uses an asynchronous callback to return the result.
1938
1939**System capability**: SystemCapability.MiscServices.InputMethodFramework
1940
1941**Parameters**
1942
1943| Name  | Type| Mandatory| Description|
1944| -------- | ----- | ---- | ----- |
1945| type     | string  | Yes  | Listening type. The value is fixed at **'deleteLeft'**.|
1946| callback | (length: number) => void | Yes  | Callback used to return the length of the text to be deleted leftward.<br>The application needs to operate the content in the edit box based on the length returned in the callback.|
1947
1948**Error codes**
1949
1950For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md) and [Universal Error Codes](../errorcode-universal.md).
1951
1952| ID| Error Message                            |
1953| -------- | -------------------------------------- |
1954| 401      | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.           |
1955| 12800009 | input method client detached. |
1956
1957**Example**
1958
1959```ts
1960try {
1961  inputMethodController.on('deleteLeft', (length: number) => {
1962    console.log(`Succeeded in subscribing deleteLeft, length: ${length}`);
1963  });
1964} catch(err) {
1965  console.error(`Failed to subscribe deleteLeft: ${JSON.stringify(err)}`);
1966}
1967```
1968
1969### off('deleteLeft')<sup>10+</sup>
1970
1971off(type: 'deleteLeft', callback?: (length: number) => void): void
1972
1973Disables listening for the leftward delete event.
1974
1975**System capability**: SystemCapability.MiscServices.InputMethodFramework
1976
1977**Parameters**
1978
1979| Name  | Type                    | Mandatory| Description                                                        |
1980| -------- | ------------------------ | ---- | ------------------------------------------------------------ |
1981| type     | string                   | Yes  | Listening type. The value is fixed at **'deleteLeft'**.|
1982| callback | (length: number) => void | No  | Callback used for disable listening, which must be the same as that passed by the **on** API.<br>If this parameter is not specified, listening will be disabled for all callbacks corresponding to the specified type.|
1983
1984**Example**
1985
1986```ts
1987let onDeleteLeftCallback = (length: number) => {
1988    console.log(`Succeeded in subscribing deleteLeft, length: ${length}`);
1989};
1990inputMethodController.off('deleteLeft', onDeleteLeftCallback);
1991inputMethodController.off('deleteLeft');
1992```
1993
1994### on('deleteRight')<sup>10+</sup>
1995
1996on(type: 'deleteRight', callback: (length: number) => void): void
1997
1998Enables listening for the rightward delete event. This API uses an asynchronous callback to return the result.
1999
2000**System capability**: SystemCapability.MiscServices.InputMethodFramework
2001
2002**Parameters**
2003
2004| Name  | Type| Mandatory| Description|
2005| -------- | ----- | ---- | ----- |
2006| type     | string  | Yes  | Listening type. The value is fixed at **'deleteRight'**.|
2007| callback | (length: number) => void | Yes  | Callback used to return the length of the text to be deleted rightward.<br>The application needs to operate the content in the edit box based on the length returned in the callback.|
2008
2009**Error codes**
2010
2011For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md) and [Universal Error Codes](../errorcode-universal.md).
2012
2013| ID| Error Message                            |
2014| -------- | -------------------------------------- |
2015| 401      | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.           |
2016| 12800009 | input method client detached. |
2017
2018**Example**
2019
2020```ts
2021try {
2022  inputMethodController.on('deleteRight', (length: number) => {
2023    console.log(`Succeeded in subscribing deleteRight, length: ${length}`);
2024  });
2025} catch(err) {
2026  console.error(`Failed to subscribe deleteRight: ${JSON.stringify(err)}`);
2027}
2028```
2029
2030### off('deleteRight')<sup>10+</sup>
2031
2032off(type: 'deleteRight', callback?: (length: number) => void): void
2033
2034Disables listening for the rightward delete event.
2035
2036**System capability**: SystemCapability.MiscServices.InputMethodFramework
2037
2038**Parameters**
2039
2040| Name  | Type                    | Mandatory| Description                                                        |
2041| -------- | ------------------------ | ---- | ------------------------------------------------------------ |
2042| type     | string                   | Yes  | Listening type. The value is fixed at `deleteRight`.|
2043| callback | (length: number) => void | No  | Callback used for disable listening, which must be the same as that passed by the **on** API.<br>If this parameter is not specified, listening will be disabled for all callbacks corresponding to the specified type.|
2044
2045**Example**
2046
2047```ts
2048let onDeleteRightCallback = (length: number) => {
2049    console.log(`Succeeded in subscribing deleteRight, length: ${length}`);
2050};
2051inputMethodController.off('deleteRight', onDeleteRightCallback);
2052inputMethodController.off('deleteRight');
2053```
2054
2055### on('sendKeyboardStatus')<sup>10+</sup>
2056
2057on(type: 'sendKeyboardStatus', callback: (keyboardStatus: KeyboardStatus) => void): void
2058
2059Enables listening for the soft keyboard status event of the input method. This API uses an asynchronous callback to return the result.
2060
2061**System capability**: SystemCapability.MiscServices.InputMethodFramework
2062
2063**Parameters**
2064
2065| Name  | Type | Mandatory| Description   |
2066| -------- | ------ | ---- | ---- |
2067| type     | string  | Yes  | Listening type. The value is fixed at **'sendKeyboardStatus'**.|
2068| callback | (keyboardStatus: [KeyboardStatus](#keyboardstatus10)) => void | Yes  | Callback used to return the soft keyboard status.<br>The application needs to perform operations based on the soft keyboard state returned in the callback.|
2069
2070**Error codes**
2071
2072For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md) and [Universal Error Codes](../errorcode-universal.md).
2073
2074| ID| Error Message                            |
2075| -------- | -------------------------------------- |
2076| 401      | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.           |
2077| 12800009 | input method client detached. |
2078
2079**Example**
2080
2081```ts
2082try {
2083  inputMethodController.on('sendKeyboardStatus', (keyboardStatus: inputMethod.KeyboardStatus) => {
2084    console.log(`Succeeded in subscribing sendKeyboardStatus, keyboardStatus: ${keyboardStatus}`);
2085  });
2086} catch(err) {
2087  console.error(`Failed to subscribe sendKeyboardStatus: ${JSON.stringify(err)}`);
2088}
2089```
2090
2091### off('sendKeyboardStatus')<sup>10+</sup>
2092
2093off(type: 'sendKeyboardStatus', callback?: (keyboardStatus: KeyboardStatus) => void): void
2094
2095Disables listening for the soft keyboard status event of the input method.
2096
2097**System capability**: SystemCapability.MiscServices.InputMethodFramework
2098
2099**Parameters**
2100
2101| Name  | Type                                                        | Mandatory| Description                                                        |
2102| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
2103| type     | string                                                       | Yes  | Listening type. The value is fixed at **'sendKeyboardStatus'**.|
2104| callback | (keyboardStatus: [KeyboardStatus](#keyboardstatus10)) => void | No  | Callback used for disable listening. If this parameter is not specified, listening will be disabled for all callbacks corresponding to the specified type.|
2105
2106**Example**
2107
2108```ts
2109let onSendKeyboardStatus = (keyboardStatus: inputMethod.KeyboardStatus) => {
2110    console.log(`Succeeded in subscribing sendKeyboardStatus, keyboardStatus: ${keyboardStatus}`);
2111};
2112inputMethodController.off('sendKeyboardStatus', onSendKeyboardStatus);
2113inputMethodController.off('sendKeyboardStatus');
2114```
2115
2116### on('sendFunctionKey')<sup>10+</sup>
2117
2118on(type: 'sendFunctionKey', callback: (functionKey: FunctionKey) => void): void
2119
2120Enables listening for the function key sending event of the input method. This API uses an asynchronous callback to return the result.
2121
2122**System capability**: SystemCapability.MiscServices.InputMethodFramework
2123
2124**Parameters**
2125
2126| Name  | Type | Mandatory| Description    |
2127| -------- | -------- | ---- | ----- |
2128| type     | string  | Yes  | Listening type. The value is fixed at **'sendFunctionKey'**.|
2129| callback | (functionKey: [FunctionKey](#functionkey10)) => void | Yes  | Callback used to return the function key information sent by the input method.<br>The application needs to perform operations based on the function key information returned in the callback.|
2130
2131**Error codes**
2132
2133For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md) and [Universal Error Codes](../errorcode-universal.md).
2134
2135| ID| Error Message                            |
2136| -------- | -------------------------------------- |
2137| 401      | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.           |
2138| 12800009 | input method client detached. |
2139
2140**Example**
2141
2142```ts
2143try {
2144  inputMethodController.on('sendFunctionKey', (functionKey: inputMethod.FunctionKey) => {
2145    console.log(`Succeeded in subscribing sendFunctionKey, functionKey.enterKeyType: ${functionKey.enterKeyType}`);
2146  });
2147} catch(err) {
2148  console.error(`Failed to subscribe sendFunctionKey: ${JSON.stringify(err)}`);
2149}
2150```
2151
2152### off('sendFunctionKey')<sup>10+</sup>
2153
2154off(type: 'sendFunctionKey', callback?: (functionKey: FunctionKey) => void): void
2155
2156Disables listening for the function key sending event of the input method.
2157
2158**System capability**: SystemCapability.MiscServices.InputMethodFramework
2159
2160**Parameters**
2161
2162| Name  | Type                                                | Mandatory| Description                                                        |
2163| -------- | ---------------------------------------------------- | ---- | ------------------------------------------------------------ |
2164| type     | string                                               | Yes  | Listening type. The value is fixed at **'sendFunctionKey'**.|
2165| callback | (functionKey: [FunctionKey](#functionkey10)) => void | No  | Callback used for disable listening, which must be the same as that passed by the **on** API.<br>If this parameter is not specified, listening will be disabled for all callbacks corresponding to the specified type.|
2166
2167**Example**
2168
2169```ts
2170let onSendFunctionKey = (functionKey: inputMethod.FunctionKey) => {
2171    console.log(`Succeeded in subscribing sendFunctionKey, functionKey: ${functionKey.enterKeyType}`);
2172};
2173inputMethodController.off('sendFunctionKey', onSendFunctionKey);
2174inputMethodController.off('sendFunctionKey');
2175```
2176
2177### on('moveCursor')<sup>10+</sup>
2178
2179on(type: 'moveCursor', callback: (direction: Direction) => void): void
2180
2181Enables listening for the cursor movement event of the input method. This API uses an asynchronous callback to return the result.
2182
2183**System capability**: SystemCapability.MiscServices.InputMethodFramework
2184
2185**Parameters**
2186
2187| Name  | Type| Mandatory| Description  |
2188| -------- | ------ | ---- | ------ |
2189| type     | string | Yes  | Listening type. The value is fixed at **'moveCursor'**.|
2190| callback | callback: (direction: [Direction<sup>10+</sup>](#direction10)) => void | Yes  | Callback used to return the cursor movement direction.<br>The application needs to change the cursor position based on the cursor movement direction returned in the callback. |
2191
2192**Error codes**
2193
2194For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md) and [Universal Error Codes](../errorcode-universal.md).
2195
2196| ID| Error Message                          |
2197| -------- | -------------------------------- |
2198| 401      | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.           |
2199| 12800009 | input method client detached. |
2200
2201**Example**
2202
2203```ts
2204try {
2205  inputMethodController.on('moveCursor', (direction: inputMethod.Direction) => {
2206    console.log(`Succeeded in subscribing moveCursor, direction: ${direction}`);
2207  });
2208} catch(err) {
2209  console.error(`Failed to subscribe moveCursor: ${JSON.stringify(err)}`);
2210}
2211```
2212
2213### off('moveCursor')<sup>10+</sup>
2214
2215off(type: 'moveCursor', callback?: (direction: Direction) => void): void
2216
2217Disables listening for the cursor movement event of the input method.
2218
2219**System capability**: SystemCapability.MiscServices.InputMethodFramework
2220
2221**Parameters**
2222
2223| Name | Type   | Mandatory| Description |
2224| ------ | ------ | ---- | ---- |
2225| type   | string | Yes  | Listening type. The value is fixed at **'moveCursor'**.|
2226| callback | (direction: [Direction<sup>10+</sup>](#direction10)) => void | No| Callback used for disable listening, which must be the same as that passed by the **on** API.<br>If this parameter is not specified, listening will be disabled for all callbacks corresponding to the specified type.|
2227
2228**Example**
2229
2230```ts
2231let onMoveCursorCallback = (direction: inputMethod.Direction) => {
2232    console.log(`Succeeded in subscribing moveCursor, direction: ${direction}`);
2233};
2234inputMethodController.off('moveCursor', onMoveCursorCallback);
2235inputMethodController.off('moveCursor');
2236```
2237
2238### on('handleExtendAction')<sup>10+</sup>
2239
2240on(type: 'handleExtendAction', callback: (action: ExtendAction) => void): void
2241
2242Enables listening for the extended action handling event of the input method. This API uses an asynchronous callback to return the result.
2243
2244**System capability**: SystemCapability.MiscServices.InputMethodFramework
2245
2246**Parameters**
2247
2248| Name  | Type | Mandatory| Description  |
2249| -------- | ------ | ---- | -------- |
2250| type     | string    | Yes  | Listening type. The value is fixed at **'handleExtendAction'**.|
2251| callback | callback: (action: [ExtendAction](#extendaction10)) => void | Yes  | Callback used to return the extended action type.<br>The application needs to perform operations based on the extended action type returned in the callback.|
2252
2253**Error codes**
2254
2255For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md) and [Universal Error Codes](../errorcode-universal.md).
2256
2257| ID| Error Message                            |
2258| -------- | -------------------------------------- |
2259| 401      | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.           |
2260| 12800009 | input method client detached. |
2261
2262**Example**
2263
2264```ts
2265try {
2266  inputMethodController.on('handleExtendAction', (action: inputMethod.ExtendAction) => {
2267    console.log(`Succeeded in subscribing handleExtendAction, action: ${action}`);
2268  });
2269} catch(err) {
2270  console.error(`Failed to subscribe handleExtendAction: ${JSON.stringify(err)}`);
2271}
2272```
2273
2274### off('handleExtendAction')<sup>10+</sup>
2275
2276off(type: 'handleExtendAction', callback?: (action: ExtendAction) => void): void
2277
2278Disables listening for the extended action handling event of the input method. This API uses an asynchronous callback to return the result.
2279
2280**System capability**: SystemCapability.MiscServices.InputMethodFramework
2281
2282**Parameters**
2283
2284| Name| Type  | Mandatory| Description |
2285| ------ | ------ | ---- | ------- |
2286| type   | string | Yes  | Listening type. The value is fixed at **'handleExtendAction'**.|
2287| callback | (action: [ExtendAction](#extendaction10)) => void | No| Callback used for disable listening, which must be the same as that passed by the **on** API.<br>If this parameter is not specified, listening will be disabled for all callbacks corresponding to the specified type.|
2288
2289**Example**
2290
2291```ts
2292try {
2293  let onHandleExtendActionCallback = (action: inputMethod.ExtendAction) => {
2294    console.log(`Succeeded in subscribing handleExtendAction, action: ${action}`);
2295  };
2296  inputMethodController.off('handleExtendAction', onHandleExtendActionCallback);
2297  inputMethodController.off('handleExtendAction');
2298} catch(err) {
2299  console.error(`Failed to subscribe handleExtendAction: ${JSON.stringify(err)}`);
2300}
2301```
2302
2303### on('selectByRange')<sup>10+</sup>
2304
2305on(type: 'selectByRange', callback: Callback&lt;Range&gt;): void
2306
2307Enables listening for the select-by-range event. This API uses an asynchronous callback to return the result.
2308
2309**System capability**: SystemCapability.MiscServices.InputMethodFramework
2310
2311**Parameters**
2312
2313| Name  | Type    | Mandatory| Description    |
2314| -------- | ---- | ---- | ------- |
2315| type     | string  | Yes  | Listening type. The value is fixed at **'selectByRange'**.|
2316| callback | Callback&lt;[Range](#range10)&gt; | Yes  | Callback used to return the range of the text to be selected.<br>The application needs to select the text based on the range returned in the callback.|
2317
2318**Error codes**
2319
2320For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
2321
2322| ID| Error Message                                               |
2323| -------- | ------------------------------------------------------- |
2324| 401      | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.           |
2325
2326**Example**
2327
2328```ts
2329try {
2330  inputMethodController.on('selectByRange', (range: inputMethod.Range) => {
2331    console.log(`Succeeded in subscribing selectByRange: start: ${range.start} , end: ${range.end}`);
2332  });
2333} catch(err) {
2334  console.error(`Failed to subscribe selectByRange: ${JSON.stringify(err)}`);
2335}
2336```
2337
2338### off('selectByRange')<sup>10+</sup>
2339
2340off(type: 'selectByRange', callback?:  Callback&lt;Range&gt;): void
2341
2342Disables listening for the select-by-range event. This API uses an asynchronous callback to return the result.
2343
2344**System capability**: SystemCapability.MiscServices.InputMethodFramework
2345
2346**Parameters**
2347
2348| Name  | Type                             | Mandatory| Description                                                        |
2349| -------- | --------------------------------- | ---- | ------------------------------------------------------------ |
2350| type     | string                            | Yes  | Listening type. The value is fixed at **'selectByRange'**.|
2351| callback | Callback&lt;[Range](#range10)&gt; | No  | Callback used for disable listening, which must be the same as that passed by the **on** API.<br>If this parameter is not specified, listening will be disabled for all callbacks corresponding to the specified type.|
2352
2353**Example**
2354
2355```ts
2356try {
2357  let onSelectByRangeCallback = (range: inputMethod.Range) => {
2358    console.log(`Succeeded in subscribing selectByRange, start: ${range.start} , end: ${range.end}`);
2359  };
2360  inputMethodController.off('selectByRange', onSelectByRangeCallback);
2361  inputMethodController.off('selectByRange');
2362} catch(err) {
2363  console.error(`Failed to subscribe selectByRange: ${JSON.stringify(err)}`);
2364}
2365```
2366
2367### on('selectByMovement')<sup>10+</sup>
2368
2369on(type: 'selectByMovement', callback: Callback&lt;Movement&gt;): void
2370
2371Enables listening for the select-by-cursor-movement event. This API uses an asynchronous callback to return the result.
2372
2373**System capability**: SystemCapability.MiscServices.InputMethodFramework
2374
2375**Parameters**
2376
2377| Name  | Type  | Mandatory| Description    |
2378| -------- | ----- | ---- | ------ |
2379| type     | string  | Yes  | Listening type. The value is fixed at **'selectByMovement'**.|
2380| callback | Callback&lt;[Movement](#movement10)&gt; | Yes  | Callback used to return the direction in which the cursor moves.<br>The application needs to select the text based on the direction returned in the callback.|
2381
2382**Error codes**
2383
2384For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
2385
2386| ID| Error Message                                               |
2387| -------- | ------------------------------------------------------- |
2388| 401      | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.           |
2389
2390**Example**
2391
2392```ts
2393try {
2394  inputMethodController.on('selectByMovement', (movement: inputMethod.Movement) => {
2395    console.log('Succeeded in subscribing selectByMovement: direction: ' + movement.direction);
2396  });
2397} catch(err) {
2398  console.error(`Failed to subscribe selectByMovement: ${JSON.stringify(err)}`);
2399}
2400```
2401
2402### off('selectByMovement')<sup>10+</sup>
2403
2404off(type: 'selectByMovement', callback?: Callback&lt;Movement&gt;): void
2405
2406Disables listening for the select-by-cursor-movement event. This API uses an asynchronous callback to return the result.
2407
2408**System capability**: SystemCapability.MiscServices.InputMethodFramework
2409
2410**Parameters**
2411
2412| Name  | Type                                | Mandatory| Description                                                        |
2413| -------- | ------------------------------------ | ---- | ------------------------------------------------------------ |
2414| type     | string                               | Yes  | Listening type. The value is fixed at **'selectByMovement'**.|
2415| callback | Callback&lt;[Movement](#movement10)> | No  | Callback used for disable listening, which must be the same as that passed by the **on** API.<br>If this parameter is not specified, listening will be disabled for all callbacks corresponding to the specified type.|
2416
2417**Example**
2418
2419```ts
2420try {
2421  let onSelectByMovementCallback = (movement: inputMethod.Movement) => {
2422    console.log(`Succeeded in subscribing selectByMovement, movement.direction: ${movement.direction}`);
2423  };
2424  inputMethodController.off('selectByMovement', onSelectByMovementCallback);
2425  inputMethodController.off('selectByMovement');
2426} catch(err) {
2427  console.error(`Failed to unsubscribing selectByMovement: ${JSON.stringify(err)}`);
2428}
2429```
2430
2431### on('getLeftTextOfCursor')<sup>10+</sup>
2432
2433on(type: 'getLeftTextOfCursor', callback: (length: number) => string): void
2434
2435Enables listening for the event of obtaining the length of text deleted leftward. This API uses an asynchronous callback to return the result.
2436
2437**System capability**: SystemCapability.MiscServices.InputMethodFramework
2438
2439**Parameters**
2440
2441| Name  | Type  | Mandatory| Description    |
2442| -------- | ----- | ---- | ------ |
2443| type     | string  | Yes  | Listening type. The value is fixed at **'getLeftTextOfCursor'**.|
2444| callback | (length: number) => string | Yes  | Callback used to obtain the text of the specified length deleted leftward.|
2445
2446**Error codes**
2447
2448For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md) and [Universal Error Codes](../errorcode-universal.md).
2449
2450| ID| Error Message                            |
2451| -------- | -------------------------------------- |
2452| 401      | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.           |
2453| 12800009 | input method client detached. |
2454
2455**Example**
2456
2457```ts
2458try {
2459  inputMethodController.on('getLeftTextOfCursor', (length: number) => {
2460    console.info(`Succeeded in subscribing getLeftTextOfCursor, length: ${length}`);
2461    let text:string = "";
2462    return text;
2463  });
2464} catch(err) {
2465  console.error(`Failed to unsubscribing getLeftTextOfCursor. err: ${JSON.stringify(err)}`);
2466}
2467```
2468
2469### off('getLeftTextOfCursor')<sup>10+</sup>
2470
2471off(type: 'getLeftTextOfCursor', callback?: (length: number) => string): void
2472
2473Disables listening for the event of obtaining the length of text deleted leftward. This API uses an asynchronous callback to return the result.
2474
2475**System capability**: SystemCapability.MiscServices.InputMethodFramework
2476
2477**Parameters**
2478
2479| Name| Type  | Mandatory| Description                                                        |
2480| ------ | ------ | ---- | ------------------------------------------------------------ |
2481| type   | string | Yes  | Listening type. The value is fixed at **'getLeftTextOfCursor'**.|
2482| callback | (length: number) => string | No | Callback used for disable listening, which must be the same as that passed by the **on** API.<br>If this parameter is not specified, listening will be disabled for all callbacks corresponding to the specified type.|
2483
2484**Example**
2485
2486```ts
2487try {
2488  let getLeftTextOfCursorCallback = (length: number) => {
2489    console.info(`Succeeded in unsubscribing getLeftTextOfCursor, length: ${length}`);
2490    let text:string = "";
2491    return text;
2492  };
2493  inputMethodController.off('getLeftTextOfCursor', getLeftTextOfCursorCallback);
2494  inputMethodController.off('getLeftTextOfCursor');
2495} catch(err) {
2496  console.error(`Failed to unsubscribing getLeftTextOfCursor. err: ${JSON.stringify(err)}`);
2497}
2498```
2499
2500### on('getRightTextOfCursor')<sup>10+</sup>
2501
2502on(type: 'getRightTextOfCursor', callback: (length: number) => string): void
2503
2504Enables listening for the event of obtaining the length of text deleted rightward. This API uses an asynchronous callback to return the result.
2505
2506**System capability**: SystemCapability.MiscServices.InputMethodFramework
2507
2508**Parameters**
2509
2510| Name  | Type  | Mandatory| Description    |
2511| -------- | ----- | ---- | ------ |
2512| type     | string  | Yes  | Listening type. The value is fixed at **'getRightTextOfCursor'**.|
2513| callback | (length: number) => string | Yes  | Callback used to obtain the text of the specified length deleted rightward.|
2514
2515**Error codes**
2516
2517For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md) and [Universal Error Codes](../errorcode-universal.md).
2518
2519| ID| Error Message                            |
2520| -------- | -------------------------------------- |
2521| 401      | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.           |
2522| 12800009 | input method client detached. |
2523
2524**Example**
2525
2526```ts
2527try {
2528  inputMethodController.on('getRightTextOfCursor', (length: number) => {
2529    console.info(`Succeeded in subscribing getRightTextOfCursor, length: ${length}`);
2530    let text:string = "";
2531    return text;
2532  });
2533} catch(err) {
2534  console.error(`Failed to subscribe getRightTextOfCursor. err: ${JSON.stringify(err)}`);
2535}
2536```
2537
2538### off('getRightTextOfCursor')<sup>10+</sup>
2539
2540off(type: 'getRightTextOfCursor', callback?: (length: number) => string): void
2541
2542Disables listening for the event of obtaining the length of text deleted rightward. This API uses an asynchronous callback to return the result.
2543
2544**System capability**: SystemCapability.MiscServices.InputMethodFramework
2545
2546**Parameters**
2547
2548| Name| Type  | Mandatory| Description                                                        |
2549| ------ | ------ | ---- | ------------------------------------------------------------ |
2550| type   | string | Yes  | Listening type. The value is fixed at **'getRightTextOfCursor'**.|
2551| callback | (length: number) => string | No |Callback used for disable listening, which must be the same as that passed by the **on** API.<br>If this parameter is not specified, listening will be disabled for all callbacks corresponding to the specified type.|
2552
2553**Example**
2554
2555```ts
2556try {
2557  let getRightTextOfCursorCallback = (length: number) => {
2558    console.info(`Succeeded in unsubscribing getRightTextOfCursor, length: ${length}`);
2559    let text:string = "";
2560    return text;
2561  };
2562  inputMethodController.off('getRightTextOfCursor', getRightTextOfCursorCallback);
2563  inputMethodController.off('getRightTextOfCursor');
2564} catch(err) {
2565  console.error(`Failed to unsubscribing getRightTextOfCursor. err: ${JSON.stringify(err)}`);
2566}
2567```
2568
2569### on('getTextIndexAtCursor')<sup>10+</sup>
2570
2571on(type: 'getTextIndexAtCursor', callback: () => number): void
2572
2573Enables listening for the event of obtaining the index of text at the cursor. This API uses an asynchronous callback to return the result.
2574
2575**System capability**: SystemCapability.MiscServices.InputMethodFramework
2576
2577**Parameters**
2578
2579| Name  | Type  | Mandatory| Description    |
2580| -------- | ----- | ---- | ------ |
2581| type     | string  | Yes  | Listening type. The value is fixed at **'getTextIndexAtCursor'**.|
2582| callback | () => number | Yes  | Callback used to obtain the index of text at the cursor.|
2583
2584**Error codes**
2585
2586For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md) and [Universal Error Codes](../errorcode-universal.md).
2587
2588| ID| Error Message                            |
2589| -------- | -------------------------------------- |
2590| 401      | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.           |
2591| 12800009 | input method client detached. |
2592
2593**Example**
2594
2595```ts
2596try {
2597  inputMethodController.on('getTextIndexAtCursor', () => {
2598    console.info(`Succeeded in subscribing getTextIndexAtCursor.`);
2599    let index:number = 0;
2600    return index;
2601  });
2602} catch(err) {
2603  console.error(`Failed to subscribe getTextIndexAtCursor. err: ${JSON.stringify(err)}`);
2604}
2605```
2606
2607### off('getTextIndexAtCursor')<sup>10+</sup>
2608
2609off(type: 'getTextIndexAtCursor', callback?: () => number): void
2610
2611Disables listening for the event of obtaining the index of text at the cursor. This API uses an asynchronous callback to return the result.
2612
2613**System capability**: SystemCapability.MiscServices.InputMethodFramework
2614
2615**Parameters**
2616
2617| Name| Type  | Mandatory| Description                                                        |
2618| ------ | ------ | ---- | ------------------------------------------------------------ |
2619| type   | string | Yes  | Listening type. The value is fixed at **'getTextIndexAtCursor'**.|
2620| callback | () => number | No | Callback used for disable listening, which must be the same as that passed by the **on** API.<br>If this parameter is not specified, listening will be disabled for all callbacks corresponding to the specified type.|
2621
2622**Example**
2623
2624```ts
2625try {
2626  let getTextIndexAtCursorCallback = () => {
2627    console.info(`Succeeded in unsubscribing getTextIndexAtCursor.`);
2628    let index:number = 0;
2629    return index;
2630  };
2631  inputMethodController.off('getTextIndexAtCursor', getTextIndexAtCursorCallback);
2632  inputMethodController.off('getTextIndexAtCursor');
2633} catch(err) {
2634  console.error(`Failed to unsubscribing getTextIndexAtCursor. err: ${JSON.stringify(err)}`);
2635}
2636```
2637
2638## InputMethodSetting<sup>8+</sup>
2639
2640In the following API examples, you must first use [getSetting](#inputmethodgetsetting9) to obtain an **InputMethodSetting** instance, and then call the APIs using the obtained instance.
2641
2642### on('imeChange')<sup>9+</sup>
2643
2644on(type: 'imeChange', callback: (inputMethodProperty: InputMethodProperty, inputMethodSubtype: InputMethodSubtype) => void): void
2645
2646Enables listening for the input method and subtype change event. This API uses an asynchronous callback to return the result.
2647
2648**System capability**: SystemCapability.MiscServices.InputMethodFramework
2649
2650**Parameters**
2651
2652| Name  | Type                           | Mandatory| Description                                                        |
2653| -------- | ------------------------------- | ---- | ------------------------------------------------------------ |
2654| type     | string                        | Yes  | Listening type. The value is fixed at **'imeChange'**.|
2655| callback | (inputMethodProperty: [InputMethodProperty](#inputmethodproperty8), inputMethodSubtype: [InputMethodSubtype](./js-apis-inputmethod-subtype.md#inputmethodsubtype)) => void  | Yes| Callback used to return the input method attributes and subtype.|
2656
2657**Example**
2658
2659```ts
2660import { InputMethodSubtype } from '@kit.IMEKit';
2661try {
2662  inputMethodSetting.on('imeChange', (inputMethodProperty: inputMethod.InputMethodProperty, inputMethodSubtype: InputMethodSubtype) => {
2663    console.log('Succeeded in subscribing imeChange: inputMethodProperty: ' + JSON.stringify(inputMethodProperty) + " , inputMethodSubtype: " + JSON.stringify(inputMethodSubtype));
2664  });
2665} catch(err) {
2666  console.error(`Failed to unsubscribing inputMethodProperty. err: ${JSON.stringify(err)}`);
2667}
2668```
2669
2670### off('imeChange')<sup>9+</sup>
2671
2672off(type: 'imeChange', callback?: (inputMethodProperty: InputMethodProperty, inputMethodSubtype: InputMethodSubtype) => void): void
2673
2674Disables listening for the input method and subtype change event. This API uses an asynchronous callback to return the result.
2675
2676**System capability**: SystemCapability.MiscServices.InputMethodFramework
2677
2678**Parameters**
2679
2680| Name  | Type   | Mandatory| Description         |
2681| -------- | --------- | ---- | --------------- |
2682| type     | string    | Yes  | Listening type. The value is fixed at **'imeChange'**.|
2683| callback | (inputMethodProperty: [InputMethodProperty](#inputmethodproperty8), inputMethodSubtype: [InputMethodSubtype](./js-apis-inputmethod-subtype.md#inputmethodsubtype)) => void  | No| Callback used to return the input method attributes and subtype.|
2684
2685**Example**
2686
2687```ts
2688inputMethodSetting.off('imeChange');
2689```
2690
2691### listInputMethodSubtype<sup>9+</sup>
2692
2693listInputMethodSubtype(inputMethodProperty: InputMethodProperty, callback: AsyncCallback&lt;Array&lt;InputMethodSubtype&gt;&gt;): void
2694
2695Obtains all subtypes of a specified input method. This API uses an asynchronous callback to return the result.
2696
2697**System capability**: SystemCapability.MiscServices.InputMethodFramework
2698
2699**Parameters**
2700
2701| Name  | Type                                              | Mandatory| Description                  |
2702| -------- | -------------------------------------------------- | ---- | ---------------------- |
2703| inputMethodProperty | [InputMethodProperty](#inputmethodproperty8)| Yes| Input method.|
2704| callback | AsyncCallback&lt;Array<[InputMethodSubtype](./js-apis-inputmethod-subtype.md#inputmethodsubtype)>&gt; | Yes| Callback used to return all subtypes of the specified input method.|
2705
2706**Error codes**
2707
2708For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md) and [Universal Error Codes](../errorcode-universal.md).
2709
2710| ID| Error Message                            |
2711| -------- | -------------------------------------- |
2712| 401      | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.           |
2713| 12800001 | bundle manager error.                 |
2714| 12800008 | input method manager service error. |
2715
2716**Example**
2717
2718```ts
2719import { InputMethodSubtype } from '@kit.IMEKit';
2720import { BusinessError } from '@kit.BasicServicesKit';
2721
2722let inputMethodProperty: inputMethod.InputMethodProperty = {
2723  name: 'com.example.kikakeyboard',
2724  id: 'propertyId',
2725  packageName: 'com.example.kikakeyboard',
2726  methodId: 'propertyId',
2727}
2728let inputMethodSetting = inputMethod.getSetting();
2729try {
2730  inputMethodSetting.listInputMethodSubtype(inputMethodProperty, (err: BusinessError, data: Array<InputMethodSubtype>) => {
2731    if (err) {
2732      console.error(`Failed to listInputMethodSubtype: ${JSON.stringify(err)}`);
2733      return;
2734    }
2735    console.log('Succeeded in listing inputMethodSubtype.');
2736  });
2737} catch (err) {
2738  console.error(`Failed to listInputMethodSubtype: ${JSON.stringify(err)}`);
2739}
2740```
2741
2742### listInputMethodSubtype<sup>9+</sup>
2743
2744listInputMethodSubtype(inputMethodProperty: InputMethodProperty): Promise&lt;Array&lt;InputMethodSubtype&gt;&gt;
2745
2746Obtains all subtypes of a specified input method. This API uses a promise to return the result.
2747
2748**System capability**: SystemCapability.MiscServices.InputMethodFramework
2749
2750**Parameters**
2751
2752| Name  | Type                                              | Mandatory| Description                  |
2753| -------- | -------------------------------------------------- | ---- | ---------------------- |
2754| inputMethodProperty | [InputMethodProperty](#inputmethodproperty8)| Yes| Input method.|
2755
2756**Return value**
2757
2758| Type                                                       | Description                  |
2759| ----------------------------------------------------------- | ---------------------- |
2760| Promise<Array<[InputMethodSubtype](./js-apis-inputmethod-subtype.md#inputmethodsubtype)>> | Promise used to return all subtypes of the specified input method.|
2761
2762**Error codes**
2763
2764For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md) and [Universal Error Codes](../errorcode-universal.md).
2765
2766| ID| Error Message                            |
2767| -------- | -------------------------------------- |
2768| 401      | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.           |
2769| 12800001 | bundle manager error.                 |
2770| 12800008 | input method manager service error. |
2771
2772**Example**
2773
2774```ts
2775import { InputMethodSubtype } from '@kit.IMEKit';
2776import { BusinessError } from '@kit.BasicServicesKit';
2777
2778let inputMethodProperty: inputMethod.InputMethodProperty = {
2779  name: 'com.example.kikakeyboard',
2780  id: 'propertyId',
2781  packageName: 'com.example.kikakeyboard',
2782  methodId: 'propertyId',
2783}
2784let inputMethodSetting = inputMethod.getSetting();
2785try {
2786  inputMethodSetting.listInputMethodSubtype(inputMethodProperty).then((data: Array<InputMethodSubtype>) => {
2787    console.log('Succeeded in listing inputMethodSubtype.');
2788  }).catch((err: BusinessError) => {
2789    console.error(`Failed to listInputMethodSubtype: ${JSON.stringify(err)}`);
2790  })
2791} catch(err) {
2792  console.error(`Failed to listInputMethodSubtype: ${JSON.stringify(err)}`);
2793}
2794```
2795
2796### listCurrentInputMethodSubtype<sup>9+</sup>
2797
2798listCurrentInputMethodSubtype(callback: AsyncCallback&lt;Array&lt;InputMethodSubtype&gt;&gt;): void
2799
2800Obtains all subtypes of this input method. This API uses an asynchronous callback to return the result.
2801
2802**System capability**: SystemCapability.MiscServices.InputMethodFramework
2803
2804**Parameters**
2805
2806| Name  | Type                                              | Mandatory| Description                  |
2807| -------- | -------------------------------------------------- | ---- | ---------------------- |
2808| callback | AsyncCallback&lt;Array<[InputMethodSubtype](./js-apis-inputmethod-subtype.md#inputmethodsubtype)>&gt; | Yes  | Callback used to return all subtypes of the current input method.|
2809
2810**Error codes**
2811
2812For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md) and [Universal Error Codes](../errorcode-universal.md).
2813
2814| ID| Error Message                            |
2815| -------- | -------------------------------------- |
2816| 12800001 | bundle manager error.                 |
2817| 12800008 | input method manager service error. |
2818
2819**Example**
2820
2821```ts
2822import { InputMethodSubtype } from '@kit.IMEKit';
2823import { BusinessError } from '@kit.BasicServicesKit';
2824
2825let inputMethodSetting = inputMethod.getSetting();
2826try {
2827  inputMethodSetting.listCurrentInputMethodSubtype((err: BusinessError, data: Array<InputMethodSubtype>) => {
2828    if (err) {
2829      console.error(`Failed to listCurrentInputMethodSubtype: ${JSON.stringify(err)}`);
2830      return;
2831    }
2832    console.log('Succeeded in listing currentInputMethodSubtype.');
2833  });
2834} catch(err) {
2835  console.error(`Failed to listCurrentInputMethodSubtype: ${JSON.stringify(err)}`);
2836}
2837```
2838
2839### listCurrentInputMethodSubtype<sup>9+</sup>
2840
2841listCurrentInputMethodSubtype(): Promise&lt;Array&lt;InputMethodSubtype&gt;&gt;
2842
2843Obtains all subtypes of this input method. This API uses a promise to return the result.
2844
2845**System capability**: SystemCapability.MiscServices.InputMethodFramework
2846
2847**Return value**
2848
2849| Type                                                       | Description                  |
2850| ----------------------------------------------------------- | ---------------------- |
2851| Promise<Array<[InputMethodSubtype](./js-apis-inputmethod-subtype.md#inputmethodsubtype)>> | Promise used to return all subtypes of the current input method.|
2852
2853**Error codes**
2854
2855For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md) and [Universal Error Codes](../errorcode-universal.md).
2856
2857| ID| Error Message                            |
2858| -------- | -------------------------------------- |
2859| 12800001 | bundle manager error.                 |
2860| 12800008 | input method manager service error. |
2861
2862**Example**
2863
2864```ts
2865import { InputMethodSubtype } from '@kit.IMEKit';
2866import { BusinessError } from '@kit.BasicServicesKit';
2867
2868let inputMethodSetting = inputMethod.getSetting();
2869try {
2870  inputMethodSetting.listCurrentInputMethodSubtype().then((data: Array<InputMethodSubtype>) => {
2871    console.log('Succeeded in listing currentInputMethodSubtype.');
2872  }).catch((err: BusinessError) => {
2873    console.error(`Failed to listCurrentInputMethodSubtype: ${JSON.stringify(err)}`);
2874  })
2875} catch(err) {
2876  console.error(`Failed to listCurrentInputMethodSubtype: ${JSON.stringify(err)}`);
2877}
2878```
2879
2880### getInputMethods<sup>9+</sup>
2881
2882getInputMethods(enable: boolean, callback: AsyncCallback&lt;Array&lt;InputMethodProperty&gt;&gt;): void
2883
2884Obtains a list of activated or deactivated input methods. This API uses an asynchronous callback to return the result.
2885
2886> **NOTE**
2887>
2888> An activated input method refers to an input method that is enabled. The default input method is enabled by default. Other input methods can be enabled or disabled as needed.
2889>
2890> The list of activated input methods includes the default input method and enabled input methods. The list of deactivated input methods includes all installed input methods except the enabled ones.
2891
2892**System capability**: SystemCapability.MiscServices.InputMethodFramework
2893
2894**Parameters**
2895
2896| Name  | Type                                               | Mandatory| Description                         |
2897| -------- | --------------------------------------------------- | ---- | ----------------------------- |
2898| enable   | boolean                                             | Yes  |Whether to return a list of activated input methods. The value **true** means to return a list of activated input methods, and **false** means to return a list of deactivated input methods.|
2899| callback | AsyncCallback&lt;Array<[InputMethodProperty](#inputmethodproperty8)>&gt; |  Yes | Callback used to return a list of activated or deactivated input methods.|
2900
2901**Error codes**
2902
2903For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md) and [Universal Error Codes](../errorcode-universal.md).
2904
2905| ID| Error Message                           |
2906| -------- | ----------------------------------- |
2907| 401      | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
2908| 12800001 | bundle manager error.               |
2909| 12800008 | input method manager service error. |
2910
2911**Example**
2912
2913```ts
2914import { BusinessError } from '@kit.BasicServicesKit';
2915
2916try {
2917  inputMethodSetting.getInputMethods(true, (err: BusinessError, data: Array<inputMethod.InputMethodProperty>) => {
2918    if (err) {
2919      console.error(`Failed to getInputMethods: ${JSON.stringify(err)}`);
2920      return;
2921    }
2922    console.log('Succeeded in getting inputMethods.');
2923  });
2924} catch (err) {
2925  console.error(`Failed to getInputMethods: ${JSON.stringify(err)}`);
2926}
2927```
2928
2929### getInputMethods<sup>9+</sup>
2930
2931getInputMethods(enable: boolean): Promise&lt;Array&lt;InputMethodProperty&gt;&gt;
2932
2933Obtains a list of activated or deactivated input methods. This API uses a promise to return the result.
2934
2935> **NOTE**
2936>
2937> An activated input method refers to an input method that is enabled. The default input method is enabled by default. Other input methods can be enabled or disabled as needed.
2938>
2939> The list of activated input methods includes the default input method and enabled input methods. The list of deactivated input methods includes all installed input methods except the enabled ones.
2940
2941**System capability**: SystemCapability.MiscServices.InputMethodFramework
2942
2943**Parameters**
2944
2945| Name| Type   | Mandatory| Description                   |
2946| ------ | ------- | ---- | ----------------------- |
2947| enable | boolean | Yes  |Whether to return a list of activated input methods. The value **true** means to return a list of activated input methods, and **false** means to return a list of deactivated input methods.|
2948
2949**Return value**
2950
2951| Type                                                        | Description                                      |
2952| ------------------------------------------------------------ | ------------------------------------------ |
2953| Promise\<Array\<[InputMethodProperty](#inputmethodproperty8)>> | Promise used to return a list of activated or deactivated input methods.|
2954
2955**Error codes**
2956
2957For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md) and [Universal Error Codes](../errorcode-universal.md).
2958
2959| ID| Error Message                           |
2960| -------- | ----------------------------------- |
2961| 401      | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
2962| 12800001 | bundle manager error.               |
2963| 12800008 | input method manager service error. |
2964
2965**Example**
2966
2967```ts
2968import { BusinessError } from '@kit.BasicServicesKit';
2969
2970try {
2971  inputMethodSetting.getInputMethods(true).then((data: Array<inputMethod.InputMethodProperty>) => {
2972    console.log('Succeeded in getting inputMethods.');
2973  }).catch((err: BusinessError) => {
2974    console.error(`Failed to getInputMethods: ${JSON.stringify(err)}`);
2975  })
2976} catch(err) {
2977  console.error(`Failed to getInputMethods: ${JSON.stringify(err)}`);
2978}
2979```
2980
2981### getInputMethodsSync<sup>11+</sup>
2982
2983getInputMethodsSync(enable: boolean): Array&lt;InputMethodProperty&gt;
2984
2985Obtains a list of activated or deactivated input methods. This API returns the result synchronously.
2986
2987> **NOTE**
2988>
2989> An activated input method refers to an input method that is enabled. The default input method is enabled by default. Other input methods can be enabled or disabled as needed.
2990>
2991> The list of activated input methods includes the default input method and enabled input methods. The list of deactivated input methods includes all installed input methods except the enabled ones.
2992
2993**System capability**: SystemCapability.MiscServices.InputMethodFramework
2994
2995**Parameters**
2996
2997| Name| Type   | Mandatory| Description                   |
2998| ------ | ------- | ---- | ----------------------- |
2999| enable | boolean | Yes  |Whether to return a list of activated input methods. The value **true** means to return a list of activated input methods, and **false** means to return a list of deactivated input methods.|
3000
3001**Return value**
3002
3003| Type                                                | Description                         |
3004| ---------------------------------------------------- | ----------------------------- |
3005| Array\<[InputMethodProperty](#inputmethodproperty8)> | List of activated or deactivated input methods.|
3006
3007**Error codes**
3008
3009For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md) and [Universal Error Codes](../errorcode-universal.md).
3010
3011| ID| Error Message                            |
3012| -------- | -------------------------------------- |
3013| 401      | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
3014| 12800001 | bundle manager error.                 |
3015| 12800008 |input method manager service error. |
3016
3017**Example**
3018
3019```ts
3020try {
3021  let imeProp = inputMethodSetting.getInputMethodsSync(true);
3022} catch(err) {
3023  console.error(`Failed to getInputMethods: ${JSON.stringify(err)}`);
3024}
3025```
3026
3027### getAllInputMethods<sup>11+</sup>
3028
3029getAllInputMethods(callback: AsyncCallback&lt;Array&lt;InputMethodProperty&gt;&gt;): void
3030
3031Obtains a list of all input methods. This API uses an asynchronous callback to return the result.
3032
3033**System capability**: SystemCapability.MiscServices.InputMethodFramework
3034
3035**Parameters**
3036
3037| Name  | Type                                                        | Mandatory| Description                          |
3038| -------- | ------------------------------------------------------------ | ---- | ------------------------------ |
3039| callback | AsyncCallback&lt;Array<[InputMethodProperty](#inputmethodproperty8)>&gt; | Yes  | Callback used to return a list of all input methods.|
3040
3041**Error codes**
3042
3043For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md) and [Universal Error Codes](../errorcode-universal.md).
3044
3045| ID| Error Message                           |
3046| -------- | ----------------------------------- |
3047| 12800001 | bundle manager error.               |
3048| 12800008 | input method manager service error. |
3049
3050**Example**
3051
3052```ts
3053import { BusinessError } from '@kit.BasicServicesKit';
3054
3055try {
3056  inputMethodSetting.getAllInputMethods((err: BusinessError, data: Array<inputMethod.InputMethodProperty>) => {
3057    if (err) {
3058      console.error(`Failed to getAllInputMethods: ${JSON.stringify(err)}`);
3059      return;
3060    }
3061    console.log('Succeeded in getting all inputMethods.');
3062  });
3063} catch (err) {
3064  console.error(`Failed to getAllInputMethods: ${JSON.stringify(err)}`);
3065}
3066```
3067
3068### getAllInputMethods<sup>11+</sup>
3069
3070getAllInputMethods(): Promise&lt;Array&lt;InputMethodProperty&gt;&gt;
3071
3072Obtains a list of all input methods. This API uses a promise to return the result.
3073
3074**System capability**: SystemCapability.MiscServices.InputMethodFramework
3075
3076**Return value**
3077
3078| Type                                                        | Description                             |
3079| ------------------------------------------------------------ | --------------------------------- |
3080| Promise\<Array\<[InputMethodProperty](#inputmethodproperty8)>> | Promise used to return a list of all input methods.|
3081
3082**Error codes**
3083
3084For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md) and [Universal Error Codes](../errorcode-universal.md).
3085
3086| ID| Error Message                           |
3087| -------- | ----------------------------------- |
3088| 12800001 | bundle manager error.              |
3089| 12800008 | input method manager service error. |
3090
3091**Example**
3092
3093```ts
3094import { BusinessError } from '@kit.BasicServicesKit';
3095
3096inputMethodSetting.getAllInputMethods().then((data: Array<inputMethod.InputMethodProperty>) => {
3097  console.log('Succeeded in getting all inputMethods.');
3098}).catch((err: BusinessError) => {
3099  console.error(`Failed to getAllInputMethods: ${JSON.stringify(err)}`);
3100})
3101```
3102
3103### getAllInputMethodsSync<sup>11+</sup>
3104
3105getAllInputMethodsSync(): Array&lt;InputMethodProperty&gt;
3106
3107Obtains a list of all input methods. This API returns the result synchronously.
3108
3109**System capability**: SystemCapability.MiscServices.InputMethodFramework
3110
3111**Return value**
3112
3113| Type                                                | Description              |
3114| ---------------------------------------------------- | ------------------ |
3115| Array\<[InputMethodProperty](#inputmethodproperty8)> | List of all input methods.|
3116
3117**Error codes**
3118
3119For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md).
3120
3121| ID| Error Message                           |
3122| -------- | ----------------------------------- |
3123| 12800001 | bundle manager error.              |
3124| 12800008 | input method manager service error. |
3125
3126**Example**
3127
3128```ts
3129try {
3130  let imeProp = inputMethodSetting.getAllInputMethodsSync();
3131} catch(err) {
3132  console.error(`Failed to getAllInputMethodsSync: ${JSON.stringify(err)}`);
3133}
3134```
3135
3136### showOptionalInputMethods<sup>9+</sup>
3137
3138showOptionalInputMethods(callback: AsyncCallback&lt;boolean&gt;): void
3139
3140Displays a dialog box for selecting an input method. This API uses an asynchronous callback to return the result.
3141
3142**System capability**: SystemCapability.MiscServices.InputMethodFramework
3143
3144**Parameters**
3145
3146| Name| Type| Mandatory| Description|
3147| -------- | -------- | -------- | -------- |
3148| callback | AsyncCallback&lt;boolean&gt; | Yes| Callback used to return the result. If the operation is successful, **err** is **undefined** and **data** is **true**. Otherwise, **err** is an error object.|
3149
3150**Error codes**
3151
3152For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md).
3153
3154| ID| Error Message                            |
3155| -------- | -------------------------------------- |
3156| 12800008 | input method manager service error. |
3157
3158**Example**
3159
3160```ts
3161import { BusinessError } from '@kit.BasicServicesKit';
3162
3163try {
3164  inputMethodSetting.showOptionalInputMethods((err: BusinessError, data: boolean) => {
3165    if (err) {
3166      console.error(`Failed to showOptionalInputMethods: ${JSON.stringify(err)}`);
3167      return;
3168    }
3169    console.log('Succeeded in showing optionalInputMethods.');
3170  });
3171} catch (err) {
3172  console.error(`Failed to showOptionalInputMethods: ${JSON.stringify(err)}`);
3173}
3174```
3175
3176### showOptionalInputMethods<sup>9+</sup>
3177
3178showOptionalInputMethods(): Promise&lt;boolean&gt;
3179
3180Displays a dialog box for selecting an input method. This API uses a promise to return the result.
3181
3182**System capability**: SystemCapability.MiscServices.InputMethodFramework
3183
3184**Return value**
3185
3186| Type| Description|
3187| -------- | -------- |
3188| Promise&lt;boolean&gt; | Promise used to return the result. If the operation is successful, **err** is **undefined** and **data** is **true**. Otherwise, **err** is an error object.|
3189
3190**Error codes**
3191
3192For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md).
3193
3194| ID| Error Message                            |
3195| -------- | -------------------------------------- |
3196| 12800008 | input method manager service error. |
3197
3198**Example**
3199
3200```ts
3201import { BusinessError } from '@kit.BasicServicesKit';
3202
3203inputMethodSetting.showOptionalInputMethods().then((data: boolean) => {
3204  console.log('Succeeded in showing optionalInputMethods.');
3205}).catch((err: BusinessError) => {
3206  console.error(`Failed to showOptionalInputMethods: ${JSON.stringify(err)}`);
3207})
3208```
3209
3210### listInputMethod<sup>(deprecated)</sup>
3211
3212listInputMethod(callback: AsyncCallback&lt;Array&lt;InputMethodProperty&gt;&gt;): void
3213
3214Obtains a list of installed input methods. This API uses an asynchronous callback to return the result.
3215
3216> **NOTE**
3217>
3218> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [getInputMethods](#getinputmethods9) instead.
3219
3220**System capability**: SystemCapability.MiscServices.InputMethodFramework
3221
3222**Parameters**
3223
3224| Name  | Type                                              | Mandatory| Description                  |
3225| -------- | -------------------------------------------------- | ---- | ---------------------- |
3226| callback | AsyncCallback&lt;Array<[InputMethodProperty](#inputmethodproperty8)>&gt; | Yes  | Callback used to return the list of installed input methods.|
3227
3228**Example**
3229
3230```ts
3231import { BusinessError } from '@kit.BasicServicesKit';
3232
3233inputMethodSetting.listInputMethod((err: BusinessError, data: Array<inputMethod.InputMethodProperty>) => {
3234  if (err) {
3235    console.error(`Failed to listInputMethod: ${JSON.stringify(err)}`);
3236    return;
3237  }
3238  console.log('Succeeded in listing inputMethod.');
3239 });
3240```
3241
3242### listInputMethod<sup>(deprecated)</sup>
3243
3244listInputMethod(): Promise&lt;Array&lt;InputMethodProperty&gt;&gt;
3245
3246Obtains a list of installed input methods. This API uses a promise to return the result.
3247
3248> **NOTE**
3249>
3250> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [getInputMethods](#getinputmethods9-1) instead.
3251
3252**System capability**: SystemCapability.MiscServices.InputMethodFramework
3253
3254**Return value**
3255
3256| Type                                                       | Description                  |
3257| ----------------------------------------------------------- | ---------------------- |
3258| Promise<Array<[InputMethodProperty](#inputmethodproperty8)>> | Promise used to return the list of installed input methods.|
3259
3260**Example**
3261
3262```ts
3263import { BusinessError } from '@kit.BasicServicesKit';
3264
3265inputMethodSetting.listInputMethod().then((data: Array<inputMethod.InputMethodProperty>) => {
3266  console.log('Succeeded in listing inputMethod.');
3267}).catch((err: BusinessError) => {
3268  console.error(`Failed to listInputMethod: ${JSON.stringify(err)}`);
3269})
3270```
3271
3272### displayOptionalInputMethod<sup>(deprecated)</sup>
3273
3274displayOptionalInputMethod(callback: AsyncCallback&lt;void&gt;): void
3275
3276Displays a dialog box for selecting an input method. This API uses an asynchronous callback to return the result.
3277
3278> **NOTE**
3279>
3280> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [showOptionalInputMethods()](#showoptionalinputmethods9) instead.
3281
3282**System capability**: SystemCapability.MiscServices.InputMethodFramework
3283
3284**Parameters**
3285
3286| Name| Type| Mandatory| Description|
3287| -------- | -------- | -------- | -------- |
3288| callback | AsyncCallback&lt;void&gt; | Yes| Callback used to return the result. If the operation is successful, **err** is **undefined**. Otherwise, **err** is an error object.|
3289
3290**Example**
3291
3292```ts
3293import { BusinessError } from '@kit.BasicServicesKit';
3294
3295inputMethodSetting.displayOptionalInputMethod((err: BusinessError) => {
3296  if (err) {
3297    console.error(`Failed to displayOptionalInputMethod: ${JSON.stringify(err)}`);
3298    return;
3299  }
3300  console.log('Succeeded in displaying optionalInputMethod.');
3301});
3302```
3303
3304### displayOptionalInputMethod<sup>(deprecated)</sup>
3305
3306displayOptionalInputMethod(): Promise&lt;void&gt;
3307
3308Displays a dialog box for selecting an input method. This API uses a promise to return the result.
3309
3310> **NOTE**
3311>
3312> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [showOptionalInputMethods()](#showoptionalinputmethods9-1) instead.
3313
3314**System capability**: SystemCapability.MiscServices.InputMethodFramework
3315
3316**Return value**
3317
3318| Type| Description|
3319| -------- | -------- |
3320| Promise&lt;void&gt; | Promise that returns no value.|
3321
3322**Example**
3323
3324```ts
3325import { BusinessError } from '@kit.BasicServicesKit';
3326
3327inputMethodSetting.displayOptionalInputMethod().then(() => {
3328  console.log('Succeeded in displaying optionalInputMethod.');
3329}).catch((err: BusinessError) => {
3330  console.error(`Failed to displayOptionalInputMethod: ${JSON.stringify(err)}`);
3331})
3332```
3333