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