• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1import prompt from '@ohos.prompt';
2/*
3 * Copyright (c) 2022 Huawei Device Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *     http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16import inputmethodengine from '@ohos.inputMethodEngine';
17import display from '@ohos.display';
18import windowManager from '@ohos.window';
19import commoneventmanager from '@ohos.commonEventManager';
20
21
22let inputMethodEngine = inputmethodengine.getInputMethodEngine();
23let inputKeyboardDelegate = inputmethodengine.createKeyboardDelegate();
24let inputMethodAbility = inputmethodengine.getInputMethodAbility();
25const TAG = "keyboardController";
26
27export class KeyboardController {
28    mContext;
29    WINDOW_TYPE_INPUT_METHOD_FLOAT = 2105;
30    windowName = 'inputApp';
31    private windowHeight: number = 0;
32    private windowWidth: number = 0;
33    private nonBarPosition: number = 0;
34
35    constructor(context) {
36        this.mContext = context;
37    }
38
39    public onCreate(): void {
40        this.initWindow();
41        let that = this;
42        inputMethodAbility.on("inputStop", () => {
43            inputMethodAbility.off("inputStop", () => {
44                console.log('====>inputMethodEngine delete inputStop notification.');
45            });
46            try{
47                that.mContext.destroy((err) => {
48                    console.info(TAG + '====>inputMethodEngine destroy err:' + JSON.stringify(err));
49                })
50            }catch(err){
51                console.info(TAG + '====>inputMethodEngine destroy catch err:' + JSON.stringify(err));
52            }
53        })
54
55        function subscriberCallback(err, data) {
56            console.debug(TAG + '====>receive event err: ' + JSON.stringify(err));
57            console.debug(TAG + '====>receive event data ' + JSON.stringify(data));
58            switch (data.code) {
59                case 1:
60                    console.debug(TAG + '====>inputMethodEngine_test_getInputMethodEngine_001 event:' + data.event);
61                    that.inputMethodEngine_test_getInputMethodEngine_001();
62                    break;
63                case 2:
64                    console.debug(TAG + '====>inputMethodEngine_test_getKeyboardDelegate_001 event:' + data.event);
65                    that.inputMethodEngine_test_getKeyboardDelegate_001();
66                    break;
67                case 28:
68                    console.debug(TAG + '====>inputMethodEngine_test_028 event:' + data.event);
69                    that.inputMethodEngine_test_028();
70                    break;
71                case 29:
72                    console.debug(TAG + '====>inputMethodEngine_test_029 event:' + data.event);
73                    that.inputMethodEngine_test_029();
74                    break;
75                case 30:
76                    console.debug(TAG + '====>inputMethodEngine_test_030 event:' + data.event);
77                    that.inputMethodEngine_test_030();
78                    break;
79                case 31:
80                    console.debug(TAG + '====>inputMethodEngine_test_031 event:' + data.event);
81                    that.inputMethodEngine_test_031();
82                    break;
83                case 32:
84                    console.debug(TAG + '====>inputMethodEngine_test_032 event:' + data.event);
85                    that.inputMethodEngine_test_032();
86                    break;
87                case 33:
88                    console.debug(TAG + '====>inputMethodEngine_test_033 event:' + data.event);
89                    that.inputMethodEngine_test_033();
90                    break;
91                case 34:
92                    console.debug(TAG + '====>inputMethodEngine_test_034 event:' + data.event);
93                    that.inputMethodEngine_test_034();
94                    break;
95                case 35:
96                    console.debug(TAG + '====>inputMethodEngine_test_035 event:' + data.event);
97                    that.inputMethodEngine_test_035();
98                    break;
99                case 36:
100                    console.debug(TAG + '====>inputMethodEngine_test_036 event:' + data.event);
101                    that.inputMethodEngine_test_036();
102                    break;
103                case 37:
104                    console.debug(TAG + '====>inputMethodEngine_test_037 event:' + data.event);
105                    that.inputMethodEngine_test_037();
106                    break;
107                case 38:
108                    console.debug(TAG + '====>inputMethodEngine_test_038 event:' + data.event);
109                    that.inputMethodEngine_test_038();
110                    break;
111                case 39:
112                    console.debug(TAG + '====>inputMethodEngine_test_039 event:' + data.event);
113                    that.inputMethodEngine_test_039();
114                    break;
115                case 40:
116                    console.debug(TAG + '====>inputMethodEngine_test_040 event:' + data.event);
117                    that.inputMethodEngine_test_040();
118                    break;
119                case 41:
120                    console.debug(TAG + '====>inputMethodEngine_test_041 event:' + data.event);
121                    that.inputMethodEngine_test_041();
122                    break;
123                case 42:
124                    console.debug(TAG + '====>inputMethodEngine_test_042 event:' + data.event);
125                    that.inputMethodEngine_test_042();
126                    break;
127                case 43:
128                    console.debug(TAG + '====>inputMethodEngine_test_043 event:' + data.event);
129                    that.inputMethodEngine_test_043();
130                    break;
131                case 49:
132                    console.debug(TAG + '====>inputMethodEngine_test_049 event:' + data.event);
133                    that.inputMethodEngine_test_049();
134                    break;
135                case 50:
136                    console.debug(TAG + '====>inputMethodEngine_test_050 event:' + data.event);
137                    that.inputMethodEngine_test_050();
138                    break;
139                case 71:
140                    console.debug(TAG + '====>inputMethodEngine_test_071 event:' + data.event);
141                    that.inputMethodEngine_test_071();
142                    break;
143                case 72:
144                    console.debug(TAG + '====>inputMethodEngine_test_072 event:' + data.event);
145                    that.inputMethodEngine_test_072();
146                    break;
147                case 73:
148                    console.debug(TAG + '====>inputMethodEngine_test_073 event:' + data.event);
149                    that.inputMethodEngine_test_073();
150                    break;
151                case 74:
152                    console.debug(TAG + '====>inputMethodEngine_test_074 event:' + data.event);
153                    that.inputMethodEngine_test_074();
154                    break;
155                case 76:
156                    console.debug(TAG + '====>inputMethodEngine_test_076 event:' + data.event);
157                    that.inputMethodEngine_test_076();
158                    break;
159                case 77:
160                    console.debug(TAG + '====>inputMethodEngine_test_077 event:' + data.event);
161                    that.inputMethodEngine_test_077();
162                    break;
163            }
164        }
165
166        var commonEventSubscribeInfo = {
167            events: ["test1"]
168        };
169
170        var subscriber;
171        commoneventmanager.createSubscriber(commonEventSubscribeInfo).then(function (data) {
172            subscriber = data;
173            commoneventmanager.subscribe(subscriber, subscriberCallback);
174            console.debug(TAG + '====>scene subscribe finish====');
175        });
176    }
177
178    public onDestroy(): void {
179        console.log('imsakitjsapp onDestroy');
180        globalThis.textInputClient.getTextIndexAtCursor().then((index) => {
181            console.log('imsakitjsapp getTextIndexAtCursor:  index = ' + index);
182            prompt.showToast({ message: 'getTextIndexAtCursor success' + index, duration: 200, bottom: 500 });
183            var win = windowManager.findWindow(this.windowName);
184            win.destroyWindow();
185            this.mContext.terminateSelf();
186            return true;
187        }).catch((err) => {
188            prompt.showToast({ message: 'getTextIndexAtCursor failed', duration: 200, bottom: 500 });
189        });
190    }
191
192    private initWindow(): void {
193        display.getDefaultDisplay().then(dis => {
194            var dWidth = dis.width;
195            var dHeight = dis.height;
196            var keyHeightRate = 0.47;
197            var keyHeight = dHeight * keyHeightRate;
198            this.windowWidth = dWidth;
199            this.windowHeight = keyHeight;
200            this.nonBarPosition = dHeight - keyHeight;
201
202            var config = {
203                name: this.windowName,
204                windowType: this.WINDOW_TYPE_INPUT_METHOD_FLOAT,
205                ctx: this.mContext
206            };
207            windowManager.createWindow(config).then((win) => {
208                win.resize(dWidth, keyHeight).then(() => {
209                    win.moveWindowTo(0, this.nonBarPosition).then(() => {
210                        win.setUIContent('pages/service/index').then(() => {
211                        });
212                    });
213                });
214            });
215        });
216    }
217
218    private publishCallback(err): void {
219        if (err) {
220            console.error(TAG + '====>publish failed: ' + JSON.stringify(err));
221        } else {
222            console.log(TAG + '====>publish');
223        }
224    }
225
226    private inputMethodEngine_test_getInputMethodEngine_001(): void {
227        console.debug(TAG + '====>receive inputMethodEngine_test_getInputMethodEngine_001 data');
228        if (typeof(inputMethodEngine) === "object") {
229            console.info(TAG + '====>receive inputMethodEngine_test_getInputMethodEngine_001 object');
230            var commonEventPublishData = {
231                data: "SUCCESS"
232            };
233        } else {
234            console.info(TAG + '====>receive inputMethodEngine_test_getInputMethodEngine_001 failed');
235            var commonEventPublishData = {
236                data: "FAILED"
237            };
238        }
239        commoneventmanager.publish("inputMethodEngine_test_getInputMethodEngine_001", commonEventPublishData, this.publishCallback);
240    }
241
242    private inputMethodEngine_test_getKeyboardDelegate_001(): void {
243        console.debug(TAG + '====>receive inputMethodEngine_test_getKeyboardDelegate_001 data');
244        if (typeof(inputKeyboardDelegate) === "object") {
245            console.info(TAG + '====>receive inputMethodEngine_test_getKeyboardDelegate_001 object');
246            var commonEventPublishData = {
247                data: "SUCCESS"
248            };
249        } else {
250            console.info(TAG + '====>receive inputMethodEngine_test_getKeyboardDelegate_001 failed');
251            var commonEventPublishData = {
252                data: "FAILED"
253            };
254        }
255        commoneventmanager.publish("inputMethodEngine_test_getKeyboardDelegate_001", commonEventPublishData, this.publishCallback);
256    }
257
258    private inputMethodEngine_test_028(): void {
259        console.debug(TAG + '====>receive inputMethodEngine_test_028 data');
260        inputMethodEngine.on('inputStart', async (keyboardController, TextInputClient) => {
261            inputMethodEngine.off('inputStart');
262            let commonEventPublishData;
263            if (TextInputClient == null) {
264                commonEventPublishData = {
265                    data: "FAILED"
266                };
267                commoneventmanager.publish("inputMethodEngine_test_028", commonEventPublishData, this.publishCallback);
268            } else {
269                let editorAttribyte = await TextInputClient.getEditorAttribute();
270                console.debug(TAG + '====>receive inputMethodEngine_test_028 editorAttribyte: ' + JSON.stringify(editorAttribyte));
271                TextInputClient.sendKeyFunction(editorAttribyte.enterKeyType, (err, value) => {
272                    if (err) {
273                        commonEventPublishData = {
274                            data: "FAILED"
275                        };
276                        console.debug(TAG + '====>inputMethodEngine_test_028 TextInputClient sendKeyFunction err: ' + JSON.stringify(err));
277                    } else {
278                        console.debug(TAG + '====>inputMethodEngine_test_028 TextInputClient sendKeyFunction value: ' + JSON.stringify(value));
279                        if (value) {
280                            commonEventPublishData = {
281                                data: "SUCCESS"
282                            };
283                        } else {
284                            commonEventPublishData = {
285                                data: "FAILED"
286                            };
287                        }
288
289                    }
290                    commoneventmanager.publish("inputMethodEngine_test_028", commonEventPublishData, this.publishCallback);
291                });
292            }
293        });
294    }
295    private inputMethodEngine_test_029(): void{
296        console.debug(TAG + '====>receive inputMethodEngine_test_029 data');
297        inputMethodEngine.on('inputStart', async(KeyboardDelegate, InputClient) =>{
298            inputMethodEngine.off('inputStart');
299            let commonEventPublishData;
300            if (InputClient == null) {
301                commonEventPublishData = {
302                    data: "FAILED"
303                };
304                commoneventmanager.publish("inputMethodEngine_test_029", commonEventPublishData, this.publishCallback);
305            } else {
306                let editorAttribyte = await InputClient.getEditorAttribute();
307                console.debug(TAG + '====>inputMethodEngine_test_029 editorAttribyte:' + JSON.stringify(editorAttribyte));
308                let value = await InputClient.sendKeyFunction(editorAttribyte.enterKeyType);
309                console.debug(TAG + '====>inputMethodEngine_test_029 sendKeyFunction:' + JSON.stringify(value));
310                if (value){
311                    commonEventPublishData = {
312                        data: "SUCCESS"
313                    };
314                } else {
315                    commonEventPublishData = {
316                        data: "FAILED"
317                    };
318                }
319                commoneventmanager.publish("inputMethodEngine_test_029", commonEventPublishData, this.publishCallback);
320            }
321        });
322    }
323
324    private inputMethodEngine_test_030(): void{
325        console.debug(TAG + '====>receive inputMethodEngine_test_030 data');
326        inputMethodEngine.on('inputStart', async(KeyboardDelegate, InputClient) =>{
327            inputMethodEngine.off('inputStart');
328            let commonEventPublishData;
329            if (InputClient == null) {
330                commonEventPublishData = {
331                    data: "FAILED"
332                };
333                commoneventmanager.publish("inputMethodEngine_test_030", commonEventPublishData, this.publishCallback);
334            } else {
335                InputClient.deleteForward(1, (err, value) => {
336                    if (err){
337                        console.debug(TAG + '====>inputMethodEngine_test_030 deleteForward err:' + JSON.stringify(err));
338                        commonEventPublishData = {
339                            data: "FAILED"
340                        };
341                    } else {
342                        console.debug(TAG + '====>inputMethodEngine_test_030 deleteForward value:' + JSON.stringify(value));
343                        if (typeof(value) === 'boolean'){
344                            commonEventPublishData = {
345                                data: "SUCCESS"
346                            };
347                        } else {
348                            commonEventPublishData = {
349                                data: "FAILED"
350                            };
351                        }
352                    }
353                    commoneventmanager.publish("inputMethodEngine_test_030", commonEventPublishData, this.publishCallback);
354                });
355            }
356        });
357    }
358    private inputMethodEngine_test_031(): void{
359        console.debug(TAG + '====>receive inputMethodEngine_test_031 data');
360        inputMethodEngine.on('inputStart', async(KeyboardDelegate, InputClient) =>{
361            inputMethodEngine.off('inputStart');
362            let commonEventPublishData;
363            if (InputClient == null) {
364                commonEventPublishData = {
365                    data: "FAILED"
366                };
367                commoneventmanager.publish("inputMethodEngine_test_031", commonEventPublishData, this.publishCallback);
368            } else {
369                let value = await InputClient.deleteForward(1);
370                console.debug(TAG + '====>inputMethodEngine_test_031 deleteForward:' + JSON.stringify(value));
371                if (typeof(value) === 'boolean'){
372                    commonEventPublishData = {
373                        data: "SUCCESS"
374                    };
375                } else {
376                    commonEventPublishData = {
377                        data: "FAILED"
378                    };
379                }
380                commoneventmanager.publish("inputMethodEngine_test_031", commonEventPublishData, this.publishCallback);
381            }
382        });
383    }
384
385    private inputMethodEngine_test_032(): void{
386        console.debug(TAG + '====>receive inputMethodEngine_test_032 data');
387        inputMethodEngine.on('inputStart', async(KeyboardDelegate, InputClient) =>{
388            inputMethodEngine.off('inputStart');
389            let commonEventPublishData;
390            if (InputClient == null) {
391                commonEventPublishData = {
392                    data: "FAILED"
393                };
394                commoneventmanager.publish("inputMethodEngine_test_032", commonEventPublishData, this.publishCallback);
395            } else {
396                InputClient.deleteBackward(1, (err, value) => {
397                    if (err){
398                        console.debug(TAG + '====>inputMethodEngine_test_032 deleteBackward err:' + JSON.stringify(err));
399                        commonEventPublishData = {
400                            data: "FAILED"
401                        };
402                    } else {
403                        console.debug(TAG + '====>inputMethodEngine_test_032 deleteBackward value:' + JSON.stringify(value));
404                        if (value){
405                            commonEventPublishData = {
406                                data: "SUCCESS"
407                            };
408                        } else {
409                            commonEventPublishData = {
410                                data: "FAILED"
411                            };
412                        }
413                    }
414                    commoneventmanager.publish("inputMethodEngine_test_032", commonEventPublishData, this.publishCallback);
415                });
416            }
417        });
418    }
419    private inputMethodEngine_test_033(): void{
420        console.debug(TAG + '====>receive inputMethodEngine_test_033 data');
421        inputMethodEngine.on('inputStart', async(KeyboardDelegate, InputClient) =>{
422            inputMethodEngine.off('inputStart');
423            let commonEventPublishData;
424            if (InputClient == null) {
425                commonEventPublishData = {
426                    data: "FAILED"
427                };
428                commoneventmanager.publish("inputMethodEngine_test_033", commonEventPublishData, this.publishCallback);
429            } else {
430                let value = await InputClient.deleteBackward(1);
431                console.debug(TAG + '====>inputMethodEngine_test_033 deleteBackward:' + JSON.stringify(value));
432                if (value){
433                    commonEventPublishData = {
434                        data: "SUCCESS"
435                    };
436                } else {
437                    commonEventPublishData = {
438                        data: "FAILED"
439                    };
440                }
441                commoneventmanager.publish("inputMethodEngine_test_033", commonEventPublishData, this.publishCallback);
442            }
443        });
444    }
445
446    private inputMethodEngine_test_034(): void{
447        console.debug(TAG + '====>receive inputMethodEngine_test_034 data');
448        inputMethodEngine.on('inputStart', async(KeyboardDelegate, InputClient) =>{
449            inputMethodEngine.off('inputStart');
450            let commonEventPublishData;
451            if (InputClient == null) {
452                commonEventPublishData = {
453                    data: "FAILED"
454                };
455                commoneventmanager.publish("inputMethodEngine_test_034", commonEventPublishData, this.publishCallback);
456            } else {
457                InputClient.insertText('test', (err, value) => {
458                    if (err){
459                        console.debug(TAG + '====>inputMethodEngine_test_034 insertText err:' + JSON.stringify(err));
460                        commonEventPublishData = {
461                            data: "FAILED"
462                        };
463                    } else {
464                        console.debug(TAG + '====>inputMethodEngine_test_034 insertText value:' + JSON.stringify(value));
465                        if (value){
466                            commonEventPublishData = {
467                                data: "SUCCESS"
468                            };
469                        } else {
470                            commonEventPublishData = {
471                                data: "FAILED"
472                            };
473                        }
474                    }
475                    commoneventmanager.publish("inputMethodEngine_test_034", commonEventPublishData, this.publishCallback);
476                });
477            }
478        });
479    }
480    private inputMethodEngine_test_035(): void{
481        console.debug(TAG + '====>receive inputMethodEngine_test_035 data');
482        inputMethodEngine.on('inputStart', async(KeyboardDelegate, InputClient) =>{
483            inputMethodEngine.off('inputStart');
484            let commonEventPublishData;
485            if (InputClient == null) {
486                commonEventPublishData = {
487                    data: "FAILED"
488                };
489                commoneventmanager.publish("inputMethodEngine_test_035", commonEventPublishData, this.publishCallback);
490            } else {
491                let value = await InputClient.insertText('test');
492                console.debug(TAG + '====>inputMethodEngine_test_035 insertText:' + JSON.stringify(value));
493                if (value){
494                    commonEventPublishData = {
495                        data: "SUCCESS"
496                    };
497                } else {
498                    commonEventPublishData = {
499                        data: "FAILED"
500                    };
501                }
502                commoneventmanager.publish("inputMethodEngine_test_035", commonEventPublishData, this.publishCallback);
503            }
504        });
505    }
506
507    private inputMethodEngine_test_036(): void{
508        console.debug(TAG + '====>receive inputMethodEngine_test_036 data');
509        inputMethodEngine.on('inputStart', async(KeyboardDelegate, InputClient) =>{
510            inputMethodEngine.off('inputStart');
511            let commonEventPublishData;
512            if (InputClient == null) {
513                commonEventPublishData = {
514                    data: "FAILED"
515                };
516                commoneventmanager.publish("inputMethodEngine_test_036", commonEventPublishData, this.publishCallback);
517            } else {
518                InputClient.getForward(1, (err, value) => {
519                    if (err){
520                        console.debug(TAG + '====>inputMethodEngine_test_036 getForward err:' + JSON.stringify(err));
521                        commonEventPublishData = {
522                            data: "FAILED"
523                        };
524                    } else {
525                        console.debug(TAG + '====>inputMethodEngine_test_036 getForward value:' + JSON.stringify(value));
526                        if (value){
527                            commonEventPublishData = {
528                                data: "SUCCESS"
529                            };
530                        } else {
531                            commonEventPublishData = {
532                                data: "FAILED"
533                            };
534                        }
535                    }
536                    commoneventmanager.publish("inputMethodEngine_test_036", commonEventPublishData, this.publishCallback);
537                });
538            }
539        });
540    }
541    private inputMethodEngine_test_037(): void{
542        console.debug(TAG + '====>receive inputMethodEngine_test_037 data');
543        inputMethodEngine.on('inputStart', async(KeyboardDelegate, InputClient) =>{
544            inputMethodEngine.off('inputStart');
545            let commonEventPublishData;
546            if (InputClient == null) {
547                commonEventPublishData = {
548                    data: "FAILED"
549                };
550                commoneventmanager.publish("inputMethodEngine_test_037", commonEventPublishData, this.publishCallback);
551            } else {
552                let value = await InputClient.getForward(1);
553                console.debug(TAG + '====>inputMethodEngine_test_037 getForward:' + JSON.stringify(value));
554                if (value){
555                    commonEventPublishData = {
556                        data: "SUCCESS"
557                    };
558                } else {
559                    commonEventPublishData = {
560                        data: "FAILED"
561                    };
562                }
563                commoneventmanager.publish("inputMethodEngine_test_037", commonEventPublishData, this.publishCallback);
564            }
565        });
566    }
567
568    private inputMethodEngine_test_038(): void{
569        console.debug(TAG + '====>receive inputMethodEngine_test_038 data');
570        inputMethodEngine.on('inputStart', async(KeyboardDelegate, InputClient) =>{
571            inputMethodEngine.off('inputStart');
572            let commonEventPublishData;
573            if (InputClient == null) {
574                commonEventPublishData = {
575                    data: "FAILED"
576                };
577                commoneventmanager.publish("inputMethodEngine_test_038", commonEventPublishData, this.publishCallback);
578            } else {
579                InputClient.getEditorAttribute((err, value) => {
580                    if (err){
581                        console.debug(TAG + '====>inputMethodEngine_test_038 getEditorAttribute err:' + JSON.stringify(err));
582                        commonEventPublishData = {
583                            data: "FAILED"
584                        };
585                    } else {
586                        console.debug(TAG + '====>inputMethodEngine_test_038 getEditorAttribute value:' + JSON.stringify(value));
587                        if (value){
588                            commonEventPublishData = {
589                                data: "SUCCESS"
590                            };
591                        } else {
592                            commonEventPublishData = {
593                                data: "FAILED"
594                            };
595                        }
596                    }
597                    commoneventmanager.publish("inputMethodEngine_test_038", commonEventPublishData, this.publishCallback);
598                });
599            }
600        });
601    }
602    private inputMethodEngine_test_039(): void{
603        console.debug(TAG + '====>receive inputMethodEngine_test_039 data');
604        inputMethodEngine.on('inputStart', async(KeyboardDelegate, InputClient) =>{
605            inputMethodEngine.off('inputStart');
606            let commonEventPublishData;
607            if (InputClient == null) {
608                commonEventPublishData = {
609                    data: "FAILED"
610                };
611                commoneventmanager.publish("inputMethodEngine_test_039", commonEventPublishData, this.publishCallback);
612            } else {
613                let value = await InputClient.getEditorAttribute();
614                console.debug(TAG + '====>inputMethodEngine_test_039 getEditorAttribute:' + JSON.stringify(value));
615                if (value){
616                    commonEventPublishData = {
617                        data: "SUCCESS"
618                    };
619                } else {
620                    commonEventPublishData = {
621                        data: "FAILED"
622                    };
623                }
624                commoneventmanager.publish("inputMethodEngine_test_039", commonEventPublishData, this.publishCallback);
625            }
626        });
627    }
628
629    private inputMethodEngine_test_040(): void{
630        console.debug(TAG + '====>receive inputMethodEngine_test_040 data');
631        inputMethodEngine.on('inputStart', async(KeyboardDelegate, InputClient) =>{
632            inputMethodEngine.off('inputStart');
633            let commonEventPublishData;
634            if (InputClient == null) {
635                commonEventPublishData = {
636                    data: "FAILED"
637                };
638                commoneventmanager.publish("inputMethodEngine_test_040", commonEventPublishData, this.publishCallback);
639            } else {
640                try{
641                    KeyboardDelegate.hideKeyboard((err, value) => {
642                        if (err){
643                            console.debug(TAG + '====>inputMethodEngine_test_040 hideKeyboard:' + JSON.stringify(err));
644                            commonEventPublishData = {
645                                data: "FAILED"
646                            };
647                        } else {
648                            commonEventPublishData = {
649                                data: "SUCCESS"
650                            };
651                        }
652                        commoneventmanager.publish("inputMethodEngine_test_040", commonEventPublishData, this.publishCallback);
653                    });
654                }catch(err){
655                    commonEventPublishData = {
656                        data: "FAILED"
657                    };
658                    console.debug(TAG + '====>inputMethodEngine_test_040 hideKeyboard throw_err:');
659                    commoneventmanager.publish("inputMethodEngine_test_040", commonEventPublishData, this.publishCallback);
660                }
661            }
662        });
663    }
664    private inputMethodEngine_test_041(): void{
665        console.debug(TAG + '====>receive inputMethodEngine_test_041 data');
666        inputMethodEngine.on('inputStart', async(KeyboardDelegate, InputClient) =>{
667            inputMethodEngine.off('inputStart');
668            let commonEventPublishData;
669            if (InputClient == null) {
670                commonEventPublishData = {
671                    data: "FAILED"
672                };
673                commoneventmanager.publish("inputMethodEngine_test_041", commonEventPublishData, this.publishCallback);
674            } else {
675                try{
676                    await KeyboardDelegate.hideKeyboard();
677                    console.debug(TAG + '====>inputMethodEngine_test_041 hideKeyboard success');
678                    commonEventPublishData = {
679                        data: "SUCCESS"
680                    };
681                }catch(err){
682                    commonEventPublishData = {
683                        data: "FAILED"
684                    };
685                    console.debug(TAG + '====>inputMethodEngine_test_041 hideKeyboard catch err:');
686                }
687                commoneventmanager.publish("inputMethodEngine_test_041", commonEventPublishData, this.publishCallback);
688            }
689        });
690    }
691
692    private inputMethodEngine_test_042(): void{
693        console.debug(TAG + '====>receive inputMethodEngine_test_042 data');
694        inputMethodEngine.on('inputStart', async(KeyboardDelegate, InputClient) =>{
695            inputMethodEngine.off('inputStart');
696            let commonEventPublishData;
697            if (InputClient == null) {
698                commonEventPublishData = {
699                    data: "FAILED"
700                };
701                commoneventmanager.publish("inputMethodEngine_test_042", commonEventPublishData, this.publishCallback);
702            } else {
703                InputClient.getBackward(1, (err, value) => {
704                    if (err){
705                        console.debug(TAG + '====>inputMethodEngine_test_042 getBackward err:' + JSON.stringify(err));
706                        commonEventPublishData = {
707                            data: "FAILED"
708                        };
709                    } else {
710                        console.debug(TAG + '====>inputMethodEngine_test_042 getBackward value:' + JSON.stringify(value));
711                        commonEventPublishData = {
712                            data: "SUCCESS"
713                        };
714                    }
715                    commoneventmanager.publish("inputMethodEngine_test_042", commonEventPublishData, this.publishCallback);
716                });
717            }
718        });
719    }
720    private inputMethodEngine_test_043(): void{
721        console.debug(TAG + '====>receive inputMethodEngine_test_043 data');
722        inputMethodEngine.on('inputStart', async(KeyboardDelegate, InputClient) =>{
723            inputMethodEngine.off('inputStart');
724            let commonEventPublishData;
725            if (InputClient == null) {
726                commonEventPublishData = {
727                    data: "FAILED"
728                };
729                commoneventmanager.publish("inputMethodEngine_test_043", commonEventPublishData, this.publishCallback);
730            } else {
731                let value = await InputClient.getBackward(1);
732                console.debug(TAG + '====>inputMethodEngine_test_043 getBackward:' + JSON.stringify(value));
733                commonEventPublishData = {
734                    data: "SUCCESS"
735                };
736                commoneventmanager.publish("inputMethodEngine_test_043", commonEventPublishData, this.publishCallback);
737            }
738        });
739    }
740
741    private inputMethodEngine_test_049(): void{
742        console.debug(TAG + '====>receive inputMethodEngine_test_049 data');
743        inputMethodEngine.on('inputStart', async(KeyboardDelegate, InputClient) =>{
744            inputMethodEngine.off('inputStart');
745            let commonEventPublishData;
746            if (InputClient == null) {
747                commonEventPublishData = {
748                    data: "FAILED"
749                };
750                commoneventmanager.publish("inputMethodEngine_test_049", commonEventPublishData, this.publishCallback);
751            } else {
752                try{
753                    KeyboardDelegate.hide((err, value) => {
754                        if (err){
755                            console.debug(TAG + '====>inputMethodEngine_test_049 hide:' + JSON.stringify(err));
756                            commonEventPublishData = {
757                                data: "FAILED"
758                            };
759                        } else {
760                            commonEventPublishData = {
761                                data: "SUCCESS"
762                            };
763                        }
764                        commoneventmanager.publish("inputMethodEngine_test_049", commonEventPublishData, this.publishCallback);
765                    });
766                }catch(err){
767                    commonEventPublishData = {
768                        data: "FAILED"
769                    };
770                    console.debug(TAG + '====>inputMethodEngine_test_049 hide throw_err:');
771                    commoneventmanager.publish("inputMethodEngine_test_040", commonEventPublishData, this.publishCallback);
772                }
773            }
774        });
775    }
776    private inputMethodEngine_test_050(): void{
777        console.debug(TAG + '====>receive inputMethodEngine_test_050 data');
778        inputMethodEngine.on('inputStart', async(KeyboardDelegate, InputClient) =>{
779            inputMethodEngine.off('inputStart');
780            let commonEventPublishData;
781            if (InputClient == null) {
782                commonEventPublishData = {
783                    data: "FAILED"
784                };
785                commoneventmanager.publish("inputMethodEngine_test_050", commonEventPublishData, this.publishCallback);
786            } else {
787                try{
788                    await KeyboardDelegate.hide();
789                    console.debug(TAG + '====>inputMethodEngine_test_050 hideKeyboard success');
790                    commonEventPublishData = {
791                        data: "SUCCESS"
792                    };
793                }catch(err){
794                    commonEventPublishData = {
795                        data: "FAILED"
796                    };
797                    console.debug(TAG + '====>inputMethodEngine_test_050 hideKeyboard catch err:');
798                }
799                commoneventmanager.publish("inputMethodEngine_test_050", commonEventPublishData, this.publishCallback);
800            }
801        });
802    }
803
804    private inputMethodEngine_test_071(): void{
805        let commonEventPublishData = {
806            data: "FAILED"
807        };
808        console.info(TAG + '====>receive inputMethodEngine_test_071 success');
809        let count = 0;
810        inputMethodEngine.on('keyboardHide', () => {
811            count += 1;
812            inputMethodEngine.off("keyboardHide");
813            console.info(TAG + '====>inputMethodEngine.off("keyboardHide") count: ' + count);
814        });
815        inputMethodEngine.on('inputStart', (KeyboardDelegate, InputClient) => {
816            inputMethodEngine.off('inputStart');
817            console.info(TAG + '====>inputMethodEngine_test_071 inputMethodEngine.on("inputStart")');
818            let t = setInterval(async () => {
819                await KeyboardDelegate.hideKeyboard();
820                console.info(TAG + '====>KeyboardDelegate.hideKeyboard count: ' +  count);
821                if(count === 1){
822                    clearInterval(t);
823                }
824            },100);
825        });
826
827        let t = setTimeout(() => {
828            if(count === 1){
829                commonEventPublishData = {
830                    data: "SUCCESS"
831                };
832            }
833            commoneventmanager.publish("inputMethodEngine_test_071", commonEventPublishData, this.publishCallback);
834            clearTimeout(t);
835        },500);
836    }
837
838    private inputMethodEngine_test_072(): void{
839        let commonEventPublishData = {
840            data: "FAILED"
841        };
842        console.info(TAG + '====>receive inputMethodEngine_test_072 success');
843        let count = 0;
844        inputMethodEngine.on('keyboardShow', () => {
845            count += 1;
846            inputMethodEngine.off("keyboardShow");
847            console.info(TAG + '====>inputMethodEngine.off("keyboardShow") count: ' + count);
848        });
849
850        let t = setTimeout(() => {
851            if(count === 1){
852                commonEventPublishData = {
853                    data: "SUCCESS"
854                };
855            }
856            commoneventmanager.publish("inputMethodEngine_test_072", commonEventPublishData, this.publishCallback);
857            clearTimeout(t);
858        },500);
859    }
860
861    private inputMethodEngine_test_073(): void{
862        let commonEventPublishData = {
863            data: "FAILED"
864        };
865        console.info(TAG + '====>receive inputMethodEngine_test_073 success');
866        let count = 0;
867        inputKeyboardDelegate.on('keyDown', (keyEvent) => {
868            inputKeyboardDelegate.off('keyDown');
869            console.info(TAG + "====>inputKeyboardDelegate.on('keyDown') count: " + count);
870            if (keyEvent.keyCode === 2000){
871                count += 1;
872            }
873            return true;
874        });
875        inputKeyboardDelegate.on('keyUp', (keyEvent) => {
876            inputKeyboardDelegate.off('keyUp');
877            console.info(TAG + "====>inputKeyboardDelegate.on('keyUp') count: " + count);
878            if (keyEvent.keyCode === 2000){
879                count += 1;
880            }
881            return true;
882        });
883        let t = setTimeout(() => {
884            commonEventPublishData = {
885                data: "SUCCESS"
886            };
887            commoneventmanager.publish("inputMethodEngine_test_073", commonEventPublishData, this.publishCallback);
888            clearTimeout(t);
889        },300);
890    }
891
892    private inputMethodEngine_test_074(): void{
893        let commonEventPublishData = {
894            data: "FAILED"
895        };
896        console.info(TAG + '====>receive inputMethodEngine_test_074 success');
897        let count = 0;
898        inputKeyboardDelegate.on('cursorContextChange', (x, y, h) => {
899            console.info(TAG + "====>inputKeyboardDelegate.on('cursorContextChange') count: " + count);
900            if (count === 1){
901                inputKeyboardDelegate.off('cursorContextChange');
902            }
903            count += 1;
904            console.info(TAG + '====>inputMethodEngine_test_074 x,y,z: ' + x + "---" + y + "---" + h);
905        });
906        inputMethodEngine.on('inputStart', (KeyboardDelegate, InputClient) => {
907            inputMethodEngine.off('inputStart');
908            console.info(TAG + '====>inputMethodEngine_test_074 inputMethodEngine.on("inputStart")');
909            let t = setInterval(async () => {
910                await InputClient.insertText("ttt");
911                console.info(TAG + '====>KeyboardDelegate.insertText count: ' +  count);
912                if(count === 2){
913                    clearInterval(t);
914                }
915            },100);
916        });
917
918        let t = setTimeout(() => {
919            console.info(TAG + '====>inputMethodEngine_test_074 setTimeout: ' +  count);
920            if(count === 2){
921                commonEventPublishData = {
922                    data: "SUCCESS"
923                };
924            }
925            commoneventmanager.publish("inputMethodEngine_test_074", commonEventPublishData, this.publishCallback);
926            clearTimeout(t);
927        },1000);
928    }
929
930    private inputMethodEngine_test_076(): void{
931        let commonEventPublishData = {
932            data: "FAILED"
933        };
934        console.info(TAG + '====>receive inputMethodEngine_test_076 success');
935        inputKeyboardDelegate.on('selectionChange', (oldBegin, oldEnd, newBegin, newEnd) => {
936            console.info(TAG + "====>inputKeyboardDelegate.on('selectionChange')");
937            inputKeyboardDelegate.off('selectionChange');
938            commonEventPublishData = {
939                data: "SUCCESS"
940            };
941            console.info(TAG + '====>inputMethodEngine_test_076 oldBegin,oldEnd,newBegin,newEnd: ' + oldBegin + "---" + oldEnd + "---" + newBegin + "---" + newEnd);
942        });
943        let t = setTimeout(() => {
944            commoneventmanager.publish("inputMethodEngine_test_076", commonEventPublishData, this.publishCallback);
945            clearTimeout(t);
946        },2000);
947    }
948
949    private inputMethodEngine_test_077(): void{
950        let commonEventPublishData = {
951            data: "FAILED"
952        };
953        console.info(TAG + '====>receive inputMethodEngine_test_077 success');
954        let count = 0;
955        inputKeyboardDelegate.on('textChange', (text) => {
956            console.info(TAG + "====>inputKeyboardDelegate.on('textChange') count:" + count);
957            if (count === 1){
958                inputKeyboardDelegate.off('textChange');
959            }
960            count += 1;
961            console.info(TAG + '====>inputMethodEngine_test_077 text: ' + text);
962        });
963        inputMethodEngine.on('inputStart', (KeyboardDelegate, InputClient) => {
964            inputMethodEngine.off('inputStart');
965            console.info(TAG + '====>inputMethodEngine_test_077 inputMethodEngine.on("inputStart")');
966            let t = setInterval(async () => {
967                await InputClient.insertText("tttt");
968                console.info(TAG + '====>KeyboardDelegate.insertText count: ' +  count);
969                if(count === 2){
970                    clearInterval(t);
971                }
972            },100);
973        });
974        let t = setTimeout(() => {
975            console.info(TAG + '====>inputMethodEngine_test_077 setTimeout: ' +  count);
976            if(count === 2){
977                commonEventPublishData = {
978                    data: "SUCCESS"
979                };
980            }
981            commoneventmanager.publish("inputMethodEngine_test_077", commonEventPublishData, this.publishCallback);
982            clearTimeout(t);
983        },500);
984    }
985
986}