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