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