• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 2022 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 *     http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15import inputConsumer from '@ohos.multimodalInput.inputConsumer';
16import { Log } from '../utils/Log';
17
18
19const TAG = "MultimodalInputManager"
20
21export class MultimodalInputManager {
22
23    //win + N
24    leftKeyOptions: any = {
25        'preKeys': [],
26        'finalKey': 2014,
27        'isFinalKeyDown': true,
28        'finalKeyDownDuration': 0
29    };
30
31    //win + I
32    rightKeyOptions: any = {
33        'preKeys': [],
34        'finalKey': 2015,
35        'isFinalKeyDown': true,
36        'finalKeyDownDuration': 0
37    };
38    escKeyOptions: any = {
39        'preKeys': [],
40        'finalKey': 2070,
41        'isFinalKeyDown': true,
42        'finalKeyDownDuration': 0
43    };
44
45    async registerListener(callback) {
46        Log.debug(TAG, `registerListener start`);
47        inputConsumer.on('key', this.leftKeyOptions, (data) => {
48            Log.debug(TAG, `notificationRegister data: ${JSON.stringify(data)}`);
49            callback(0);
50        });
51        inputConsumer.on('key', this.rightKeyOptions, (data) => {
52            Log.debug(TAG, `controlRegister data: ${JSON.stringify(data)}`);
53            callback(1);
54        });
55        inputConsumer.on('key', this.escKeyOptions, (data) => {
56            Log.debug(TAG, `escRegister data: ${JSON.stringify(data)}`);
57            callback(2);
58        });
59        Log.debug(TAG, `registerListener end`);
60    }
61
62    async unregisterListener() {
63        Log.debug(TAG, `unregisterListener start`);
64        inputConsumer.off('key', this.leftKeyOptions, (data) => {
65            Log.debug(TAG, `notificationUnregister data: ${JSON.stringify(data)}`);
66        });
67        inputConsumer.off('key', this.rightKeyOptions, (data) => {
68            Log.debug(TAG, `controlUnregister data: ${JSON.stringify(data)}`);
69        });
70        inputConsumer.off('key', this.escKeyOptions, (data) => {
71            Log.debug(TAG, `escUnregister data: ${JSON.stringify(data)}`);
72        });
73        Log.debug(TAG, `unregisterListener end`);
74    }
75}
76
77let mMultimodalInputManager = new MultimodalInputManager();
78
79export default mMultimodalInputManager as MultimodalInputManager;