1 /* 2 * Copyright (c) 2021 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 FOUNDATION_ACE_FRAMEWORKS_CORE_EVENT_KEY_EVENT_RECOGNIZER_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_EVENT_KEY_EVENT_RECOGNIZER_H 18 19 #include <unordered_map> 20 #include <vector> 21 22 #include "core/event/key_event.h" 23 24 namespace OHOS::Ace { 25 26 class KeyEventRecognizer { 27 public: 28 // This method recognizes events by recording raw key events. If the raw event can be identified as a special 29 // event, it returns the raw event and the identified special event, otherwise it returns only the raw event. 30 std::vector<KeyEvent> GetKeyEvents(int32_t keyCode, int32_t keyAction, int32_t repeatTime, int64_t timeStamp = 0, 31 int64_t timeStampStart = 0, int32_t metaKey = 0, int32_t keySource = 0, int64_t deviceId = 0, 32 std::string msg = ""); 33 private: 34 std::vector<KeyCode> getPressedKeys() const; 35 void addPressedKey(const int32_t keyCode); 36 void removeReleasedKey(const int32_t keyCode); 37 void clearPressedKey(); 38 private: 39 std::unordered_map<int32_t, bool> keyMap_; 40 std::vector<int32_t> keys_; 41 }; 42 43 } // namespace OHOS::Ace 44 45 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_EVENT_KEY_EVENT_RECOGNIZER_H 46