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