• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# @ohos.inputMethodEngine (输入法服务)
2
3本模块面向输入法应用(包括系统输入法应用、三方输入法应用),为输入法应用提供能力,包括:创建软键盘窗口、插入/删除字符、选中文本、监听物理键盘按键事件等。
4
5> **说明:**
6>
7>本模块首批接口从API version 8开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
8
9## 导入模块
10
11```ts
12import { inputMethodEngine } from '@kit.IMEKit';
13```
14
15## 常量
16
17功能键常量值、编辑框常量值及光标常量值。
18
19**系统能力:** SystemCapability.MiscServices.InputMethodFramework
20
21| 名称 | 类型 | 值 | 说明 |
22| -------- | -------- | -------- | -------- |
23| ENTER_KEY_TYPE_UNSPECIFIED | number | 0 | 无功能键。 |
24| ENTER_KEY_TYPE_GO | number | 2 | “前往”功能键。 |
25| ENTER_KEY_TYPE_SEARCH | number | 3 | “搜索”功能键。 |
26| ENTER_KEY_TYPE_SEND | number | 4 | “发送”功能键。 |
27| ENTER_KEY_TYPE_NEXT | number | 5 | “下一个”功能键。 |
28| ENTER_KEY_TYPE_DONE | number | 6 | “回车”功能键。 |
29| ENTER_KEY_TYPE_PREVIOUS | number | 7 | “前一个”功能键。 |
30| ENTER_KEY_TYPE_NEWLINE<sup>12+</sup> | number | 8 | “换行”功能键。 |
31| PATTERN_NULL | number | -1 | 无特殊性编辑框。 |
32| PATTERN_TEXT | number | 0 | 文本编辑框。 |
33| PATTERN_NUMBER | number | 2 | 数字编辑框。 |
34| PATTERN_PHONE | number | 3 | 电话号码编辑框。 |
35| PATTERN_DATETIME | number | 4 | 日期编辑框。 |
36| PATTERN_EMAIL | number | 5 | 邮件编辑框。 |
37| PATTERN_URI | number | 6 | 超链接编辑框。 |
38| PATTERN_PASSWORD | number | 7 | 密码编辑框。 |
39| PATTERN_PASSWORD_NUMBER<sup>11+</sup> | number | 8 | 数字密码编辑框。 |
40| PATTERN_PASSWORD_SCREEN_LOCK<sup>11+</sup> | number | 9 | 锁屏密码编辑框。 |
41| OPTION_ASCII | number | 20 | 允许输入ASCII值。 |
42| OPTION_NONE | number | 0 | 不指定编辑框输入属性。 |
43| OPTION_AUTO_CAP_CHARACTERS | number | 2 | 允许输入字符。 |
44| OPTION_AUTO_CAP_SENTENCES | number | 8 | 允许输入句子。 |
45| OPTION_AUTO_WORDS | number | 4 | 允许输入单词。 |
46| OPTION_MULTI_LINE | number | 1 | 允许输入多行。 |
47| OPTION_NO_FULLSCREEN | number | 10 | 半屏样式。 |
48| FLAG_SELECTING | number | 2 | 编辑框处于选择状态。 |
49| FLAG_SINGLE_LINE | number | 1 | 编辑框为单行。 |
50| DISPLAY_MODE_PART | number | 0 | 编辑框显示为半屏。 |
51| DISPLAY_MODE_FULL | number | 1 | 编辑框显示为全屏。 |
52| CURSOR_UP<sup>9+</sup> | number | 1 | 光标上移。 |
53| CURSOR_DOWN<sup>9+</sup> | number | 2 | 光标下移。 |
54| CURSOR_LEFT<sup>9+</sup> | number | 3 | 光标左移。 |
55| CURSOR_RIGHT<sup>9+</sup> | number | 4 | 光标右移。 |
56| WINDOW_TYPE_INPUT_METHOD_FLOAT<sup>9+</sup> | number | 2105 | 输入法应用窗口风格标识。 |
57
58## inputMethodEngine.getInputMethodAbility<sup>9+</sup>
59
60getInputMethodAbility(): InputMethodAbility
61
62获取输入法应用客户端实例[InputMethodAbility](#inputmethodability),仅支持输入法应用调用。<br/>输入法应用获取该实例后,可订阅软键盘显示/隐藏请求事件、创建/销毁输入法面板等。
63
64**系统能力:** SystemCapability.MiscServices.InputMethodFramework
65
66**返回值:**
67
68| 类型                                      | 说明               |
69| ----------------------------------------- | ------------------ |
70| [InputMethodAbility](#inputmethodability) | 输入法应用客户端。 |
71
72**示例:**
73
74```ts
75let InputMethodAbility = inputMethodEngine.getInputMethodAbility();
76```
77
78## inputMethodEngine.getKeyboardDelegate<sup>9+</sup>
79
80getKeyboardDelegate(): KeyboardDelegate
81
82获取客户端编辑事件监听代理实例[KeyboardDelegate](#keyboarddelegate)。<br/>输入法应用获取该实例后,可订阅物理键盘按键事件、选中文本变化事件等。
83
84**系统能力:** SystemCapability.MiscServices.InputMethodFramework
85
86**返回值:**
87
88| 类型                                  | 说明                     |
89| ------------------------------------- | ------------------------ |
90| [KeyboardDelegate](#keyboarddelegate) | 客户端编辑事件监听代理。 |
91
92**示例:**
93
94```ts
95let KeyboardDelegate = inputMethodEngine.getKeyboardDelegate();
96```
97
98## inputMethodEngine.getInputMethodEngine<sup>(deprecated)</sup>
99
100getInputMethodEngine(): InputMethodEngine
101
102获取输入法应用客户端实例[InputMethodEngine](#inputmethodengine)。<br/>输入法应用获取该实例后,可订阅软键盘显示/隐藏请求事件等。
103
104> **说明:**
105>
106> 从API version 8开始支持,API version 9开始废弃,建议使用[getInputMethodAbility()](#inputmethodenginegetinputmethodability9)替代。
107
108**系统能力:** SystemCapability.MiscServices.InputMethodFramework
109
110**返回值:**
111
112| 类型                                      | 说明               |
113| ----------------------------------------- | ------------------ |
114| [InputMethodEngine](#inputmethodengine) | 输入法应用客户端。 |
115
116**示例:**
117
118```ts
119let InputMethodEngine = inputMethodEngine.getInputMethodEngine();
120```
121
122## inputMethodEngine.createKeyboardDelegate<sup>(deprecated)</sup>
123
124createKeyboardDelegate(): KeyboardDelegate
125
126获取客户端编辑事件监听代理实例[KeyboardDelegate](#keyboarddelegate)。输入法应用获取该实例后,可订阅物理键盘按键事件、选中文本变化事件等。
127
128> **说明:**
129>
130>从API version 8开始支持,API version 9开始废弃,建议使用[getKeyboardDelegate()](#inputmethodenginegetkeyboarddelegate9)替代。
131
132**系统能力:** SystemCapability.MiscServices.InputMethodFramework
133
134**返回值:**
135
136| 类型                                  | 说明                     |
137| ------------------------------------- | ------------------------ |
138| [KeyboardDelegate](#keyboarddelegate) | 客户端编辑事件监听代理。 |
139
140**示例:**
141
142```ts
143let keyboardDelegate = inputMethodEngine.createKeyboardDelegate();
144```
145
146## CommandDataType<sup>12+</sup>
147
148type CommandDataType = number | string | boolean;
149
150表示私有数据类型,接口参数具体类型根据其功能而定。
151
152**系统能力:** SystemCapability.MiscServices.InputMethodFramework
153
154| 类型    | 说明                 |
155| ------- | -------------------- |
156| string  | 表示值类型为字符串。  |
157| number  | 表示值类型为数字。   |
158| boolean | 表示值类型为布尔值。 |
159
160**示例:**
161
162```ts
163import { inputMethodEngine } from '@kit.IMEKit';
164import { BusinessError } from '@kit.BasicServicesKit';
165
166try {
167  let record: Record<string, inputMethodEngine.CommandDataType> = {
168    "valueString1": "abcdefg",
169    "valueString2": true,
170    "valueString3": 500,
171  }
172  inputClient.sendPrivateCommand(record).then(() => {
173  }).catch((err: BusinessError) => {
174    console.error(`sendPrivateCommand catch error: ${JSON.stringify(err)}`);
175  });
176} catch (err) {
177  let error = err as BusinessError;
178  console.error(`sendPrivateCommand catch error: ${error.code} ${error.message}`);
179}
180```
181
182## SizeChangeCallback<sup>15+</sup>
183
184type SizeChangeCallback = (size: window.Size, keyboardArea?: KeyboardArea) => void
185
186当输入法面板大小变化时触发的回调。
187
188**系统能力:** SystemCapability.MiscServices.InputMethodFramework
189
190| 参数名       | 类型                                                 | 必填 | 说明                             |
191| ------------ | ---------------------------------------------------- | ---- | -------------------------------- |
192| size         | [window.Size](../apis-arkui/js-apis-window.md#size7) | 是   | 当前面板大小。                   |
193| keyboardArea | [KeyboardArea](#keyboardarea15)                      | 否   | 当前面板中可作为键盘区域的大小。 |
194
195## InputMethodEngine
196
197下列API均需使用[getInputMethodEngine](#inputmethodenginegetinputmethodenginedeprecated)获取到InputMethodEngine实例后,通过实例调用。
198
199### on('inputStart')
200
201on(type: 'inputStart', callback: (kbController: KeyboardController, textInputClient: TextInputClient) => void): void
202
203订阅输入法绑定成功事件。使用callback异步回调。
204
205**系统能力:** SystemCapability.MiscServices.InputMethodFramework
206
207**参数:**
208
209| 参数名   | 类型                            | 必填 | 说明                                                         |
210| -------- | ------------------------------- | ---- | ------------------------------------------------------------ |
211| type     | string                        | 是   | 设置监听类型,固定取值为'inputStart'。 |
212| callback | (kbController: [KeyboardController](#keyboardcontroller), textInputClient: [TextInputClient](#textinputclientdeprecated)) => void | 是 | 回调函数,返回订阅输入法的KeyboardController和TextInputClient实例。 |
213
214**示例:**
215
216```ts
217try {
218  inputMethodEngine.getInputMethodEngine()
219    .on('inputStart', (kbController: inputMethodEngine.KeyboardController, textClient: inputMethodEngine.TextInputClient) => {
220      let keyboardController = kbController;
221      let textInputClient = textClient;
222  });
223} catch(err) {
224  console.error(`Failed to inputStart: ${JSON.stringify(err)}`);
225}
226```
227
228### off('inputStart')
229
230off(type: 'inputStart', callback?: (kbController: KeyboardController, textInputClient: TextInputClient) => void): void
231
232取消订阅输入法绑定成功事件。
233
234**系统能力:** SystemCapability.MiscServices.InputMethodFramework
235
236**参数:**
237
238| 参数名   | 类型                 | 必填 | 说明                     |
239| -------- | -------------------- | ---- | ------------------------ |
240| type | string                                                       | 是   | 设置监听类型,固定取值为'inputStart'。 |
241| callback | (kbController: [KeyboardController](#keyboardcontroller), textInputClient: [TextInputClient](#textinputclientdeprecated)) => void | 否 | 取消订阅的回调函数。参数不填写时,取消订阅type对应的所有回调事件。|
242
243**示例:**
244
245```ts
246try {
247  inputMethodEngine.getInputMethodEngine()
248    .off('inputStart', (kbController: inputMethodEngine.KeyboardController, textClient: inputMethodEngine.TextInputClient) => {
249      console.log('delete inputStart notification.');
250  });
251} catch(err) {
252  console.error(`Failed to inputStart: ${JSON.stringify(err)}`);
253}
254```
255
256### on('keyboardShow'|'keyboardHide')
257
258on(type: 'keyboardShow'|'keyboardHide', callback: () => void): void
259
260订阅输入法软键盘显示或隐藏事件。使用callback异步回调。
261
262**系统能力:** SystemCapability.MiscServices.InputMethodFramework
263
264**参数:**
265
266| 参数名   | 类型   | 必填 | 说明                                                         |
267| -------- | ------ | ---- | ------------------------------------------------------------ |
268| type     | string | 是   | 设置监听类型。<br/>-'keyboardShow'表示显示输入法软键盘。<br/>-'keyboardHide'表示隐藏输入法软键盘。 |
269| callback | () => void   | 是   | 回调函数。                                                   |
270
271**示例:**
272
273```ts
274try {
275  inputMethodEngine.getInputMethodEngine().on('keyboardShow', () => {
276    console.log('inputMethodEngine keyboardShow.');
277  });
278  inputMethodEngine.getInputMethodEngine().on('keyboardHide', () => {
279    console.log('inputMethodEngine keyboardHide.');
280  });
281} catch(err) {
282  console.error(`Failed to InputMethodEngine: ${JSON.stringify(err)}`);
283}
284```
285
286### off('keyboardShow'|'keyboardHide')
287
288off(type: 'keyboardShow'|'keyboardHide', callback?: () => void): void
289
290取消订阅输入法软键盘显示或隐藏事件。使用callback异步回调。
291
292**系统能力:** SystemCapability.MiscServices.InputMethodFramework
293
294**参数:**
295
296| 参数名   | 类型   | 必填 | 说明                                                         |
297| -------- | ------ | ---- | ------------------------------------------------------------ |
298| type     | string | 是   | 要取消监听的输入法软键盘类型。<br/>-'keyboardShow'表示显示输入法软键盘。<br/>-'keyboardHide'表示隐藏输入法软键盘。|
299| callback | () => void   | 否   | 取消订阅的回调函数。参数不填写时,取消订阅type对应的所有回调事件。 |
300
301**示例:**
302
303```ts
304inputMethodEngine.getInputMethodEngine().off('keyboardShow');
305inputMethodEngine.getInputMethodEngine().off('keyboardHide');
306```
307
308## InputMethodAbility
309
310下列API均需使用[getInputMethodAbility](#inputmethodenginegetinputmethodability9)获取到InputMethodAbility实例后,通过实例调用。
311
312### on('inputStart')<sup>9+</sup>
313
314on(type: 'inputStart', callback: (kbController: KeyboardController, inputClient: InputClient) => void): void
315
316订阅输入法绑定成功事件。使用callback异步回调。
317
318**系统能力:** SystemCapability.MiscServices.InputMethodFramework
319
320**参数:**
321
322| 参数名   | 类型                            | 必填 | 说明                                                         |
323| -------- | ------------------------------- | ---- | ------------------------------------------------------------ |
324| type     | string                        | 是   | 设置监听类型,固定取值为'inputStart'。 |
325| callback | (kbController: [KeyboardController](#keyboardcontroller), inputClient: [InputClient](#inputclient9)) => void | 是 | 回调函数,返回输入法操作相关实例。 |
326
327**示例:**
328
329```ts
330try {
331  inputMethodEngine.getInputMethodAbility()
332    .on('inputStart', (kbController: inputMethodEngine.KeyboardController, client: inputMethodEngine.InputClient) => {
333      let keyboardController = kbController;
334      let inputClient = client;
335  });
336} catch(err) {
337    console.error(`Failed to InputMethodAbility: ${JSON.stringify(err)}`);
338}
339```
340
341### off('inputStart')<sup>9+</sup>
342
343off(type: 'inputStart', callback?: (kbController: KeyboardController, inputClient: InputClient) => void): void
344
345取消订阅输入法绑定成功事件。使用callback异步回调。
346
347**系统能力:** SystemCapability.MiscServices.InputMethodFramework
348
349**参数:**
350
351| 参数名   | 类型                 | 必填 | 说明                     |
352| -------- | -------------------- | ---- | ------------------------ |
353| type | string                                                       | 是   | 设置监听类型,固定取值为'inputStart'。 |
354| callback | (kbController: [KeyboardController](#keyboardcontroller), inputClient: [InputClient](#inputclient9)) => void | 否 | 取消订阅的回调函数。参数不填写时,取消订阅type对应的所有回调事件。|
355
356**示例:**
357
358```ts
359inputMethodEngine.getInputMethodAbility().off('inputStart');
360```
361
362### on('inputStop')<sup>9+</sup>
363
364on(type: 'inputStop', callback: () => void): void
365
366订阅停止输入法应用事件。使用callback异步回调。
367
368**系统能力:** SystemCapability.MiscServices.InputMethodFramework
369
370**参数:**
371
372| 参数名   | 类型   | 必填 | 说明                                                         |
373| -------- | ------ | ---- | ------------------------------------------------------------ |
374| type     | string | 是   | 设置监听类型,固定取值为'inputStop'。 |
375| callback | () => void   | 是   | 回调函数。                        |
376
377**示例:**
378
379```ts
380try {
381  inputMethodEngine.getInputMethodAbility().on('inputStop', () => {
382    console.log('inputMethodAbility inputStop');
383  });
384} catch(err) {
385    console.error(`Failed to inputStop: ${JSON.stringify(err)}`);
386}
387```
388
389### off('inputStop')<sup>9+</sup>
390
391off(type: 'inputStop', callback: () => void): void
392
393取消订阅停止输入法应用事件。使用callback异步回调。
394
395**系统能力:** SystemCapability.MiscServices.InputMethodFramework
396
397**参数:**
398
399| 参数名   | 类型   | 必填 | 说明                                                         |
400| -------- | ------ | ---- | ------------------------------------------------------------ |
401| type     | string | 是   | 设置监听类型,固定取值为'inputStop'。 |
402| callback | () => void   | 是   | 取消订阅的回调函数。参数不填写时,取消订阅type对应的所有回调事件。        |
403
404**示例:**
405
406```ts
407try {
408  inputMethodEngine.getInputMethodAbility().off('inputStop', () => {
409    console.log('inputMethodAbility delete inputStop notification.');
410  });
411} catch(err) {
412    console.error(`Failed to inputStop: ${JSON.stringify(err)}`);
413}
414```
415
416### on('setCallingWindow')<sup>9+</sup>
417
418on(type: 'setCallingWindow', callback: (wid: number) => void): void
419
420订阅设置调用窗口事件。使用callback异步回调。
421
422**系统能力:** SystemCapability.MiscServices.InputMethodFramework
423
424**参数:**
425
426| 参数名   | 类型   | 必填 | 说明                                                         |
427| -------- | ------ | ---- | ------------------------------------------------------------ |
428| type     | string | 是   | 设置监听类型,固定取值为'setCallingWindow'。 |
429| callback | (wid: number) => void | 是   | 回调函数,返回调用方窗口的Id。                     |
430
431**示例:**
432
433```ts
434try {
435  inputMethodEngine.getInputMethodAbility().on('setCallingWindow', (wid: number) => {
436    console.log('inputMethodAbility setCallingWindow');
437  });
438} catch(err) {
439    console.error(`Failed to setCallingWindow: ${JSON.stringify(err)}`);
440}
441```
442
443### off('setCallingWindow')<sup>9+</sup>
444
445off(type: 'setCallingWindow', callback: (wid:number) => void): void
446
447取消订阅设置调用窗口事件。使用callback异步回调。
448
449**系统能力:** SystemCapability.MiscServices.InputMethodFramework
450
451**参数:**
452
453| 参数名   | 类型   | 必填 | 说明                                                         |
454| -------- | ------ | ---- | ------------------------------------------------------------ |
455| type     | string | 是   | 设置监听类型,固定取值为'setCallingWindow'。|
456| callback | (wid:number) => void | 是   | 取消订阅的回调函数。参数不填写时,取消订阅type对应的所有回调事件。 |
457
458**示例:**
459
460```ts
461try {
462  inputMethodEngine.getInputMethodAbility().off('setCallingWindow', (wid: number) => {
463    console.log('inputMethodAbility delete setCallingWindow notification.');
464  });
465} catch(err) {
466    console.error(`Failed to setCallingWindow: ${JSON.stringify(err)}`);
467}
468```
469
470### on('keyboardShow'|'keyboardHide')<sup>9+</sup>
471
472on(type: 'keyboardShow'|'keyboardHide', callback: () => void): void
473
474订阅输入法软键盘显示或隐藏事件。使用callback异步回调。
475
476**系统能力:** SystemCapability.MiscServices.InputMethodFramework
477
478**参数:**
479
480| 参数名   | 类型   | 必填 | 说明                                                         |
481| -------- | ------ | ---- | ------------------------------------------------------------ |
482| type     | string | 是   | 设置监听类型。<br/>- 'keyboardShow'表示显示输入法软键盘。<br/>- 'keyboardHide'表示隐藏输入法软键盘。 |
483| callback | () => void   | 是   | 回调函数。                                                   |
484
485**示例:**
486
487```ts
488try {
489  inputMethodEngine.getInputMethodAbility().on('keyboardShow', () => {
490    console.log('InputMethodAbility keyboardShow.');
491  });
492  inputMethodEngine.getInputMethodAbility().on('keyboardHide', () => {
493    console.log('InputMethodAbility keyboardHide.');
494  });
495} catch(err) {
496    console.error(`Failed to keyboard: ${JSON.stringify(err)}`);
497}
498```
499
500### off('keyboardShow'|'keyboardHide')<sup>9+</sup>
501
502off(type: 'keyboardShow'|'keyboardHide', callback?: () => void): void
503
504取消订阅输入法事件。使用callback异步回调。
505
506**系统能力:** SystemCapability.MiscServices.InputMethodFramework
507
508**参数:**
509
510| 参数名   | 类型   | 必填 | 说明                                                         |
511| -------- | ------ | ---- | ------------------------------------------------------------ |
512| type     | string | 是   | 设置监听类型。<br/>- 'keyboardShow'表示显示键盘。<br/>- 'keyboardHide'表示隐藏键盘。 |
513| callback | () => void   | 否   | 回调函数。 |
514
515**示例:**
516
517```ts
518try {
519  inputMethodEngine.getInputMethodAbility().off('keyboardShow', () => {
520    console.log('InputMethodAbility delete keyboardShow notification.');
521  });
522  inputMethodEngine.getInputMethodAbility().off('keyboardHide', () => {
523    console.log('InputMethodAbility delete keyboardHide notification.');
524  });
525} catch(err) {
526    console.error(`Failed to keyboard: ${JSON.stringify(err)}`);
527}
528```
529
530### on('setSubtype')<sup>9+</sup>
531
532on(type: 'setSubtype', callback: (inputMethodSubtype: InputMethodSubtype) => void): void
533
534订阅设置输入法子类型事件。使用callback异步回调。
535
536**系统能力:** SystemCapability.MiscServices.InputMethodFramework
537
538**参数:**
539
540| 参数名    | 类型 | 必填  | 说明 |
541| -------- | --- | ---- | --- |
542| type     | string | 是   | 设置监听类型,固定取值为'setSubtype'。 |
543| callback | (inputMethodSubtype: [InputMethodSubtype](js-apis-inputmethod-subtype.md)) => void | 是   | 回调函数,返回设置的输入法子类型。                         |
544
545**示例:**
546
547```ts
548import { InputMethodSubtype } from '@kit.IMEKit';
549
550try {
551  inputMethodEngine.getInputMethodAbility().on('setSubtype', (inputMethodSubtype: InputMethodSubtype) => {
552    console.log('InputMethodAbility setSubtype.');
553  });
554} catch(err) {
555    console.error(`Failed to setSubtype: ${JSON.stringify(err)}`);
556}
557```
558
559### off('setSubtype')<sup>9+</sup>
560
561off(type: 'setSubtype', callback?: (inputMethodSubtype: InputMethodSubtype) => void): void
562
563取消订阅输入法软键盘显示或隐藏事件。使用callback异步回调。
564
565**系统能力:** SystemCapability.MiscServices.InputMethodFramework
566
567**参数:**
568
569| 参数名   | 类型  | 必填 | 说明   |
570| ------- | ----- | ---- | ---- |
571| type     | string | 是   | 设置监听类型,固定取值为'setSubtype'。 |
572| callback | (inputMethodSubtype: [InputMethodSubtype](js-apis-inputmethod-subtype.md)) => void | 否   | 取消订阅的回调函数。参数不填写时,取消订阅type对应的所有回调事件。  |
573
574**示例:**
575
576```ts
577try {
578  inputMethodEngine.getInputMethodAbility().off('setSubtype', () => {
579    console.log('InputMethodAbility delete setSubtype notification.');
580  });
581} catch(err) {
582    console.error(`Failed to setSubtype: ${JSON.stringify(err)}`);
583}
584```
585
586### on('securityModeChange')<sup>11+</sup>
587
588on(type: 'securityModeChange', callback: Callback< SecurityMode>): void
589
590订阅输入法安全模式改变类型事件。使用callback异步回调。
591
592**系统能力:** SystemCapability.MiscServices.InputMethodFramework
593
594**参数:**
595
596| 参数名   | 类型                                        | 必填 | 说明                                           |
597| -------- | ------------------------------------------- | ---- | ---------------------------------------------- |
598| type     | string                                      | 是   | 设置监听类型,固定取值为'securityModeChange'。 |
599| callback | Callback\<[SecurityMode](#securitymode11))> | 是   | 回调函数,返回当前输入法应用的安全模式。       |
600
601**示例:**
602
603```ts
604try {
605  inputMethodEngine.getInputMethodAbility().on('securityModeChange', (securityMode: inputMethodEngine.SecurityMode) => {
606    console.log(`InputMethodAbility securityModeChange, security is ${securityMode}`);
607  });
608} catch(err) {
609    console.error(`Failed to on securityModeChange: ${JSON.stringify(err)}`);
610}
611```
612
613### off('securityModeChange')<sup>11+</sup>
614
615off(type: 'securityModeChange', callback?: Callback< SecurityMode>): void
616
617取消订阅输入法安全模式改变类型事件。使用callback异步回调。
618
619**系统能力:** SystemCapability.MiscServices.InputMethodFramework
620
621**参数:**
622
623| 参数名   | 类型                                        | 必填 | 说明                                                         |
624| -------- | ------------------------------------------- | ---- | ------------------------------------------------------------ |
625| type     | string                                      | 是   | 设置监听类型,固定取值为'securityModeChange'。               |
626| callback | Callback\<[SecurityMode](#securitymode11))> | 否   | 取消订阅的回调函数。参数不填写时,取消订阅type对应的所有回调事件。 |
627
628**示例:**
629
630```ts
631let securityChangeCallback = (securityMode: inputMethodEngine.SecurityMode) => {
632  console.log(`InputMethodAbility securityModeChange, security is ${securityMode}`);
633};
634let inputMethodAbility = inputMethodEngine.getInputMethodAbility();
635inputMethodAbility.on('securityModeChange', securityChangeCallback);
636try {
637  inputMethodAbility.off('securityModeChange', securityChangeCallback);
638} catch(err) {
639  console.error(`Failed to off securityModeChange: ${JSON.stringify(err)}`);
640}
641```
642
643### on('privateCommand')<sup>12+</sup>
644
645on(type: 'privateCommand', callback: Callback<Record<string, CommandDataType>>): void;
646
647订阅输入法私有数据事件。使用callback异步回调。
648
649**系统能力:** SystemCapability.MiscServices.InputMethodFramework
650
651**参数:**
652
653| 参数名   | 类型                                          | 必填 | 说明                                       |
654| -------- | --------------------------------------------- | ---- | ------------------------------------------ |
655| type     | string                                        | 是   | 设置监听类型,固定取值为'privateCommand'。 |
656| callback | Callback<Record<string, [CommandDataType](#commanddatatype12)>> | 是   | 回调函数,返回向输入法应用发送的私有数据。 |
657
658**错误码:**
659
660以下错误码的详细介绍请参见[输入法框架错误码](errorcode-inputmethod-framework.md)。
661
662| 错误码ID | 错误信息                                       |
663| -------- | ---------------------------------------------- |
664| 12800010 | not the preconfigured default input method. |
665
666**示例:**
667
668```ts
669import { BusinessError } from '@kit.BasicServicesKit';
670import { inputMethodEngine } from '@kit.IMEKit';
671
672let privateCommandCallback = (record: Record<string, inputMethodEngine.CommandDataType>) => {
673  for (let i = 0; i < record.length; i++) {
674    console.log(`private command key: ${i}, value: ${record[i]}`);
675  }
676}
677try {
678  console.log(`regist private command `);
679  inputMethodEngine.getInputMethodAbility().on('privateCommand', privateCommandCallback);
680} catch (err) {
681  let error = err as BusinessError;
682  console.error(`regist private command error: ${error.code} ${error.message}`);
683}
684```
685
686### off('privateCommand')<sup>12+</sup>
687
688off(type: 'privateCommand', callback?: Callback<Record<string, CommandDataType>>): void
689
690取消订阅输入法私有数据事件。使用callback异步回调。
691
692**系统能力:** SystemCapability.MiscServices.InputMethodFramework
693
694**参数:**
695
696| 参数名   | 类型                                        | 必填 | 说明                                                         |
697| -------- | ------------------------------------------- | ---- | ------------------------------------------------------------ |
698| type     | string                                      | 是   | 设置监听类型,固定取值为'privateCommand'。                   |
699| callback | Callback<Record<string, [CommandDataType](#commanddatatype12)>> | 否   | 取消订阅的回调函数。参数不填写时,取消订阅type对应的所有回调事件。 |
700
701**错误码:**
702
703以下错误码的详细介绍请参见[输入法框架错误码](errorcode-inputmethod-framework.md)。
704
705| 错误码ID | 错误信息                                       |
706| -------- | ---------------------------------------------- |
707| 12800010 | not the preconfigured default input method. |
708
709**示例:**
710
711```ts
712import { BusinessError } from '@kit.BasicServicesKit';
713import { inputMethodEngine } from '@kit.IMEKit';
714
715let privateCommandCallback = (record: Record<string, inputMethodEngine.CommandDataType>) => {
716  for (let i = 0; i < record.length; i++) {
717    console.log(`private command key: ${i}, value: ${record[i]}`);
718  }
719}
720try {
721  console.log(`regist private command `);
722  inputMethodEngine.getInputMethodAbility().off('privateCommand', privateCommandCallback);
723} catch (err) {
724  let error = err as BusinessError;
725  console.error(`regist private command error: ${error.code} ${error.message}`);
726}
727```
728
729### getSecurityMode<sup>11+</sup>
730
731getSecurityMode(): SecurityMode
732
733获取输入法应用的当前安全模式。
734
735**系统能力:** SystemCapability.MiscServices.InputMethodFramework
736
737**返回值:**
738
739| 类型                            | 说明       |
740| ------------------------------- | ---------- |
741| [SecurityMode](#securitymode11) | 安全模式。 |
742
743**错误码:**
744
745| 错误码ID | 错误信息                       |
746| -------- | ------------------------------ |
747| 12800004 | not an input method. |
748
749**示例:**
750
751```ts
752try {
753  let security = inputMethodEngine.getInputMethodAbility().getSecurityMode();
754  console.error(`getSecurityMode, securityMode is : ${security}`);
755} catch (err) {
756  console.error(`Failed to getSecurityMode: ${JSON.stringify(err)}`);
757}
758```
759
760### createPanel<sup>10+</sup>
761
762createPanel(ctx: BaseContext, info: PanelInfo, callback: AsyncCallback\<Panel>): void
763
764创建输入法面板,仅支持输入法应用调用。使用callback异步回调。<br>单个输入法应用仅允许创建一个[软键盘类型](#paneltype10)和[状态栏类型](#paneltype10)的面板。
765
766**系统能力:** SystemCapability.MiscServices.InputMethodFramework
767
768**参数:**
769
770| 参数名   | 类型        | 必填 | 说明                     |
771| ------- | ----------- | ---- | ------------------------ |
772| ctx     | [BaseContext](../apis-ability-kit/js-apis-inner-application-baseContext.md) | 是   | 当前输入法应用上下文信息。 |
773| info    | [PanelInfo](#panelinfo10)   | 是   | 输入法应用信息。 |
774| callback | AsyncCallback\<[Panel](#panel10)> | 是   | 回调函数。当输入法面板创建成功,返回当前创建的输入法面板对象。  |
775
776**错误码:**
777
778| 错误码ID   | 错误信息                       |
779| ---------- | ----------------------------- |
780| 401        | parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
781| 12800004   | not an input method. |
782
783**示例:**
784
785```ts
786import { BusinessError } from '@kit.BasicServicesKit';
787
788let panelInfo: inputMethodEngine.PanelInfo = {
789  type: inputMethodEngine.PanelType.SOFT_KEYBOARD,
790  flag: inputMethodEngine.PanelFlag.FLG_FIXED
791}
792try {
793  inputMethodEngine.getInputMethodAbility()
794    .createPanel(this.context, panelInfo, (err: BusinessError, panel: inputMethodEngine.Panel) => {
795      if (err) {
796        console.error(`Failed to createPanel: ${JSON.stringify(err)}`);
797        return;
798      }
799      console.log('Succeed in creating panel.');
800    })
801} catch (err) {
802  console.error(`Failed to createPanel: ${JSON.stringify(err)}`);
803}
804```
805
806### createPanel<sup>10+</sup>
807
808createPanel(ctx: BaseContext, info: PanelInfo): Promise\<Panel>
809
810创建输入法面板,仅支持输入法应用调用。使用promise异步回调。<br>单个输入法应用仅允许创建一个[软键盘类型](#paneltype10)和[状态栏类型](#paneltype10)的面板。
811
812**系统能力:** SystemCapability.MiscServices.InputMethodFramework
813
814**参数:**
815
816| 参数名   | 类型        | 必填 | 说明                     |
817| ------- | ----------- | ---- | ------------------------ |
818| ctx     | [BaseContext](../apis-ability-kit/js-apis-inner-application-baseContext.md) | 是   | 当前输入法应用上下文信息。 |
819| info    | [PanelInfo](#panelinfo10)   | 是   | 输入法面板信息。 |
820
821**返回值:**
822| 类型   | 说明                                                                 |
823| ------- | ------------------------------------------------------------------ |
824| Promise\<[Panel](#panel10)> | 回调函数。当输入法面板创建成功,返回当前创建的输入法面板对象。  |
825
826**错误码:**
827
828| 错误码ID   | 错误信息                       |
829| ---------- | ----------------------------- |
830| 401        | parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
831| 12800004   | not an input method. |
832
833**示例:**
834
835```ts
836import { BusinessError } from '@kit.BasicServicesKit';
837
838let panelInfo: inputMethodEngine.PanelInfo = {
839  type: inputMethodEngine.PanelType.SOFT_KEYBOARD,
840  flag: inputMethodEngine.PanelFlag.FLG_FIXED
841}
842inputMethodEngine.getInputMethodAbility().createPanel(this.context, panelInfo)
843  .then((panel: inputMethodEngine.Panel) => {
844    console.log('Succeed in creating panel.');
845  }).catch((err: BusinessError) => {
846    console.error(`Failed to create panel: ${JSON.stringify(err)}`);
847  })
848```
849
850### destroyPanel<sup>10+</sup>
851
852destroyPanel(panel: Panel, callback: AsyncCallback\<void>): void
853
854销毁输入法面板。使用callback异步回调。
855
856**系统能力:** SystemCapability.MiscServices.InputMethodFramework
857
858**参数:**
859
860| 参数名   | 类型        | 必填 | 说明                     |
861| ------- | ----------- | ---- | ------------------------ |
862| panel     | [Panel](#panel10) | 是   | 要销毁的面板对象。 |
863| callback | AsyncCallback\<void> | 是   | 回调函数。当输入法面板销毁成功,err为undefined,否则为错误对象。  |
864
865**错误码:**
866
867以下错误码的详细介绍请参见[通用错误码说明文档](../errorcode-universal.md)。
868
869| 错误码ID | 错误信息                                                |
870| -------- | ------------------------------------------------------- |
871| 401      | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.           |
872
873**示例:**
874
875```ts
876import { BusinessError } from '@kit.BasicServicesKit';
877
878let panelInfo: inputMethodEngine.PanelInfo = {
879  type: inputMethodEngine.PanelType.SOFT_KEYBOARD,
880  flag: inputMethodEngine.PanelFlag.FLG_FIXED
881}
882let inputPanel: inputMethodEngine.Panel | undefined = undefined;
883try {
884  inputMethodEngine.getInputMethodAbility()
885    .createPanel(this.context, panelInfo, (err: BusinessError, panel: inputMethodEngine.Panel) => {
886      if (err) {
887        console.error(`Failed to create panel: ${JSON.stringify(err)}`);
888        return;
889      }
890      inputPanel = panel;
891      console.log('Succeed in creating panel.');
892    })
893} catch (err) {
894  console.error(`Failed to create panel: ${JSON.stringify(err)}`);
895}
896try {
897  if (inputPanel) {
898    inputMethodEngine.getInputMethodAbility().destroyPanel(inputPanel, (err: BusinessError) => {
899      if (err !== undefined) {
900        console.error(`Failed to destroy panel: ${JSON.stringify(err)}`);
901        return;
902      }
903      console.log('Succeed in destroying panel.');
904    })
905  }
906} catch (err) {
907  console.error(`Failed to destroy panel: ${JSON.stringify(err)}`);
908}
909```
910
911### destroyPanel<sup>10+</sup>
912
913destroyPanel(panel: Panel): Promise\<void>
914
915销毁输入法面板。使用promise异步回调。
916
917**系统能力:** SystemCapability.MiscServices.InputMethodFramework
918
919**参数:**
920
921| 参数名   | 类型        | 必填 | 说明                     |
922| ---------| ----------- | ---- | ------------------------ |
923| panel    | [Panel](#panel10)       | 是   | 要销毁的面板对象。      |
924
925**返回值:**
926| 类型    | 说明                                                                 |
927| ------- | -------------------------------------------------------------------- |
928| Promise\<void> | 无返回结果的Promise对象。|
929
930**错误码:**
931
932以下错误码的详细介绍请参见[通用错误码说明文档](../errorcode-universal.md)。
933
934| 错误码ID | 错误信息                                                |
935| -------- | ------------------------------------------------------- |
936| 401      | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.           |
937
938**示例:**
939
940```ts
941import { BusinessError } from '@kit.BasicServicesKit';
942
943let panelInfo: inputMethodEngine.PanelInfo = {
944  type: inputMethodEngine.PanelType.SOFT_KEYBOARD,
945  flag: inputMethodEngine.PanelFlag.FLG_FIXED
946}
947let inputPanel: inputMethodEngine.Panel | undefined = undefined;
948try {
949  inputMethodEngine.getInputMethodAbility()
950    .createPanel(this.context, panelInfo, (err: BusinessError, panel: inputMethodEngine.Panel) => {
951      if (err) {
952        console.error(`Failed to create panel: ${JSON.stringify(err)}`);
953        return;
954      }
955      inputPanel = panel;
956      console.log('Succeed in creating panel.');
957    })
958} catch (err) {
959  console.error(`Failed to create panel: ${JSON.stringify(err)}`);
960}
961
962try {
963  if (inputPanel) {
964    inputMethodEngine.getInputMethodAbility().destroyPanel(inputPanel).then(() => {
965      console.log('Succeed in destroying panel.');
966    }).catch((err: BusinessError) => {
967      console.error(`Failed to destroy panel: ${JSON.stringify(err)}`);
968    });
969  }
970} catch (err) {
971  console.error(`Failed to destroy panel: ${JSON.stringify(err)}`);
972}
973```
974
975## KeyboardDelegate
976
977下列API均需使用[getKeyboardDelegate](#inputmethodenginegetkeyboarddelegate9)获取到KeyboardDelegate实例后,通过实例调用。
978
979### on('keyDown'|'keyUp')
980
981on(type: 'keyDown'|'keyUp', callback: (event: KeyEvent) => boolean): void
982
983订阅硬键盘(即物理键盘)上物理按键的按下或抬起事件。使用callback异步回调。
984
985**系统能力:** SystemCapability.MiscServices.InputMethodFramework
986
987**参数:**
988
989| 参数名   | 类型                            | 必填 | 说明                                                  |
990| -------- | ------------------------------- | ---- |-----------------------------------------------------|
991| type   | string         | 是   | 设置监听类型。<br/>- 'keyDown'表示键盘按下。<br/>- 'keyUp'表示键盘抬起。 |
992| callback | (event: [KeyEvent](#keyevent)) => boolean | 是 | 回调函数,返回按键信息。 若按键事件被事件订阅者消费,则callback应返回true,否则返回false。   |
993
994**示例:**
995
996```ts
997try {
998  inputMethodEngine.getKeyboardDelegate().on('keyUp', (keyEvent: inputMethodEngine.KeyEvent) => {
999    console.log(`inputMethodEngine keyCode.(keyDown): ${keyEvent.keyCode}`);
1000    console.log(`inputMethodEngine keyAction.(keyDown): ${keyEvent.keyAction}`);
1001    return true;
1002  });
1003  inputMethodEngine.getKeyboardDelegate().on('keyDown', (keyEvent: inputMethodEngine.KeyEvent) => {
1004    console.log(`inputMethodEngine keyCode.(keyDown): ${keyEvent.keyCode}`);
1005    console.log(`inputMethodEngine keyAction.(keyDown): ${keyEvent.keyAction}`);
1006    return true;
1007  });
1008} catch(err) {
1009    console.error(`Failed to KeyboardDelegate: ${JSON.stringify(err)}`);
1010}
1011```
1012
1013### off('keyDown'|'keyUp')
1014
1015off(type: 'keyDown'|'keyUp', callback?: (event: KeyEvent) => boolean): void
1016
1017取消订阅硬键盘(即物理键盘)上物理按键的按下或抬起事件。使用callback异步回调。
1018
1019**系统能力:** SystemCapability.MiscServices.InputMethodFramework
1020
1021**参数:**
1022
1023| 参数名    | 类型     | 必填  | 说明  |
1024| -------- | ------- | ---- | ----- |
1025| type     | string  | 是   | 设置监听类型。<br/>- 'keyDown'表示键盘按下。<br/>- 'keyUp'表示键盘抬起。 |
1026| callback | (event: [KeyEvent](#keyevent)) => boolean | 否   | 取消订阅的回调函数。参数不填写时,取消订阅type对应的所有回调事件。   |
1027
1028**示例:**
1029
1030```ts
1031try {
1032  inputMethodEngine.getKeyboardDelegate().off('keyUp', (keyEvent: inputMethodEngine.KeyEvent) => {
1033    console.log('delete keyUp notification.');
1034    return true;
1035  });
1036  inputMethodEngine.getKeyboardDelegate().off('keyDown', (keyEvent: inputMethodEngine.KeyEvent) => {
1037    console.log('delete keyDown notification.');
1038    return true;
1039  });
1040} catch(err) {
1041    console.error(`Failed to keyevent: ${JSON.stringify(err)}`);
1042}
1043```
1044
1045### on('keyEvent')<sup>10+</sup>
1046
1047on(type: 'keyEvent', callback: (event: InputKeyEvent) => boolean): void
1048
1049订阅硬键盘(即物理键盘)事件。使用callback异步回调。
1050
1051**系统能力:** SystemCapability.MiscServices.InputMethodFramework
1052
1053**参数:**
1054
1055| 参数名   | 类型     | 必填 | 说明                                                         |
1056| -------- | -------- | ---- | ------------------------------------------------------------ |
1057| type     | string   | 是   | 设置监听类型,固定取值为'keyEvent'。 |
1058| callback | (event: [InputKeyEvent](../apis-input-kit/js-apis-keyevent.md#keyevent)) => boolean | 是   | 回调函数,入参为按键事件信息,返回值类型为布尔类型。<br/>-&nbsp;入参按键事件信息的数据类型为[InputKeyEvent](../apis-input-kit/js-apis-keyevent.md#keyevent)。<br/>-&nbsp;若按键事件被事件订阅者消费,则callback应返回true,否则返回false。|
1059
1060**示例:**
1061
1062```ts
1063import type { KeyEvent } from '@kit.InputKit';
1064
1065try {
1066  inputMethodEngine.getKeyboardDelegate().on('keyEvent', (keyEvent: KeyEvent) => {
1067    console.log('inputMethodEngine keyEvent.action:' + JSON.stringify(keyEvent.action));
1068    console.log('inputMethodEngine keyEvent.key.code:' + JSON.stringify(keyEvent.key.code));
1069    console.log(`inputMethodEngine keyEvent.ctrlKey: ${keyEvent.ctrlKey}`);
1070    console.log(`inputMethodEngine keyEvent.unicodeChar: ${keyEvent.unicodeChar}`);
1071    return true;
1072  });
1073} catch(err) {
1074    console.error(`Failed to inputMethodEngine: ${JSON.stringify(err)}`);
1075}
1076```
1077
1078### off('keyEvent')<sup>10+</sup>
1079
1080off(type: 'keyEvent', callback?: (event: InputKeyEvent) => boolean): void
1081
1082取消订阅硬键盘(即物理键盘)事件。使用callback异步回调。
1083
1084**系统能力:** SystemCapability.MiscServices.InputMethodFramework
1085
1086**参数:**
1087
1088| 参数名   | 类型     | 必填 | 说明                                                         |
1089| -------- | -------- | ---- | ------------------------------------------------------------ |
1090| type     | string   | 是   | 设置监听类型,固定取值为'keyEvent'。 |
1091| callback | function | 否   | 取消订阅的回调函数。参数不填写时,取消订阅type对应的所有回调事件。|
1092
1093**示例:**
1094
1095```ts
1096import type { KeyEvent } from '@kit.InputKit';
1097
1098try {
1099  inputMethodEngine.getKeyboardDelegate().off('keyEvent', (keyEvent: KeyEvent) => {
1100    console.log('This is a callback function which will be deregistered.');
1101    return true;
1102  });
1103  inputMethodEngine.getKeyboardDelegate().off('keyEvent');
1104} catch(err) {
1105    console.error(`Failed to keyEvent: ${JSON.stringify(err)}`);
1106}
1107```
1108
1109### on('cursorContextChange')
1110
1111on(type: 'cursorContextChange', callback: (x: number, y:number, height:number) => void): void
1112
1113订阅光标变化事件。使用callback异步回调。
1114
1115**系统能力:** SystemCapability.MiscServices.InputMethodFramework
1116
1117**参数:**
1118
1119| 参数名    | 类型  | 必填  | 说明  |
1120| -------- | ---- | ---- | ----- |
1121| type     | string | 是   | 光标变化事件,固定取值为'cursorContextChange'。 |
1122| callback | (x: number, y: number, height: number) => void | 是   | 回调函数,返回光标信息。<br/>-x为光标上端的的x坐标值,y为光标上端的y坐标值,height为光标的高度值。 |
1123
1124**示例:**
1125
1126```ts
1127try {
1128  inputMethodEngine.getKeyboardDelegate().on('cursorContextChange', (x: number, y: number, height: number) => {
1129    console.log('inputMethodEngine cursorContextChange x:' + x);
1130    console.log('inputMethodEngine cursorContextChange y:' + y);
1131    console.log('inputMethodEngine cursorContextChange height:' + height);
1132  });
1133} catch(err) {
1134    console.error(`Failed to cursorContextChange: ${JSON.stringify(err)}`);
1135}
1136```
1137
1138### off('cursorContextChange')
1139
1140off(type: 'cursorContextChange', callback?: (x: number, y: number, height: number) => void): void
1141
1142取消订阅光标变化事件。使用callback异步回调。
1143
1144**系统能力:** SystemCapability.MiscServices.InputMethodFramework
1145
1146  **参数:**
1147
1148| 参数名    | 类型  | 必填  | 说明   |
1149| -------- | ---- | ---- | ------ |
1150| type     | string  | 是   | 光标变化事件,固定取值为'cursorContextChange'。 |
1151| callback | (x: number, y:number, height:number) => void | 否   | 取消订阅的回调函数。参数不填写时,取消订阅type对应的所有回调事件。 |
1152
1153
1154  **示例:**
1155
1156```ts
1157try {
1158  inputMethodEngine.getKeyboardDelegate().off('cursorContextChange', (x: number, y: number, height: number) => {
1159    console.log('delete cursorContextChange notification.');
1160  });
1161} catch(err) {
1162    console.error(`Failed to cursorContextChange: ${JSON.stringify(err)}`);
1163}
1164```
1165### on('selectionChange')
1166
1167on(type: 'selectionChange', callback: (oldBegin: number, oldEnd: number, newBegin: number, newEnd: number) => void): void
1168
1169订阅文本选择范围变化事件。使用callback异步回调。
1170
1171**系统能力:** SystemCapability.MiscServices.InputMethodFramework
1172
1173**参数:**
1174
1175| 参数名    | 类型   | 必填 | 说明   |
1176| -------- | ----- | ---- | ---- |
1177| type     | string  | 是   | 文本选择变化事件,固定取值为'selectionChange'。 |
1178| callback | (oldBegin: number, oldEnd: number, newBegin: number, newEnd: number) => void | 是   | 回调函数,返回文本选择信息。<br/>- oldBegin为变化前被选中文本的起始下标,oldEnd为变化前被选中文本的终止下标。<br/>- newBegin为变化后被选中文本的起始下标,newEnd为变化后被选中文本的终止下标。|
1179
1180**示例:**
1181
1182```ts
1183try {
1184  inputMethodEngine.getKeyboardDelegate()
1185    .on('selectionChange', (oldBegin: number, oldEnd: number, newBegin: number, newEnd: number) => {
1186      console.log('inputMethodEngine beforeEach selectionChange oldBegin:' + oldBegin);
1187      console.log('inputMethodEngine beforeEach selectionChange oldEnd:' + oldEnd);
1188      console.log('inputMethodEngine beforeEach selectionChange newBegin:' + newBegin);
1189      console.log('inputMethodEngine beforeEach selectionChange newEnd:' + newEnd);
1190    });
1191} catch(err) {
1192    console.error(`Failed to selectionChange: ${JSON.stringify(err)}`);
1193}
1194```
1195
1196### off('selectionChange')
1197
1198off(type: 'selectionChange', callback?: (oldBegin: number, oldEnd: number, newBegin: number, newEnd: number) => void): void
1199
1200取消订阅文本选择范围变化事件。使用callback异步回调。
1201
1202**系统能力:** SystemCapability.MiscServices.InputMethodFramework
1203
1204**参数:**
1205
1206| 参数名   | 类型  | 必填 | 说明     |
1207| -------- | ------- | ---- | ------- |
1208| type     | string  | 是   | 文本选择变化事件,固定取值为'selectionChange'。 |
1209| callback | (oldBegin: number, oldEnd: number, newBegin: number, newEnd: number) => void | 否   | 取消订阅的回调函数。参数不填写时,取消订阅type对应的所有回调事件。|
1210
1211**示例:**
1212
1213```ts
1214try {
1215  inputMethodEngine.getKeyboardDelegate()
1216    .off('selectionChange', (oldBegin: number, oldEnd: number, newBegin: number, newEnd: number)  => {
1217      console.log('delete selectionChange notification.');
1218    });
1219} catch(err) {
1220    console.error(`Failed to selectionChange: ${JSON.stringify(err)}`);
1221}
1222```
1223
1224
1225### on('textChange')
1226
1227on(type: 'textChange', callback: (text: string) => void): void
1228
1229订阅文本内容变化事件。使用callback异步回调。
1230
1231**系统能力:** SystemCapability.MiscServices.InputMethodFramework
1232
1233**参数:**
1234
1235| 参数名   | 类型   | 必填 | 说明                                                         |
1236| -------- | ------ | ---- | ------------------------------------------------------------ |
1237| type     | string | 是   | 文本变化事件,固定取值为'textChange'。 |
1238| callback | (text: string) => void | 是   | 回调函数,返回订阅的文本内容。|
1239
1240**示例:**
1241
1242```ts
1243try {
1244  inputMethodEngine.getKeyboardDelegate().on('textChange', (text: string) => {
1245    console.log('inputMethodEngine textChange. text:' + text);
1246  });
1247} catch(err) {
1248    console.error(`Failed to textChange: ${JSON.stringify(err)}`);
1249}
1250```
1251
1252### off('textChange')
1253
1254off(type: 'textChange', callback?: (text: string) => void): void
1255
1256取消订阅文本内容变化事件。使用callback异步回调。
1257
1258**系统能力:** SystemCapability.MiscServices.InputMethodFramework
1259
1260**参数:**
1261
1262| 参数名   | 类型   | 必填 | 说明                                                         |
1263| -------- | ------ | ---- | ------------------------------------------------------------ |
1264| type     | string | 是   | 文本变化事件,固定取值为'textChange'。 |
1265| callback | (text: string) => void | 否   | 取消订阅的回调函数。参数不填写时,取消订阅type对应的所有回调事件。|
1266
1267**示例:**
1268
1269```ts
1270try {
1271  inputMethodEngine.getKeyboardDelegate().off('textChange', (text: string) => {
1272    console.log('delete textChange notification. text:' + text);
1273  });
1274} catch(err) {
1275    console.error(`Failed to textChange: ${JSON.stringify(err)}`);
1276}
1277```
1278
1279### on('editorAttributeChanged')<sup>10+</sup>
1280on(type: 'editorAttributeChanged', callback: (attr: EditorAttribute) => void): void
1281
1282
1283订阅编辑框属性变化事件。使用callback异步回调。
1284
1285**系统能力:** SystemCapability.MiscServices.InputMethodFramework
1286
1287**参数:**
1288
1289| 参数名   | 类型   | 必填 | 说明                                                         |
1290| -------- | ------ | ---- | ------------------------------------------------------------ |
1291| type     | string | 是   | 文本变化事件,固定取值为'editorAttributeChanged'。 |
1292| callback | (attr: EditorAttribute) => void | 是   | 回调函数,返回变化的编辑框属性。|
1293
1294**示例:**
1295
1296```ts
1297try {
1298  inputMethodEngine.getKeyboardDelegate().on('editorAttributeChanged', (attr: inputMethodEngine.EditorAttribute) => {
1299    console.log(`Succeeded in receiving attribute of editor, inputPattern = ${attr.inputPattern}, enterKeyType = ${attr.enterKeyType}`);
1300  });
1301} catch(err) {
1302    console.error(`Failed to textChange: ${JSON.stringify(err)}`);
1303}
1304```
1305
1306### off('editorAttributeChanged')<sup>10+</sup>
1307
1308off(type: 'editorAttributeChanged', callback?: (attr: EditorAttribute) => void): void
1309
1310取消订阅编辑框属性变化事件。使用callback异步回调。
1311
1312**系统能力:** SystemCapability.MiscServices.InputMethodFramework
1313
1314**参数:**
1315
1316| 参数名   | 类型   | 必填 | 说明                                                         |
1317| -------- | ------ | ---- | ------------------------------------------------------------ |
1318| type     | string | 是   | 文本变化事件,固定取值为'editorAttributeChanged'。 |
1319| callback | (attr: EditorAttribute) => void | 否   | 所要取消订阅的回调处理函数。参数不填写时,取消订阅type对应的所有回调事件。 |
1320
1321**示例:**
1322
1323```ts
1324inputMethodEngine.getKeyboardDelegate().off('editorAttributeChanged');
1325```
1326
1327## Panel<sup>10+</sup>
1328
1329下列API均需使用[createPanel](#createpanel10)获取到Panel实例后,通过实例调用。
1330
1331### setUiContent<sup>10+</sup>
1332
1333setUiContent(path: string, callback: AsyncCallback\<void>): void
1334
1335为当前的输入法面板加载具体页面内容,使用callback异步回调。
1336
1337**系统能力:** SystemCapability.MiscServices.InputMethodFramework
1338
1339**参数:**
1340
1341| 参数名   | 类型                   | 必填 | 说明     |
1342| -------- | ---------------------- | ---- | -------- |
1343| path | string | 是   | 具体页面的路径。 |
1344| callback | AsyncCallback\<void> | 是   | 回调函数。当面板页面内容加载成功,err为undefined,否则err为错误对象。 |
1345
1346**错误码:**
1347
1348以下错误码的详细介绍请参见[通用错误码说明文档](../errorcode-universal.md)。
1349
1350| 错误码ID | 错误信息                                                |
1351| -------- | ------------------------------------------------------- |
1352| 401      | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.           |
1353
1354**示例:**
1355
1356```ts
1357import { BusinessError } from '@kit.BasicServicesKit';
1358
1359try {
1360  panel.setUiContent('pages/page2/page2', (err: BusinessError) => {
1361    if (err) {
1362      console.error(`Failed to setUiContent: ${JSON.stringify(err)}`);
1363      return;
1364    }
1365    console.log('Succeeded in setting the content.');
1366  });
1367} catch (err) {
1368  console.error(`Failed to setUiContent: ${JSON.stringify(err)}`);
1369}
1370```
1371
1372### setUiContent<sup>10+</sup>
1373
1374setUiContent(path: string): Promise\<void>
1375
1376为当前的输入法面板加载具体页面内容,使用Promise异步回调。
1377
1378**系统能力:** SystemCapability.MiscServices.InputMethodFramework
1379
1380**参数:**
1381
1382| 参数名   | 类型                   | 必填 | 说明     |
1383| -------- | ---------------------- | ---- | -------- |
1384| path | string | 是   |  具体页面的路径。 |
1385
1386**返回值:**
1387
1388| 类型   | 说明                             |
1389| ------- | ------------------------------ |
1390| Promise\<void> | 无返回结果的Promise对象。  |
1391
1392**错误码:**
1393
1394以下错误码的详细介绍请参见[通用错误码说明文档](../errorcode-universal.md)。
1395
1396| 错误码ID | 错误信息                                                |
1397| -------- | ------------------------------------------------------- |
1398| 401      | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.           |
1399
1400**示例:**
1401
1402```ts
1403import { BusinessError } from '@kit.BasicServicesKit';
1404
1405try {
1406  panel.setUiContent('pages/page2/page2').then(() => {
1407    console.log('Succeeded in setting the content.');
1408  }).catch((err: BusinessError) => {
1409    console.error(`Failed to setUiContent: ${JSON.stringify(err)}`);
1410  });
1411} catch (err) {
1412  console.error(`Failed to setUiContent: ${JSON.stringify(err)}`);
1413}
1414```
1415
1416### setUiContent<sup>10+</sup>
1417
1418setUiContent(path: string, storage: LocalStorage, callback: AsyncCallback\<void>): void
1419
1420为当前的输入法面板加载与LocalStorage相关联的具体页面内容,使用callback异步回调。
1421
1422**系统能力:** SystemCapability.MiscServices.InputMethodFramework
1423
1424**参数:**
1425
1426| 参数名   | 类型                   | 必填 | 说明     |
1427| -------- | ---------------------- | ---- | -------- |
1428| path | string | 是   | LocalStorage相关联的具体页面的路径。 |
1429| storage | [LocalStorage](../apis-arkui/arkui-ts/ts-state-management.md#localstorage9) | 是   | 存储单元,为应用程序范围内的可变和不可变状态属性提供存储。|
1430| callback | AsyncCallback\<void> | 是   | 回调函数。当面板页面内容加载成功,err为undefined,否则err为错误对象。 |
1431
1432**错误码:**
1433
1434以下错误码的详细介绍请参见[通用错误码说明文档](../errorcode-universal.md)。
1435
1436| 错误码ID | 错误信息                                                |
1437| -------- | ------------------------------------------------------- |
1438| 401      | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.           |
1439
1440**示例:**
1441
1442```ts
1443import { BusinessError } from '@kit.BasicServicesKit';
1444
1445let storage = new LocalStorage();
1446storage.setOrCreate('storageSimpleProp',121);
1447try {
1448  panel.setUiContent('pages/page2/page2', storage, (err: BusinessError) => {
1449    if (err) {
1450      console.error(`Failed to setUiContent: ${JSON.stringify(err)}`);
1451      return;
1452    }
1453    console.log('Succeeded in setting the content.');
1454  });
1455} catch (err) {
1456  console.error(`Failed to setUiContent: ${JSON.stringify(err)}`);
1457}
1458```
1459
1460### setUiContent<sup>10+</sup>
1461
1462setUiContent(path: string, storage: LocalStorage): Promise\<void>
1463
1464为当前面板加载与LocalStorage相关联的具体页面内容,使用Promise异步回调。
1465
1466**系统能力:** SystemCapability.MiscServices.InputMethodFramework
1467
1468**参数:**
1469
1470| 参数名   | 类型                   | 必填 | 说明     |
1471| -------- | ---------------------- | ---- | -------- |
1472| path | string | 是   | 设置加载页面的路径。 |
1473| storage | [LocalStorage](../apis-arkui/arkui-ts/ts-state-management.md#localstorage9) | 是   | 存储单元,为应用程序范围内的可变状态属性和非可变状态属性提供存储。|
1474
1475**返回值:**
1476
1477| 类型   | 说明                             |
1478| ------- | ------------------------------ |
1479| Promise\<void> | 无返回结果的Promise对象。  |
1480
1481**错误码:**
1482
1483以下错误码的详细介绍请参见[通用错误码说明文档](../errorcode-universal.md)。
1484
1485| 错误码ID | 错误信息                                                |
1486| -------- | ------------------------------------------------------- |
1487| 401      | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.           |
1488
1489**示例:**
1490
1491```ts
1492import { BusinessError } from '@kit.BasicServicesKit';
1493
1494let storage = new LocalStorage();
1495storage.setOrCreate('storageSimpleProp',121);
1496try {
1497  panel.setUiContent('pages/page2/page2', storage).then(() => {
1498    console.log('Succeeded in setting the content.');
1499  }).catch((err: BusinessError) => {
1500    console.error(`Failed to setUiContent: ${JSON.stringify(err)}`);
1501  });
1502} catch (err) {
1503  console.error(`Failed to setUiContent: ${JSON.stringify(err)}`);
1504}
1505```
1506
1507### resize<sup>10+</sup>
1508
1509resize(width: number, height: number, callback: AsyncCallback\<void>): void
1510
1511改变当前输入法面板的大小,使用callback异步回调。
1512
1513> **说明**
1514>
1515> 面板宽度不超出屏幕宽度,面板高度不高于屏幕高度的0.6倍。
1516
1517**系统能力:** SystemCapability.MiscServices.InputMethodFramework
1518
1519**参数:**
1520
1521| 参数名   | 类型                   | 必填 | 说明     |
1522| -------- | ---------------------- | ---- | -------- |
1523| width | number | 是   | 目标面板的宽度,单位为px。|
1524| height | number | 是   | 目标面板的高度,单位为px。|
1525| callback | AsyncCallback\<void> | 是   | 回调函数。当面板大小改变成功,err为undefined,否则err为错误对象。 |
1526
1527**错误码:**
1528
1529以下错误码的详细介绍请参见[通用错误码说明文档](../errorcode-universal.md)。
1530
1531| 错误码ID | 错误信息                                                |
1532| -------- | ------------------------------------------------------- |
1533| 401      | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.           |
1534
1535**示例:**
1536
1537```ts
1538import { BusinessError } from '@kit.BasicServicesKit';
1539
1540try {
1541  panel.resize(500, 1000, (err: BusinessError) => {
1542    if (err) {
1543      console.error(`Failed to resize panel: ${JSON.stringify(err)}`);
1544      return;
1545    }
1546    console.log('Succeeded in changing the panel size.');
1547  });
1548} catch (err) {
1549  console.error(`Failed to resize panel: ${JSON.stringify(err)}`);
1550}
1551```
1552
1553### resize<sup>10+</sup>
1554
1555resize(width: number, height: number): Promise\<void>
1556
1557改变当前输入法面板的大小,使用Promise异步回调。
1558
1559> **说明**
1560>
1561> 面板宽度不超出屏幕宽度,面板高度不高于屏幕高度的0.6倍。
1562
1563**系统能力:** SystemCapability.MiscServices.InputMethodFramework
1564
1565**参数:**
1566
1567| 参数名   | 类型                   | 必填 | 说明     |
1568| -------- | ---------------------- | ---- | -------- |
1569| width | number | 是   | 目标面板的宽度,单位为px。|
1570| height | number | 是   | 目标面板的高度,单位为px。|
1571
1572**返回值:**
1573
1574| 类型   | 说明                             |
1575| ------- | ------------------------------ |
1576| Promise\<void> | 无返回结果的Promise对象。  |
1577
1578**错误码:**
1579
1580以下错误码的详细介绍请参见[通用错误码说明文档](../errorcode-universal.md)。
1581
1582| 错误码ID | 错误信息                                                |
1583| -------- | ------------------------------------------------------- |
1584| 401      | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.           |
1585
1586**示例:**
1587
1588```ts
1589import { BusinessError } from '@kit.BasicServicesKit';
1590
1591try {
1592  panel.resize(500, 1000).then(() => {
1593    console.log('Succeeded in changing the panel size.');
1594  }).catch((err: BusinessError) => {
1595    console.error(`Failed to resize panel: ${JSON.stringify(err)}`);
1596  });
1597} catch (err) {
1598  console.error(`Failed to resize panel: ${JSON.stringify(err)}`);
1599}
1600```
1601
1602### moveTo<sup>10+</sup>
1603
1604moveTo(x: number, y: number, callback: AsyncCallback\<void>): void
1605
1606移动面板位置,使用callback异步回调。[面板状态](#panelflag10)为固定态时,不产生实际移动效果。
1607
1608**系统能力:** SystemCapability.MiscServices.InputMethodFramework
1609
1610**参数:**
1611
1612| 参数名   | 类型                   | 必填 | 说明     |
1613| -------- | ---------------------- | ---- | -------- |
1614| x | number | 是   | x轴方向移动的值,值大于0表示右移,单位为px。|
1615| y | number | 是   | y轴方向移动的值,值大于0表示下移,单位为px。|
1616| callback | AsyncCallback\<void> | 是   | 回调函数。当面板位置移动成功,err为undefined,否则err为错误对象。 |
1617
1618**错误码:**
1619
1620以下错误码的详细介绍请参见[通用错误码说明文档](../errorcode-universal.md)。
1621
1622| 错误码ID | 错误信息                                                |
1623| -------- | ------------------------------------------------------- |
1624| 401      | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
1625
1626**示例:**
1627
1628```ts
1629import { BusinessError } from '@kit.BasicServicesKit';
1630
1631try {
1632  panel.moveTo(300, 300, (err: BusinessError) =>{
1633    if (err) {
1634      console.error(`Failed to move panel: ${JSON.stringify(err)}`);
1635      return;
1636    }
1637    console.log('Succeeded in moving the panel.');
1638  });
1639} catch (err) {
1640    console.error(`Failed to move panel: ${JSON.stringify(err)}`);
1641}
1642```
1643
1644### moveTo<sup>10+</sup>
1645
1646moveTo(x: number, y: number): Promise\<void>
1647
1648移动面板位置,使用promise异步回调。[面板状态](#panelflag10)为固定态时,不产生实际移动效果。
1649
1650**系统能力:** SystemCapability.MiscServices.InputMethodFramework
1651
1652**参数:**
1653
1654| 参数名   | 类型                   | 必填 | 说明     |
1655| -------- | ---------------------- | ---- | -------- |
1656| x | number | 是   |x轴方向移动的值,值大于0表示右移,单位为px。|
1657| y | number | 是   |y轴方向移动的值,值大于0表示下移,单位为px。|
1658
1659**返回值:**
1660
1661| 类型   | 说明                             |
1662| ------- | ------------------------------ |
1663| Promise\<void> | 无返回结果的Promise对象。  |
1664
1665**错误码:**
1666
1667以下错误码的详细介绍请参见[通用错误码说明文档](../errorcode-universal.md)。
1668
1669| 错误码ID | 错误信息                                                |
1670| -------- | ------------------------------------------------------- |
1671| 401      | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
1672
1673**示例:**
1674
1675```ts
1676import { BusinessError } from '@kit.BasicServicesKit';
1677
1678try {
1679  panel.moveTo(300, 300).then(() => {
1680    console.log('Succeeded in moving the panel.');
1681  }).catch((err: BusinessError) => {
1682    console.error(`Failed to move panel: ${JSON.stringify(err)}`);
1683  });
1684} catch (err) {
1685  console.error(`Failed to move panel: ${JSON.stringify(err)}`);
1686}
1687```
1688
1689### startMoving<sup>15+</sup>
1690
1691startMoving(): void
1692
1693发送移动命令给窗口,不产生实际移动效果(仅在鼠标点击作用才可以移动)。
1694
1695**系统能力:** SystemCapability.MiscServices.InputMethodFramework
1696
1697**错误码:**
1698
1699以下错误码的详细介绍请参见[输入法框架错误码](errorcode-inputmethod-framework.md)。
1700
1701| 错误码ID | 错误信息                                                |
1702| -------- | ------------------------------------------------------- |
1703| 12800002 | input method engine error. |
1704| 12800013 | window manager service error. |
1705| 12800017 | invalid panel type or panel flag. |
1706
1707**示例:**
1708
1709```ts
1710
1711try {
1712  panel.startMoving();
1713  console.log('Succeeded in moving the panel.');
1714} catch (err) {
1715  console.error(`Failed to move panel: ${JSON.stringify(err)}`);
1716}
1717```
1718
1719### getDisplayId<sup>15+</sup>
1720
1721getDisplayId(): Promise\<number>
1722
1723获取当前窗口的所在id,使用Promise异步回调。
1724
1725**系统能力:** SystemCapability.MiscServices.InputMethodFramework
1726
1727**返回值:**
1728
1729| 类型   | 说明                             |
1730| ------- | ------------------------------ |
1731|Promise\<number>| Promise对象。返回窗口的displayId。  |
1732
1733**错误码:**
1734
1735以下错误码的详细介绍请参见[输入法框架错误码](errorcode-inputmethod-framework.md)。
1736
1737| 错误码ID | 错误信息                                                |
1738| -------- | ------------------------------------------------------- |
1739| 12800002 | input method engine error. |
1740| 12800013 | window manager service error. |
1741
1742**示例:**
1743
1744```ts
1745import { BusinessError } from '@kit.BasicServicesKit';
1746
1747try {
1748  panel.getDisplayId().then((result: number) => {
1749    console.log('get displayId:' + result);
1750  }).catch((err: BusinessError) => {
1751    console.error(`Failed to get displayId: ${JSON.stringify(err)}`);
1752  });
1753} catch (err) {
1754  console.error(`Failed to get displayId: ${JSON.stringify(err)}`);
1755}
1756```
1757
1758### show<sup>10+</sup>
1759
1760show(callback: AsyncCallback\<void>): void
1761
1762显示当前输入法面板,使用callback异步回调。输入法应用与编辑框绑定成功后可正常调用。
1763
1764**系统能力:** SystemCapability.MiscServices.InputMethodFramework
1765
1766**参数:**
1767
1768| 参数名   | 类型                   | 必填 | 说明     |
1769| -------- | ---------------------- | ---- | -------- |
1770| callback | AsyncCallback\<void> | 是   | 回调函数。当面板显示成功,err为undefined,否则err为错误对象。 |
1771
1772**示例:**
1773
1774```ts
1775import { BusinessError } from '@kit.BasicServicesKit';
1776
1777panel.show((err: BusinessError) => {
1778  if (err) {
1779    console.error(`Failed to show panel: ${JSON.stringify(err)}`);
1780    return;
1781  }
1782  console.log('Succeeded in showing the panel.');
1783});
1784```
1785
1786### show<sup>10+</sup>
1787
1788show(): Promise\<void>
1789
1790显示当前输入法面板,使用promise异步回调。输入法应用与编辑框绑定成功后可正常调用。
1791
1792**系统能力:** SystemCapability.MiscServices.InputMethodFramework
1793
1794**返回值:**
1795
1796| 类型   | 说明                             |
1797| ------- | ------------------------------ |
1798| Promise\<void> | 无返回结果的Promise对象。  |
1799
1800**示例:**
1801
1802```ts
1803import { BusinessError } from '@kit.BasicServicesKit';
1804
1805panel.show().then(() => {
1806  console.log('Succeeded in showing the panel.');
1807}).catch((err: BusinessError) => {
1808  console.error(`Failed to show panel: ${JSON.stringify(err)}`);
1809});
1810```
1811
1812### hide<sup>10+</sup>
1813
1814hide(callback: AsyncCallback\<void>): void
1815
1816隐藏当前输入法面板,使用callback异步回调。
1817
1818**系统能力:** SystemCapability.MiscServices.InputMethodFramework
1819
1820**参数:**
1821
1822| 参数名   | 类型                   | 必填 | 说明     |
1823| -------- | ---------------------- | ---- | -------- |
1824| callback | AsyncCallback\<void> | 是   | 回调函数。当面板隐藏成功,err为undefined,否则err为错误对象。 |
1825
1826**示例:**
1827
1828```ts
1829import { BusinessError } from '@kit.BasicServicesKit';
1830
1831panel.hide((err: BusinessError) => {
1832  if (err) {
1833    console.error(`Failed to hide panel: ${JSON.stringify(err)}`);
1834    return;
1835  }
1836  console.log('Succeeded in hiding the panel.');
1837});
1838```
1839
1840### hide<sup>10+</sup>
1841
1842hide(): Promise\<void>
1843
1844隐藏当前输入法面板,使用promise异步回调。
1845
1846**系统能力:** SystemCapability.MiscServices.InputMethodFramework
1847
1848**返回值:**
1849
1850| 类型   | 说明                             |
1851| ------- | ------------------------------ |
1852| Promise\<void> | 无返回结果的Promise对象。  |
1853
1854**示例:**
1855
1856```ts
1857import { BusinessError } from '@kit.BasicServicesKit';
1858
1859panel.hide().then(() => {
1860  console.log('Succeeded in hiding the panel.');
1861}).catch((err: BusinessError) => {
1862  console.error(`Failed to hide panel: ${JSON.stringify(err)}`);
1863});
1864```
1865
1866### adjustPanelRect<sup>12+</sup>
1867
1868adjustPanelRect(flag: PanelFlag, rect: PanelRect): void
1869
1870预设置输入法应用横竖屏大小。
1871
1872**系统能力:** SystemCapability.MiscServices.InputMethodFramework
1873
1874**参数:**
1875
1876| 参数名   | 类型                   | 必填 | 说明     |
1877| -------- | ---------------------- | ---- | -------- |
1878| flag | [PanelFlag](#panelflag10) | 是 | 目标面板状态类型。类型为FLG_FIXED或FLG_FLOATING。 |
1879| rect | [PanelRect](#panelrect12) | 是   | 目标面板横屏状态及竖屏状态的横坐标,纵坐标,宽度以及高度。固定态:高度不能超过屏幕高度的70%,宽度不能超过屏幕宽度;悬浮态:高度不能超过屏幕高度,宽度不能超过屏幕宽度。|
1880
1881**错误码:**
1882
1883以下错误码的详细介绍请参见[输入法框架错误码](errorcode-inputmethod-framework.md)。
1884
1885| 错误码ID | 错误信息                                                |
1886| -------- | ------------------------------------------------------- |
1887| 401      | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.           |
1888| 12800013 | window manager service error. |
1889
1890**示例:**
1891
1892```ts
1893import { BusinessError } from '@kit.BasicServicesKit';
1894
1895try {
1896  let panelFlag = inputMethodEngine.PanelFlag.FLG_FIXED;
1897  let panelRect:inputMethodEngine.PanelRect = {
1898    landscapeRect:{left:100, top:100, width:400, height:400},
1899    portraitRect:{left:200, top:200, width:300, height:300}
1900  };
1901  panel.adjustPanelRect(panelFlag, panelRect);
1902} catch(err) {
1903  console.error(`Failed to adjustPanelRect: ${JSON.stringify(err)}`);
1904}
1905```
1906
1907### adjustPanelRect<sup>15+</sup>
1908
1909adjustPanelRect(flag: PanelFlag, rect: EnhancedPanelRect): void
1910
1911预设置输入法应用横竖屏大小、位置、自定义避让区域以及热区。
1912
1913> **说明:**
1914>
1915> 仅用于SOFT_KEYBOARD类型,状态为FLG_FIXED或FLG_FLOATING的面板。此接口兼容[adjustPanelRect](#adjustpanelrect12)的调用方法,若入参rect仅填写属性landscapeRect和portraitRect,则默认调用[adjustPanelRect](#adjustpanelrect12)。
1916>
1917> 此接口为同步接口,接口返回仅代表系统侧收到设置的请求,不代表已完成设置。
1918
1919**系统能力:** SystemCapability.MiscServices.InputMethodFramework
1920
1921**参数:**
1922
1923| 参数名 | 类型                                      | 必填 | 说明                                                       |
1924| ------ | ----------------------------------------- | ---- | ---------------------------------------------------------- |
1925| flag   | [PanelFlag](#panelflag10)                 | 是   | 目标面板状态类型。类型为FLG_FIXED或FLG_FLOATING。          |
1926| rect   | [EnhancedPanelRect](#enhancedpanelrect15) | 是   | 目标面板横屏状态及竖屏状态的位置、大小、避让区域以及热区。 |
1927
1928**错误码:**
1929
1930以下错误码的详细介绍请参见[输入法框架错误码](errorcode-inputmethod-framework.md)。
1931
1932| 错误码ID | 错误信息                                                     |
1933| -------- | ------------------------------------------------------------ |
1934| 401      | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
1935| 12800013 | window manager service error.                                |
1936| 12800017 | invalid panel type or panel flag.                            |
1937
1938**示例:**
1939
1940```ts
1941import { BusinessError } from '@kit.BasicServicesKit';
1942
1943try {
1944  let panelFlag = inputMethodEngine.PanelFlag.FLG_FIXED;
1945  let panelRect:inputMethodEngine.EnhancedPanelRect = {
1946    landscapeAvoidY: 650,
1947    landscapeInputRegion: [{left:300, top:650, width:2000, height:500}],
1948    portraitAvoidY: 1800,
1949    portraitInputRegion: [{left:0, top:1800, width:1200, height:800}],
1950    fullScreenMode: true
1951  };
1952  panel.adjustPanelRect(panelFlag, panelRect);
1953} catch(err) {
1954  console.error(`Failed to adjustPanelRect: ${JSON.stringify(err)}`);
1955}
1956```
1957
1958### updatelnputRegion<sup>15+</sup>
1959
1960updateRegion(inputRegion: Array&lt;window.Rect&gt;): void
1961
1962更新当前状态下输入法面板内的热区。
1963
1964> **说明:**
1965>
1966> 仅用于SOFT_KEYBOARD类型,状态为FLG_FIXED或FLG_FLOATING的面板。
1967>
1968> 此接口为同步接口,接口返回仅代表系统侧收到更新热区的请求,不代表已完成热区更新。
1969
1970**系统能力:** SystemCapability.MiscServices.InputMethodFramework
1971
1972**参数:**
1973
1974| 参数名      | 类型                                                         | 必填 | 说明                                                         |
1975| ----------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
1976| inputRegion | Array&lt;[window.Rect](../apis-arkui/js-apis-window.md#rect7)&gt; | 是   | 面板内接收输入事件的区域。<br/>- 数组大小限制为[1, 4]。<br/>- 传入的热区位置是相对于输入法面板窗口左顶点的位置。 |
1977
1978**错误码:**
1979
1980以下错误码的详细介绍请参见[输入法框架错误码](errorcode-inputmethod-framework.md)。
1981
1982| 错误码ID | 错误信息                                                     |
1983| -------- | ------------------------------------------------------------ |
1984| 401      | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
1985| 12800013 | window manager service error.                                |
1986| 12800017 | invalid panel type or panel flag.                            |
1987
1988**示例:**
1989
1990```ts
1991import { BusinessError } from '@kit.BasicServicesKit';
1992import { window } from '@kit.ArkUI';
1993
1994try {
1995  let inputRegion: Array<window.Rect> = [{left:300, top:650, width:2000, height:500}];
1996  panel.updateRegion(inputRegion);
1997} catch(err) {
1998  console.error(`Failed to updateRegion: ${JSON.stringify(err)}`);
1999}
2000```
2001
2002### on('show')<sup>10+</sup>
2003
2004on(type: 'show', callback: () => void): void
2005
2006监听当前面板显示状态,使用callback异步回调。
2007
2008**系统能力:** SystemCapability.MiscServices.InputMethodFramework
2009
2010**参数:**
2011
2012| 参数名   | 类型                   | 必填 | 说明     |
2013| -------- | ---------------------- | ---- | -------- |
2014| type | string | 是 | 监听当前面板的状态类型,固定取值为'show'。 |
2015| callback | () => void | 是   | 回调函数。 |
2016
2017**示例:**
2018
2019```ts
2020try {
2021  panel.on('show', () => {
2022    console.log('Panel is showing.');
2023  });
2024} catch(err) {
2025    console.error(`Failed to show: ${JSON.stringify(err)}`);
2026}
2027```
2028
2029### on('hide')<sup>10+</sup>
2030
2031on(type: 'hide', callback: () => void): void
2032
2033监听当前面板隐藏状态,使用callback异步回调。
2034
2035**系统能力:** SystemCapability.MiscServices.InputMethodFramework
2036
2037**参数:**
2038
2039| 参数名   | 类型                   | 必填 | 说明     |
2040| -------- | ---------------------- | ---- | -------- |
2041| type | string | 是 | 监听当前面板的状态类型,固定取值为'hide'。 |
2042| callback | () => void | 是   | 回调函数。 |
2043
2044**示例:**
2045
2046```ts
2047try {
2048  panel.on('hide', () => {
2049    console.log('Panel is hiding.');
2050  });
2051} catch(err) {
2052    console.error(`Failed to hide: ${JSON.stringify(err)}`);
2053}
2054```
2055
2056### on('sizeChange')<sup>12+</sup>
2057
2058on(type: 'sizeChange', callback: SizeChangeCallback): void
2059
2060监听当前面板大小变化,使用callback异步回调。
2061
2062> **说明:**
2063>
2064> 仅用于SOFT_KEYBOARD类型,状态为FLG_FIXED或FLG_FLOATING的面板。输入法通过adjustPanelRect等接口对面板大小进行调节时,系统会根据一定规则校验计算出最终的数值(例如超出屏幕等场景),输入法应用可通过该回调获取的真实面板大小,完成最终的面板布局刷新。
2065>
2066>-  从API version 12-14开始支持,此接口回调函数中仅包含[window.Size](../apis-arkui/js-apis-window.md#size7)类型的必选参数。
2067>-  从API version 15起,调用[adjustPanelRect](#adjustpanelrect15)接口后,此接口回调函数增加[KeyboardArea](#keyboardarea15)类型的可选参数。
2068
2069**系统能力:** SystemCapability.MiscServices.InputMethodFramework
2070
2071**参数:**
2072
2073| 参数名   | 类型                                        | 必填 | 说明                                                   |
2074| -------- | ------------------------------------------- | ---- | ------------------------------------------------------ |
2075| type     | string                                      | 是   | 监听当前面板的大小是否产生变化,固定值为'sizeChange'。 |
2076| callback | [SizeChangeCallback](#sizechangecallback15) | 是   | 回调函数。返回当前软键盘面板的大小,包含宽度和高度值。 |
2077
2078**示例:**
2079
2080```ts
2081import { window } from '@kit.ArkUI';
2082try {
2083  panel.on('sizeChange', (windowSize: window.Size) => {
2084    console.info(`panel size changed, width: ${windowSize.width}, height: ${windowSize.height}`);
2085  });
2086} catch(err) {
2087  console.error(`Failed to subscribe sizeChange: ${JSON.stringify(err)}`);
2088}
2089try {
2090  panel.on('sizeChange', (windowSize: window.Size, keyboardArea: inputMethodEngine.KeyboardArea) => {
2091    console.info(`panel size changed, windowSize: ${JSON.stringify(windowSize)}, keyboardArea: ${JSON.stringify(keyboardArea)}`);
2092  });
2093} catch(err) {
2094  console.error(`Failed to subscribe sizeChange: ${JSON.stringify(err)}`);
2095}
2096```
2097
2098### off('show')<sup>10+</sup>
2099
2100off(type: 'show', callback?: () => void): void
2101
2102取消监听当前输入法面板的隐藏状态,使用callback异步回调。
2103
2104**系统能力:** SystemCapability.MiscServices.InputMethodFramework
2105
2106**参数:**
2107
2108| 参数名   | 类型                   | 必填 | 说明     |
2109| -------- | ---------------------- | ---- | -------- |
2110| type | string | 是 | 取消监听当前面板的状态类型,固定取值为'show'。 |
2111| callback | () => void | 否   | 取消订阅的回调函数。参数不填写时,取消订阅type对应的所有回调事件。 |
2112
2113**错误码:**
2114
2115以下错误码的详细介绍请参见[通用错误码说明文档](../errorcode-universal.md)。
2116
2117| 错误码ID | 错误信息                                                |
2118| -------- | ------------------------------------------------------- |
2119| 401      | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.           |
2120
2121**示例:**
2122
2123```ts
2124try {
2125  panel.off('show');
2126} catch(err) {
2127    console.error(`Failed to show: ${JSON.stringify(err)}`);
2128}
2129```
2130
2131### off('hide')<sup>10+</sup>
2132
2133off(type: 'hide', callback?: () => void): void
2134
2135取消监听当前面板隐藏状态,使用callback异步回调。
2136
2137**系统能力:** SystemCapability.MiscServices.InputMethodFramework
2138
2139**参数:**
2140
2141| 参数名   | 类型                   | 必填 | 说明     |
2142| -------- | ---------------------- | ---- | -------- |
2143| type | string | 是 | 要取消监听的当前面板状态类型,固定取值为'hide'。 |
2144| callback | () => void | 否   | 取消订阅的回调函数。参数不填写时,取消订阅type对应的所有回调事件。 |
2145
2146**错误码:**
2147
2148以下错误码的详细介绍请参见[通用错误码说明文档](../errorcode-universal.md)。
2149
2150| 错误码ID | 错误信息                                                |
2151| -------- | ------------------------------------------------------- |
2152| 401      | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.           |
2153
2154**示例:**
2155
2156```ts
2157try {
2158  panel.off('hide');
2159} catch(err) {
2160    console.error(`Failed to hide: ${JSON.stringify(err)}`);
2161}
2162```
2163
2164### off('sizeChange')<sup>12+</sup>
2165
2166off(type: 'sizeChange', callback?: SizeChangeCallback): void
2167
2168取消监听当前面板大小变化,使用callback异步回调。
2169
2170> **说明:**
2171>
2172> 仅用于SOFT_KEYBOARD类型,状态为FLG_FIXED或FLG_FLOATING的面板。输入法通过adjustPanelRect等接口对面板大小进行调节时,系统会根据一定规则校验计算出最终的数值(例如超出屏幕等场景),输入法应用可通过该回调获取的真实面板大小,完成最终的面板布局刷新。
2173>
2174>-  从API version 12-14开始支持,此接口回调函数中仅包含[window.Size](../apis-arkui/js-apis-window.md#size7)类型的必选参数。
2175>-  从API version 15起,调用[adjustPanelRect](#adjustpanelrect15)接口后,此接口回调函数增加[KeyboardArea](#keyboardarea15)类型的可选参数。
2176
2177**系统能力:** SystemCapability.MiscServices.InputMethodFramework
2178
2179**参数:**
2180
2181| 参数名   | 类型                                        | 必填 | 说明                                                     |
2182| -------- | ------------------------------------------- | ---- | -------------------------------------------------------- |
2183| type     | string                                      | 是   | 监听当前面板的大小是否产生变化,固定取值为'sizeChange'。 |
2184| callback | [SizeChangeCallback](#sizechangecallback15) | 否   | 回调函数。返回当前软键盘面板的大小,包含宽度和高度值。   |
2185
2186**示例:**
2187
2188```ts
2189import { window } from '@kit.ArkUI';
2190try {
2191  panel.off('sizeChange', (windowSize: window.Size) => {
2192    console.info(`panel size changed, width: ${windowSize.width}, height: ${windowSize.height}`);
2193  });
2194} catch(err) {
2195    console.error(`Failed to subscribe sizeChange: ${JSON.stringify(err)}`);
2196}
2197```
2198
2199### changeFlag<sup>10+</sup>
2200
2201changeFlag(flag: PanelFlag): void
2202
2203将输入法应用的面板状态改变为固定态或者悬浮态,仅对[SOFT_KEYBOARD](#paneltype10)生效。
2204
2205**系统能力:** SystemCapability.MiscServices.InputMethodFramework
2206
2207**参数:**
2208
2209| 参数名   | 类型                   | 必填 | 说明     |
2210| -------- | ---------------------- | ---- | -------- |
2211| flag | [PanelFlag](#panelflag10) | 是 | 目标面板状态类型。 |
2212
2213**错误码:**
2214
2215以下错误码的详细介绍请参见[通用错误码说明文档](../errorcode-universal.md)。
2216
2217| 错误码ID | 错误信息                                                |
2218| -------- | ------------------------------------------------------- |
2219| 401      | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.           |
2220
2221**示例:**
2222
2223```ts
2224try {
2225  let panelFlag = inputMethodEngine.PanelFlag.FLG_FIXED;
2226  panel.changeFlag(panelFlag);
2227} catch(err) {
2228    console.error(`Failed to panelFlag: ${JSON.stringify(err)}`);
2229}
2230```
2231
2232### setPrivacyMode<sup>11+</sup>
2233
2234setPrivacyMode(isPrivacyMode: boolean): void
2235
2236将输入法应用的面板设置为隐私模式,隐私模式不可被录屏、截屏。
2237
2238**需要权限:** ohos.permission.PRIVACY_WINDOW
2239
2240**系统能力:** SystemCapability.MiscServices.InputMethodFramework
2241
2242**参数:**
2243
2244| 参数名        | 类型    | 必填 | 说明               |
2245| ------------- | ------- | ---- | ------------------ |
2246| isPrivacyMode | boolean | 是   | 是否设置隐私模式。 |
2247
2248**错误码:**
2249
2250以下错误码的详细介绍请参见[通用错误码说明文档](../errorcode-universal.md)。
2251
2252| 错误码ID | 错误信息                                                |
2253| -------- | ------------------------------------------------------- |
2254| 201      | permissions check fails.  |
2255| 401      | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
2256
2257**示例:**
2258
2259```ts
2260try {
2261    let isPrivacyMode = true;
2262    panel.setPrivacyMode(isPrivacyMode);
2263} catch(err) {
2264    console.error(`Failed to set privacy mode: ${JSON.stringify(err)}`);
2265}
2266```
2267
2268### setImmersiveMode<sup>15+</sup>
2269
2270setImmersiveMode(mode: ImmersiveMode): void
2271
2272设置输入法应用的沉浸模式。只能设置不使用沉浸模式(NONE_IMMERSIVE)、浅色沉浸模式(LIGHT_IMMERSIVE)或深色沉浸模式(DARK_IMMERSIVE)。不能设置为沉浸模式(IMMERSIVE)。
2273
2274**系统能力:** SystemCapability.MiscServices.InputMethodFramework
2275
2276**参数:**
2277
2278| 参数名   | 类型                   | 必填 | 说明     |
2279| -------- | ---------------------- | ---- | -------- |
2280| mode | [ImmersiveMode](#immersivemode15) | 是   | 沉浸模式。 |
2281
2282**错误码:**
2283
2284以下错误码的详细介绍请参见[通用错误码说明文档](../errorcode-universal.md)和[输入法框架错误码](errorcode-inputmethod-framework.md)。
2285
2286| 错误码ID | 错误信息                                                |
2287| -------- | ------------------------------------------------------- |
2288| 401      | parameter error. Possible causes: 1.Incorrect parameter types; 2.Parameter verification failed.           |
2289| 12800002  | input method engine error.                                |
2290| 12800013  | window manager service error.                          |
2291
2292**示例:**
2293
2294```ts
2295try {
2296  panel.setImmersiveMode(inputMethodEngine.ImmersiveMode.LIGHT_IMMERSIVE);
2297} catch (err) {
2298  console.error(`Failed to setImmersiveMode: ${JSON.stringify(err)}`);
2299}
2300```
2301
2302### getImmersiveMode<sup>15+</sup>
2303
2304getImmersiveMode(): ImmersiveMode
2305
2306获取输入法应用沉浸模式。
2307
2308**系统能力:** SystemCapability.MiscServices.InputMethodFramework
2309
2310**返回值:**
2311
2312| 类型                            | 说明       |
2313| ------------------------------- | ---------- |
2314| [ImmersiveMode](#immersivemode15) | 沉浸模式。 |
2315
2316**示例:**
2317
2318```ts
2319try {
2320  let mode = panel.getImmersiveMode();
2321} catch (err) {
2322  console.error(`Failed to getImmersiveMode: ${JSON.stringify(err)}`);
2323}
2324```
2325
2326
2327## KeyboardController
2328
2329下列API均需使用[on('inputStart')](#oninputstart9)获取到KeyboardController实例后,通过实例调用。
2330
2331### hide<sup>9+</sup>
2332
2333hide(callback: AsyncCallback&lt;void&gt;): void
2334
2335隐藏输入法。使用callback异步回调。
2336
2337**系统能力:** SystemCapability.MiscServices.InputMethodFramework
2338
2339**参数:**
2340
2341| 参数名   | 类型                   | 必填 | 说明     |
2342| -------- | ---------------------- | ---- | -------- |
2343| callback | AsyncCallback&lt;void> | 是   | 回调函数。当输入法隐藏成功,err为undefined,否则为错误对象。 |
2344
2345**错误码:**
2346
2347以下错误码的详细介绍请参见[输入法框架错误码](errorcode-inputmethod-framework.md)。
2348
2349| 错误码ID | 错误信息                 |
2350| -------- | -------------------------- |
2351| 12800003 | input method client error. |
2352
2353**示例:**
2354
2355```ts
2356import { BusinessError } from '@kit.BasicServicesKit';
2357
2358keyboardController.hide((err: BusinessError) => {
2359  if (err) {
2360    console.error(`Failed to hide: ${JSON.stringify(err)}`);
2361    return;
2362  }
2363  console.log('Succeeded in hiding keyboard.');
2364});
2365```
2366
2367### hide<sup>9+</sup>
2368
2369hide(): Promise&lt;void&gt;
2370
2371隐藏输入法。使用promise异步回调。
2372
2373**系统能力:** SystemCapability.MiscServices.InputMethodFramework
2374
2375**返回值:**
2376
2377| 类型             | 说明                      |
2378| ---------------- | ------------------------- |
2379| Promise&lt;void> | 无返回结果的Promise对象。 |
2380
2381**错误码:**
2382
2383以下错误码的详细介绍请参见[输入法框架错误码](errorcode-inputmethod-framework.md)。
2384
2385| 错误码ID | 错误信息                 |
2386| -------- | -------------------------- |
2387| 12800003 | input method client error. |
2388
2389**示例:**
2390
2391```ts
2392import { BusinessError } from '@kit.BasicServicesKit';
2393
2394keyboardController.hide().then(() => {
2395  console.log('Succeeded in hiding keyboard.');
2396}).catch((err: BusinessError) => {
2397  console.log(`Failed to hide: ${JSON.stringify(err)}`);
2398});
2399```
2400
2401### hideKeyboard<sup>(deprecated)</sup>
2402
2403hideKeyboard(callback: AsyncCallback&lt;void&gt;): void
2404
2405隐藏输入法。使用callback异步回调。
2406
2407> **说明:**
2408>
2409> 从API version 8开始支持,API version 9开始废弃,建议使用[hide](#hide9)替代。
2410
2411**系统能力:** SystemCapability.MiscServices.InputMethodFramework
2412
2413**参数:**
2414
2415| 参数名   | 类型                   | 必填 | 说明     |
2416| -------- | ---------------------- | ---- | -------- |
2417| callback | AsyncCallback&lt;void> | 是   | 回调函数。当输入法隐藏成功,err为undefined,否则为错误对象。 |
2418
2419**示例:**
2420
2421```ts
2422import { BusinessError } from '@kit.BasicServicesKit';
2423
2424keyboardController.hideKeyboard((err: BusinessError) => {
2425  if (err) {
2426    console.error(`Failed to hideKeyboard: ${JSON.stringify(err)}`);
2427    return;
2428  }
2429  console.log('Succeeded in hiding keyboard.');
2430});
2431```
2432
2433### hideKeyboard<sup>(deprecated)</sup>
2434
2435hideKeyboard(): Promise&lt;void&gt;
2436
2437隐藏输入法。使用promise异步回调。
2438
2439> **说明:**
2440>
2441> 从API version 8开始支持,API version 9开始废弃,建议使用[hide](#hide9-1)替代。
2442
2443**系统能力:** SystemCapability.MiscServices.InputMethodFramework
2444
2445**返回值:**
2446
2447| 类型             | 说明                      |
2448| ---------------- | ------------------------- |
2449| Promise&lt;void> | 无返回结果的Promise对象。 |
2450
2451**示例:**
2452
2453```ts
2454import { BusinessError } from '@kit.BasicServicesKit';
2455
2456keyboardController.hideKeyboard().then(() => {
2457  console.log('Succeeded in hiding keyboard.');
2458}).catch((err: BusinessError) => {
2459  console.log(`Failed to hideKeyboard: ${JSON.stringify(err)}`);
2460});
2461```
2462
2463### exitCurrentInputType<sup>11+</sup>
2464
2465exitCurrentInputType(callback: AsyncCallback&lt;void&gt;): void
2466
2467退出当前输入类型,仅支持系统配置的默认输入法应用调用。使用callback异步回调。
2468
2469**系统能力:** SystemCapability.MiscServices.InputMethodFramework
2470
2471**参数:**
2472
2473| 参数名   | 类型                   | 必填 | 说明                                                         |
2474| -------- | ---------------------- | ---- | ------------------------------------------------------------ |
2475| callback | AsyncCallback&lt;void> | 是   | 回调函数。当退出当前输入类型成功,err为undefined,否则为错误对象。 |
2476
2477**错误码:**
2478
2479以下错误码的详细介绍请参见[输入法框架错误码](errorcode-inputmethod-framework.md)。
2480
2481| 错误码ID | 错误信息                                       |
2482| -------- | ---------------------------------------------- |
2483| 12800008 | input method manager service error.            |
2484| 12800010 | not the preconfigured default input method. |
2485
2486**示例:**
2487
2488```ts
2489import { BusinessError } from '@kit.BasicServicesKit';
2490
2491keyboardController.exitCurrentInputType((err: BusinessError) => {
2492  if (err) {
2493    console.error(`Failed to exitCurrentInputType: ${JSON.stringify(err)}`);
2494    return;
2495  }
2496  console.log('Succeeded in exiting current input type.');
2497});
2498```
2499
2500### exitCurrentInputType<sup>11+</sup>
2501
2502exitCurrentInputType(): Promise&lt;void&gt;
2503
2504退出当前输入类型,仅支持系统配置的默认输入法应用调用。使用promise异步回调。
2505
2506**系统能力:** SystemCapability.MiscServices.InputMethodFramework
2507
2508**返回值:**
2509
2510| 类型             | 说明                      |
2511| ---------------- | ------------------------- |
2512| Promise&lt;void> | 无返回结果的Promise对象。 |
2513
2514**错误码:**
2515
2516以下错误码的详细介绍请参见[输入法框架错误码](errorcode-inputmethod-framework.md)。
2517
2518| 错误码ID | 错误信息                                       |
2519| -------- | ---------------------------------------------- |
2520| 12800008 | input method manager service error.            |
2521| 12800010 | not the preconfigured default input method. |
2522
2523**示例:**
2524
2525```ts
2526import { BusinessError } from '@kit.BasicServicesKit';
2527
2528keyboardController.exitCurrentInputType().then(() => {
2529  console.log('Succeeded in exiting current input type.');
2530}).catch((err: BusinessError) => {
2531  console.log(`Failed to exit current input type: ${JSON.stringify(err)}`);
2532});
2533```
2534
2535## SecurityMode<sup>11+</sup>
2536
2537输入法的安全模式,如BASIC或FULL。
2538
2539**系统能力**: SystemCapability.MiscServices.InputMethodFramework
2540
2541| 名称  | 值   | 说明                                         |
2542| ----- | ---- | -------------------------------------------- |
2543| BASIC | 0    | 基础访问模式,基础打字模式,会限制网络访问。 |
2544| FULL  | 1    | 完全访问模式,不做限制,可以访问网络。       |
2545
2546## ExtendAction<sup>10+</sup>
2547
2548编辑框中文本的扩展编辑操作类型,如剪切、复制等。
2549
2550**系统能力**: SystemCapability.MiscServices.InputMethodFramework
2551
2552| 名称 | 值 |说明 |
2553| -------- | -------- |-------- |
2554| SELECT_ALL  | 0 |全选。 |
2555| CUT  | 3 |剪切。 |
2556| COPY  | 4 |复制。 |
2557| PASTE  | 5 |粘贴。 |
2558
2559## Direction<sup>10+</sup>
2560
2561光标的移动方向。
2562
2563**系统能力**: SystemCapability.MiscServices.InputMethodFramework
2564
2565| 名称 | 值 |说明 |
2566| -------- | -------- |-------- |
2567| CURSOR_UP  | 1 |向上。 |
2568| CURSOR_DOWN  | 2 |向下。 |
2569| CURSOR_LEFT  | 3 |向左。 |
2570| CURSOR_RIGHT  | 4 |向右。 |
2571
2572## Range<sup>10+</sup>
2573
2574选中的文本范围。
2575
2576**系统能力:** SystemCapability.MiscServices.InputMethodFramework
2577
2578| 名称 | 类型 | 只读 | 可选 | 说明 |
2579| -------- | -------- | -------- | -------- | -------- |
2580| start  | number | 否 | 否 | 选中文本的首字符在编辑框的索引值。|
2581| end  | number | 否 | 否 | 选中文本的末字符在编辑框的索引值。|
2582
2583## Movement<sup>10+</sup>
2584
2585选中文本时,光标移动的方向
2586
2587**系统能力:** SystemCapability.MiscServices.InputMethodFramework
2588
2589| 名称 | 类型 | 只读 | 可选 | 说明 |
2590| -------- | -------- | -------- | -------- | -------- |
2591| direction  | [Direction](#direction10) | 否 | 否 | 选中文本时,光标的移动方向。|
2592
2593## MessageHandler<sup>15+</sup>
2594
2595自定义通信对象。
2596
2597> **说明**
2598>
2599> 开发者可通过注册此对象来接收已绑定当前输入法应用的编辑框应用所发送的自定义通信数据,接收到自定义通信数据时会触发此对象中[onMessage](#onmessage15)回调函数。
2600>
2601> 此对象全局唯一,多次注册仅保留最后一次注册的对象及有效性,并触发上一个已注册对象的[onTerminated](#onmessage15)回调函数。
2602>
2603> 若取消注册全局已注册的对象时,会触发被取消对象中[onTerminated](#onterminated15)回调函数。
2604
2605### onMessage<sup>15+</sup>
2606
2607onMessage(msgId: string, msgParam?: ArrayBuffer): void
2608
2609接收已绑定当前输入法应用的编辑框应用发送的自定义数据回调函数。
2610
2611> **说明**
2612>
2613> 当已注册的MeesageHandler接收到来自已绑定当前输入法应用的编辑框应用所发送的自定义通信数据时,会触发该回调函数。
2614>
2615> msgId为必选参数,msgParam为可选参数。存在收到仅有msgId自定义数据的可能,需与数据发送方确认自定义数据。
2616
2617**系统能力:** SystemCapability.MiscServices.InputMethodFramework
2618
2619**参数:**
2620
2621| 参数名   | 类型        | 必填 | 说明                             |
2622| -------- | ----------- | ---- | -------------------------------- |
2623| msgId    | string      | 是   | 接收到的自定义通信数据的标识符。 |
2624| msgParam | ArrayBuffer | 否   | 接收到的自定义通信数据的消息体。 |
2625
2626**示例:**
2627
2628```ts
2629import { BusinessError } from '@kit.BasicServicesKit';
2630
2631try {
2632  inputMethodEngine.getInputMethodAbility()
2633    .on('inputStart', (kbController: inputMethodEngine.KeyboardController, client: inputMethodEngine.InputClient) => {
2634      let keyboardController = kbController;
2635      let inputClient = client;
2636      try {
2637        let messageHandler: inputMethodEngine.MessageHandler = {
2638          onTerminated(): void {
2639            console.log('OnTerminated.');
2640          },
2641          onMessage(msgId: string, msgParam?:ArrayBuffer): void {
2642            console.log('recv message.');
2643          }
2644        }
2645        inputClient.recvMessage(messageHandler);
2646      } catch(err) {
2647        console.error(`Failed to recvMessage: ${JSON.stringify(err)}`);
2648      }
2649  });
2650} catch(err) {
2651    console.error(`Failed to InputMethodAbility: ${JSON.stringify(err)}`);
2652}
2653```
2654
2655### onTerminated<sup>15+</sup>
2656
2657onTerminated(): void
2658
2659监听对象终止回调函数。
2660
2661> **说明**
2662>
2663> 当应用注册新的MessageHandler对象时,会触发上一个已注册MessageHandler对象的OnTerminated回调函数。
2664>
2665> 当应用取消注册时,会触发当前已注册MessageHandler对象的OnTerminated回调函数。
2666
2667**系统能力:** SystemCapability.MiscServices.InputMethodFramework
2668
2669**示例:**
2670
2671```ts
2672import { BusinessError } from '@kit.BasicServicesKit';
2673
2674try {
2675  inputMethodEngine.getInputMethodAbility()
2676    .on('inputStart', (kbController: inputMethodEngine.KeyboardController, client: inputMethodEngine.InputClient) => {
2677      let keyboardController = kbController;
2678      let inputClient = client;
2679      try {
2680        let messageHandler: inputMethodEngine.MessageHandler = {
2681          onTerminated(): void {
2682            console.log('OnTerminated.');
2683          },
2684          onMessage(msgId: string, msgParam?:ArrayBuffer): void {
2685            console.log('recv message.');
2686          }
2687        }
2688        inputClient.recvMessage(messageHandler);
2689      } catch(err) {
2690        console.error(`Failed to recvMessage: ${JSON.stringify(err)}`);
2691      }
2692  });
2693} catch(err) {
2694    console.error(`Failed to InputMethodAbility: ${JSON.stringify(err)}`);
2695}
2696```
2697
2698## InputClient<sup>9+</sup>
2699
2700下列API均需使用[on('inputStart')](#oninputstart9)获取到InputClient实例后,通过实例调用。
2701
2702### sendKeyFunction<sup>9+</sup>
2703
2704sendKeyFunction(action:number, callback: AsyncCallback&lt;boolean&gt;): void
2705
2706发送功能键。使用callback异步回调。
2707
2708**系统能力:** SystemCapability.MiscServices.InputMethodFramework
2709
2710  **参数:**
2711
2712| 参数名 | 类型 | 必填 | 说明 |
2713| -------- | -------- | -------- | -------- |
2714| action | number | 是 | 功能键键值。<br/>- 当值为0时,表示无效按键。<br/>- 当值为1时,表示确认键(即回车键)。 |
2715| callback | AsyncCallback&lt;boolean&gt; | 是 | 回调函数。当功能键发送成功,err为undefined,data为true;否则为错误对象。 |
2716
2717**错误码:**
2718
2719以下错误码的详细介绍请参见[输入法框架错误码](errorcode-inputmethod-framework.md),[通用错误码说明文档](../errorcode-universal.md)。
2720
2721| 错误码ID | 错误信息                 |
2722| -------- | -------------------------- |
2723| 401      | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
2724| 12800003 | input method client error. |
2725
2726 **示例:**
2727
2728```ts
2729import { BusinessError } from '@kit.BasicServicesKit';
2730
2731let action = 1;
2732try {
2733  inputClient.sendKeyFunction(action, (err: BusinessError, result: boolean) => {
2734    if (err) {
2735      console.error(`Failed to sendKeyFunction: ${JSON.stringify(err)}`);
2736      return;
2737    }
2738    if (result) {
2739      console.log('Succeeded in sending key function.');
2740    } else {
2741      console.error('Failed to sendKeyFunction.');
2742    }
2743  });
2744} catch (err) {
2745  console.error(`Failed to sendKeyFunction: ${JSON.stringify(err)}`);
2746}
2747```
2748
2749### sendKeyFunction<sup>9+</sup>
2750
2751sendKeyFunction(action: number): Promise&lt;boolean&gt;
2752
2753发送功能键。使用promise异步回调。
2754
2755**系统能力:** SystemCapability.MiscServices.InputMethodFramework
2756
2757**参数:**
2758
2759| 参数名 | 类型 | 必填 | 说明 |
2760| -------- | -------- | -------- | -------- |
2761| action | number | 是 | 功能键键值。<br/>当值为0时,表示无效按键;<br/>当值为1时,表示确认键(即回车键)。 |
2762
2763**返回值:**
2764
2765| 类型                            | 说明                                                         |
2766| ------------------------------- | ------------------------------------------------------------ |
2767| Promise&lt;boolean&gt; |  Promise对象。返回true表示功能键发送成功;返回false表示功能键发送失败。|
2768
2769**错误码:**
2770
2771以下错误码的详细介绍请参见[输入法框架错误码](errorcode-inputmethod-framework.md),[通用错误码说明文档](../errorcode-universal.md)。
2772
2773| 错误码ID | 错误信息                 |
2774| -------- | -------------------------- |
2775| 401      | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
2776| 12800003 | input method client error. |
2777
2778**示例:**
2779
2780```ts
2781import { BusinessError } from '@kit.BasicServicesKit';
2782
2783let action = 1;
2784try {
2785  inputClient.sendKeyFunction(action).then((result: boolean) => {
2786    if (result) {
2787      console.log('Succeeded in sending key function.');
2788    } else {
2789      console.error('Failed to sendKeyFunction.');
2790    }
2791  }).catch((err: BusinessError) => {
2792    console.error(`Failed to sendKeyFunction: ${JSON.stringify(err)}`);
2793  });
2794} catch (err) {
2795  console.error(`Failed to sendKeyFunction: ${JSON.stringify(err)}`);
2796}
2797```
2798
2799### getForward<sup>9+</sup>
2800
2801getForward(length:number, callback: AsyncCallback&lt;string&gt;): void
2802
2803获取光标前固定长度的文本。使用callback异步回调。
2804
2805**系统能力:** SystemCapability.MiscServices.InputMethodFramework
2806
2807**参数:**
2808
2809| 参数名 | 类型 | 必填 | 说明 |
2810| -------- | -------- | -------- | -------- |
2811| length | number | 是 | 文本长度。不能小于0。 |
2812| callback | AsyncCallback&lt;string&gt; | 是 | 回调函数。当光标前固定长度的文本获取成功,err为undefined,data为获取到的文本;否则为错误对象。 |
2813
2814**错误码:**
2815
2816以下错误码的详细介绍请参见[输入法框架错误码](errorcode-inputmethod-framework.md),[通用错误码说明文档](../errorcode-universal.md)。
2817
2818| 错误码ID | 错误信息                     |
2819| -------- | ------------------------------ |
2820| 401      | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
2821| 12800003 | input method client error.     |
2822| 12800006 | Input method controller error. |
2823
2824**示例:**
2825
2826```ts
2827import { BusinessError } from '@kit.BasicServicesKit';
2828
2829let length = 1;
2830try {
2831  inputClient.getForward(length, (err: BusinessError, text: string) => {
2832    if (err) {
2833      console.error(`Failed to getForward: ${JSON.stringify(err)}`);
2834      return;
2835    }
2836    console.log('Succeeded in getting forward, text: ' + text);
2837  });
2838} catch (err) {
2839  console.error(`Failed to getForward: ${JSON.stringify(err)}`);
2840}
2841```
2842
2843### getForward<sup>9+</sup>
2844
2845getForward(length:number): Promise&lt;string&gt;
2846
2847获取光标前固定长度的文本。使用promise异步回调。
2848
2849**系统能力:** SystemCapability.MiscServices.InputMethodFramework
2850
2851**参数:**
2852
2853| 参数名 | 类型 | 必填 | 说明 |
2854| -------- | -------- | -------- | -------- |
2855| length | number | 是 | 文本长度。不能小于0 |
2856
2857**返回值:**
2858
2859| 类型                            | 说明                                                         |
2860| ------------------------------- | ------------------------------------------------------------ |
2861| Promise&lt;string&gt;           |  Promise对象,返回光标前固定长度的文本。                     |
2862
2863**错误码:**
2864
2865以下错误码的详细介绍请参见[输入法框架错误码](errorcode-inputmethod-framework.md),[通用错误码说明文档](../errorcode-universal.md)。
2866
2867| 错误码ID | 错误信息                     |
2868| -------- | ------------------------------ |
2869| 401      | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
2870| 12800003 | input method client error.     |
2871| 12800006 | Input method controller error. |
2872
2873**示例:**
2874
2875```ts
2876import { BusinessError } from '@kit.BasicServicesKit';
2877
2878let length = 1;
2879try {
2880  inputClient.getForward(length).then((text: string) => {
2881    console.log('Succeeded in getting forward, text: ' + text);
2882  }).catch((err: BusinessError) => {
2883    console.error(`Failed to getForward: ${JSON.stringify(err)}`);
2884  });
2885} catch (err) {
2886  console.error(`Failed to getForward: ${JSON.stringify(err)}`);
2887}
2888```
2889
2890### getForwardSync<sup>10+</sup>
2891
2892getForwardSync(length:number): string
2893
2894获取光标前固定长度的文本。
2895
2896**系统能力:** SystemCapability.MiscServices.InputMethodFramework
2897
2898**参数:**
2899
2900| 参数名 | 类型   | 必填 | 说明       |
2901| ------ | ------ | ---- | ---------- |
2902| length | number | 是   | 文本长度。不能小于0。 |
2903
2904**返回值:**
2905
2906| 类型   | 说明                       |
2907| ------ | -------------------------- |
2908| string | 返回光标前固定长度的文本。 |
2909
2910**错误码:**
2911
2912以下错误码的详细介绍请参见[输入法框架错误码](errorcode-inputmethod-framework.md),[通用错误码说明文档](../errorcode-universal.md)。
2913
2914| 错误码ID | 错误信息                       |
2915| -------- | ------------------------------ |
2916| 401      | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.           |
2917| 12800003 | input method client error.     |
2918| 12800006 | input method controller error. |
2919
2920**示例:**
2921
2922```ts
2923let length = 1;
2924try {
2925  let text: string = inputClient.getForwardSync(length);
2926  console.log(`Succeeded in getting forward, text: ${text}`);
2927} catch (err) {
2928  console.error(`Failed to getForwardSync: ${JSON.stringify(err)}`);
2929}
2930```
2931
2932### getBackward<sup>9+</sup>
2933
2934getBackward(length:number, callback: AsyncCallback&lt;string&gt;): void
2935
2936获取光标后固定长度的文本。使用callback异步回调。
2937
2938**系统能力:** SystemCapability.MiscServices.InputMethodFramework
2939
2940**参数:**
2941
2942| 参数名 | 类型 | 必填 | 说明 |
2943| -------- | -------- | -------- | -------- |
2944| length | number | 是 | 文本长度。不能小于0。 |
2945| callback | AsyncCallback&lt;string&gt; | 是 | 回调函数。当光标后固定长度的文本获取成功,err为undefined,data为获取到的文本;否则为错误对象。|
2946
2947**错误码:**
2948
2949以下错误码的详细介绍请参见[输入法框架错误码](errorcode-inputmethod-framework.md),[通用错误码说明文档](../errorcode-universal.md)。
2950
2951| 错误码ID | 错误信息                     |
2952| -------- | ------------------------------ |
2953| 401      | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
2954| 12800003 | input method client error.     |
2955| 12800006 | Input method controller error. |
2956
2957**示例:**
2958
2959```ts
2960import { BusinessError } from '@kit.BasicServicesKit';
2961
2962let length = 1;
2963try {
2964  inputClient.getBackward(length, (err: BusinessError, text: string) => {
2965    if (err) {
2966      console.error(`Failed to getBackward: ${JSON.stringify(err)}`);
2967      return;
2968    }
2969    console.log('Succeeded in getting backward, text: ' + text);
2970  });
2971} catch (err) {
2972  console.error(`Failed to getBackward: ${JSON.stringify(err)}`);
2973}
2974```
2975
2976### getBackward<sup>9+</sup>
2977
2978getBackward(length:number): Promise&lt;string&gt;
2979
2980获取光标后固定长度的文本。使用promise异步回调。
2981
2982**系统能力:** SystemCapability.MiscServices.InputMethodFramework
2983
2984**参数:**
2985
2986| 参数名 | 类型 | 必填 | 说明 |
2987| -------- | -------- | -------- | -------- |
2988| length | number | 是 | 文本长度。不能小于0。 |
2989
2990**返回值:**
2991
2992| 类型                            | 说明                                                         |
2993| ------------------------------- | ------------------------------------------------------------ |
2994| Promise&lt;string&gt;           |  Promise对象,返回光标后固定长度的文本。                     |
2995
2996**错误码:**
2997
2998以下错误码的详细介绍请参见[输入法框架错误码](errorcode-inputmethod-framework.md),[通用错误码说明文档](../errorcode-universal.md)。
2999
3000| 错误码ID | 错误信息                     |
3001| -------- | ------------------------------ |
3002| 401      | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
3003| 12800003 | input method client error.     |
3004| 12800006 | Input method controller error. |
3005
3006**示例:**
3007
3008```ts
3009import { BusinessError } from '@kit.BasicServicesKit';
3010
3011let length = 1;
3012try {
3013  inputClient.getBackward(length).then((text: string) => {
3014    console.log('Succeeded in getting backward, text: ' + text);
3015  }).catch((err: BusinessError) => {
3016    console.error(`Failed to getBackward: ${JSON.stringify(err)}`);
3017  });
3018} catch (err) {
3019  console.error(`Failed to getBackward: ${JSON.stringify(err)}`);
3020}
3021```
3022
3023### getBackwardSync<sup>10+</sup>
3024
3025getBackwardSync(length:number): string
3026
3027获取光标后固定长度的文本。
3028
3029**系统能力:** SystemCapability.MiscServices.InputMethodFramework
3030
3031**参数:**
3032
3033| 参数名 | 类型   | 必填 | 说明       |
3034| ------ | ------ | ---- | ---------- |
3035| length | number | 是   | 文本长度。不能小于0。 |
3036
3037**返回值:**
3038
3039| 类型   | 说明                       |
3040| ------ | -------------------------- |
3041| string | 返回光标后固定长度的文本。 |
3042
3043**错误码:**
3044
3045以下错误码的详细介绍请参见[输入法框架错误码](errorcode-inputmethod-framework.md),[通用错误码说明文档](../errorcode-universal.md)。
3046
3047| 错误码ID | 错误信息                       |
3048| -------- | ------------------------------ |
3049| 401      | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.           |
3050| 12800003 | input method client error.     |
3051| 12800006 | input method controller error. |
3052
3053**示例:**
3054
3055```ts
3056let length = 1;
3057try {
3058  let text: string = inputClient.getBackwardSync(length);
3059  console.log(`Succeeded in getting backward, text: ${text}`);
3060} catch (err) {
3061  console.error(`Failed to getBackwardSync: ${JSON.stringify(err)}`);
3062}
3063```
3064
3065### deleteForward<sup>9+</sup>
3066
3067deleteForward(length:number, callback: AsyncCallback&lt;boolean&gt;): void
3068
3069删除光标前固定长度的文本。使用callback异步回调。
3070
3071**系统能力:** SystemCapability.MiscServices.InputMethodFramework
3072
3073**参数:**
3074
3075| 参数名 | 类型 | 必填 | 说明 |
3076| -------- | -------- | -------- | -------- |
3077| length | number | 是 | 文本长度。不能小于0。 |
3078| callback | AsyncCallback&lt;boolean&gt; | 是 | 回调函数。当光标前固定长度的文本删除成功,err为undefined,data为true;否则为错误对象。 |
3079
3080**错误码:**
3081
3082以下错误码的详细介绍请参见[输入法框架错误码](errorcode-inputmethod-framework.md),[通用错误码说明文档](../errorcode-universal.md)。
3083
3084| 错误码ID | 错误信息                 |
3085| -------- | -------------------------- |
3086| 401      | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
3087| 12800002 | Input method engine error. |
3088| 12800003 | input method client error. |
3089
3090**示例:**
3091
3092```ts
3093import { BusinessError } from '@kit.BasicServicesKit';
3094
3095let length = 1;
3096try {
3097  inputClient.deleteForward(length, (err: BusinessError, result: boolean) => {
3098    if (err) {
3099      console.error(`Failed to deleteForward: ${JSON.stringify(err)}`);
3100      return;
3101    }
3102    if (result) {
3103      console.log('Succeeded in deleting forward.');
3104    } else {
3105      console.error(`Failed to deleteForward.`);
3106    }
3107  });
3108} catch (err) {
3109  console.error(`Failed to deleteForward: ${JSON.stringify(err)}`);
3110}
3111```
3112
3113### deleteForward<sup>9+</sup>
3114
3115deleteForward(length:number): Promise&lt;boolean&gt;
3116
3117删除光标前固定长度的文本。使用promise异步回调。
3118
3119**系统能力:** SystemCapability.MiscServices.InputMethodFramework
3120
3121**参数:**
3122
3123| 参数名 | 类型   | 必填 | 说明       |
3124| ------ | ------ | ---- | ---------- |
3125| length | number | 是   | 文本长度。不能小于0。 |
3126
3127**返回值:**
3128
3129| 类型                   | 说明           |
3130| ---------------------- | -------------- |
3131| Promise&lt;boolean&gt; | Promise对象。返回true表示删除光标前固定长度的文本成功;返回false表示删除光标前固定长度的文本失败。|
3132
3133**错误码:**
3134
3135以下错误码的详细介绍请参见[输入法框架错误码](errorcode-inputmethod-framework.md),[通用错误码说明文档](../errorcode-universal.md)。
3136
3137| 错误码ID | 错误信息                 |
3138| -------- | -------------------------- |
3139| 401      | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
3140| 12800002 | Input method engine error. |
3141| 12800003 | input method client error. |
3142
3143**示例:**
3144
3145```ts
3146import { BusinessError } from '@kit.BasicServicesKit';
3147
3148let length = 1;
3149try {
3150  inputClient.deleteForward(length).then((result: boolean) => {
3151    if (result) {
3152      console.log('Succeeded in deleting forward.');
3153    } else {
3154      console.error('Failed to delete Forward.');
3155    }
3156  }).catch((err: BusinessError) => {
3157    console.error(`Failed to deleteForward: ${JSON.stringify(err)}`);
3158  });
3159} catch (err) {
3160  console.error(`Failed to deleteForward: ${JSON.stringify(err)}`);
3161}
3162```
3163
3164### deleteForwardSync<sup>10+</sup>
3165
3166deleteForwardSync(length:number): void
3167
3168删除光标前固定长度的文本。
3169
3170**系统能力:** SystemCapability.MiscServices.InputMethodFramework
3171
3172**参数:**
3173
3174| 参数名 | 类型   | 必填 | 说明       |
3175| ------ | ------ | ---- | ---------- |
3176| length | number | 是   | 文本长度。不能小于0。 |
3177
3178**错误码:**
3179
3180以下错误码的详细介绍请参见[输入法框架错误码](errorcode-inputmethod-framework.md),[通用错误码说明文档](../errorcode-universal.md)。
3181
3182| 错误码ID | 错误信息                   |
3183| -------- | -------------------------- |
3184| 401      | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.           |
3185| 12800002 | input method engine error. |
3186| 12800003 | input method client error. |
3187
3188**示例:**
3189
3190```ts
3191let length = 1;
3192try {
3193  inputClient.deleteForwardSync(length);
3194  console.log('Succeeded in deleting forward.');
3195} catch (err) {
3196  console.error('deleteForwardSync err: ' + JSON.stringify(err));
3197}
3198```
3199
3200### deleteBackward<sup>9+</sup>
3201
3202deleteBackward(length:number, callback: AsyncCallback&lt;boolean&gt;): void
3203
3204删除光标后固定长度的文本。使用callback异步回调。
3205
3206**系统能力:** SystemCapability.MiscServices.InputMethodFramework
3207
3208**参数:**
3209
3210| 参数名   | 类型                         | 必填 | 说明           |
3211| -------- | ---------------------------- | ---- | -------------- |
3212| length   | number                       | 是   | 文本长度。不能小于0。     |
3213| callback | AsyncCallback&lt;boolean&gt; | 是   | 回调函数。当光标后固定长度的文本删除成功,err为undefined,data为true;否则为错误对象。 |
3214
3215**错误码:**
3216
3217以下错误码的详细介绍请参见[输入法框架错误码](errorcode-inputmethod-framework.md),[通用错误码说明文档](../errorcode-universal.md)。
3218
3219| 错误码ID | 错误信息                 |
3220| -------- | -------------------------- |
3221| 401      | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
3222| 12800002 | Input method engine error. |
3223| 12800003 | input method client error. |
3224
3225**示例:**
3226
3227```ts
3228import { BusinessError } from '@kit.BasicServicesKit';
3229
3230let length = 1;
3231try {
3232  inputClient.deleteBackward(length, (err: BusinessError, result: boolean) => {
3233    if (err) {
3234      console.error(`Failed to deleteBackward: ${JSON.stringify(err)}`);
3235      return;
3236    }
3237    if (result) {
3238      console.log('Succeeded in deleting backward.');
3239    } else {
3240      console.error(`Failed to deleteBackward.`);
3241    }
3242  });
3243} catch (err) {
3244  console.error('deleteBackward err: ' + JSON.stringify(err));
3245}
3246```
3247
3248### deleteBackward<sup>9+</sup>
3249
3250deleteBackward(length:number): Promise&lt;boolean&gt;
3251
3252删除光标后固定长度的文本。使用promise异步回调。
3253
3254**系统能力:** SystemCapability.MiscServices.InputMethodFramework
3255
3256**参数:**
3257
3258| 参数名 | 类型 | 必填 | 说明 |
3259| -------- | -------- | -------- | -------- |
3260| length | number | 是 | 文本长度。不能小于0。    |
3261
3262**返回值:**
3263
3264| 类型                            | 说明                                                         |
3265| ------------------------------- | ------------------------------------------------------------ |
3266| Promise&lt;boolean&gt; |  Promise对象。返回true表示删除光标后固定长度的文本成功;返回false表示删除光标后固定长度的文本失败。 |
3267
3268**错误码:**
3269
3270以下错误码的详细介绍请参见[输入法框架错误码](errorcode-inputmethod-framework.md),[通用错误码说明文档](../errorcode-universal.md)。
3271
3272| 错误码ID | 错误信息                 |
3273| -------- | -------------------------- |
3274| 401      | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
3275| 12800002 | Input method engine error. |
3276| 12800003 | input method client error. |
3277
3278**示例:**
3279
3280```ts
3281import { BusinessError } from '@kit.BasicServicesKit';
3282
3283let length = 1;
3284inputClient.deleteBackward(length).then((result: boolean) => {
3285  if (result) {
3286    console.log('Succeeded in deleting backward.');
3287  } else {
3288    console.error('Failed to deleteBackward.');
3289  }
3290}).catch((err: BusinessError) => {
3291  console.error(`Failed to deleteBackward: ${JSON.stringify(err)}`);
3292});
3293```
3294
3295### deleteBackwardSync<sup>10+</sup>
3296
3297deleteBackwardSync(length:number): void
3298
3299删除光标后固定长度的文本。
3300
3301**系统能力:** SystemCapability.MiscServices.InputMethodFramework
3302
3303**参数:**
3304
3305| 参数名 | 类型   | 必填 | 说明       |
3306| ------ | ------ | ---- | ---------- |
3307| length | number | 是   | 文本长度。不能小于0。  |
3308
3309**错误码:**
3310
3311以下错误码的详细介绍请参见[输入法框架错误码](errorcode-inputmethod-framework.md),[通用错误码说明文档](../errorcode-universal.md)。
3312
3313| 错误码ID | 错误信息                   |
3314| -------- | -------------------------- |
3315| 401      | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.           |
3316| 12800002 | input method engine error. |
3317| 12800003 | input method client error. |
3318
3319**示例:**
3320
3321```ts
3322let length = 1;
3323try {
3324  inputClient.deleteBackwardSync(length);
3325  console.log('Succeeded in deleting backward.');
3326} catch (err) {
3327  console.error('deleteBackwardSync err: ' + JSON.stringify(err));
3328}
3329```
3330
3331### insertText<sup>9+</sup>
3332
3333insertText(text:string, callback: AsyncCallback&lt;boolean&gt;): void
3334
3335插入文本。使用callback异步回调。
3336
3337**系统能力:** SystemCapability.MiscServices.InputMethodFramework
3338
3339**参数:**
3340
3341| 参数名 | 类型 | 必填 | 说明 |
3342| -------- | -------- | -------- | -------- |
3343| text | string | 是 | 文本内容。 |
3344| callback | AsyncCallback&lt;boolean&gt; | 是 | 回调函数。当文本插入成功,err为undefined,data为true;否则为错误对象。 |
3345
3346**错误码:**
3347
3348以下错误码的详细介绍请参见[输入法框架错误码](errorcode-inputmethod-framework.md),[通用错误码说明文档](../errorcode-universal.md)。
3349
3350| 错误码ID | 错误信息                 |
3351| -------- | -------------------------- |
3352| 401      | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
3353| 12800002 | Input method engine error. |
3354| 12800003 | input method client error. |
3355
3356**示例:**
3357
3358```ts
3359import { BusinessError } from '@kit.BasicServicesKit';
3360
3361inputClient.insertText('test', (err: BusinessError, result: boolean) => {
3362  if (err) {
3363    console.error(`Failed to insertText: ${JSON.stringify(err)}`);
3364    return;
3365  }
3366  if (result) {
3367    console.log('Succeeded in inserting text.');
3368  } else {
3369    console.error('Failed to insertText.');
3370  }
3371});
3372```
3373
3374### insertText<sup>9+</sup>
3375
3376insertText(text:string): Promise&lt;boolean&gt;
3377
3378插入文本。使用promise异步回调。
3379
3380**系统能力:** SystemCapability.MiscServices.InputMethodFramework
3381
3382**参数:**
3383
3384| 参数名 | 类型 | 必填 | 说明 |
3385| -------- | -------- | -------- | -------- |
3386| text | string | 是 | 文本。 |
3387
3388**返回值:**
3389
3390| 类型                            | 说明                                                         |
3391| ------------------------------- | ------------------------------------------------------------ |
3392| Promise&lt;boolean&gt;  |  Promise对象。返回true表示插入文本成功;返回false表示插入文本失败。  |
3393
3394**错误码:**
3395
3396以下错误码的详细介绍请参见[输入法框架错误码](errorcode-inputmethod-framework.md),[通用错误码说明文档](../errorcode-universal.md)。
3397
3398| 错误码ID | 错误信息                 |
3399| -------- | -------------------------- |
3400| 401      | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
3401| 12800002 | Input method engine error. |
3402| 12800003 | input method client error. |
3403
3404**示例:**
3405
3406```ts
3407import { BusinessError } from '@kit.BasicServicesKit';
3408
3409try {
3410  inputClient.insertText('test').then((result: boolean) => {
3411    if (result) {
3412      console.log('Succeeded in inserting text.');
3413    } else {
3414      console.error('Failed to insertText.');
3415    }
3416  }).catch((err: BusinessError) => {
3417    console.error(`Failed to insertText: ${JSON.stringify(err)}`);
3418  });
3419} catch (err) {
3420  console.error(`Failed to insertText: ${JSON.stringify(err)}`);
3421}
3422```
3423
3424### insertTextSync<sup>10+</sup>
3425
3426insertTextSync(text: string): void
3427
3428插入文本。
3429
3430**系统能力:** SystemCapability.MiscServices.InputMethodFramework
3431
3432**参数:**
3433
3434| 参数名 | 类型   | 必填 | 说明       |
3435| ------ | ------ | ---- | ---------- |
3436| text   | string | 是   | 文本内容。 |
3437
3438**错误码:**
3439
3440以下错误码的详细介绍请参见[输入法框架错误码](errorcode-inputmethod-framework.md),[通用错误码说明文档](../errorcode-universal.md)。
3441
3442| 错误码ID | 错误信息                   |
3443| -------- | -------------------------- |
3444| 401      | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
3445| 12800002 | input method engine error. |
3446| 12800003 | input method client error. |
3447
3448**示例:**
3449
3450```ts
3451try {
3452  inputClient.insertTextSync('test');
3453  console.log('Succeeded in inserting text.');
3454} catch (err) {
3455  console.error(`Failed to insertTextSync: ${JSON.stringify(err)}`);
3456}
3457```
3458
3459### getEditorAttribute<sup>9+</sup>
3460
3461getEditorAttribute(callback: AsyncCallback&lt;EditorAttribute&gt;): void
3462
3463获取编辑框属性值。使用callback异步回调。
3464
3465**系统能力:** SystemCapability.MiscServices.InputMethodFramework
3466
3467**参数:**
3468
3469| 参数名                         | 类型                          | 必填                            | 说明                                                         |
3470| ------------------------------- | ------------------------------------------------------------ | ------------------------------------------------------------ | ------------------------------------------------------------ |
3471| callback | AsyncCallback&lt;[EditorAttribute](#editorattribute)&gt; | 是 |  回调函数。当编辑框属性值获取成功,err为undefined,data为编辑框属性值;否则为错误对象。|
3472
3473**错误码:**
3474
3475以下错误码的详细介绍请参见[输入法框架错误码](errorcode-inputmethod-framework.md)。
3476
3477| 错误码ID | 错误信息                 |
3478| -------- | -------------------------- |
3479| 12800003 | input method client error. |
3480
3481**示例:**
3482
3483```ts
3484import { BusinessError } from '@kit.BasicServicesKit';
3485
3486inputClient.getEditorAttribute((err: BusinessError, editorAttribute: inputMethodEngine.EditorAttribute) => {
3487  if (err) {
3488    console.error(`Failed to getEditorAttribute: ${JSON.stringify(err)}`);
3489    return;
3490  }
3491  console.log(`editorAttribute.inputPattern:  ${editorAttribute.inputPattern}`);
3492  console.log(`editorAttribute.enterKeyType:  ${editorAttribute.enterKeyType}`);
3493});
3494```
3495
3496### getEditorAttribute<sup>9+</sup>
3497
3498getEditorAttribute(): Promise&lt;EditorAttribute&gt;
3499
3500获取编辑框属性值。使用promise异步回调。
3501
3502**系统能力:** SystemCapability.MiscServices.InputMethodFramework
3503
3504**返回值:**
3505
3506| 类型                            | 说明                                                         |
3507| ------------------------------- | ------------------------------------------------------------ |
3508| Promise&lt;[EditorAttribute](#editorattribute)&gt; |  Promise对象,返回编辑框属性值。           |
3509
3510**错误码:**
3511
3512以下错误码的详细介绍请参见[输入法框架错误码](errorcode-inputmethod-framework.md)。
3513
3514| 错误码ID | 错误信息                 |
3515| -------- | -------------------------- |
3516| 12800003 | input method client error. |
3517
3518**示例:**
3519
3520```ts
3521import { BusinessError } from '@kit.BasicServicesKit';
3522
3523try {
3524  inputClient.getEditorAttribute().then((editorAttribute: inputMethodEngine.EditorAttribute) => {
3525    console.log(`editorAttribute.inputPattern:  ${editorAttribute.inputPattern}`);
3526    console.log(`editorAttribute.enterKeyType:  ${editorAttribute.enterKeyType}`);
3527  }).catch((err: BusinessError) => {
3528    console.error(`Failed to getEditorAttribute: ${JSON.stringify(err)}`);
3529  });
3530} catch(err) {
3531    console.error(`Failed to getEditorAttribute: ${JSON.stringify(err)}`);
3532}
3533```
3534
3535### getEditorAttributeSync<sup>10+</sup>
3536
3537getEditorAttributeSync(): EditorAttribute
3538
3539获取编辑框属性值。
3540
3541**系统能力:** SystemCapability.MiscServices.InputMethodFramework
3542
3543**返回值:**
3544
3545| 类型                                | 说明           |
3546| ----------------------------------- | -------------- |
3547| [EditorAttribute](#editorattribute) | 编辑框属性对象 |
3548
3549**错误码:**
3550
3551以下错误码的详细介绍请参见[输入法框架错误码](errorcode-inputmethod-framework.md)。
3552
3553| 错误码ID | 错误信息                   |
3554| -------- | -------------------------- |
3555| 12800003 | input method client error. |
3556
3557**示例:**
3558
3559```ts
3560try {
3561  let editorAttribute: inputMethodEngine.EditorAttribute = inputClient.getEditorAttributeSync();
3562    console.log(`editorAttribute.inputPattern:  ${editorAttribute.inputPattern}`);
3563    console.log(`editorAttribute.enterKeyType:  ${editorAttribute.enterKeyType}`);
3564} catch (err) {
3565  console.error(`Failed to getEditorAttributeSync: ${JSON.stringify(err)}`);
3566}
3567```
3568
3569### moveCursor<sup>9+</sup>
3570
3571moveCursor(direction: number, callback: AsyncCallback&lt;void&gt;): void
3572
3573移动光标。使用callback异步回调。
3574
3575**系统能力:** SystemCapability.MiscServices.InputMethodFramework
3576
3577**参数:**
3578
3579| 参数名    | 类型                      | 必填 | 说明           |
3580| --------- | ------------------------- | ---- | -------------- |
3581| direction | number                    | 是   | 光标移动方向。<br/>- 当值为1时,表示向上。<br/>- 当值为2时,表示向下。<br/>- 当值为3时,表示向左。<br/>- 当值为4时,表示向右。不能小于0。 |
3582| callback  | AsyncCallback&lt;void&gt; | 是   | 回调函数。当光标移动成功,err为undefined,否则为错误对象。    |
3583
3584**错误码:**
3585
3586以下错误码的详细介绍请参见[输入法框架错误码](errorcode-inputmethod-framework.md),[通用错误码说明文档](../errorcode-universal.md)。
3587
3588| 错误码ID | 错误信息                 |
3589| -------- | -------------------------- |
3590| 401      | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.           |
3591| 12800003 | input method client error. |
3592
3593**示例:**
3594
3595```ts
3596import { BusinessError } from '@kit.BasicServicesKit';
3597
3598try {
3599  inputClient.moveCursor(inputMethodEngine.Direction.CURSOR_UP, (err: BusinessError) => {
3600    if (err) {
3601      console.error(`Failed to moveCursor: ${JSON.stringify(err)}`);
3602      return;
3603    }
3604    console.log('Succeeded in moving cursor.');
3605  });
3606} catch (err) {
3607  console.error(`Failed to moveCursor: ${JSON.stringify(err)}`);
3608}
3609```
3610
3611### moveCursor<sup>9+</sup>
3612
3613moveCursor(direction: number): Promise&lt;void&gt;
3614
3615移动光标。使用promise异步回调。
3616
3617**系统能力:** SystemCapability.MiscServices.InputMethodFramework
3618
3619**参数:**
3620
3621| 参数名    | 类型   | 必填 | 说明                                                         |
3622| --------- | ------ | ---- | ------------------------------------------------------------ |
3623| direction | number | 是   | 光标移动方向。<br/>- 当值为1时,表示向上。<br/>- 当值为2时,表示向下。<br/>- 当值为3时,表示向左。<br/>- 当值为4时,表示向右。不能小于0。 |
3624
3625**返回值:**
3626
3627| 类型                | 说明                      |
3628| ------------------- | ------------------------- |
3629| Promise&lt;void&gt; | 无返回结果的Promise对象。 |
3630
3631**错误码:**
3632
3633以下错误码的详细介绍请参见[输入法框架错误码](errorcode-inputmethod-framework.md),[通用错误码说明文档](../errorcode-universal.md)。
3634
3635| 错误码ID | 错误信息                 |
3636| -------- | -------------------------- |
3637| 401      | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.           |
3638| 12800003 | input method client error. |
3639
3640**示例:**
3641
3642```ts
3643import { BusinessError } from '@kit.BasicServicesKit';
3644
3645try {
3646  inputClient.moveCursor(inputMethodEngine.Direction.CURSOR_UP).then(() => {
3647    console.log('Succeeded in moving cursor.');
3648  }).catch((err: BusinessError) => {
3649    console.error(`Failed to moveCursor: ${JSON.stringify(err)}`);
3650  });
3651} catch (err) {
3652  console.error(`Failed to moveCursor: ${JSON.stringify(err)}`);
3653}
3654```
3655
3656### moveCursorSync<sup>10+</sup>
3657
3658moveCursorSync(direction: number): void
3659
3660移动光标。
3661
3662**系统能力:** SystemCapability.MiscServices.InputMethodFramework
3663
3664**参数:**
3665
3666| 参数名    | 类型   | 必填 | 说明                                                         |
3667| --------- | ------ | ---- | ------------------------------------------------------------ |
3668| direction | number | 是   | 光标移动方向。<br/>- 当值为1时,表示向上。<br/>- 当值为2时,表示向下。<br/>- 当值为3时,表示向左。<br/>- 当值为4时,表示向右。不能小于0。 |
3669
3670**错误码:**
3671
3672以下错误码的详细介绍请参见[输入法框架错误码](errorcode-inputmethod-framework.md),[通用错误码说明文档](../errorcode-universal.md)。
3673
3674| 错误码ID | 错误信息                   |
3675| -------- | -------------------------- |
3676| 401      | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.           |
3677| 12800003 | input method client error. |
3678
3679**示例:**
3680
3681```ts
3682try {
3683  inputClient.moveCursorSync(inputMethodEngine.Direction.CURSOR_UP);
3684  console.log('Succeeded in moving cursor.');
3685} catch (err) {
3686  console.error(`Failed to moveCursorSync: ${JSON.stringify(err)}`);
3687}
3688```
3689
3690### selectByRange<sup>10+</sup>
3691
3692selectByRange(range: Range, callback: AsyncCallback&lt;void&gt;): void
3693
3694根据索引范围选中文本。使用callback异步回调。
3695
3696**系统能力:** SystemCapability.MiscServices.InputMethodFramework
3697
3698**参数:**
3699
3700| 参数名   | 类型                                                      | 必填 | 说明                                                         |
3701| -------- | --------------------------------------------------------- | ---- | ------------------------------------------------------------ |
3702| range    | [Range](#range10) | 是   | 选中文本的范围。                                             |
3703| callback | AsyncCallback&lt;void&gt;                                 | 是   | 回调函数。当成功发送选中事件后,err为undefined,否则为错误对象。 |
3704
3705**错误码:**
3706
3707以下错误码的详细介绍请参见[输入法框架错误码](errorcode-inputmethod-framework.md),[通用错误码说明文档](../errorcode-universal.md)。
3708
3709| 错误码ID | 错误信息                   |
3710| -------- | -------------------------- |
3711| 401      | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.           |
3712| 12800003 | input method client error. |
3713
3714**示例:**
3715
3716```ts
3717import { BusinessError } from '@kit.BasicServicesKit';
3718
3719try {
3720  let range: inputMethodEngine.Range = { start: 0, end: 1 };
3721  inputClient.selectByRange(range, (err: BusinessError) => {
3722    if (err) {
3723      console.error(`Failed to selectByRange: ${JSON.stringify(err)}`);
3724      return;
3725    }
3726    console.log('Succeeded in selecting by range.');
3727  });
3728} catch (err) {
3729  console.error(`Failed to selectByRange: ${JSON.stringify(err)}`);
3730}
3731```
3732
3733### selectByRange<sup>10+</sup>
3734
3735selectByRange(range: Range): Promise&lt;void&gt;
3736
3737根据索引范围选中文本。使用promise异步回调。
3738
3739**系统能力:** SystemCapability.MiscServices.InputMethodFramework
3740
3741**参数:**
3742
3743| 参数名 | 类型                                                      | 必填 | 说明             |
3744| ------ | --------------------------------------------------------- | ---- | ---------------- |
3745| range  | [Range](#range10) | 是   | 选中文本的范围。 |
3746
3747**返回值:**
3748
3749| 类型                | 说明                      |
3750| ------------------- | ------------------------- |
3751| Promise&lt;void&gt; | 无返回结果的Promise对象。 |
3752
3753**错误码:**
3754
3755以下错误码的详细介绍请参见[输入法框架错误码](errorcode-inputmethod-framework.md),[通用错误码说明文档](../errorcode-universal.md)。
3756
3757| 错误码ID | 错误信息                   |
3758| -------- | -------------------------- |
3759| 401      | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.           |
3760| 12800003 | input method client error. |
3761
3762**示例:**
3763
3764```ts
3765import { BusinessError } from '@kit.BasicServicesKit';
3766
3767try {
3768  let range: inputMethodEngine.Range = { start: 0, end: 1 };
3769  inputClient.selectByRange(range).then(() => {
3770    console.log('Succeeded in selecting by range.');
3771  }).catch((err: BusinessError) => {
3772    console.error(`Failed to selectByRange: ${JSON.stringify(err)}`);
3773  });
3774} catch (err) {
3775  console.error(`Failed to selectByRange: ${JSON.stringify(err)}`);
3776}
3777```
3778
3779### selectByRangeSync<sup>10+</sup>
3780
3781selectByRangeSync(range: Range): void
3782
3783根据索引范围选中文本。
3784
3785**系统能力:** SystemCapability.MiscServices.InputMethodFramework
3786
3787**参数:**
3788
3789| 参数名 | 类型              | 必填 | 说明             |
3790| ------ | ----------------- | ---- | ---------------- |
3791| range  | [Range](#range10) | 是   | 选中文本的范围。 |
3792
3793**错误码:**
3794
3795以下错误码的详细介绍请参见[输入法框架错误码](errorcode-inputmethod-framework.md),[通用错误码说明文档](../errorcode-universal.md)。
3796
3797| 错误码ID | 错误信息                   |
3798| -------- | -------------------------- |
3799| 401      | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.           |
3800| 12800003 | input method client error. |
3801
3802**示例:**
3803
3804```ts
3805try {
3806  let range: inputMethodEngine.Range = { start: 0, end: 1 };
3807  inputClient.selectByRangeSync(range);
3808  console.log('Succeeded in selecting by range.');
3809} catch (err) {
3810  console.error(`Failed to selectByRangeSync: ${JSON.stringify(err)}`);
3811}
3812```
3813
3814### selectByMovement<sup>10+</sup>
3815
3816selectByMovement(movement: Movement, callback: AsyncCallback&lt;void&gt;): void
3817
3818根据光标移动方向选中文本。使用callback异步回调。
3819
3820**系统能力:** SystemCapability.MiscServices.InputMethodFramework
3821
3822**参数:**
3823
3824| 参数名   | 类型  | 必填 | 说明   |
3825| -------- | ------ | ---- | ------ |
3826| movement | [Movement](#movement10)   | 是   | 选中时光标移动的方向。  |
3827| callback | AsyncCallback&lt;void&gt; | 是   | 回调函数。当成功发送选中事件后,err为undefined,否则为错误对象。 |
3828
3829**错误码:**
3830
3831以下错误码的详细介绍请参见[输入法框架错误码](errorcode-inputmethod-framework.md),[通用错误码说明文档](../errorcode-universal.md)。
3832
3833| 错误码ID | 错误信息                   |
3834| -------- | -------------------------- |
3835| 401      | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.           |
3836| 12800003 | input method client error. |
3837
3838**示例:**
3839
3840```ts
3841import { BusinessError } from '@kit.BasicServicesKit';
3842
3843try {
3844  let movement: inputMethodEngine.Movement = { direction: 1 };
3845  inputClient.selectByMovement(movement, (err: BusinessError) => {
3846    if (err) {
3847      console.error(`Failed to selectByMovement: ${JSON.stringify(err)}`);
3848      return;
3849    }
3850    console.log('Succeeded in selecting by movement.');
3851  });
3852} catch (err) {
3853  console.error(`Failed to selectByMovement: ${JSON.stringify(err)}`);
3854}
3855```
3856
3857### selectByMovement<sup>10+</sup>
3858
3859selectByMovement(movement: Movement): Promise&lt;void&gt;
3860
3861根据索引范围选中文本。使用promise异步回调。
3862
3863**系统能力:** SystemCapability.MiscServices.InputMethodFramework
3864
3865**参数:**
3866
3867| 参数名   | 类型                                                         | 必填 | 说明                   |
3868| -------- | ------------------------------------------------------------ | ---- | ---------------------- |
3869| movement | [Movement](#movement10) | 是   | 选中时光标移动的方向。 |
3870
3871**返回值:**
3872
3873| 类型                | 说明                      |
3874| ------------------- | ------------------------- |
3875| Promise&lt;void&gt; | 无返回结果的Promise对象。 |
3876
3877**错误码:**
3878
3879以下错误码的详细介绍请参见[输入法框架错误码](errorcode-inputmethod-framework.md),[通用错误码说明文档](../errorcode-universal.md)。
3880
3881| 错误码ID | 错误信息                   |
3882| -------- | -------------------------- |
3883| 401      | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.           |
3884| 12800003 | input method client error. |
3885
3886**示例:**
3887
3888```ts
3889import { BusinessError } from '@kit.BasicServicesKit';
3890
3891try {
3892  let movement: inputMethodEngine.Movement = { direction: 1 };
3893  inputClient.selectByMovement(movement).then(() => {
3894    console.log('Succeeded in selecting by movement.');
3895  }).catch((err: BusinessError) => {
3896    console.error(`Failed to selectByMovement: ${JSON.stringify(err)}`);
3897  });
3898} catch (err) {
3899  console.error(`Failed to selectByMovement: ${JSON.stringify(err)}`);
3900}
3901```
3902
3903### selectByMovementSync<sup>10+</sup>
3904
3905selectByMovementSync(movement: Movement): void
3906
3907根据光标移动方向选中文本。
3908
3909**系统能力:** SystemCapability.MiscServices.InputMethodFramework
3910
3911**参数:**
3912
3913| 参数名   | 类型                    | 必填 | 说明                   |
3914| -------- | ----------------------- | ---- | ---------------------- |
3915| movement | [Movement](#movement10) | 是   | 选中时光标移动的方向。 |
3916
3917**错误码:**
3918
3919以下错误码的详细介绍请参见[输入法框架错误码](errorcode-inputmethod-framework.md),[通用错误码说明文档](../errorcode-universal.md)。
3920
3921| 错误码ID | 错误信息                   |
3922| -------- | -------------------------- |
3923| 401      | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
3924| 12800003 | input method client error. |
3925
3926**示例:**
3927
3928```ts
3929try {
3930  let movement: inputMethodEngine.Movement = { direction: 1 };
3931  inputClient.selectByMovementSync(movement);
3932  console.log('Succeeded in selecting by movement.');
3933} catch (err) {
3934  console.error(`Failed to selectByMovement: ${JSON.stringify(err)}`);
3935}
3936```
3937
3938### getTextIndexAtCursor<sup>10+</sup>
3939
3940getTextIndexAtCursor(callback: AsyncCallback&lt;number&gt;): void
3941
3942获取光标所在处的文本索引。使用callback异步回调。
3943
3944**系统能力:** SystemCapability.MiscServices.InputMethodFramework
3945
3946**参数:**
3947
3948| 参数名   | 类型                        | 必填 | 说明                                                         |
3949| -------- | --------------------------- | ---- | ------------------------------------------------------------ |
3950| callback | AsyncCallback&lt;number&gt; | 是   | 回调函数。当文本索引获取成功,err为undefined,否则为错误对象。 |
3951
3952**错误码:**
3953
3954以下错误码的详细介绍请参见[输入法框架错误码](errorcode-inputmethod-framework.md)。
3955
3956| 错误码ID | 错误信息                       |
3957| -------- | ------------------------------ |
3958| 12800003 | input method client error.     |
3959| 12800006 | Input method controller error. |
3960
3961**示例:**
3962
3963```ts
3964import { BusinessError } from '@kit.BasicServicesKit';
3965
3966inputClient.getTextIndexAtCursor((err: BusinessError, index: number) => {
3967  if (err) {
3968    console.error(`Failed to getTextIndexAtCursor: ${JSON.stringify(err)}`);
3969    return;
3970  }
3971  console.log('Succeeded in getTextIndexAtCursor: ' + index);
3972});
3973```
3974
3975### getTextIndexAtCursor<sup>10+</sup>
3976
3977getTextIndexAtCursor(): Promise&lt;number&gt;
3978
3979获取光标所在处的文本索引。使用promise异步回调。
3980
3981**系统能力:** SystemCapability.MiscServices.InputMethodFramework
3982
3983**返回值:**
3984
3985| 类型                  | 说明                                    |
3986| --------------------- | --------------------------------------- |
3987| Promise&lt;number&gt; | Promise对象,返回光标所在处的文本索引。 |
3988
3989**错误码:**
3990
3991以下错误码的详细介绍请参见[输入法框架错误码](errorcode-inputmethod-framework.md)。
3992
3993| 错误码ID | 错误信息                       |
3994| -------- | ------------------------------ |
3995| 12800003 | input method client error.     |
3996| 12800006 | Input method controller error. |
3997
3998**示例:**
3999
4000```ts
4001import { BusinessError } from '@kit.BasicServicesKit';
4002
4003inputClient.getTextIndexAtCursor().then((index: number) => {
4004  console.log('Succeeded in getTextIndexAtCursor: ' + index);
4005}).catch((err: BusinessError) => {
4006  console.error(`Failed to getTextIndexAtCursor: ${JSON.stringify(err)}`);
4007});
4008```
4009
4010### getTextIndexAtCursorSync<sup>10+</sup>
4011
4012getTextIndexAtCursorSync(): number
4013
4014获取光标所在处的文本索引。
4015
4016**系统能力:** SystemCapability.MiscServices.InputMethodFramework
4017
4018**返回值:**
4019
4020| 类型   | 说明                       |
4021| ------ | -------------------------- |
4022| number | 返回光标所在处的文本索引。 |
4023
4024**错误码:**
4025
4026以下错误码的详细介绍请参见[输入法框架错误码](errorcode-inputmethod-framework.md)。
4027
4028| 错误码ID | 错误信息                       |
4029| -------- | ------------------------------ |
4030| 12800003 | input method client error.     |
4031| 12800006 | Input method controller error. |
4032
4033**示例:**
4034
4035```ts
4036try{
4037  let index: number = inputClient.getTextIndexAtCursorSync();
4038  console.log(`Succeeded in getTextIndexAtCursorSync, index: ${index}`);
4039} catch (err) {
4040  console.error(`Failed to getTextIndexAtCursorSync: ${JSON.stringify(err)}`);
4041}
4042```
4043
4044### sendExtendAction<sup>10+</sup>
4045
4046sendExtendAction(action: ExtendAction, callback: AsyncCallback&lt;void&gt;): void
4047
4048发送扩展编辑操作。使用callback异步回调。
4049
4050> **说明**
4051>
4052> 输入法应用调用该接口向编辑框发送扩展编辑操作,编辑框监听相应事件[on('handleExtendAction')](./js-apis-inputmethod.md#onhandleextendaction10),从而进一步做出处理。
4053
4054**系统能力:** SystemCapability.MiscServices.InputMethodFramework
4055
4056**参数:**
4057
4058| 参数名   | 类型                        | 必填 | 说明                                                         |
4059| -------- | --------------------------- | ---- | ------------------------------------------------------------ |
4060| action | [ExtendAction](#extendaction10) | 是   | 要发送的扩展操作。 |
4061| callback | AsyncCallback&lt;void&gt; | 是   | 回调函数。发送成功,err为undefined,否则为错误对象。 |
4062
4063**错误码:**
4064
4065以下错误码的详细介绍请参见[输入法框架错误码](errorcode-inputmethod-framework.md),[通用错误码说明文档](../errorcode-universal.md)。
4066
4067| 错误码ID | 错误信息                       |
4068| -------- | ------------------------------ |
4069| 401      | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
4070| 12800003 | input method client error.     |
4071| 12800006 | Input method controller error. |
4072
4073**示例:**
4074
4075```ts
4076import { BusinessError } from '@kit.BasicServicesKit';
4077
4078try {
4079  inputClient.sendExtendAction(inputMethodEngine.ExtendAction.COPY, (err: BusinessError) => {
4080    if (err) {
4081      console.error(`Failed to sendExtendAction: ${JSON.stringify(err)}`);
4082      return;
4083    }
4084    console.log('Succeeded in sending extend action.');
4085  });
4086} catch(err) {
4087  console.error(`Failed to sendExtendAction: ${JSON.stringify(err)}`);
4088}
4089```
4090
4091### sendExtendAction<sup>10+</sup>
4092
4093sendExtendAction(action: ExtendAction): Promise&lt;void&gt;
4094
4095发送扩展编辑操作。使用promise异步回调。
4096
4097>**说明**
4098>
4099> 输入法应用调用该接口向编辑框发送扩展编辑操作,编辑框监听相应事件[on('handleExtendAction')](./js-apis-inputmethod.md#onhandleextendaction10),从而进一步做出处理。
4100
4101**系统能力:** SystemCapability.MiscServices.InputMethodFramework
4102
4103**参数:**
4104
4105| 参数名 | 类型 | 必填 | 说明 |
4106| -------- | -------- | -------- | -------- |
4107| action | [ExtendAction](#extendaction10) | 是 | 要发送的扩展操作。 |
4108
4109**返回值:**
4110
4111| 类型                  | 说明                                    |
4112| --------------------- | --------------------------------------- |
4113| Promise&lt;void&gt; | 无返回结果的Promise对象。 |
4114
4115**错误码:**
4116
4117以下错误码的详细介绍请参见[输入法框架错误码](errorcode-inputmethod-framework.md),[通用错误码说明文档](../errorcode-universal.md)。
4118
4119| 错误码ID | 错误信息                       |
4120| -------- | ------------------------------ |
4121| 401      | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
4122| 12800003 | input method client error.     |
4123| 12800006 | Input method controller error. |
4124
4125**示例:**
4126
4127```ts
4128import { BusinessError } from '@kit.BasicServicesKit';
4129
4130try {
4131  inputClient.sendExtendAction(inputMethodEngine.ExtendAction.COPY).then(() => {
4132    console.log('Succeeded in sending extend action.');
4133  }).catch((err: BusinessError) => {
4134    console.error(`Failed to sendExtendAction: ${JSON.stringify(err)}`);
4135  });
4136} catch(err) {
4137  console.error(`Failed to sendExtendAction: ${JSON.stringify(err)}`);
4138}
4139```
4140
4141### sendPrivateCommand<sup>12+</sup>
4142
4143sendPrivateCommand(commandData: Record&lt;string, CommandDataType&gt;): Promise&lt;void&gt;
4144
4145发送私有数据至需要与输入法应用通信的系统其他部分。
4146
4147>**说明:**
4148>
4149> - 私有数据通道是系统预置输入法应用与系统特定组件(如文本框、桌面应用等)的通信机制,常用于设备级厂商在特定设备上实现自定义的输入法功能。
4150> - 私有数据规格限制:总大小32KB,数量限制5条。
4151
4152**系统能力:** SystemCapability.MiscServices.InputMethodFramework
4153
4154**参数:**
4155
4156| 参数名      | 类型                            | 必填 | 说明       |
4157| ----------- | ------------------------------- | ---- | ---------- |
4158| commandData | Record<string, [CommandDataType](#commanddatatype12)> | 是   | 私有数据。 |
4159
4160**返回值:**
4161
4162| 类型                | 说明                      |
4163| ------------------- | ------------------------- |
4164| Promise&lt;void&gt; | 无返回结果的Promise对象。 |
4165
4166**错误码:**
4167
4168以下错误码的详细介绍请参见[输入法框架错误码](errorcode-inputmethod-framework.md),[通用错误码说明文档](../errorcode-universal.md)。
4169
4170| 错误码ID | 错误信息                                       |
4171| -------- | ---------------------------------------------- |
4172| 401      | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.           |
4173| 12800003 | input method client error.                     |
4174| 12800010 | not the preconfigured default input method. |
4175
4176**示例:**
4177
4178```ts
4179import { inputMethodEngine } from '@kit.IMEKit';
4180import { BusinessError } from '@kit.BasicServicesKit';
4181
4182inputMethodEngine.getInputMethodAbility().on('inputStart', (kbController, textInputClient) => {
4183  try {
4184    let record: Record<string, inputMethodEngine.CommandDataType> = {
4185      "valueString1": "abcdefg",
4186      "valueString2": true,
4187      "valueString3": 500,
4188    }
4189    textInputClient.sendPrivateCommand(record).then(() => {
4190    }).catch((err: BusinessError) => {
4191      if (err !== undefined) {
4192        let error = err as BusinessError;
4193        console.error(`sendPrivateCommand catch error: ${error.code} ${error.message}`);
4194      }
4195    });
4196  } catch (err) {
4197    let error = err as BusinessError;
4198    console.error(`sendPrivateCommand catch error: ${error.code} ${error.message}`);
4199  }
4200})
4201```
4202
4203### getCallingWindowInfo<sup>12+</sup>
4204
4205getCallingWindowInfo(): Promise&lt;WindowInfo&gt;
4206
4207获取当前拉起输入法的输入框所在应用窗口信息。使用promise异步回调。
4208
4209>**说明:**
4210>
4211>本接口仅适用于适配使用[Panel](#panel10)作为软键盘窗口的输入法应用。
4212
4213**系统能力:** SystemCapability.MiscServices.InputMethodFramework
4214
4215**返回值:**
4216
4217| 类型                                       | 说明                                                  |
4218| ------------------------------------------ | ----------------------------------------------------- |
4219| Promise&lt;[WindowInfo](#windowinfo12)&gt; | Promise对象,返回拉起输入法的输入框所在应用窗口信息。 |
4220
4221**错误码:**
4222
4223以下错误码的详细介绍请参见[输入法框架错误码](errorcode-inputmethod-framework.md)。
4224
4225| 错误码ID | 错误信息                          |
4226| -------- | --------------------------------- |
4227| 12800003 | input method client error.        |
4228| 12800012 | the input method panel does not exist. |
4229| 12800013 | window manager service error.     |
4230
4231**示例:**
4232
4233```ts
4234import { BusinessError } from '@kit.BasicServicesKit';
4235
4236try {
4237  inputClient.getCallingWindowInfo().then((windowInfo: inputMethodEngine.WindowInfo) => {
4238    console.log(`windowInfo.rect: ${JSON.stringify(windowInfo.rect)}`);
4239    console.log('windowInfo.status: ' + JSON.stringify(windowInfo.status));
4240  }).catch((err: BusinessError) => {
4241    console.error(`Failed to getCallingWindowInfo: ${JSON.stringify(err)}`);
4242  });
4243} catch(err) {
4244    console.error(`Failed to getCallingWindowInfo: ${JSON.stringify(err)}`);
4245}
4246```
4247
4248### setPreviewText<sup>12+</sup>
4249
4250setPreviewText(text: string, range: Range): Promise&lt;void&gt;
4251
4252设置预上屏文本。使用promise异步回调。
4253
4254**系统能力:** SystemCapability.MiscServices.InputMethodFramework
4255
4256**参数:**
4257
4258| 参数名 | 类型              | 必填 | 说明                                                         |
4259| ------ | ----------------- | ---- | ------------------------------------------------------------ |
4260| text   | string            | 是   | 将被预上屏的文本。                                           |
4261| range  | [Range](#range10) | 是   | 目标替换的文本范围。<br/>- 当值为{ start: -1, end: -1 }时,默认将参数text替换当前预上屏区域全部文本。<br/>- 当start等于end,默认将参数text插入start对应的光标位置。<br/>- 当start不等于end,将参数text替换range对应区域的文本。<br/>- 当start与end为其他含有负数值的组合,按照参数错误返回。<br/>- 当输入框已有预上屏文本,参数range不得超过预上屏文本范围,否则按照参数错误返回。<br/>- 当输入框无预上屏文本,参数range不得超过输入框文本范围,否则按照参数错误返回。 |
4262
4263**返回值:**
4264
4265| 类型                | 说明                      |
4266| ------------------- | ------------------------- |
4267| Promise&lt;void&gt; | 无返回结果的Promise对象。 |
4268
4269**错误码:**
4270
4271以下错误码的详细介绍请参见[输入法框架错误码](errorcode-inputmethod-framework.md),[通用错误码说明文档](../errorcode-universal.md)。
4272
4273| 错误码ID | 错误信息                                                     |
4274| -------- | ------------------------------------------------------------ |
4275| 401      | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.           |
4276| 12800003 | input method client error.                                   |
4277| 12800011 | text preview not supported.                               |
4278
4279**示例:**
4280
4281```ts
4282import { BusinessError } from '@kit.BasicServicesKit';
4283
4284try {
4285  let range: inputMethodEngine.Range = { start: 0, end: 1 };
4286  inputClient.setPreviewText('test', range).then(() => {
4287    console.log('Succeeded in setting preview text.');
4288  }).catch((err: BusinessError) => {
4289    console.error(`Failed to setPreviewText: ${JSON.stringify(err)}`);
4290  });
4291} catch(err) {
4292    console.error(`Failed to setPreviewText: ${JSON.stringify(err)}`);
4293}
4294```
4295
4296### setPreviewTextSync<sup>12+</sup>
4297
4298setPreviewTextSync(text: string, range: Range): void
4299
4300设置预上屏文本。
4301
4302**系统能力:** SystemCapability.MiscServices.InputMethodFramework
4303
4304**参数:**
4305
4306| 参数名 | 类型              | 必填 | 说明                                                         |
4307| ------ | ----------------- | ---- | ------------------------------------------------------------ |
4308| text   | string            | 是   | 将被预上屏的文本。                                           |
4309| range  | [Range](#range10) | 是   | 目标替换的文本范围。<br/>- 当值为{ start: -1, end: -1 }时,默认将参数text替换当前预上屏区域全部文本。<br/>- 当start等于end,默认将参数text插入start对应的光标位置。<br/>- 当start不等于end,将参数text替换range对应区域的文本。<br/>- 当start与end为其他含有负数值的组合,按照参数错误返回。<br/>- 当输入框已有预上屏文本,参数range不得超过预上屏文本范围,否则按照参数错误返回。<br/>- 当输入框无预上屏文本,参数range不得超过输入框文本范围,否则按照参数错误返回。 |
4310
4311**错误码:**
4312
4313以下错误码的详细介绍请参见[输入法框架错误码](errorcode-inputmethod-framework.md),[通用错误码说明文档](../errorcode-universal.md)。
4314
4315| 错误码ID | 错误信息                                                     |
4316| -------- | ------------------------------------------------------------ |
4317| 401      | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.           |
4318| 12800003 | input method client error.                                   |
4319| 12800011 | text preview not supported.                               |
4320
4321**示例:**
4322
4323```ts
4324try {
4325  let range: inputMethodEngine.Range = { start: 0, end: 1 };
4326  inputClient.setPreviewTextSync('test', range);
4327  console.log('Succeeded in setting preview text with synchronized method.');
4328} catch (err) {
4329  console.error(`Failed to setPreviewTextSync: ${JSON.stringify(err)}`);
4330}
4331```
4332
4333### finishTextPreview<sup>12+</sup>
4334
4335finishTextPreview(): Promise&lt;void&gt;
4336
4337结束预上屏。使用promise异步回调。
4338
4339>**说明:**
4340>
4341>若当前输入框已有预上屏状态文本,调用此接口后,预上屏内容将被系统正式上屏。
4342
4343**系统能力:** SystemCapability.MiscServices.InputMethodFramework
4344
4345**返回值:**
4346
4347| 类型                | 说明                      |
4348| ------------------- | ------------------------- |
4349| Promise&lt;void&gt; | 无返回结果的Promise对象。 |
4350
4351**错误码:**
4352
4353以下错误码的详细介绍请参见[输入法框架错误码](errorcode-inputmethod-framework.md)。
4354
4355| 错误码ID | 错误信息                       |
4356| -------- | ------------------------------ |
4357| 12800003 | input method client error.     |
4358| 12800011 | text preview not supported. |
4359
4360**示例:**
4361
4362```ts
4363import { BusinessError } from '@kit.BasicServicesKit';
4364
4365try {
4366  inputClient.finishTextPreview().then(() => {
4367    console.log('Succeeded in finishing text preview.');
4368  }).catch((err: BusinessError) => {
4369    console.error(`Failed to finishTextPreview: ${JSON.stringify(err)}`);
4370  });
4371} catch(err) {
4372    console.error(`Failed to finishTextPreview: ${JSON.stringify(err)}`);
4373}
4374```
4375
4376### finishTextPreviewSync<sup>12+</sup>
4377
4378finishTextPreviewSync(): void
4379
4380结束预上屏。
4381
4382>**说明:**
4383>
4384>若当前输入框已有预上屏状态文本,调用此接口后,预上屏内容将被系统正式上屏。
4385
4386**系统能力:** SystemCapability.MiscServices.InputMethodFramework
4387
4388**错误码:**
4389
4390以下错误码的详细介绍请参见[输入法框架错误码](errorcode-inputmethod-framework.md)。
4391
4392| 错误码ID | 错误信息                       |
4393| -------- | ------------------------------ |
4394| 12800003 | input method client error.     |
4395| 12800011 | text preview not supported. |
4396
4397**示例:**
4398
4399```ts
4400try {
4401  inputClient.finishTextPreviewSync();
4402  console.log('Succeeded in finishing text preview with synchronized method.');
4403} catch (err) {
4404  console.error(`Failed to finishTextPreviewSync: ${JSON.stringify(err)}`);
4405}
4406```
4407
4408### sendMessage<sup>15+</sup>
4409
4410sendMessage(msgId: string, msgParam?: ArrayBuffer): Promise<void&gt;
4411
4412发送自定义通信至已绑定当前输入法应用的编辑框应用。使用Promise异步回调。
4413
4414> **说明:**
4415>
4416> 该接口需要编辑框与输入法绑定并进入编辑状态,且输入法应用处于完整体验模式时才能调用。
4417>
4418> msgId最大限制256B,msgParam最大限制128KB。
4419
4420**系统能力:**  SystemCapability.MiscServices.InputMethodFramework
4421
4422**参数:**
4423
4424| 参数名   | 类型        | 必填 | 说明                                                         |
4425| -------- | ----------- | ---- | ------------------------------------------------------------ |
4426| msgId    | string      | 是   | 需要发送至已绑定当前输入法应用的编辑框应用的自定义数据的标识符。 |
4427| msgParam | ArrayBuffer | 否   | 需要发送至已绑定当前输入法应用的编辑框应用的自定义数据的消息体。 |
4428
4429**返回值:**
4430
4431| 类型                | 说明                      |
4432| ------------------- | ------------------------- |
4433| Promise&lt;void&gt; | 无返回结果的Promise对象。 |
4434
4435**错误码:**
4436
4437以下错误码的详细介绍请参见[输入法框架错误码](errorcode-inputmethod-framework.md),[通用错误码说明文档](../errorcode-universal.md)。
4438
4439| 错误码ID | 错误信息                                    |
4440| -------- | ------------------------------------------- |
4441| 401      | parameter error. Possible causes: 1. Incorrect parameter types. 2. Incorrect parameter length.  |
4442| 12800003 | input method client error.                  |
4443| 12800009 | input method client detached.               |
4444| 12800014 | the input method is in basic mode.          |
4445| 12800015 | the other side does not accept the request. |
4446| 12800016 | input method client is not editable.        |
4447
4448**示例:**
4449
4450```ts
4451import { BusinessError } from '@kit.BasicServicesKit';
4452
4453let msgId: string = "testMsgId";
4454let msgParam: ArrayBuffer = new ArrayBuffer(128);
4455inputMethodController.sendMessage(msgId, msgParam).then(() => {
4456  console.log('Succeeded send message.');
4457}).catch((err: BusinessError) => {
4458  console.error(`Failed to send message: ${JSON.stringify(err)}`);
4459});
4460```
4461
4462### recvMessage<sup>15+</sup>
4463
4464recvMessage(msgHandler?: MessageHandler): void;
4465
4466注册或取消注册Messagehandler。
4467
4468> **说明:**
4469>
4470> [MessageHandler](#messagehandler15)对象全局唯一,多次注册仅保留最后一次注册的对象及有效性,并触发上一个已注册对象的[onTerminated](#onterminated15)回调函数。
4471>
4472> 未填写参数,则取消全局已注册的[MessageHandler](#messagehandler15),并会触发被取消注册对象中[onTerminated](#onterminated15)回调函数。
4473
4474**系统能力:**  SystemCapability.MiscServices.InputMethodFramework
4475
4476**参数:**
4477
4478| 参数名     | 类型                                | 必填 | 说明                                                         |
4479| ---------- | ----------------------------------- | ---- | ------------------------------------------------------------ |
4480| msgHandler | [MessageHandler](#messagehandler15) | 否   | 该对象将通过[onMessage](#onmessage15)接收来自已绑定当前输入法应用的编辑框应用所发送的自定义通信数据,以及[onTerminated](#onterminated15)接收终止此对象订阅的消息。若不填写此参数,则取消全局已注册的[MessageHandler](#messagehandler15)对象,并触发其[onTerminated](#onterminated15)回调函数。 |
4481
4482**返回值:**
4483
4484| 类型 | 说明         |
4485| ---- | ------------ |
4486| void | 无返回结果。 |
4487
4488**错误码:**
4489
4490以下错误码的详细介绍请参见[输入法框架错误码](errorcode-inputmethod-framework.md),[通用错误码说明文档](../errorcode-universal.md)。
4491
4492| 错误码ID | 错误信息         |
4493| -------- | ---------------- |
4494| 401      | parameter error. Possible causes: 1. Incorrect parameter types. |
4495
4496**示例:**
4497
4498```ts
4499import { BusinessError } from '@kit.BasicServicesKit';
4500
4501try {
4502  inputMethodEngine.getInputMethodAbility()
4503    .on('inputStart', (kbController: inputMethodEngine.KeyboardController, client: inputMethodEngine.InputClient) => {
4504      let keyboardController = kbController;
4505      let inputClient = client;
4506      try {
4507        let messageHandler: inputMethodEngine.MessageHandler = {
4508          onTerminated(): void {
4509            console.log('OnTerminated.');
4510          },
4511          onMessage(msgId: string, msgParam?:ArrayBuffer): void {
4512            console.log('recv message.');
4513          }
4514        }
4515        inputClient.recvMessage(messageHandler);
4516        inputClient.recvMessage();
4517      } catch(err) {
4518        console.error(`Failed to recvMessage: ${JSON.stringify(err)}`);
4519      }
4520  });
4521} catch(err) {
4522    console.error(`Failed to InputMethodAbility: ${JSON.stringify(err)}`);
4523}
4524```
4525
4526### EditorAttribute
4527
4528编辑框属性值。
4529
4530**系统能力:** SystemCapability.MiscServices.InputMethodFramework
4531
4532| 名称         | 类型 | 只读 | 可选 | 说明               |
4533| ------------ | -------- | ---- | ---- | ------------------ |
4534| enterKeyType | number   | 是   | 否   | 编辑框的功能属性。 |
4535| inputPattern | number   | 是   | 否   | 编辑框的文本属性。 |
4536| isTextPreviewSupported<sup>12+</sup> | boolean | 否 | 否 | 编辑框是否支持预上屏。 |
4537| bundleName<sup>14+</sup> | string | 是 | 是 | 编辑框所属应用包名;该值可能为"",使用该属性时需要考虑为""的场景。 |
4538| immersiveMode<sup>15+</sup> | [ImmersiveMode](#immersivemode15) | 是   | 是   | 输入法沉浸模式。 |
4539
4540## KeyEvent
4541
4542按键属性值。
4543
4544**系统能力:** SystemCapability.MiscServices.InputMethodFramework
4545
4546| 名称      | 类型 | 只读 | 可选 | 说明         |
4547| --------- | -------- | ---- | ---- | ------------ |
4548| keyCode   | number   | 是   | 否   | 按键的键值。键码值说明参考[KeyCode](../apis-input-kit/js-apis-keycode.md#keycode)。 |
4549| keyAction | number   | 是   | 否   | 按键事件类型。<br/>- 当值为2时,表示按下事件;<br/>- 当值为3时,表示抬起事件。 |
4550
4551## PanelFlag<sup>10+</sup>
4552
4553输入法面板状态类型枚举。
4554
4555**系统能力:** SystemCapability.MiscServices.InputMethodFramework
4556
4557| 名称         | 值 | 说明               |
4558| ------------ | -- | ------------------ |
4559| FLG_FIXED  | 0 | 固定态面板类型。 |
4560| FLG_FLOATING | 1 | 悬浮态面板类型。 |
4561| FLAG_CANDIDATE<sup>15+</sup> | 2 | 候选词态面板类型。 |
4562
4563## PanelType<sup>10+</sup>
4564
4565输入法面板类型枚举。
4566
4567**系统能力:** SystemCapability.MiscServices.InputMethodFramework
4568
4569| 名称         | 值 | 说明               |
4570| ------------ | -- | ------------------ |
4571| SOFT_KEYBOARD | 0 | 软键盘类型。 |
4572| STATUS_BAR   | 1 | 状态栏类型。 |
4573
4574## PanelInfo<sup>10+</sup>
4575
4576输入法面板属性。
4577
4578**系统能力:** SystemCapability.MiscServices.InputMethodFramework
4579
4580| 名称      | 类型 | 只读 | 可选 | 说明         |
4581| --------- | -------- | ---- | ---- | ------------ |
4582| type   	| [PanelType](#paneltype10)   | 否   | 否   | 面板的类型。 |
4583| flag	    | [PanelFlag](#panelflag10)   | 否   | 是   | 面板的状态类型。 |
4584
4585## PanelRect<sup>12+</sup>
4586
4587输入法面板位置大小信息。
4588
4589**系统能力:** SystemCapability.MiscServices.InputMethodFramework
4590
4591| 名称         | 类型 | 只读 | 可选 | 说明               |
4592| ------------ | -------- | ---- | ---- | ------------------ |
4593| landscapeRect | [window.Rect](../apis-arkui/js-apis-window.md#rect7)   | 否   | 否   | 横屏状态时输入法面板窗口的位置大小。 |
4594| portraitRect | [window.Rect](../apis-arkui/js-apis-window.md#rect7)   | 否   | 否   | 竖屏状态时输入法面板窗口的位置大小。 |
4595
4596## EnhancedPanelRect<sup>15+</sup>
4597
4598增强的输入法面板位置、大小信息,包含自定义避让区域、自定义热区。
4599
4600**系统能力:** SystemCapability.MiscServices.InputMethodFramework
4601
4602| 名称                 | 类型                                                         | 只读 | 可选 | 说明                                                         |
4603| -------------------- | ------------------------------------------------------------ | ---- | ---- | ------------------------------------------------------------ |
4604| landscapeRect        | [window.Rect](../apis-arkui/js-apis-window.md#rect7)         | 否   | 是   | 横屏状态时输入法面板窗口的位置大小。<br/>- 当fullScreenMode不填写或值为false时,此属性为必选。 |
4605| portraitRect         | [window.Rect](../apis-arkui/js-apis-window.md#rect7)         | 否   | 是   | 竖屏状态时,输入法面板窗口的位置大小。<br/>- 当fullScreenMode不填写或值为false时,此属性为必选。 |
4606| landscapeAvoidY      | number                                                       | 否   | 是   | 横屏状态时,面板中的避让线距离面板顶部的距离。默认值为0。<br/>- 应用内其他系统组件会对避让线以下的输入法面板区域进行避让。<br/>- 面板为固定态时,避让线到屏幕底部的高度不能超过屏幕高度的70%。 |
4607| landscapeInputRegion | Array&lt;[window.Rect](../apis-arkui/js-apis-window.md#rect7)&gt; | 否   | 是   | 横屏状态时,面板接收输入事件的区域。<br/>- 数组大小限制为[1, 4]。默认值为横屏时的面板大小。<br/>- 传入的热区位置是相对于输入法面板窗口左顶点的位置。 |
4608| portraitAvoidY       | number                                                       | 否   | 是   | 竖屏状态时,面板中的避让线距离面板顶部的距离。默认值为0。<br/>- 应用内其他系统组件会对避让线以下的输入法面板区域进行避让。<br/>- 面板为固定态时,避让线到屏幕底部的高度不能超过屏幕高度的70%。 |
4609| portraitInputRegion  | Array&lt;[window.Rect](../apis-arkui/js-apis-window.md#rect7)&gt; | 否   | 是   | 竖屏状态时,面板接收输入事件的区域。<br/>- 数组大小限制为[1, 4]。默认值为竖屏时的面板大小。<br/>- 传入的热区位置是相对于输入法面板窗口左顶点的位置。 |
4610| fullScreenMode       | boolean                                                      | 否   | 是   | 是否开启全屏模式。默认值为false。<br/>- 值为true,landscapeRect和portraitRect可不填写。<br/>- 值为false,landscapeRect和portraitRect为必选属性。 |
4611
4612## KeyboardArea<sup>15+</sup>
4613
4614面板中的键盘区域。
4615
4616**系统能力:** SystemCapability.MiscServices.InputMethodFramework
4617
4618| 名称   | 类型   | 只读 | 可选 | 说明                                                         |
4619| ------ | ------ | ---- | ---- | ------------------------------------------------------------ |
4620| top    | number | 是   | 否   | 键盘区域的上边界到面板区域上边界的距离,单位为px,该参数为整数。 |
4621| bottom | number | 是   | 否   | 键盘区域的下边界到面板区域下边界的距离,单位为px,该参数为整数。 |
4622| left   | number | 是   | 否   | 键盘区域的左边界到面板区域左边界的距离,单位为px,该参数为整数。 |
4623| right  | number | 是   | 否   | 键盘区域的右边界到面板区域右边界的距离,单位为px,该参数为整数。 |
4624
4625## WindowInfo<sup>12+</sup>
4626
4627窗口信息。
4628
4629**系统能力:** SystemCapability.MiscServices.InputMethodFramework
4630
4631| 名称   | 类型                                                         | 只读 | 可选 | 说明           |
4632| ------ | ------------------------------------------------------------ | ---- | ---- | -------------- |
4633| rect   | [window.Rect](../apis-arkui/js-apis-window.md#rect7)         | 否   | 否   | 窗口矩形区域。 |
4634| status | [window.WindowStatusType](../apis-arkui/js-apis-window.md#windowstatustype11) | 否   | 否   | 窗口模式类型。 |
4635
4636## ImmersiveMode<sup>15+</sup>
4637
4638枚举,输入法沉浸模式。
4639
4640**系统能力:** SystemCapability.MiscServices.InputMethodFramework
4641
4642| 名称         | 值 | 说明               |
4643| ------------ | -- | ------------------ |
4644| NONE_IMMERSIVE | 0 | 不使用沉浸模式。 |
4645| IMMERSIVE      | 1 | 沉浸模式,由输入法应用确定沉浸模式类型。 |
4646| LIGHT_IMMERSIVE  | 2 | 浅色沉浸模式。 |
4647| DARK_IMMERSIVE   | 3 | 深色沉浸模式。 |
4648
4649## TextInputClient<sup>(deprecated)</sup>
4650
4651> **说明:**
4652>
4653> 从API version 8开始支持,API version 9开始废弃,建议使用[InputClient](#inputclient9)替代。
4654
4655下列API示例中都需使用[on('inputStart')](#oninputstart)回调获取到TextInputClient实例,再通过此实例调用对应方法。
4656
4657### getForward<sup>(deprecated)</sup>
4658
4659getForward(length:number, callback: AsyncCallback&lt;string&gt;): void
4660
4661获取光标前固定长度的文本。使用callback异步回调。
4662
4663> **说明:**
4664>
4665> 从API version 8开始支持,API version 9开始废弃,建议使用[getForward](#getforward9)替代。
4666
4667**系统能力:** SystemCapability.MiscServices.InputMethodFramework
4668
4669**参数:**
4670
4671| 参数名 | 类型 | 必填 | 说明 |
4672| -------- | -------- | -------- | -------- |
4673| length | number | 是 | 文本长度。不能小于0。 |
4674| callback | AsyncCallback&lt;string&gt; | 是 | 回调函数。当光标前固定长度的文本获取成功,err为undefined,data为获取到的文本;否则为错误对象。|
4675
4676**示例:**
4677
4678```ts
4679import { BusinessError } from '@kit.BasicServicesKit';
4680
4681let length = 1;
4682textInputClient.getForward(length, (err: BusinessError, text: string) => {
4683  if (err) {
4684    console.error(`Failed to getForward: ${JSON.stringify(err)}`);
4685    return;
4686  }
4687  console.log('Succeeded in getting forward, text: ' + text);
4688});
4689```
4690
4691### getForward<sup>(deprecated)</sup>
4692
4693getForward(length:number): Promise&lt;string&gt;
4694
4695获取光标前固定长度的文本。使用promise异步回调。
4696
4697> **说明:**
4698>
4699> 从API version 8开始支持,API version 9开始废弃,建议使用[getForward](#getforward9)替代。
4700
4701**系统能力:** SystemCapability.MiscServices.InputMethodFramework
4702
4703**参数:**
4704
4705| 参数名 | 类型 | 必填 | 说明 |
4706| -------- | -------- | -------- | -------- |
4707| length | number | 是 | 文本长度。不能小于0。|
4708
4709**返回值:**
4710
4711| 类型                            | 说明                                                         |
4712| ------------------------------- | ------------------------------------------------------------ |
4713| Promise&lt;string&gt; |  Promise对象,返回光标前固定长度的文本。                |
4714
4715**示例:**
4716
4717```ts
4718import { BusinessError } from '@kit.BasicServicesKit';
4719
4720let length = 1;
4721textInputClient.getForward(length).then((text: string) => {
4722  console.log('Succeeded in getting forward, text: ' + text);
4723}).catch((err: BusinessError) => {
4724  console.error(`Failed to getForward: ${JSON.stringify(err)}`);
4725});
4726```
4727
4728### getBackward<sup>(deprecated)</sup>
4729
4730getBackward(length:number, callback: AsyncCallback&lt;string&gt;): void
4731
4732获取光标后固定长度的文本。使用callback异步回调。
4733
4734> **说明:**
4735>
4736> 从API version 8开始支持,API version 9开始废弃,建议使用[getBackward](#getbackward9)替代。
4737
4738**系统能力:** SystemCapability.MiscServices.InputMethodFramework
4739
4740**参数:**
4741
4742| 参数名 | 类型 | 必填 | 说明 |
4743| -------- | -------- | -------- | -------- |
4744| length | number | 是 | 文本长度。不能小于0。 |
4745| callback | AsyncCallback&lt;string&gt; | 是 | 回调函数。当光标后固定长度的文本获取成功,err为undefined,data为获取到的文本;否则为错误对象。 |
4746
4747**示例:**
4748
4749```ts
4750import { BusinessError } from '@kit.BasicServicesKit';
4751
4752let length = 1;
4753textInputClient.getBackward(length, (err: BusinessError, text: string) => {
4754  if (err) {
4755    console.error(`Failed to getBackward: ${JSON.stringify(err)}`);
4756    return;
4757  }
4758  console.log('Succeeded in getting borward, text: ' + text);
4759});
4760```
4761
4762### getBackward<sup>(deprecated)</sup>
4763
4764getBackward(length:number): Promise&lt;string&gt;
4765
4766获取光标后固定长度的文本。使用promise异步回调。
4767
4768> **说明:**
4769>
4770> 从API version 8开始支持,API version 9开始废弃,建议使用[getBackward](#getbackward9)替代。
4771
4772**系统能力:** SystemCapability.MiscServices.InputMethodFramework
4773
4774**参数:**
4775
4776| 参数名 | 类型 | 必填 | 说明 |
4777| -------- | -------- | -------- | -------- |
4778| length | number | 是 | 文本长度。不能小于0。 |
4779
4780**返回值:**
4781
4782| 类型                            | 说明                                                         |
4783| ------------------------------- | ------------------------------------------------------------ |
4784| Promise&lt;string&gt; |  Promise对象,返回光标后固定长度的文本。                |
4785
4786**示例:**
4787
4788```ts
4789import { BusinessError } from '@kit.BasicServicesKit';
4790
4791let length = 1;
4792textInputClient.getBackward(length).then((text: string) => {
4793  console.log('Succeeded in getting backward: ' + JSON.stringify(text));
4794}).catch((err: BusinessError) => {
4795  console.error(`Failed to getBackward: ${JSON.stringify(err)}`);
4796});
4797```
4798
4799### deleteForward<sup>(deprecated)</sup>
4800
4801deleteForward(length:number, callback: AsyncCallback&lt;boolean&gt;): void
4802
4803删除光标前固定长度的文本。使用callback异步回调。
4804
4805> **说明:**
4806>
4807> 从API version 8开始支持,API version 9开始废弃,建议使用[deleteForward](#deleteforward9)替代。
4808
4809**系统能力:** SystemCapability.MiscServices.InputMethodFramework
4810
4811**参数:**
4812
4813| 参数名 | 类型 | 必填 | 说明 |
4814| -------- | -------- | -------- | -------- |
4815| length | number | 是 | 文本长度。不能小于0。 |
4816| callback | AsyncCallback&lt;boolean&gt; | 是 | 回调函数。当光标前固定长度的文本删除成功,err为undefined,data为true;否则为错误对象。 |
4817
4818**示例:**
4819
4820```ts
4821import { BusinessError } from '@kit.BasicServicesKit';
4822
4823let length = 1;
4824textInputClient.deleteForward(length, (err: BusinessError, result: boolean) => {
4825  if (err) {
4826    console.error(`Failed to deleteForward: ${JSON.stringify(err)}`);
4827    return;
4828  }
4829  if (result) {
4830    console.log('Succeeded in deleting forward.');
4831  } else {
4832    console.error('Failed to deleteForward.');
4833  }
4834});
4835```
4836
4837### deleteForward<sup>(deprecated)</sup>
4838
4839deleteForward(length:number): Promise&lt;boolean&gt;
4840
4841删除光标前固定长度的文本。使用promise异步回调。
4842
4843> **说明:**
4844>
4845> 从API version 8开始支持,API version 9开始废弃,建议使用[deleteForward](#deleteforward9)替代。
4846
4847**系统能力:** SystemCapability.MiscServices.InputMethodFramework
4848
4849**参数:**
4850
4851| 参数名 | 类型   | 必填 | 说明       |
4852| ------ | ------ | ---- | ---------- |
4853| length | number | 是   | 文本长度。不能小于0。 |
4854
4855**返回值:**
4856
4857| 类型                   | 说明           |
4858| ---------------------- | -------------- |
4859| Promise&lt;boolean&gt; | Promise对象。返回true表示删除光标前固定长度的文本成功;返回false表示删除光标前固定长度的文本失败。|
4860
4861**示例:**
4862
4863```ts
4864import { BusinessError } from '@kit.BasicServicesKit';
4865
4866let length = 1;
4867textInputClient.deleteForward(length).then((result: boolean) => {
4868  if (result) {
4869    console.log('Succeeded in deleting forward.');
4870  } else {
4871    console.error('Failed to delete forward.');
4872  }
4873}).catch((err: BusinessError) => {
4874  console.error(`Failed to deleteForward: ${JSON.stringify(err)}`);
4875});
4876```
4877
4878### deleteBackward<sup>(deprecated)</sup>
4879
4880deleteBackward(length:number, callback: AsyncCallback&lt;boolean&gt;): void
4881
4882删除光标后固定长度的文本。使用callback异步回调。
4883
4884> **说明:**
4885>
4886> 从API version 8开始支持,API version 9开始废弃,建议使用[deleteBackward](#deletebackward9)替代。
4887
4888**系统能力:** SystemCapability.MiscServices.InputMethodFramework
4889
4890**参数:**
4891
4892| 参数名   | 类型                         | 必填 | 说明           |
4893| -------- | ---------------------------- | ---- | -------------- |
4894| length   | number                       | 是   | 文本长度。不能小于0。      |
4895| callback | AsyncCallback&lt;boolean&gt; | 是   | 回调函数。当光标后固定长度的文本删除成功,err为undefined,data为true;否则为错误对象。|
4896
4897**示例:**
4898
4899```ts
4900import { BusinessError } from '@kit.BasicServicesKit';
4901
4902let length = 1;
4903textInputClient.deleteBackward(length, (err: BusinessError, result: boolean) => {
4904  if (err) {
4905    console.error(`Failed to deleteBackward: ${JSON.stringify(err)}`);
4906    return;
4907  }
4908  if (result) {
4909    console.log('Succeeded in deleting backward.');
4910  } else {
4911    console.error('Failed to deleteBackward.');
4912  }
4913});
4914```
4915
4916### deleteBackward<sup>(deprecated)</sup>
4917
4918deleteBackward(length:number): Promise&lt;boolean&gt;
4919
4920删除光标后固定长度的文本。使用promise异步回调。
4921
4922> **说明:**
4923>
4924> 从API version 8开始支持,API version 9开始废弃,建议使用[deleteBackward](#deletebackward9)替代。
4925
4926**系统能力:** SystemCapability.MiscServices.InputMethodFramework
4927
4928**参数:**
4929
4930| 参数名 | 类型 | 必填 | 说明 |
4931| -------- | -------- | -------- | -------- |
4932| length | number | 是 | 文本长度。不能小于0。  |
4933
4934**返回值:**
4935
4936| 类型                            | 说明                                                         |
4937| ------------------------------- | ------------------------------------------------------------ |
4938| Promise&lt;boolean&gt; |  Promise对象。返回true表示删除光标后固定长度的文本成功;返回false表示删除光标后固定长度的文本失败。|
4939
4940**示例:**
4941
4942```ts
4943import { BusinessError } from '@kit.BasicServicesKit';
4944
4945let length = 1;
4946textInputClient.deleteBackward(length).then((result: boolean) => {
4947  if (result) {
4948    console.log('Succeeded in deleting backward.');
4949  } else {
4950    console.error('Failed to deleteBackward.');
4951  }
4952}).catch((err: BusinessError) => {
4953  console.error(`Failed to deleteBackward: ${JSON.stringify(err)}`);
4954});
4955```
4956### sendKeyFunction<sup>(deprecated)</sup>
4957
4958sendKeyFunction(action: number, callback: AsyncCallback&lt;boolean&gt;): void
4959
4960发送功能键。使用callback异步回调。
4961
4962> **说明:**
4963>
4964> 从API version 8开始支持,API version 9开始废弃,建议使用[sendKeyFunction](#sendkeyfunction9)替代。
4965
4966**系统能力:** SystemCapability.MiscServices.InputMethodFramework
4967
4968**参数:**
4969
4970| 参数名 | 类型 | 必填 | 说明 |
4971| -------- | -------- | -------- | -------- |
4972| action | number | 是 | 功能键键值。<br/>- 当值为0时,表示无效按键;<br/>- 当值为1时,表示确认键(即回车键)。 |
4973| callback | AsyncCallback&lt;boolean&gt; | 是 | 回调函数。当功能键发送成功,err为undefined,data为true;否则为错误对象。 |
4974
4975**示例:**
4976
4977```ts
4978import { BusinessError } from '@kit.BasicServicesKit';
4979
4980let action = 1;
4981textInputClient.sendKeyFunction(action, (err: BusinessError, result: boolean) => {
4982  if (err) {
4983    console.error(`Failed to sendKeyFunction: ${JSON.stringify(err)}`);
4984    return;
4985  }
4986  if (result) {
4987    console.log('Succeeded in sending key function.');
4988  } else {
4989    console.error('Failed to sendKeyFunction.');
4990  }
4991});
4992```
4993
4994### sendKeyFunction<sup>(deprecated)</sup>
4995
4996sendKeyFunction(action: number): Promise&lt;boolean&gt;
4997
4998发送功能键。使用promise异步回调。
4999
5000> **说明:**
5001>
5002> 从API version 8开始支持,API version 9开始废弃,建议使用[sendKeyFunction](#sendkeyfunction9)替代。
5003
5004**系统能力:** SystemCapability.MiscServices.InputMethodFramework
5005
5006**参数:**
5007
5008| 参数名 | 类型 | 必填 | 说明 |
5009| -------- | -------- | -------- | -------- |
5010| action | number | 是 | 功能键键值。<br/>当值为0时,表示无效按键;<br/>当值为1时,表示确认键(即回车键)。 |
5011
5012**返回值:**
5013
5014| 类型                            | 说明                                                         |
5015| ------------------------------- | ------------------------------------------------------------ |
5016| Promise&lt;boolean&gt; |  Promise对象。返回true表示发送功能键成功;返回false表示发送功能键失败。 |
5017
5018**示例:**
5019
5020```ts
5021import { BusinessError } from '@kit.BasicServicesKit';
5022
5023let action = 1;
5024textInputClient.sendKeyFunction(action).then((result: boolean) => {
5025  if (result) {
5026    console.log('Succeeded in sending key function.');
5027  } else {
5028    console.error('Failed to sendKeyFunction.');
5029  }
5030}).catch((err: BusinessError) => {
5031  console.error(`Failed to sendKeyFunction: ${JSON.stringify(err)}`);
5032});
5033```
5034
5035### insertText<sup>(deprecated)</sup>
5036
5037insertText(text:string, callback: AsyncCallback&lt;boolean&gt;): void
5038
5039插入文本。使用callback异步回调。
5040
5041> **说明:**
5042>
5043> 从API version 8开始支持,API version 9开始废弃,建议使用[insertText](#inserttext9)替代。
5044
5045**系统能力:** SystemCapability.MiscServices.InputMethodFramework
5046
5047**参数:**
5048
5049| 参数名 | 类型 | 必填 | 说明 |
5050| -------- | -------- | -------- | -------- |
5051| text | string | 是 | 文本。 |
5052| callback | AsyncCallback&lt;boolean&gt; | 是 | 回调函数。当文本插入成功,err为undefined,data为true;否则为错误对象。 |
5053
5054**示例:**
5055
5056```ts
5057import { BusinessError } from '@kit.BasicServicesKit';
5058
5059textInputClient.insertText('test', (err: BusinessError, result: boolean) => {
5060  if (err) {
5061    console.error(`Failed to insertText: ${JSON.stringify(err)}`);
5062    return;
5063  }
5064  if (result) {
5065    console.log('Succeeded in inserting text.');
5066  } else {
5067    console.error('Failed to insertText.');
5068  }
5069});
5070```
5071
5072### insertText<sup>(deprecated)</sup>
5073
5074insertText(text:string): Promise&lt;boolean&gt;
5075
5076插入文本。使用promise异步回调。
5077
5078> **说明:**
5079>
5080> 从API version 8开始支持,API version 9开始废弃,建议使用[insertText](#inserttext9)替代。
5081
5082**系统能力:** SystemCapability.MiscServices.InputMethodFramework
5083
5084**参数:**
5085
5086| 参数名 | 类型 | 必填 | 说明 |
5087| -------- | -------- | -------- | -------- |
5088| text | string | 是 | 文本。 |
5089
5090**返回值:**
5091
5092| 类型                            | 说明                                                         |
5093| ------------------------------- | ------------------------------------------------------------ |
5094| Promise&lt;boolean&gt; |  Promise对象。返回true表示插入文本成功;返回false表示插入文本失败。 |
5095
5096**示例:**
5097
5098```ts
5099import { BusinessError } from '@kit.BasicServicesKit';
5100
5101textInputClient.insertText('test').then((result: boolean) => {
5102  if (result) {
5103    console.log('Succeeded in inserting text.');
5104  } else {
5105    console.error('Failed to insertText.');
5106  }
5107}).catch((err: BusinessError) => {
5108  console.error(`Failed to insertText: ${JSON.stringify(err)}`);
5109});
5110```
5111
5112### getEditorAttribute<sup>(deprecated)</sup>
5113
5114getEditorAttribute(callback: AsyncCallback&lt;EditorAttribute&gt;): void
5115
5116获取编辑框属性值。使用callback异步回调。
5117
5118> **说明:**
5119>
5120> 从API version 8开始支持,API version 9开始废弃,建议使用[getEditorAttribute](#geteditorattribute9)替代。
5121
5122**系统能力:** SystemCapability.MiscServices.InputMethodFramework
5123
5124**参数:**
5125
5126| 参数名    | 类型   | 必填  | 说明   |
5127| -------- | ----- | ----- | ----- |
5128| callback | AsyncCallback&lt;[EditorAttribute](#editorattribute)&gt; | 是 |  回调函数。当编辑框的属性值获取成功,err为undefined,data为编辑框属性值;否则为错误对象。|
5129
5130**示例:**
5131
5132```ts
5133import { BusinessError } from '@kit.BasicServicesKit';
5134
5135textInputClient.getEditorAttribute((err: BusinessError, editorAttribute: inputMethodEngine.EditorAttribute) => {
5136  if (err) {
5137    console.error(`Failed to getEditorAttribute: ${JSON.stringify(err)}`);
5138    return;
5139  }
5140  console.log(`editorAttribute.inputPattern: ${editorAttribute.inputPattern}`;
5141  console.log(`editorAttribute.enterKeyType: ${editorAttribute.enterKeyType}`);
5142});
5143```
5144
5145### getEditorAttribute<sup>(deprecated)</sup>
5146
5147getEditorAttribute(): Promise&lt;EditorAttribute&gt;
5148
5149获取编辑框属性值。使用promise异步回调。
5150
5151> **说明:**
5152>
5153> 从API version 8开始支持,API version 9开始废弃,建议使用[getEditorAttribute](#geteditorattribute9)替代。
5154
5155**系统能力:** SystemCapability.MiscServices.InputMethodFramework
5156
5157**返回值:**
5158
5159| 类型                            | 说明                                                         |
5160| ------------------------------- | ------------------------------------------------------------ |
5161| Promise&lt;[EditorAttribute](#editorattribute)&gt; |  Promise对象,返回编辑框属性值。           |
5162
5163**示例:**
5164
5165```ts
5166import { BusinessError } from '@kit.BasicServicesKit';
5167
5168textInputClient.getEditorAttribute().then((editorAttribute: inputMethodEngine.EditorAttribute) => {
5169  console.log('editorAttribute.inputPattern: ' + JSON.stringify(editorAttribute.inputPattern));
5170  console.log('editorAttribute.enterKeyType: ' + JSON.stringify(editorAttribute.enterKeyType));
5171}).catch((err: BusinessError) => {
5172  console.error(`Failed to getEditorAttribute: ${JSON.stringify(err)}`);
5173});
5174```
5175<!--no_check-->