1 /* 2 * Copyright (c) 2020-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 /** 17 * @addtogroup UI_Events 18 * @{ 19 * 20 * @brief Defines UI events, such as press, click and drag events. 21 * 22 * @since 1.0 23 * @version 1.0 24 */ 25 26 /** 27 * @file key_event.h 28 * 29 * @brief Declares a key event, which indicates that a physical button is pressed or released. 30 * 31 * @since 1.0 32 * @version 1.0 33 */ 34 35 #ifndef GRAPHIC_LITE_KEY_EVENT_H 36 #define GRAPHIC_LITE_KEY_EVENT_H 37 38 #include "event.h" 39 40 namespace OHOS { 41 constexpr uint16_t INVALID_KEY_STATE = UINT16_MAX; 42 43 /** 44 * @brief Defines a key event, which indicates that a physical button is pressed or released. 45 * 46 * @since 1.0 47 * @version 1.0 48 */ 49 class KeyEvent : public Event { 50 public: 51 KeyEvent() = delete; 52 53 /** 54 * @brief A constructor used to create a <b>KeyEvent</b> instance. 55 * @param keyId Indicates the key ID. 56 * @param state Indicates the key state. 57 * @since 1.0 58 * @version 1.0 59 */ KeyEvent(uint16_t keyId,uint16_t state)60 KeyEvent(uint16_t keyId, uint16_t state) : keyId_(keyId), state_(state) {} 61 62 /** 63 * @brief A destructor used to delete the <b>KeyEvent</b> instance. 64 * @since 1.0 65 * @version 1.0 66 */ ~KeyEvent()67 ~KeyEvent() {} 68 69 /** 70 * @brief Obtains the key ID. 71 * @since 1.0 72 * @version 1.0 73 */ GetKeyId()74 uint16_t GetKeyId() const 75 { 76 return keyId_; 77 } 78 79 /** 80 * @brief Obtains the key state. 81 * @since 1.0 82 * @version 1.0 83 */ GetState()84 uint16_t GetState() const 85 { 86 return state_; 87 } 88 89 private: 90 uint16_t keyId_; 91 uint16_t state_; 92 }; 93 } // namespace OHOS 94 #endif // GRAPHIC_LITE_KEY_EVENT_H 95