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  */
15 
16 #ifndef IMF_KEYBOARD_EVENT_H
17 #define IMF_KEYBOARD_EVENT_H
18 
19 #include <cstdint>
20 #include <functional>
21 
22 #include "global.h"
23 #include "key_event.h"
24 #include "key_option.h"
25 
26 namespace OHOS {
27 namespace MiscServices {
28 using KeyHandle = std::function<int32_t(uint32_t)>;
29 
30 class KeyboardEvent {
31 public:
32     static KeyboardEvent &GetInstance();
33     static int32_t AddKeyEventMonitor(KeyHandle handle);
34     static constexpr uint8_t SHIFT_LEFT_MASK = 0X1;
35     static constexpr uint8_t SHIFT_RIGHT_MASK = 0X1 << 1;
36     static constexpr uint8_t CTRL_LEFT_MASK = 0X1 << 2;
37     static constexpr uint8_t CTRL_RIGHT_MASK = 0X1 << 3;
38     static constexpr uint8_t CAPS_MASK = 0X1 << 4;
39     static constexpr uint8_t META_MASK = 0X1 << 5;
40     static constexpr uint8_t SPACE_MASK = 0X1 << 6;
41     using CombinationKeyCallBack = std::function<void(std::shared_ptr<MMI::KeyEvent> keyEvent)>;
42 
43 private:
44     static constexpr int32_t PRESS_KEY_DELAY_MS = 200;
45     KeyboardEvent() = default;
46     KeyboardEvent(const KeyboardEvent &) = delete;
47     KeyboardEvent(KeyboardEvent &&) = delete;
48     KeyboardEvent &operator=(const KeyboardEvent &) = delete;
49     KeyboardEvent &operator=(KeyboardEvent &&) = delete;
50     static void SubscribeCombinationKey(int32_t preKey, int32_t finalKey, CombinationKeyCallBack callback);
51 };
52 } // namespace MiscServices
53 } // namespace OHOS
54 #endif // IMF_KEYBOARD_EVENT_H
55